Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gaoqiaoCJY
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
go
gaoqiaoCJY
Commits
78fa6d17
Commit
78fa6d17
authored
Nov 17, 2022
by
孙香冬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
9a0f9fdb
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
73 additions
and
60 deletions
+73
-60
go.mod
go.mod
+1
-0
go.sum
go.sum
+2
-0
error.log
logs/error.log
+5
-0
main.go
main.go
+11
-8
serverConfig.xml
serverConfig.xml
+1
-1
db.go
src/db/db.go
+6
-6
entrepreneurship.go
src/db/entrepreneurship.go
+1
-1
initMongo.go
src/db/initMongo.go
+45
-43
logger.go
src/log/logger.go
+1
-1
No files found.
go.mod
View file @
78fa6d17
...
...
@@ -4,5 +4,6 @@ go 1.16
require (
github.com/gin-gonic/gin v1.8.1 // indirect
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 // indirect
go.mongodb.org/mongo-driver v1.11.0 // indirect
)
go.sum
View file @
78fa6d17
...
...
@@ -5,6 +5,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8=
github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 h1:DujepqpGd1hyOd7aW59XpK7Qymp8iy83xq74fLr21is=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
...
...
logs/error.log
0 → 100644
View file @
78fa6d17
[ERROR]2022/11/17 13:54:26 logger.go:54: ------ErrorLog
[ERROR]2022/11/17 15:08:01 logger.go:54: ------ErrorLog
[ERROR]2022/11/17 15:20:13 logger.go:54: ------ErrorLog
[ERROR]2022/11/17 15:20:55 logger.go:54: ------ErrorLog
[ERROR]2022/11/17 15:22:39 logger.go:54: ------ErrorLog
main.go
View file @
78fa6d17
package
main
import
(
"gaoqiaoCJY/src/config"
"gaoqiaoCJY/src/server"
"gaoqiaoCJY/src/db"
)
func
main
()
{
config
.
InitConfig
()
//xml do
server
.
CreateHttpServer
()
//http
//异常
//log
// logger.ErrorLog("------ErrorLog") //log
// config.InitConfig() //xml do
// server.CreateHttpServer() //http do
// errors.Wrap(err, "自定义文本") //异常
// errors.New("自定义文本")
db
.
Init
()
// db.GetList(bson.M{"level": 55})
//mongodb
//excel
//中间件
...
...
serverConfig.xml
View file @
78fa6d17
<config>
<port>
30088
</port>
<port>
:
30088
</port>
<dbConfig>
<mongodbConnectionStr>
http://sfsdfasdfasfasd
...
...
src/db/db.go
View file @
78fa6d17
...
...
@@ -31,11 +31,11 @@ type Objs interface {
}
var
(
url
=
"mongodb://root:root@127.0.0.1:27017"
// 带账号名的链接
DB_NAME
=
"gaoqiaoDB"
// 数据库名
maxTime
=
time
.
Duration
(
5
)
// 链接超时时间
DB_CLIENT_MAX_NUM
uint64
=
100
// 链接数
ENTREPRENEURSHIP_TBL
=
"entrepreneurship_tbl"
// 创业能力测评题库表名
url
=
"mongodb://root:root@127.0.0.1:27017
/?connect=direct;authSource=admin
"
// 带账号名的链接
DB_NAME
=
"gaoqiaoDB"
// 数据库名
maxTime
=
time
.
Duration
(
5
)
// 链接超时时间
DB_CLIENT_MAX_NUM
uint64
=
100
// 链接数
ENTREPRENEURSHIP_TBL
=
"entrepreneurship_tbl"
// 创业能力测评题库表名
db_mutex
sync
.
Mutex
db_ready
=
false
toDB
*
mongo
.
Database
// database 话柄
...
...
@@ -72,7 +72,7 @@ func ConnectToDB(uri, name string, timeout time.Duration, num uint64) (*mongo.Da
return
client
.
Database
(
name
),
nil
}
func
i
nit
()
{
func
I
nit
()
{
var
err
error
collection_map
=
make
(
map
[
string
]
*
mongo
.
Collection
)
...
...
src/db/entrepreneurship.go
View file @
78fa6d17
...
...
@@ -9,7 +9,7 @@ import (
)
type
Entrepreneurship
struct
{
id
int32
`json:"
id"`
_id
int32
`json:"_
id"`
typeName
string
`json:"typeName"`
question
string
`json:"question"`
A
string
`json:"A"`
...
...
src/db/initMongo.go
View file @
78fa6d17
package
db
import
(
"context"
"log"
"time"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var
mgoCli
*
mongo
.
Client
func
initDb
()
{
var
err
error
credential
:=
options
.
Credential
{
AuthMechanism
:
"SCRAM-SHA-1"
,
// 阿里云服务的
Username
:
"root"
,
// mongodb用户名
Password
:
"root"
,
//mongodb 密码
AuthSource
:
"admin"
,
//默认admin不需要改
PasswordSet
:
true
,
}
clientOpts
:=
options
.
Client
()
.
ApplyURI
(
"mongodb://localhost:3733"
)
.
SetAuth
(
credential
)
//连接到MongoDB
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
5
*
time
.
Second
)
// 设置5s超时
defer
cancel
()
client
,
err
:=
mongo
.
Connect
(
ctx
,
clientOpts
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
//检查连接
err
=
client
.
Ping
(
context
.
TODO
(),
nil
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
func
MgoCli
()
*
mongo
.
Client
{
if
mgoCli
==
nil
{
initDb
()
}
return
mgoCli
}
// import (
// "context"
// "fmt"
// "log"
// "go.mongodb.org/mongo-driver/bson"
// "go.mongodb.org/mongo-driver/mongo"
// "go.mongodb.org/mongo-driver/mongo/options"
// )
// var client *mongo.Client
// func InitMongoDB() {
// // Rest of the code will go here
// // Set client options 设置连接参数
// clientOptions := options.Client().ApplyURI("mongodb://root:root@127.0.0.1:27017/?connect=direct;authSource=admin")
// // Connect to MongoDB 连接数据库
// client, err := mongo.Connect(context.TODO(), clientOptions)
// if err != nil {
// log.Fatal(err)
// }
// // Check the connection 测试连接
// err = client.Ping(context.TODO(), nil)
// if err != nil {
// log.Fatal(err)
// }
// fmt.Println("Connected to MongoDB!")
// databases, err := client.ListDatabases(context.TODO(), bson.M{})
// if err != nil {
// log.Fatal(err)
// }
// fmt.Println(databases.TotalSize / 1024 / 1024 / 1024)
// err = client.Disconnect(context.TODO())
// if err != nil {
// log.Fatal(err)
// }
// fmt.Println("Connection to MongoDB closed.")
// }
src/log/logger.go
View file @
78fa6d17
...
...
@@ -20,7 +20,7 @@ var (
infoLogger
*
log
.
Logger
warningLogger
*
log
.
Logger
errorLogger
*
log
.
Logger
defaultLogFile
=
"./logs/
web
.log"
defaultLogFile
=
"./logs/
error
.log"
)
func
init
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment