Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"cookie.go",
"http.go",
"token.go",
],
importpath = "go-common/app/service/main/passport-auth/http",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/passport-auth/conf:go_default_library",
"//app/service/main/passport-auth/service:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/middleware/verify:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,19 @@
package http
import (
"go-common/library/ecode"
bm "go-common/library/net/http/blademaster"
)
func cookieInfo(c *bm.Context) {
session := c.Request.Form.Get("session")
if session == "" {
c.JSON(nil, ecode.RequestErr)
return
}
res, err := svr.CookieInfo(c, session)
if err == nil {
c.Set("mid", res.Mid)
}
c.JSON(res, err)
}

View File

@@ -0,0 +1,45 @@
package http
import (
"go-common/app/service/main/passport-auth/conf"
"go-common/app/service/main/passport-auth/service"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/middleware/verify"
)
var (
svr *service.Service
vfy *verify.Verify
)
// Init init config
func Init(c *conf.Config, srv *service.Service) {
initService(c, srv)
engineOut := bm.DefaultServer(c.BM)
outerRouter(engineOut)
if err := engineOut.Start(); err != nil {
log.Error("bm.DefaultServer error(%v)", err)
}
}
func initService(c *conf.Config, srv *service.Service) {
svr = srv
vfy = verify.New(c.VerifyConfig)
}
// outerRouter init outer router
func outerRouter(e *bm.Engine) {
e.GET("/monitor/ping", ping)
group := e.Group("/x/internal/passport-auth", vfy.Verify)
{
group.GET("/cookie_info", cookieInfo)
group.GET("/token_info", tokenInfo)
group.GET("/refresh_info", refreshInfo)
group.GET("/old_token_info", oldTokenInfo)
}
}
func ping(c *bm.Context) {
}

View File

@@ -0,0 +1,45 @@
package http
import (
"go-common/library/ecode"
bm "go-common/library/net/http/blademaster"
)
func tokenInfo(c *bm.Context) {
ak := c.Request.Form.Get("access_token")
if len(ak) != 32 {
c.JSON(nil, ecode.RequestErr)
return
}
res, err := svr.TokenInfo(c, ak)
if err == nil {
c.Set("mid", res.Mid)
}
c.JSON(res, err)
}
func refreshInfo(c *bm.Context) {
rk := c.Request.Form.Get("refresh_token")
if len(rk) != 32 {
c.JSON(nil, ecode.RequestErr)
return
}
res, err := svr.RefreshInfo(c, rk)
if res != nil {
c.Set("mid", res.Mid)
}
c.JSON(res, err)
}
func oldTokenInfo(c *bm.Context) {
ak := c.Request.Form.Get("access_token")
if len(ak) != 32 {
c.JSON(nil, ecode.RequestErr)
return
}
res, err := svr.OldTokenInfo(c, ak)
if res != nil {
c.Set("mid", res.Mid)
}
c.JSON(res, err)
}