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,46 @@
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"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = [
"client.go",
"common.go",
"medal.go",
"pendant.go",
],
importpath = "go-common/app/service/main/usersuit/rpc/client",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/usersuit/model:go_default_library",
"//library/net/rpc: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,92 @@
package client
import (
"context"
"go-common/app/service/main/usersuit/model"
"go-common/library/net/rpc"
)
const (
_appid = "account.service.usersuit"
)
var (
_noRes = &struct{}{}
)
// Service2 struct
type Service2 struct {
client *rpc.Client2
}
// New Service2 init
func New(c *rpc.ClientConfig) (s *Service2) {
s = &Service2{}
s.client = rpc.NewDiscoveryCli(_appid, c)
return
}
const (
_buy = "RPC.Buy"
_apply = "RPC.Apply"
_stat = "RPC.Stat"
_generate = "RPC.Generate"
_list = "RPC.List"
_equip = "RPC.Equip"
_grantByMids = "RPC.GrantByMids"
_groupPendantMid = "RPC.GroupPendantMid"
)
// Buy buy invite
func (s *Service2) Buy(c context.Context, arg *model.ArgBuy) (res []*model.Invite, err error) {
res = make([]*model.Invite, 0)
err = s.client.Call(c, _buy, arg, &res)
return
}
// Apply apply
func (s *Service2) Apply(c context.Context, arg *model.ArgApply) (err error) {
err = s.client.Call(c, _apply, arg, _noRes)
return
}
// Stat stat
func (s *Service2) Stat(c context.Context, arg *model.ArgStat) (res *model.InviteStat, err error) {
res = new(model.InviteStat)
err = s.client.Call(c, _stat, arg, res)
return
}
// Generate generator
func (s *Service2) Generate(c context.Context, arg *model.ArgGenerate) (res []*model.Invite, err error) {
res = make([]*model.Invite, 0)
err = s.client.Call(c, _generate, arg, &res)
return
}
// List list
func (s *Service2) List(c context.Context, arg *model.ArgList) (res []*model.Invite, err error) {
res = make([]*model.Invite, 0)
err = s.client.Call(c, _list, arg, &res)
return
}
// Equip pendant equip.
func (s *Service2) Equip(c context.Context, arg *model.ArgEquip) (err error) {
err = s.client.Call(c, _equip, arg, _noRes)
return
}
// GrantByMids one pendant give to multiple users.
func (s *Service2) GrantByMids(c context.Context, arg *model.ArgGrantByMids) (err error) {
err = s.client.Call(c, _grantByMids, arg, _noRes)
return
}
// GroupPendantMid get share group pendant by mid
func (s *Service2) GroupPendantMid(c context.Context, arg *model.ArgGPMID) (res []*model.GroupPendantList, err error) {
res = make([]*model.GroupPendantList, 0)
err = s.client.Call(c, _groupPendantMid, arg, &res)
return
}

View File

@@ -0,0 +1,18 @@
package client
import (
"context"
"go-common/app/service/main/usersuit/model"
)
const (
_pointFlag = "RPC.PointFlag"
)
// PointFlag obtain new pendant noify.
func (s *Service2) PointFlag(c context.Context, arg *model.ArgMID) (res *model.PointFlag, err error) {
res = new(model.PointFlag)
err = s.client.Call(c, _pointFlag, arg, res)
return
}

View File

@@ -0,0 +1,75 @@
package client
import (
"context"
"go-common/app/service/main/usersuit/model"
)
const (
_medalHomeInfo = "RPC.MedalHomeInfo"
_medalUserInfo = "RPC.MedalUserInfo"
_medalInstall = "RPC.MedalInstall"
_medalPopup = "RPC.MedalPopup"
_medalMyInfo = "RPC.MedalMyInfo"
_medalAllInfo = "RPC.MedalAllInfo"
_medalGrant = "RPC.MedalGrant"
_medalActivated = "RPC.MedalActivated"
_medalActivatedMulti = "RPC.MedalActivatedMulti"
)
// MedalHomeInfo return user mdeal home info.
func (s *Service2) MedalHomeInfo(c context.Context, arg *model.ArgMid) (res []*model.MedalHomeInfo, err error) {
err = s.client.Call(c, _medalHomeInfo, arg, &res)
return
}
// MedalUserInfo return medal user info.
func (s *Service2) MedalUserInfo(c context.Context, arg *model.ArgMedalUserInfo) (res *model.MedalUserInfo, err error) {
res = new(model.MedalUserInfo)
err = s.client.Call(c, _medalUserInfo, arg, res)
return
}
// MedalInstall install or uninstall medal.
func (s *Service2) MedalInstall(c context.Context, arg *model.ArgMedalInstall) (err error) {
err = s.client.Call(c, _medalInstall, arg, _noRes)
return
}
// MedalPopup return medal popup.
func (s *Service2) MedalPopup(c context.Context, arg *model.ArgMid) (res *model.MedalPopup, err error) {
res = new(model.MedalPopup)
err = s.client.Call(c, _medalPopup, arg, res)
return
}
// MedalMyInfo return medal my info.
func (s *Service2) MedalMyInfo(c context.Context, arg *model.ArgMid) (res []*model.MedalMyInfos, err error) {
err = s.client.Call(c, _medalMyInfo, arg, &res)
return
}
// MedalAllInfo return medal all info.
func (s *Service2) MedalAllInfo(c context.Context, arg *model.ArgMid) (res *model.MedalAllInfos, err error) {
err = s.client.Call(c, _medalAllInfo, arg, &res)
return
}
// MedalGrant send a medal to user.
func (s *Service2) MedalGrant(c context.Context, arg *model.ArgMIDNID) (err error) {
err = s.client.Call(c, _medalGrant, arg, _noRes)
return
}
// MedalActivated get the user activated medal info.
func (s *Service2) MedalActivated(c context.Context, arg *model.ArgMid) (res *model.MedalInfo, err error) {
err = s.client.Call(c, _medalActivated, arg, &res)
return
}
// MedalActivatedMulti Multi get the user activated medal info(at most 50).
func (s *Service2) MedalActivatedMulti(c context.Context, arg *model.ArgMids) (res map[int64]*model.MedalInfo, err error) {
err = s.client.Call(c, _medalActivatedMulti, arg, &res)
return
}

View File

@@ -0,0 +1,24 @@
package client
import (
"context"
"go-common/app/service/main/usersuit/model"
)
const (
_pendantEquip = "RPC.Equipment"
_pendantEquips = "RPC.Equipments"
)
// Equipment obtian equipment by mid
func (s *Service2) Equipment(c context.Context, arg *model.ArgEquipment) (res *model.PendantEquip, err error) {
res = new(model.PendantEquip)
err = s.client.Call(c, _pendantEquip, arg.Mid, res)
return
}
// Equipments obtian equipment by mids
func (s *Service2) Equipments(c context.Context, arg *model.ArgEquipments) (res map[int64]*model.PendantEquip, err error) {
err = s.client.Call(c, _pendantEquips, arg.Mids, &res)
return
}

View File

@@ -0,0 +1,10 @@
package client
import (
"testing"
)
// TestRPC_Equipment test
func TestRPC_Equipment(t *testing.T) {
}

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()
}
}