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 = ["server_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/location/api:go_default_library",
"//app/service/main/location/conf:go_default_library",
"//app/service/main/location/service:go_default_library",
"//library/net/rpc/warden:go_default_library",
"//library/time:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["server.go"],
importpath = "go-common/app/service/main/location/server/grpc",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/location/api:go_default_library",
"//app/service/main/location/model:go_default_library",
"//app/service/main/location/service:go_default_library",
"//library/net/rpc/warden: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,47 @@
// Package server generate by warden_gen
package grpc
import (
"context"
"fmt"
pb "go-common/app/service/main/location/api"
"go-common/app/service/main/location/model"
"go-common/app/service/main/location/service"
"go-common/library/net/rpc/warden"
)
// New Location warden rpc server
func New(c *warden.ServerConfig, svr *service.Service) *warden.Server {
ws := warden.NewServer(c)
pb.RegisterLocationServer(ws.Server(), &server{svr})
ws, err := ws.Start()
if err != nil {
panic(fmt.Sprintf("start warden server fail! %s", err))
}
return ws
}
type server struct {
svr *service.Service
}
var _ pb.LocationServer = &server{}
// Info get ip info.
func (s *server) Info(c context.Context, arg *pb.InfoReq) (res *pb.InfoReply, err error) {
var ipinfo *model.Info
if ipinfo, err = s.svr.Info(c, arg.Addr); err != nil {
return
}
res = &pb.InfoReply{
Addr: ipinfo.Addr,
Country: ipinfo.Country,
Province: ipinfo.Province,
City: ipinfo.City,
Isp: ipinfo.ISP,
Latitude: ipinfo.Latitude,
Longitude: ipinfo.Longitude,
ZoneId: ipinfo.ZoneID}
return
}

View File

@@ -0,0 +1,60 @@
package grpc
import (
"context"
"fmt"
"testing"
"time"
pb "go-common/app/service/main/location/api"
"go-common/app/service/main/location/conf"
"go-common/app/service/main/location/service"
"go-common/library/net/rpc/warden"
xtime "go-common/library/time"
)
// rpc server const
const (
addr = "127.0.0.1:9000"
)
// TestLocation test rpc server
func TestLocation(t *testing.T) {
if err := conf.Init(); err != nil {
t.Errorf("conf.Init() error(%v)", err)
t.FailNow()
}
svr := service.New(conf.Conf)
New(conf.Conf.WardenServer, svr)
time.Sleep(time.Second * 3)
cfg := &warden.ClientConfig{
Dial: xtime.Duration(time.Second * 3),
Timeout: xtime.Duration(time.Second * 3),
}
cc, err := warden.NewClient(cfg).Dial(context.Background(), addr)
if err != nil {
t.Errorf("rpc.Dial(tcp, \"%s\") error(%v)", addr, err)
t.FailNow()
}
client := pb.NewLocationClient(cc)
infoGRPC(client, t)
}
func infoGRPC(client pb.LocationClient, t *testing.T) {
arg := &pb.InfoReq{
Addr: "211.139.80.6",
}
res, err := client.Info(context.TODO(), arg)
if err != nil {
t.Error(err)
} else {
result("info", t, res)
}
}
func result(name string, t *testing.T, res interface{}) {
fmt.Printf("res : %+v \n", res)
t.Log("[==========" + name + "单元测试结果==========]")
t.Log(res)
t.Log("[↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑]\r\n")
}