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/interface/main/history/model:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = ["client.go"],
importpath = "go-common/app/interface/main/history/rpc/client",
tags = ["automanaged"],
deps = [
"//app/interface/main/history/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,82 @@
package client
import (
"context"
"go-common/app/interface/main/history/model"
"go-common/library/net/rpc"
)
const (
_progress = "RPC.Progress"
_position = "RPC.Position"
_add = "RPC.Add"
_delete = "RPC.Delete"
_history = "RPC.History"
_historyCursor = "RPC.HistoryCursor"
_clear = "RPC.Clear"
)
var (
_noRes = &struct{}{}
)
// Service struct info.
type Service struct {
client *rpc.Client2
}
const (
_appid = "community.service.history"
)
// New create instance of service and return.
func New(c *rpc.ClientConfig) (s *Service) {
s = &Service{}
s.client = rpc.NewDiscoveryCli(_appid, c)
return
}
// Progress return map[mid]*history.
func (s *Service) Progress(c context.Context, arg *model.ArgPro) (res map[int64]*model.History, err error) {
res = make(map[int64]*model.History)
err = s.client.Call(c, _progress, arg, &res)
return
}
// Position return map[mid]*history.
func (s *Service) Position(c context.Context, arg *model.ArgPos) (res *model.History, err error) {
res = &model.History{}
err = s.client.Call(c, _position, arg, res)
return
}
// Add add history .
func (s *Service) Add(c context.Context, arg *model.ArgHistory) (err error) {
err = s.client.Call(c, _add, arg, _noRes)
return
}
// Delete add history .
func (s *Service) Delete(c context.Context, arg *model.ArgDelete) (err error) {
err = s.client.Call(c, _delete, arg, _noRes)
return
}
// History return all histories .
func (s *Service) History(c context.Context, arg *model.ArgHistories) (res []*model.Resource, err error) {
err = s.client.Call(c, _history, arg, &res)
return
}
// HistoryCursor return all histories .
func (s *Service) HistoryCursor(c context.Context, arg *model.ArgCursor) (res []*model.Resource, err error) {
err = s.client.Call(c, _historyCursor, arg, &res)
return
}
// Clear clear history
func (s *Service) Clear(c context.Context, arg *model.ArgClear) (err error) {
err = s.client.Call(c, _clear, arg, _noRes)
return
}

View File

@@ -0,0 +1,33 @@
package client
import (
"context"
"testing"
"time"
"go-common/app/interface/main/history/model"
)
func TestHistory(t *testing.T) {
s := New(nil)
time.Sleep(1 * time.Second)
testProgress(t, s)
testAdd(t, s)
}
// testProgress test progress rpc.
func testProgress(t *testing.T, s *Service) {
if res, err := s.Progress(context.TODO(), &model.ArgPro{Mid: 88888966, Aids: []int64{5463286}}); err != nil {
t.Errorf("Service: Progress err: %v", err)
} else {
t.Logf("Service: zone res: %+v", res)
}
}
// testAdd test add rpc .
func testAdd(t *testing.T, s *Service) {
h := &model.History{Mid: 88888966, Aid: 5463286, TP: -1, Unix: 1494217922}
if err := s.Add(context.TODO(), &model.ArgHistory{Mid: 88888966, History: h}); err != nil {
t.Errorf("Service: Add err: %v", err)
}
}