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 @@
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = ["secure.go"],
importpath = "go-common/app/service/main/secure/rpc/client",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/secure/model:go_default_library",
"//library/net/rpc:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["secure_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = ["//app/service/main/secure/model: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,58 @@
package secure
import (
"context"
model "go-common/app/service/main/secure/model"
"go-common/library/net/rpc"
)
const (
_status = "RPC.Status"
_expect = "RPC.ExpectionLoc"
_addFeedback = "RPC.AddFeedBack"
_closeNotify = "RPC.CloseNotify"
)
const (
_appid = "account.service.secure"
)
var (
_noRes = &struct{}{}
)
// Service rpc 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
}
// Status get the ip info.
func (s *Service) Status(c context.Context, arg *model.ArgSecure) (res *model.Msg, err error) {
res = new(model.Msg)
err = s.client.Call(c, _status, arg, &res)
return
}
// CloseNotify clsoe notify.
func (s *Service) CloseNotify(c context.Context, arg *model.ArgSecure) (err error) {
return s.client.Call(c, _closeNotify, arg, &_noRes)
}
// AddFeedBack add expection feedback.
func (s *Service) AddFeedBack(c context.Context, arg *model.ArgFeedBack) (err error) {
return s.client.Call(c, _addFeedback, arg, &_noRes)
}
// ExpectionLoc get expection loc.
func (s *Service) ExpectionLoc(c context.Context, arg *model.ArgSecure) (res []*model.Expection, err error) {
err = s.client.Call(c, _expect, arg, &res)
return
}

View File

@@ -0,0 +1,35 @@
package secure
import (
"context"
"testing"
"time"
model "go-common/app/service/main/secure/model"
)
var s *Service
func TestSecure(t *testing.T) {
s = New(nil)
time.Sleep(1000 * time.Second)
testStatus(t)
testExpectionLoc(t)
}
// TestStatus test status rpc.
func testStatus(t *testing.T) {
if res, err := s.Status(context.TODO(), &model.ArgSecure{Mid: 1, UUID: "2"}); err != nil {
t.Errorf("Service: Status err: %v", err)
} else {
t.Logf("Service: Status res: %+v", res)
}
}
func testExpectionLoc(t *testing.T) {
if res, err := s.ExpectionLoc(context.TODO(), &model.ArgSecure{Mid: 1, UUID: "2"}); err != nil {
t.Errorf("Service : Expection err:%v", err)
} else {
t.Logf("Service: Status res: %+v", res)
}
}

View File

@@ -0,0 +1,33 @@
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["rpc.go"],
importpath = "go-common/app/service/main/secure/rpc/server",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/secure/conf:go_default_library",
"//app/service/main/secure/model:go_default_library",
"//app/service/main/secure/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,56 @@
package rpc
import (
"go-common/app/service/main/secure/conf"
model "go-common/app/service/main/secure/model"
"go-common/app/service/main/secure/service"
"go-common/library/net/rpc"
"go-common/library/net/rpc/context"
)
// RPC rpc service.
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
}
// Status rpc status.
func (r *RPC) Status(c context.Context, a *model.ArgSecure, res *model.Msg) (err error) {
var tmp *model.Msg
if tmp, err = r.s.Status(c, a.Mid, a.UUID); err == nil && tmp != nil {
*res = *tmp
}
return
}
// CloseNotify rpc close notify.
func (r *RPC) CloseNotify(c context.Context, arg *model.ArgSecure, res *struct{}) (err error) {
err = r.s.CloseNotify(c, arg.Mid, arg.UUID)
return
}
// AddFeedBack rpc add feedback.
func (r *RPC) AddFeedBack(c context.Context, arg *model.ArgFeedBack, res *struct{}) (err error) {
err = r.s.AddFeedBack(c, arg.Mid, arg.Ts, arg.Type, arg.IP)
return
}
// ExpectionLoc rpc expection loc list.
func (r *RPC) ExpectionLoc(c context.Context, arg *model.ArgSecure, res *[]*model.Expection) (err error) {
*res, err = r.s.ExpectionLoc(c, arg.Mid)
return
}