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 = ["client_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = ["//app/service/main/location/model:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = ["client.go"],
importpath = "go-common/app/service/main/location/rpc/client",
tags = ["automanaged"],
deps = [
"//app/service/main/location/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,87 @@
package client
import (
"context"
"go-common/app/service/main/location/model"
"go-common/library/net/rpc"
)
const (
_archive = "RPC.Archive"
_archive2 = "RPC.Archive2"
_group = "RPC.Group"
_authPIDs = "RPC.AuthPIDs"
// new
_info = "RPC.Info"
_infos = "RPC.Infos"
_infoComplete = "RPC.InfoComplete"
_infosComplete = "RPC.InfosComplete"
// app id
_appid = "location.service"
)
// Service is resource rpc client.
type Service struct {
client *rpc.Client2
}
// New new a resource rpc client.
func New(c *rpc.ClientConfig) (s *Service) {
s = &Service{}
s.client = rpc.NewDiscoveryCli(_appid, c)
return
}
// Archive get the aid auth.
func (s *Service) Archive(c context.Context, arg *model.Archive) (res *int64, err error) {
res = new(int64)
err = s.client.Call(c, _archive, arg, res)
return
}
// Archive2 get the aid auth.
func (s *Service) Archive2(c context.Context, arg *model.Archive) (res *model.Auth, err error) {
res = new(model.Auth)
err = s.client.Call(c, _archive2, arg, res)
return
}
// Group get the gip auth.
func (s *Service) Group(c context.Context, arg *model.Group) (res *model.Auth, err error) {
res = new(model.Auth)
err = s.client.Call(c, _group, arg, res)
return
}
// AuthPIDs check if ip in pids.
func (s *Service) AuthPIDs(c context.Context, arg *model.ArgPids) (res map[int64]*model.Auth, err error) {
err = s.client.Call(c, _authPIDs, arg, &res)
return
}
// Info get the ip info.
func (s *Service) Info(c context.Context, arg *model.ArgIP) (res *model.Info, err error) {
res = new(model.Info)
err = s.client.Call(c, _info, arg, res)
return
}
// Infos get the ips info.
func (s *Service) Infos(c context.Context, arg []string) (res map[string]*model.Info, err error) {
err = s.client.Call(c, _infos, arg, &res)
return
}
// InfoComplete get the whold ip info.
func (s *Service) InfoComplete(c context.Context, arg *model.ArgIP) (res *model.InfoComplete, err error) {
res = new(model.InfoComplete)
err = s.client.Call(c, _infoComplete, arg, res)
return
}
// InfosComplete get the whold ips infos.
func (s *Service) InfosComplete(c context.Context, arg []string) (res map[string]*model.InfoComplete, err error) {
err = s.client.Call(c, _infosComplete, arg, &res)
return
}

View File

@@ -0,0 +1,94 @@
package client
import (
"context"
"testing"
"time"
"go-common/app/service/main/location/model"
)
const (
_aid = 16428
_gid = 317
_mid = 0
_ip = "139.214.144.59"
_cip = "127.0.0.1"
)
func TestLocation(t *testing.T) {
s := New(nil)
time.Sleep(1 * time.Second)
testArchive(t, s)
testArchive2(t, s)
testGroup(t, s)
testAuthPIDs(t, s)
testInfo(t, s)
testInfos(t, s)
testInfoComplete(t, s)
testInfosComplete(t, s)
}
func testArchive(t *testing.T, s *Service) {
if res, err := s.Archive(context.TODO(), &model.Archive{Aid: _aid, Mid: _mid, IP: _ip, CIP: _cip}); err != nil {
t.Errorf("Service: archive err: %v", err)
} else {
t.Logf("Service: archive res: %v", res)
}
}
func testArchive2(t *testing.T, s *Service) {
if res, err := s.Archive2(context.TODO(), &model.Archive{Aid: _aid, Mid: _mid, IP: _ip, CIP: _cip}); err != nil {
t.Errorf("Service: archive2 err: %v", err)
} else {
t.Logf("Service: archive2 res: %v", res)
}
}
func testGroup(t *testing.T, s *Service) {
if res, err := s.Group(context.TODO(), &model.Group{Gid: _gid, Mid: _mid, IP: _ip, CIP: _cip}); err != nil {
t.Errorf("Service: group err: %v", err)
} else {
t.Logf("Service: group res: %v", res)
}
}
func testAuthPIDs(t *testing.T, s *Service) {
if res, err := s.AuthPIDs(context.TODO(), &model.ArgPids{IP: _ip, Pids: "2,1163,86,87", CIP: _cip}); err != nil {
t.Errorf("Service: AuthPIDs err: %v", err)
} else {
t.Logf("Service: AuthPIDs res: %v", res)
}
}
func testInfo(t *testing.T, s *Service) {
if res, err := s.Info(context.TODO(), &model.ArgIP{IP: _ip}); err != nil {
t.Errorf("Service: info err: %v", err)
} else {
t.Logf("Service: info res: %v", res)
}
}
func testInfos(t *testing.T, s *Service) {
if res, err := s.Infos(context.TODO(), []string{"61.216.166.156", "211.139.80.6"}); err != nil {
t.Errorf("Service: infos err: %v", err)
} else {
t.Logf("Service: infos res: %v", res)
}
}
func testInfoComplete(t *testing.T, s *Service) {
if res, err := s.InfoComplete(context.TODO(), &model.ArgIP{IP: _ip}); err != nil {
t.Errorf("Service: infoComplete err: %v", err)
} else {
t.Logf("Service: infoComplete res: %v", res)
}
}
func testInfosComplete(t *testing.T, s *Service) {
if res, err := s.InfosComplete(context.TODO(), []string{"61.216.166.156", "211.139.80.6"}); err != nil {
t.Errorf("Service: infosComplete err: %v", err)
} else {
t.Logf("Service: infosComplete res: %v", res)
}
}