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,58 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"pendant_test.go",
"rpc_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/usersuit/conf:go_default_library",
"//app/service/main/usersuit/model:go_default_library",
"//app/service/main/usersuit/service:go_default_library",
"//library/log:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"common.go",
"medal.go",
"pendant.go",
"rpc.go",
],
importpath = "go-common/app/service/main/usersuit/rpc/server",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/usersuit/conf:go_default_library",
"//app/service/main/usersuit/model:go_default_library",
"//app/service/main/usersuit/service:go_default_library",
"//library/net/rpc:go_default_library",
"//library/net/rpc/context: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,15 @@
package server
import (
"go-common/app/service/main/usersuit/model"
"go-common/library/net/rpc/context"
)
// PointFlag obtain new pendant noify.
func (r *RPC) PointFlag(c context.Context, arg *model.ArgMID, res *model.PointFlag) (err error) {
var pf *model.PointFlag
if pf, err = r.s.PointFlag(c, arg); err == nil && pf != nil {
*res = *pf
}
return
}

View File

@@ -0,0 +1,72 @@
package server
import (
"go-common/app/service/main/usersuit/model"
"go-common/library/net/rpc/context"
)
// MedalHomeInfo return user mdeal home info.
func (r *RPC) MedalHomeInfo(c context.Context, arg *model.ArgMid, res *[]*model.MedalHomeInfo) (err error) {
*res, err = r.s.MedalHomeInfo(c, arg.Mid)
return
}
// MedalUserInfo return medal user info.
func (r *RPC) MedalUserInfo(c context.Context, arg *model.ArgMedalUserInfo, res *model.MedalUserInfo) (err error) {
var mui *model.MedalUserInfo
if mui, err = r.s.MedalUserInfo(c, arg.Mid, arg.IP); err == nil && mui != nil {
*res = *mui
}
return
}
// MedalInstall install or uninstall medal.
func (r *RPC) MedalInstall(c context.Context, arg *model.ArgMedalInstall, res *struct{}) (err error) {
err = r.s.MedalInstall(c, arg.Mid, arg.Nid, arg.IsActivated)
return
}
// MedalPopup return medal popup.
func (r *RPC) MedalPopup(c context.Context, arg *model.ArgMid, res *model.MedalPopup) (err error) {
var mp *model.MedalPopup
if mp, err = r.s.MedalPopup(c, arg.Mid); err == nil && mp != nil {
*res = *mp
}
return
}
// MedalMyInfo return medal my info.
func (r *RPC) MedalMyInfo(c context.Context, arg *model.ArgMid, res *[]*model.MedalMyInfos) (err error) {
*res, err = r.s.MedalMyInfo(c, arg.Mid)
return
}
// MedalAllInfo return medal all info.
func (r *RPC) MedalAllInfo(c context.Context, arg *model.ArgMid, res *model.MedalAllInfos) (err error) {
var mai *model.MedalAllInfos
if mai, err = r.s.MedalAllInfo(c, arg.Mid); err == nil && mai != nil {
*res = *mai
}
return
}
// MedalGrant send a medal to user.
func (r *RPC) MedalGrant(c context.Context, arg *model.ArgMIDNID, res *struct{}) (err error) {
err = r.s.MedalGet(c, arg.MID, arg.NID)
return
}
// MedalActivated get the user activated medal info.
func (r *RPC) MedalActivated(c context.Context, arg *model.ArgMid, res *model.MedalInfo) (err error) {
var ma *model.MedalInfo
if ma, err = r.s.MedalActivated(c, arg.Mid); err == nil && ma != nil {
*res = *ma
}
return
}
// MedalActivatedMulti Multi get get the user activated medal info(at most 50).
func (r *RPC) MedalActivatedMulti(c context.Context, arg *model.ArgMids, res *map[int64]*model.MedalInfo) (err error) {
*res, err = r.s.MedalActivatedMulti(c, arg.Mids)
return
}

View File

@@ -0,0 +1,21 @@
package server
import (
"go-common/app/service/main/usersuit/model"
"go-common/library/net/rpc/context"
)
// Equipment obtain Equipment by mid .
func (r *RPC) Equipment(c context.Context, mid int64, res *model.PendantEquip) (err error) {
var pe *model.PendantEquip
if pe, err = r.s.Equipment(c, mid); err == nil && pe != nil {
*res = *pe
}
return
}
// Equipments obtain equipments by mids .
func (r *RPC) Equipments(c context.Context, mids []int64, res *map[int64]*model.PendantEquip) (err error) {
*res, err = r.s.Equipments(c, mids)
return
}

View File

@@ -0,0 +1,45 @@
package server
import (
"go-common/app/service/main/usersuit/model"
"testing"
)
const (
_pendantEquip = "RPC.Equipment"
_pendantEquips = "RPC.Equipments"
)
// TestRPC_Equipment test
func TestRPC_Equipment(t *testing.T) {
var (
res = new(model.PendantEquip)
err error
)
once.Do(startServer)
arg := &model.ArgEquipment{
Mid: 27515240,
}
if err = client.Call(_pendantEquip, arg.Mid, &res); err != nil {
t.Errorf("client.Call(%s) error(%v)", _pendantEquip, err)
t.FailNow()
}
t.Logf("res (%v)", res)
}
// TestRPC_Equipment test
func TestRPC_Equipments(t *testing.T) {
var (
res = make(map[int64]*model.PendantEquip)
err error
)
once.Do(startServer)
arg := &model.ArgEquipments{
Mids: []int64{27515240, 100},
}
if err = client.Call(_pendantEquips, arg.Mids, &res); err != nil {
t.Errorf("client.Call(%s) error(%v)", _pendantEquips, err)
t.FailNow()
}
t.Logf("res (%v)", res)
}

View File

@@ -0,0 +1,68 @@
package server
import (
"go-common/app/service/main/usersuit/conf"
"go-common/app/service/main/usersuit/model"
"go-common/app/service/main/usersuit/service"
"go-common/library/net/rpc"
"go-common/library/net/rpc/context"
)
// RPC server struct
type RPC struct {
s *service.Service
}
// New new rpc server.
func New(c *conf.Config, s *service.Service) (svr *rpc.Server) {
r := &RPC{s: s}
svr = rpc.NewServer(c.RPCServer)
if err := svr.Register(r); err != nil {
panic(err)
}
return
}
// Ping check connection success.
func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
return
}
// Buy buy invite code
func (r *RPC) Buy(c context.Context, arg *model.ArgBuy, res *[]*model.Invite) (err error) {
*res, err = r.s.BuyInvite(c, arg.Mid, arg.Num, arg.IP)
return
}
// Apply apply invite code
func (r *RPC) Apply(c context.Context, arg *model.ArgApply, res *struct{}) (err error) {
err = r.s.ApplyInvite(c, arg.Mid, arg.Code, arg.Cookie, arg.IP)
return
}
// Stat stat code
func (r *RPC) Stat(c context.Context, arg *model.ArgStat, res *model.InviteStat) (err error) {
var stat *model.InviteStat
if stat, err = r.s.Stat(c, arg.Mid, arg.IP); err == nil && stat != nil {
*res = *stat
}
return
}
// Equip pendant equip.
func (r *RPC) Equip(c context.Context, arg *model.ArgEquip, res *struct{}) (err error) {
err = r.s.EquipPendant(c, arg.Mid, arg.Pid, arg.Status, arg.Source)
return
}
// GrantByMids one pendant give to multiple users.
func (r *RPC) GrantByMids(c context.Context, arg *model.ArgGrantByMids, res *struct{}) (err error) {
err = r.s.BatchGrantPendantByMid(c, arg.Pid, arg.Expire, arg.Mids)
return
}
// GroupPendantMid get group pendant by mid and gid
func (r *RPC) GroupPendantMid(c context.Context, arg *model.ArgGPMID, res *[]*model.GroupPendantList) (err error) {
*res, err = r.s.GroupPendantMid(c, arg)
return
}

View File

@@ -0,0 +1,47 @@
package server
import (
"net/rpc"
"sync"
"testing"
"time"
"go-common/app/service/main/usersuit/conf"
"go-common/app/service/main/usersuit/service"
"go-common/library/log"
)
const (
addr = "127.0.0.1:7269"
_testPing = "RPC.Ping"
)
var (
_noArg = &struct{}{}
client *rpc.Client
once sync.Once
)
func startServer() {
if err := conf.Init(); err != nil {
panic(err)
}
log.Init(conf.Conf.Xlog)
defer log.Close()
svr := service.New(conf.Conf)
New(conf.Conf, svr)
time.Sleep(time.Second * 3)
var err error
client, err = rpc.Dial("tcp", addr)
if err != nil {
panic(err)
}
}
func TestRPC_Ping(t *testing.T) {
once.Do(startServer)
if err := client.Call(_testPing, &_noArg, &_noArg); err != nil {
t.Errorf("client.Call(%s) error(%v)", _testPing, err)
t.FailNow()
}
}