增加gin组件
This commit is contained in:
parent
5903333242
commit
054cbb910e
|
|
@ -0,0 +1,8 @@
|
|||
package gin
|
||||
|
||||
//GIN 配置
|
||||
type Config struct {
|
||||
RootPath string
|
||||
Addr string
|
||||
Port int
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package gin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Service(conf *Config) {
|
||||
go func() {
|
||||
router := gin.New()
|
||||
routerSetup(router)
|
||||
s := &http.Server{
|
||||
Addr: fmt.Sprintf("%s:%d", conf.Addr, conf.Port),
|
||||
Handler: router,
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
MaxHeaderBytes: 1 << 20,
|
||||
}
|
||||
log.Printf("start service on %s", fmt.Sprintf("%s:%d", conf.Addr, conf.Port))
|
||||
log.Fatal(s.ListenAndServe())
|
||||
}()
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package gin
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
//路由配置
|
||||
func routerSetup(router *gin.Engine) {
|
||||
router.Use(gin.Recovery())
|
||||
router.GET(`/health/check`)
|
||||
|
||||
r := router.Group(`/user`)
|
||||
{
|
||||
r.POST(`/register`)
|
||||
r.GET(`/accountcheck/:accname`)
|
||||
r.POST(`/login`)
|
||||
r.POST(`/forgot`)
|
||||
}
|
||||
|
||||
ug := router.Group(`/user`)
|
||||
{
|
||||
ug.GET(`/choose/:orgid`)
|
||||
ug.GET(`/detail`)
|
||||
ug.POST(`/update`)
|
||||
}
|
||||
}
|
||||
2
go.mod
2
go.mod
|
|
@ -6,6 +6,7 @@ require (
|
|||
github.com/gin-gonic/gin v1.7.4
|
||||
github.com/gomodule/redigo v1.8.5
|
||||
github.com/hashicorp/consul/api v1.10.1
|
||||
go.mongodb.org/mongo-driver v1.7.4
|
||||
google.golang.org/grpc v1.40.0
|
||||
gorm.io/driver/mysql v1.1.2
|
||||
gorm.io/driver/sqlite v1.1.4
|
||||
|
|
@ -53,7 +54,6 @@ require (
|
|||
github.com/xdg-go/scram v1.0.2 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||
go.mongodb.org/mongo-driver v1.7.4 // indirect
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
|
||||
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||
|
|
|
|||
Loading…
Reference in New Issue