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,41 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["rpc_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = ["rpc.go"],
importpath = "go-common/app/service/main/point/rpc/client",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/point/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,70 @@
package client
import (
"context"
"go-common/app/service/main/point/model"
"go-common/library/net/rpc"
)
const (
_pointInfo = "RPC.PointInfo"
_pointConsume = "RPC.ConsumePoint"
_pointAdd = "RPC.PointAdd"
_pointHistory = "RPC.PointHistory"
_pointAddByBp = "RPC.PointAddByBp"
)
const (
_appid = "account.service.point"
)
// Service is a question service.
type Service struct {
client *rpc.Client2
}
// New new rpc service.
func New(c *rpc.ClientConfig) (s *Service) {
s = &Service{}
s.client = rpc.NewDiscoveryCli(_appid, c)
return
}
// Ping rpc ping.
func (s *Service) Ping(c context.Context, arg *struct{}) (res *int, err error) {
err = s.client.Call(c, "RPC.Ping", arg, res)
return
}
//PointInfo point info.
func (s *Service) PointInfo(c context.Context, arg *model.ArgRPCMid) (res *model.PointInfo, err error) {
res = new(model.PointInfo)
err = s.client.Call(c, _pointInfo, arg, res)
return
}
//ConsumePoint consume point.
func (s *Service) ConsumePoint(c context.Context, arg *model.ArgPointConsume) (status int8, err error) {
err = s.client.Call(c, _pointConsume, arg, &status)
return
}
//AddPoint add point.
func (s *Service) AddPoint(c context.Context, arg *model.ArgPoint) (status int8, err error) {
err = s.client.Call(c, _pointAdd, arg, &status)
return
}
// PointHistory point history.
func (s *Service) PointHistory(c context.Context, arg *model.ArgRPCPointHistory) (res *model.PointHistoryResp, err error) {
res = new(model.PointHistoryResp)
err = s.client.Call(c, _pointHistory, arg, res)
return
}
// PointAddByBp point add by bp.
func (s *Service) PointAddByBp(c context.Context, arg *model.ArgPointAdd) (res *int64, err error) {
err = s.client.Call(c, _pointAddByBp, arg, &res)
return
}

View File

@@ -0,0 +1 @@
package client

View File

@@ -0,0 +1,44 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["rpc_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = ["rpc.go"],
importpath = "go-common/app/service/main/point/rpc/server",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/point/conf:go_default_library",
"//app/service/main/point/model:go_default_library",
"//app/service/main/point/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,77 @@
package server
import (
"go-common/app/service/main/point/conf"
"go-common/app/service/main/point/model"
"go-common/app/service/main/point/service"
"go-common/library/net/rpc"
"go-common/library/net/rpc/context"
)
// RPC represent rpc server
type RPC struct {
s *service.Service
}
// New init rpc.
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
}
// Auth check connection success.
func (r *RPC) Auth(c context.Context, arg *rpc.Auth, res *struct{}) (err error) {
return
}
// PointInfo point info.
func (r *RPC) PointInfo(c context.Context, a *model.ArgRPCMid, res *model.PointInfo) (err error) {
var p *model.PointInfo
if p, err = r.s.PointInfo(c, a.Mid); err == nil && p != nil {
*res = *p
}
return
}
// ConsumePoint point consume.
func (r *RPC) ConsumePoint(c context.Context, a *model.ArgPointConsume, status *int8) (err error) {
*status, err = r.s.ConsumePoint(c, a)
return
}
// PointAddByBp point add by bp.
func (r *RPC) PointAddByBp(c context.Context, arg *model.ArgPointAdd, res *int64) (err error) {
*res, err = r.s.PointAddByBp(c, arg)
return
}
// PointAdd point add.
func (r *RPC) PointAdd(c context.Context, a *model.ArgPoint, status *int8) (err error) {
*status, err = r.s.AddPoint(c, a)
return
}
// PointHistory point history.
func (r *RPC) PointHistory(c context.Context, arg *model.ArgRPCPointHistory, res *model.PointHistoryResp) (err error) {
var (
phs []*model.OldPointHistory
total int
)
if phs, total, err = r.s.OldPointHistory(c, arg.Mid, arg.PN, arg.PS); err == nil && len(phs) > 0 {
p := &model.PointHistoryResp{
Phs: phs,
Total: total,
}
*res = *p
}
return
}

View File

@@ -0,0 +1 @@
package server