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,50 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["rpcserver_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/upcredit/conf:go_default_library",
"//app/service/main/upcredit/service:go_default_library",
"//library/net/rpc:go_default_library",
"//library/time:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["rpcserver.go"],
importmap = "go-common/app/service/main/upcredit/rpc/server",
importpath = "go-common/app/service/main/upcredit/rpc/server",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/upcredit/conf:go_default_library",
"//app/service/main/upcredit/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,28 @@
package server
import (
"go-common/app/service/main/upcredit/conf"
"go-common/app/service/main/upcredit/service"
"go-common/library/net/rpc"
"go-common/library/net/rpc/context"
)
//RPC rpc server
type RPC struct {
s *service.Service
}
//New create
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
}

View File

@@ -0,0 +1,41 @@
package server
import (
"flag"
"path/filepath"
"testing"
"time"
_ "time"
"go-common/app/service/main/upcredit/conf"
"go-common/app/service/main/upcredit/service"
"go-common/library/net/rpc"
xtime "go-common/library/time"
)
func init() {
dir, _ := filepath.Abs("../../cmd/upcredit-service.toml")
flag.Set("conf", dir)
}
func initSvrAndClient(t *testing.T) (client *rpc.Client, err error) {
if err = conf.Init(); err != nil {
t.Errorf("conf.Init() error(%v)", err)
t.FailNow()
}
svr := service.New(conf.Conf)
New(conf.Conf, svr)
client = rpc.Dial("127.0.0.1:6079", xtime.Duration(time.Second), nil)
return
}
func TestInfo(t *testing.T) {
client, err := initSvrAndClient(t)
defer client.Close()
if err != nil {
t.Errorf("rpc.Dial error(%v)", err)
t.FailNow()
}
//time.Sleep(1 * time.Second)
}