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,43 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"acc.go",
"http.go",
"v1.go",
"v2.go",
],
importpath = "go-common/app/service/main/account/server/http",
tags = ["automanaged"],
deps = [
"//app/service/main/account/api:go_default_library",
"//app/service/main/account/conf:go_default_library",
"//app/service/main/account/model:go_default_library",
"//app/service/main/account/service:go_default_library",
"//app/service/main/member/model: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,135 @@
package http
import (
"go-common/app/service/main/account/model"
bm "go-common/library/net/http/blademaster"
)
// info
func info(c *bm.Context) {
p := new(model.ParamMid)
if err := c.Bind(p); err != nil {
return
}
info, err := accSvc.Info(c, p.Mid)
if err != nil {
c.JSON(nil, err)
return
}
c.JSON(info, nil)
}
// infoByName
func infoByName(c *bm.Context) {
p := new(model.ParamNames)
if err := c.Bind(p); err != nil {
return
}
infos, err := accSvc.InfosByName(c, p.Names)
if err != nil {
c.JSON(nil, err)
return
}
c.JSON(infos, nil)
}
// infos
func infos(c *bm.Context) {
p := new(model.ParamMids)
if err := c.Bind(p); err != nil {
return
}
infos, err := accSvc.Infos(c, p.Mids)
if err != nil {
c.JSON(nil, err)
return
}
c.JSON(infos, nil)
}
// card
func card(c *bm.Context) {
p := new(model.ParamMid)
if err := c.Bind(p); err != nil {
return
}
card, err := accSvc.Card(c, p.Mid)
if err != nil {
c.JSON(nil, err)
return
}
c.JSON(card, nil)
}
// cards
func cards(c *bm.Context) {
p := new(model.ParamMids)
if err := c.Bind(p); err != nil {
return
}
cards, err := accSvc.Cards(c, p.Mids)
if err != nil {
c.JSON(nil, err)
return
}
c.JSON(cards, nil)
}
// vip
func vip(c *bm.Context) {
p := new(model.ParamMid)
if err := c.Bind(p); err != nil {
return
}
v, err := accSvc.Vip(c, p.Mid)
if err != nil {
c.JSON(nil, err)
return
}
c.JSON(v, nil)
}
func vips(c *bm.Context) {
p := new(model.ParamMids)
if err := c.Bind(p); err != nil {
return
}
c.JSON(accSvc.Vips(c, p.Mids))
}
// profile
func profile(c *bm.Context) {
p := new(model.ParamMid)
if err := c.Bind(p); err != nil {
return
}
pfl, err := accSvc.Profile(c, p.Mid)
if err != nil {
c.JSON(nil, err)
return
}
c.JSON(pfl, nil)
}
// profileWithStat
func profileWithStat(c *bm.Context) {
p := new(model.ParamMid)
if err := c.Bind(p); err != nil {
return
}
pfl, err := accSvc.ProfileWithStat(c, p.Mid)
if err != nil {
c.JSON(nil, err)
return
}
c.JSON(pfl, nil)
}
// privacy
func privacy(c *bm.Context) {
p := new(model.ParamMid)
if err := c.Bind(p); err != nil {
return
}
c.JSON(accSvc.Privacy(c, p.Mid))
}

View File

@@ -0,0 +1,135 @@
package http
import (
"encoding/json"
"net/http"
"go-common/app/service/main/account/conf"
"go-common/app/service/main/account/model"
"go-common/app/service/main/account/service"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
v "go-common/library/net/http/blademaster/middleware/verify"
)
var (
accSvc *service.Service
verify *v.Verify
)
// Init init account service.
func Init(c *conf.Config, s *service.Service) {
accSvc = s
verify = v.New(c.Verify)
// engine
engine := bm.DefaultServer(c.BM)
innerRouter(engine)
// init inner server
if err := engine.Start(); err != nil {
log.Error("engine.Start() error(%v)", err)
panic(err)
}
}
func filterByAppkey(keys []string) func(*bm.Context) {
allowed := make(map[string]struct{}, len(keys))
for _, k := range keys {
allowed[k] = struct{}{}
}
return func(ctx *bm.Context) {
req := ctx.Request
params := req.Form
appkey := params.Get("appkey")
if _, ok := allowed[appkey]; !ok {
log.Error("appkey: %s try to access %s failed", appkey, req.URL)
ctx.JSON(nil, ecode.AccessDenied)
ctx.Abort()
return
}
}
}
// innerRouter init inner router.
func innerRouter(e *bm.Engine) {
e.Ping(ping)
e.Register(register)
group := e.Group("/x/internal/v3/account", verify.Verify)
{
group.GET("/info", info)
group.GET("/info/by/name", infoByName)
group.GET("/infos", infos)
group.GET("/card", card)
group.GET("/cards", cards)
group.GET("/vip", vip)
group.GET("/vips", vips)
group.GET("/profile", profile)
group.GET("/profile/stat", profileWithStat)
group.GET("/privacy", filterByAppkey(conf.Conf.AppkeyFilter.Privacy), privacy)
group.GET("/cache/del", cacheDel)
group.POST("/cache/clear", cacheClear)
}
v2Group := e.Group("/x/internal/account/v2", verify.Verify)
{
v2Group.GET("/myinfo", v2MyInfo)
v2Group.GET("/userinfo", v2MyInfo)
}
v1Group := e.Group("/x/internal/account", verify.Verify)
{
v1Group.GET("/info", v1Info)
v1Group.GET("/infos", v1Infos)
v1Group.GET("/card", v1Card)
v1Group.GET("/vip", v1Vip)
}
}
// ping check server ok.
func ping(c *bm.Context) {
if err := accSvc.Ping(c); err != nil {
log.Error("ping error(%v)", err)
c.AbortWithStatus(http.StatusServiceUnavailable)
}
}
// register support discovery.
func register(c *bm.Context) {
c.JSON(map[string]struct{}{}, nil)
}
// cache del
func cacheDel(c *bm.Context) {
p := new(model.ParamModify)
if err := c.Bind(p); err != nil {
return
}
c.JSON(nil, accSvc.DelCache(c, p.Mid, p.ModifiedAttr))
}
// cache clear
func cacheClear(c *bm.Context) {
p := new(model.ParamMsg)
if err := c.Bind(p); err != nil {
return
}
var m struct {
New struct {
Mid int64 `json:"mid"`
} `json:"new,omitempty"`
Mid int64 `json:"mid"`
Action string `json:"action"`
}
if err := json.Unmarshal([]byte(p.Msg), &m); err != nil {
c.JSON(nil, err)
return
}
mid := m.Mid
if mid == 0 {
mid = m.New.Mid
}
if mid == 0 {
log.Warn("cache clear no mid msg(%s)", p.Msg)
return
}
log.Info("Try to delete cache with mid: %d and param: %+v", mid, p)
c.JSON(nil, accSvc.DelCache(c, mid, m.Action))
}

View File

@@ -0,0 +1,213 @@
package http
import (
"strconv"
v1 "go-common/app/service/main/account/api"
"go-common/app/service/main/account/model"
bm "go-common/library/net/http/blademaster"
)
// v1Info
func v1Info(c *bm.Context) {
p := new(model.ParamMid)
if err := c.Bind(p); err != nil {
return
}
card, err := accSvc.Card(c, p.Mid)
if err != nil {
c.JSON(nil, err)
return
}
i := &V1Info{}
i.FromCard(card)
c.JSON(i, nil)
}
// v1Infos
func v1Infos(c *bm.Context) {
p := new(model.ParamMids)
if err := c.Bind(p); err != nil {
return
}
cards, err := accSvc.Cards(c, p.Mids)
if err != nil {
c.JSON(nil, err)
return
}
im := make(map[int64]*V1Info, len(cards))
for _, card := range cards {
i := &V1Info{}
i.FromCard(card)
im[card.Mid] = i
}
c.JSON(im, nil)
}
// card
func v1Card(c *bm.Context) {
p := new(model.ParamMid)
if err := c.Bind(p); err != nil {
return
}
ps, err := accSvc.ProfileWithStat(c, p.Mid)
if err != nil {
c.JSON(nil, err)
return
}
card := &V1Card{}
card.FromProfile(ps)
c.JSON(card, nil)
}
// vip
func v1Vip(c *bm.Context) {
p := new(model.ParamMid)
if err := c.Bind(p); err != nil {
return
}
vi, err := accSvc.Vip(c, p.Mid)
if err != nil {
c.JSON(nil, err)
return
}
v := &V1Vip{}
v.FromVip(vi)
c.JSON(v, nil)
}
// V1Info info.
type V1Info struct {
Mid string `json:"mid"`
Name string `json:"uname"`
Sex string `json:"sex"`
Sign string `json:"sign"`
Avatar string `json:"avatar"`
Rank string `json:"rank"`
DisplayRank string `json:"DisplayRank"`
LevelInfo struct {
Cur int `json:"current_level"`
Min int `json:"current_min"`
NowExp int `json:"current_exp"`
NextExp interface{} `json:"next_exp"`
} `json:"level_info"`
Pendant v1.PendantInfo `json:"pendant"`
Nameplate v1.NameplateInfo `json:"nameplate"`
OfficialVerify model.OldOfficial `json:"official_verify"`
Vip struct {
Type int `json:"vipType"`
DueDate int64 `json:"vipDueDate"`
DueRemark string `json:"dueRemark"`
AccessStatus int `json:"accessStatus"`
VipStatus int `json:"vipStatus"`
VipStatusWarn string `json:"vipStatusWarn"`
} `json:"vip"`
}
// FromCard from card.
func (i *V1Info) FromCard(c *v1.Card) {
i.Mid = strconv.FormatInt(c.Mid, 10)
i.Name = c.Name
i.Sex = c.Sex
i.Sign = c.Sign
i.Avatar = c.Face
i.Rank = strconv.FormatInt(int64(c.Rank), 10)
i.DisplayRank = "0"
i.LevelInfo.Cur = int(c.Level)
i.LevelInfo.Min = 0
i.LevelInfo.NowExp = 0
i.LevelInfo.NextExp = 0
i.Pendant = c.Pendant
i.Nameplate = c.Nameplate
i.OfficialVerify = model.CvtOfficial(c.Official)
i.Vip.Type = int(c.Vip.Type)
i.Vip.VipStatus = int(c.Vip.Status)
i.Vip.DueDate = c.Vip.DueDate
}
// V1Card card
type V1Card struct {
Mid string `json:"mid"`
Name string `json:"name"`
Approve bool `json:"approve"`
Sex string `json:"sex"`
Rank string `json:"rank"`
Face string `json:"face"`
DisplayRank string `json:"DisplayRank"`
Regtime int64 `json:"regtime"`
Spacesta int `json:"spacesta"`
Birthday string `json:"birthday"`
Place string `json:"place"`
Description string `json:"description"`
Article int `json:"article"`
Attentions []int64 `json:"attentions"`
Fans int `json:"fans"`
Friend int `json:"friend"`
Attention int `json:"attention"`
Sign string `json:"sign"`
LevelInfo struct {
Cur int `json:"current_level"`
Min int `json:"current_min"`
NowExp int `json:"current_exp"`
NextExp interface{} `json:"next_exp"`
} `json:"level_info"`
Pendant v1.PendantInfo `json:"pendant"`
Nameplate v1.NameplateInfo `json:"nameplate"`
OfficialVerify model.OldOfficial `json:"official_verify"`
Vip struct {
Type int `json:"vipType"`
DueDate int64 `json:"vipDueDate"`
DueRemark string `json:"dueRemark"`
AccessStatus int `json:"accessStatus"`
VipStatus int `json:"vipStatus"`
VipStatusWarn string `json:"vipStatusWarn"`
} `json:"vip"`
}
// FromProfile from profile.
func (i *V1Card) FromProfile(c *model.ProfileStat) {
i.Mid = strconv.FormatInt(c.Mid, 10)
i.Name = c.Name
i.Sex = c.Sex
i.Sign = c.Sign
i.Face = c.Face
i.Rank = strconv.FormatInt(int64(c.Rank), 10)
i.DisplayRank = "0"
i.Regtime = int64(c.JoinTime)
if c.Silence == 1 {
i.Spacesta = -2
}
i.Attentions = []int64{}
i.Fans = int(c.Follower)
i.Attention = int(c.Following)
i.LevelInfo.Cur = int(c.Level)
i.LevelInfo.Min = int(c.LevelExp.Min)
i.LevelInfo.NowExp = int(c.LevelExp.NowExp)
i.LevelInfo.NextExp = c.LevelExp.NextExp
if c.LevelExp.NowExp == -1 {
i.LevelInfo.NextExp = "--"
}
i.Pendant = c.Pendant
i.Nameplate = c.Nameplate
i.OfficialVerify = model.CvtOfficial(c.Official)
i.Vip.Type = int(c.Vip.Type)
i.Vip.VipStatus = int(c.Vip.Status)
i.Vip.DueDate = c.Vip.DueDate
}
// V1Vip vip
type V1Vip struct {
Type int `json:"vipType"`
DueDate int64 `json:"vipDueDate"`
DueRemark string `json:"dueRemark"`
AccessStatus int `json:"accessStatus"`
VipStatus int `json:"vipStatus"`
VipStatusWarn string `json:"vipStatusWarn"`
}
// FromVip from vip.
func (v *V1Vip) FromVip(vi *v1.VipInfo) {
v.Type = int(vi.Type)
v.VipStatus = int(vi.Status)
v.DueDate = vi.DueDate
}

View File

@@ -0,0 +1,98 @@
package http
import (
v1 "go-common/app/service/main/account/api"
"go-common/app/service/main/account/model"
member "go-common/app/service/main/member/model"
bm "go-common/library/net/http/blademaster"
)
// v2MyInfo
func v2MyInfo(c *bm.Context) {
p := new(model.ParamMid)
if err := c.Bind(p); err != nil {
return
}
ps, err := accSvc.ProfileWithStat(c, p.Mid)
if err != nil {
c.JSON(nil, err)
return
}
info := &V2MyInfo{}
info.FromProfile(ps)
c.JSON(info, nil)
}
// V2MyInfo myinfo.
type V2MyInfo struct {
Mid int64 `json:"mid"`
Name string `json:"uname"`
Face string `json:"face"`
Rank int32 `json:"rank"`
Scores int32 `json:"scores"`
Coins float64 `json:"coins"`
Sex int32 `json:"sex"`
Sign string `json:"sign"`
JoinTime int32 `json:"jointime"`
Spacesta int32 `json:"spacesta"`
Active int32 `json:"active"`
Silence int32 `protobuf:"varint,12,opt,name=Silence,proto3" json:"silence"`
EmailStatus int32 `protobuf:"varint,13,opt,name=EmailStatus,proto3" json:"email_status"`
TelStatus int32 `protobuf:"varint,14,opt,name=TelStatus,proto3" json:"tel_status"`
Identification int32 `protobuf:"varint,15,opt,name=Identification,proto3" json:"identification"`
Moral int32 `protobuf:"varint,16,opt,name=Moral,proto3" json:"moral"`
Birthday string `protobuf:"bytes,17,opt,name=Birthday,proto3" json:"birthday"`
Telephone string `protobuf:"bytes,18,opt,name=Telephone,proto3" json:"telephone"`
Level member.LevelInfo `protobuf:"bytes,19,opt,name=Level" json:"level_info"`
Pendant v1.PendantInfo `protobuf:"bytes,20,opt,name=Pendant" json:"pendant"`
Nameplate v1.NameplateInfo `protobuf:"bytes,21,opt,name=Nameplate" json:"nameplate"`
Official model.OldOfficial `json:"official_verify"`
Vip struct {
Type int32 `protobuf:"varint,1,opt,name=Type,proto3" json:"vipType"`
DueDate int64 `protobuf:"varint,2,opt,name=DueDate,proto3" json:"vipDueDate"`
DueRemark string `protobuf:"bytes,3,opt,name=DueRemark,proto3" json:"dueRemark"`
AccessStatus int32 `protobuf:"varint,4,opt,name=AccessStatus,proto3" json:"accessStatus"`
VipStatus int32 `protobuf:"varint,5,opt,name=VipStatus,proto3" json:"vipStatus"`
VipStatusWarn string `protobuf:"bytes,6,opt,name=VipStatusWarn,proto3" json:"vipStatusWarn"`
} `json:"vip"`
}
// FromProfile from profile.
func (i *V2MyInfo) FromProfile(c *model.ProfileStat) {
i.Mid = c.Mid
i.Name = c.Name
switch c.Sex {
case "男":
i.Sex = 1
case "女":
i.Sex = 2
default:
i.Sex = 0
}
i.Sign = c.Sign
i.Face = c.Face
i.Rank = c.Rank
i.JoinTime = c.JoinTime
i.Silence = c.Silence
if c.Silence == 1 {
i.Spacesta = -2
}
i.EmailStatus = c.EmailStatus
i.TelStatus = c.TelStatus
if c.EmailStatus == 1 || c.TelStatus == 1 {
i.Active = 1
}
i.Identification = c.Identification
i.Coins = c.Coins
i.Moral = c.Moral
i.Level.Cur = c.Level
i.Level.Min = c.LevelExp.Min
i.Level.NowExp = c.LevelExp.NowExp
i.Level.NextExp = c.LevelExp.NextExp
i.Pendant = c.Pendant
i.Nameplate = c.Nameplate
i.Official = model.CvtOfficial(c.Official)
i.Vip.Type = c.Vip.Type
i.Vip.VipStatus = c.Vip.Status
i.Vip.DueDate = c.Vip.DueDate
}