Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
douyincloud-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
何进财
douyincloud-service
Commits
6a6542cb
Commit
6a6542cb
authored
Feb 02, 2026
by
hejincai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init commit
parent
9c9a2276
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
3 additions
and
327 deletions
+3
-327
mongo.go
component/mongo.go
+0
-119
redis.go
component/redis.go
+0
-70
types.go
component/types.go
+0
-60
go.mod
go.mod
+1
-16
go.sum
go.sum
+1
-37
main.go
main.go
+0
-2
service.go
service/service.go
+1
-23
No files found.
component/mongo.go
deleted
100644 → 0
View file @
9c9a2276
/*
Copyright (year) Bytedance Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
component
import
(
"context"
"fmt"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"net/url"
"os"
"time"
)
var
(
// mongo地址
mongoAddr
=
""
// mongo用户名
mongoUserName
=
""
// mongo密码
mongoPassWord
=
""
)
const
collectionName
=
"demo"
type
mongoComponent
struct
{
client
*
mongo
.
Client
dataBase
string
}
type
model
struct
{
Key
string
`bson:"key"`
//类型
Value
string
`bson:"value"`
//值
}
func
(
m
*
mongoComponent
)
GetName
(
ctx
context
.
Context
,
key
string
)
(
name
string
,
err
error
)
{
coll
:=
m
.
client
.
Database
(
m
.
dataBase
)
.
Collection
(
collectionName
)
doc
:=
&
model
{}
filter
:=
bson
.
M
{
"key"
:
key
}
result
:=
coll
.
FindOne
(
ctx
,
filter
)
if
err
:=
result
.
Decode
(
doc
);
err
!=
nil
{
return
""
,
err
}
return
doc
.
Value
,
err
}
func
(
m
*
mongoComponent
)
SetName
(
ctx
context
.
Context
,
key
string
,
name
string
)
error
{
coll
:=
m
.
client
.
Database
(
m
.
dataBase
)
.
Collection
(
collectionName
)
filter
:=
bson
.
M
{
"key"
:
key
}
update
:=
bson
.
M
{
"$set"
:
model
{
Key
:
key
,
Value
:
name
}}
_
,
err
:=
coll
.
UpdateMany
(
ctx
,
filter
,
update
)
if
err
!=
nil
{
return
err
}
return
nil
}
//NewMongoComponent 新建一个mongodbComponent,其实现了HelloWorldComponent接口
func
NewMongoComponent
()
*
mongoComponent
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
tmp
,
err
:=
url
.
Parse
(
mongoAddr
)
if
err
!=
nil
{
panic
(
"mongo addr parse error"
)
}
authSource
:=
tmp
.
Query
()
.
Get
(
"authSource"
)
credential
:=
options
.
Credential
{
AuthSource
:
authSource
,
Username
:
mongoUserName
,
Password
:
mongoPassWord
,
}
mongoUrl
:=
fmt
.
Sprintf
(
"mongodb://%s"
,
mongoAddr
)
client
,
err
:=
mongo
.
Connect
(
ctx
,
options
.
Client
()
.
ApplyURI
(
mongoUrl
)
.
SetAuth
(
credential
))
if
err
!=
nil
{
fmt
.
Printf
(
"mongoClient init error. err %s
\n
"
,
err
)
panic
(
"mongo connect error"
)
}
dataBase
:=
"demo"
doc
:=
&
model
{
Key
:
"name"
,
Value
:
Mongo
,
}
_
,
err
=
client
.
Database
(
dataBase
)
.
Collection
(
collectionName
)
.
InsertOne
(
context
.
TODO
(),
doc
)
if
err
!=
nil
{
fmt
.
Printf
(
"mongoClient init error. err %s
\n
"
,
err
)
panic
(
"mongo init error"
)
}
return
&
mongoComponent
{
client
,
dataBase
}
}
//init 项目启动时,会从环境变量中获取mongodb的地址,用户名和密码
func
init
()
{
mongoAddr
=
os
.
Getenv
(
"MONGO_ADDRESS"
)
mongoUserName
=
os
.
Getenv
(
"MONGO_USERNAME"
)
mongoPassWord
=
os
.
Getenv
(
"MONGO_PASSWORD"
)
}
component/redis.go
deleted
100644 → 0
View file @
9c9a2276
/*
Copyright (year) Bytedance Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
component
import
(
"context"
"fmt"
"github.com/go-redis/redis/v8"
"os"
)
var
(
//Redis地址
redisAddr
=
""
//Redis用户名
redisUserName
=
""
//Redis密码
redisPassword
=
""
)
type
redisComponent
struct
{
client
*
redis
.
Client
}
func
(
r
*
redisComponent
)
GetName
(
ctx
context
.
Context
,
key
string
)
(
name
string
,
err
error
)
{
return
r
.
client
.
Get
(
ctx
,
key
)
.
Result
()
}
func
(
r
*
redisComponent
)
SetName
(
ctx
context
.
Context
,
key
string
,
name
string
)
error
{
_
,
err
:=
r
.
client
.
Set
(
ctx
,
key
,
name
,
0
)
.
Result
()
return
err
}
//NewRedisComponent 初始化一个实现了HelloWorldComponent接口的RedisComponent
func
NewRedisComponent
()
*
redisComponent
{
rdb
:=
redis
.
NewClient
(
&
redis
.
Options
{
Addr
:
redisAddr
,
Username
:
redisUserName
,
Password
:
redisPassword
,
DB
:
0
,
// use default DB
})
_
,
err
:=
rdb
.
Ping
(
context
.
TODO
())
.
Result
()
if
err
!=
nil
{
fmt
.
Printf
(
"redisClient init error. err %s"
,
err
)
panic
(
fmt
.
Sprintf
(
"redis init failed. err %s
\n
"
,
err
))
}
return
&
redisComponent
{
client
:
rdb
,
}
}
//init 项目启动时会从环境变量中获取
func
init
()
{
redisAddr
=
os
.
Getenv
(
"REDIS_ADDRESS"
)
redisUserName
=
os
.
Getenv
(
"REDIS_USERNAME"
)
redisPassword
=
os
.
Getenv
(
"REDIS_PASSWORD"
)
}
component/types.go
deleted
100644 → 0
View file @
9c9a2276
/*
Copyright (year) Bytedance Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
component
import
(
"context"
"fmt"
)
type
HelloWorldComponent
interface
{
GetName
(
ctx
context
.
Context
,
key
string
)
(
name
string
,
err
error
)
SetName
(
ctx
context
.
Context
,
key
string
,
name
string
)
error
}
const
Mongo
=
"mongodb"
const
Redis
=
"redis"
var
(
mongoHelloWorld
*
mongoComponent
redisHelloWorld
*
redisComponent
)
//GetComponent 通过传入的component的名称返回实现了HelloWorldComponent接口的component
func
GetComponent
(
component
string
)
(
HelloWorldComponent
,
error
)
{
switch
component
{
case
Mongo
:
return
mongoHelloWorld
,
nil
case
Redis
:
return
redisHelloWorld
,
nil
default
:
return
nil
,
fmt
.
Errorf
(
"invalid component"
)
}
}
func
InitComponents
()
{
mongoHelloWorld
=
NewMongoComponent
()
redisHelloWorld
=
NewRedisComponent
()
ctx
:=
context
.
TODO
()
err
:=
mongoHelloWorld
.
SetName
(
ctx
,
"name"
,
"mongodb"
)
if
err
!=
nil
{
panic
(
err
)
}
err
=
redisHelloWorld
.
SetName
(
ctx
,
"name"
,
"redis"
)
if
err
!=
nil
{
panic
(
err
)
}
}
go.mod
View file @
6a6542cb
...
...
@@ -2,38 +2,23 @@ module douyincloud-gin-demo
go 1.18
require (
github.com/gin-gonic/gin v1.8.1
github.com/go-redis/redis/v8 v8.11.5
go.mongodb.org/mongo-driver v1.10.0
)
require github.com/gin-gonic/gin v1.8.1
require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
...
...
go.sum
View file @
6a6542cb
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
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=
...
...
@@ -19,21 +14,14 @@ github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/j
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
github.com/go-playground/validator/v10 v10.10.0 h1:I7mrTYv78z8k8VXa/qJlOlEXn/nBh+BF8dHX5nt/dr0=
github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM=
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
...
...
@@ -50,16 +38,9 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/pelletier/go-toml/v2 v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV0GUKU=
github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
...
...
@@ -71,31 +52,16 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E=
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs=
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
go.mongodb.org/mongo-driver v1.10.0 h1:UtV6N5k14upNp4LTduX0QCufG124fSu25Wz9tu94GLg=
go.mongodb.org/mongo-driver v1.10.0/go.mod h1:wsihk0Kdgv8Kqu1Anit4sfK+22vSFbUrAVEYRhCXrA8=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
...
...
@@ -117,10 +83,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
main.go
View file @
6a6542cb
...
...
@@ -16,13 +16,11 @@ limitations under the License.
package
main
import
(
"douyincloud-gin-demo/component"
"douyincloud-gin-demo/service"
"github.com/gin-gonic/gin"
)
func
main
()
{
component
.
InitComponents
()
r
:=
gin
.
Default
()
r
.
GET
(
"/api/hello"
,
service
.
Hello
)
...
...
service/service.go
View file @
6a6542cb
...
...
@@ -16,7 +16,6 @@ limitations under the License.
package
service
import
(
"douyincloud-gin-demo/component"
"fmt"
"github.com/gin-gonic/gin"
)
...
...
@@ -28,18 +27,7 @@ func Hello(ctx *gin.Context) {
return
}
fmt
.
Printf
(
"target= %s
\n
"
,
target
)
hello
,
err
:=
component
.
GetComponent
(
target
)
if
err
!=
nil
{
Failure
(
ctx
,
fmt
.
Errorf
(
"param invalid"
))
return
}
name
,
err
:=
hello
.
GetName
(
ctx
,
"name"
)
if
err
!=
nil
{
Failure
(
ctx
,
err
)
return
}
Success
(
ctx
,
name
)
Success
(
ctx
,
target
)
}
func
SetName
(
ctx
*
gin
.
Context
)
{
...
...
@@ -49,16 +37,6 @@ func SetName(ctx *gin.Context) {
Failure
(
ctx
,
err
)
return
}
hello
,
err
:=
component
.
GetComponent
(
req
.
Target
)
if
err
!=
nil
{
Failure
(
ctx
,
fmt
.
Errorf
(
"param invalid"
))
return
}
err
=
hello
.
SetName
(
ctx
,
"name"
,
req
.
Name
)
if
err
!=
nil
{
Failure
(
ctx
,
err
)
return
}
Success
(
ctx
,
""
)
}
...
...
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