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
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
69 additions
and
56 deletions
+69
-56
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
+2
-2
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
...
@@ -4,5 +4,6 @@ go 1.16
require (
require (
github.com/gin-gonic/gin v1.8.1 // indirect
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.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
...
@@ -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-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 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8=
github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
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/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 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
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
package
main
import
(
import
(
"gaoqiaoCJY/src/config"
"gaoqiaoCJY/src/db"
"gaoqiaoCJY/src/server"
)
)
func
main
()
{
func
main
()
{
config
.
InitConfig
()
// logger.ErrorLog("------ErrorLog") //log
//xml do
server
.
CreateHttpServer
()
// config.InitConfig() //xml do
//http
//异常
// server.CreateHttpServer() //http do
//log
// errors.Wrap(err, "自定义文本") //异常
// errors.New("自定义文本")
db
.
Init
()
// db.GetList(bson.M{"level": 55})
//mongodb
//mongodb
//excel
//excel
//中间件
//中间件
...
...
serverConfig.xml
View file @
78fa6d17
<config>
<config>
<port>
30088
</port>
<port>
:
30088
</port>
<dbConfig>
<dbConfig>
<mongodbConnectionStr>
<mongodbConnectionStr>
http://sfsdfasdfasfasd
http://sfsdfasdfasfasd
...
...
src/db/db.go
View file @
78fa6d17
...
@@ -31,7 +31,7 @@ type Objs interface {
...
@@ -31,7 +31,7 @@ type Objs interface {
}
}
var
(
var
(
url
=
"mongodb://root:root@127.0.0.1:27017"
// 带账号名的链接
url
=
"mongodb://root:root@127.0.0.1:27017
/?connect=direct;authSource=admin
"
// 带账号名的链接
DB_NAME
=
"gaoqiaoDB"
// 数据库名
DB_NAME
=
"gaoqiaoDB"
// 数据库名
maxTime
=
time
.
Duration
(
5
)
// 链接超时时间
maxTime
=
time
.
Duration
(
5
)
// 链接超时时间
DB_CLIENT_MAX_NUM
uint64
=
100
// 链接数
DB_CLIENT_MAX_NUM
uint64
=
100
// 链接数
...
@@ -72,7 +72,7 @@ func ConnectToDB(uri, name string, timeout time.Duration, num uint64) (*mongo.Da
...
@@ -72,7 +72,7 @@ func ConnectToDB(uri, name string, timeout time.Duration, num uint64) (*mongo.Da
return
client
.
Database
(
name
),
nil
return
client
.
Database
(
name
),
nil
}
}
func
i
nit
()
{
func
I
nit
()
{
var
err
error
var
err
error
collection_map
=
make
(
map
[
string
]
*
mongo
.
Collection
)
collection_map
=
make
(
map
[
string
]
*
mongo
.
Collection
)
...
...
src/db/entrepreneurship.go
View file @
78fa6d17
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
)
)
type
Entrepreneurship
struct
{
type
Entrepreneurship
struct
{
id
int32
`json:"
id"`
_id
int32
`json:"_
id"`
typeName
string
`json:"typeName"`
typeName
string
`json:"typeName"`
question
string
`json:"question"`
question
string
`json:"question"`
A
string
`json:"A"`
A
string
`json:"A"`
...
...
src/db/initMongo.go
View file @
78fa6d17
package
db
package
db
import
(
// import (
"context"
// "context"
"log"
// "fmt"
"time"
// "log"
"go.mongodb.org/mongo-driver/mongo"
// "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
// "go.mongodb.org/mongo-driver/mongo"
)
// "go.mongodb.org/mongo-driver/mongo/options"
// )
var
mgoCli
*
mongo
.
Client
// var client *mongo.Client
func
initDb
()
{
var
err
error
// func InitMongoDB() {
credential
:=
options
.
Credential
{
// // Rest of the code will go here
AuthMechanism
:
"SCRAM-SHA-1"
,
// 阿里云服务的
// // Set client options 设置连接参数
Username
:
"root"
,
// mongodb用户名
// clientOptions := options.Client().ApplyURI("mongodb://root:root@127.0.0.1:27017/?connect=direct;authSource=admin")
Password
:
"root"
,
//mongodb 密码
AuthSource
:
"admin"
,
//默认admin不需要改
// // Connect to MongoDB 连接数据库
PasswordSet
:
true
,
// client, err := mongo.Connect(context.TODO(), clientOptions)
}
// if err != nil {
clientOpts
:=
options
.
Client
()
.
ApplyURI
(
"mongodb://localhost:3733"
)
.
// log.Fatal(err)
SetAuth
(
credential
)
// }
//连接到MongoDB
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
5
*
time
.
Second
)
// 设置5s超时
// // Check the connection 测试连接
defer
cancel
()
// err = client.Ping(context.TODO(), nil)
client
,
err
:=
mongo
.
Connect
(
ctx
,
clientOpts
)
// if err != nil {
if
err
!=
nil
{
// log.Fatal(err)
log
.
Fatal
(
err
)
// }
}
//检查连接
// fmt.Println("Connected to MongoDB!")
err
=
client
.
Ping
(
context
.
TODO
(),
nil
)
if
err
!=
nil
{
// databases, err := client.ListDatabases(context.TODO(), bson.M{})
log
.
Fatal
(
err
)
// if err != nil {
}
// log.Fatal(err)
}
// }
func
MgoCli
()
*
mongo
.
Client
{
// fmt.Println(databases.TotalSize / 1024 / 1024 / 1024)
if
mgoCli
==
nil
{
// err = client.Disconnect(context.TODO())
initDb
()
}
// if err != nil {
return
mgoCli
// log.Fatal(err)
}
// }
// fmt.Println("Connection to MongoDB closed.")
// }
src/log/logger.go
View file @
78fa6d17
...
@@ -20,7 +20,7 @@ var (
...
@@ -20,7 +20,7 @@ var (
infoLogger
*
log
.
Logger
infoLogger
*
log
.
Logger
warningLogger
*
log
.
Logger
warningLogger
*
log
.
Logger
errorLogger
*
log
.
Logger
errorLogger
*
log
.
Logger
defaultLogFile
=
"./logs/
web
.log"
defaultLogFile
=
"./logs/
error
.log"
)
)
func
init
()
{
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