Create & Init Project...
This commit is contained in:
46
app/interface/main/app-intl/dao/location/BUILD
Normal file
46
app/interface/main/app-intl/dao/location/BUILD
Normal file
@ -0,0 +1,46 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_test",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["dao_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["dao.go"],
|
||||
importpath = "go-common/app/interface/main/app-intl/dao/location",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/service/main/location/model:go_default_library",
|
||||
"//app/service/main/location/rpc/client:go_default_library",
|
||||
"//library/log: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"],
|
||||
)
|
54
app/interface/main/app-intl/dao/location/dao.go
Normal file
54
app/interface/main/app-intl/dao/location/dao.go
Normal file
@ -0,0 +1,54 @@
|
||||
package location
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
locmdl "go-common/app/service/main/location/model"
|
||||
locrpc "go-common/app/service/main/location/rpc/client"
|
||||
"go-common/library/log"
|
||||
)
|
||||
|
||||
// Dao is location dao.
|
||||
type Dao struct {
|
||||
// rpc
|
||||
locRPC *locrpc.Service
|
||||
}
|
||||
|
||||
// New new a location dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
// rpc
|
||||
locRPC: locrpc.New(c.LocationRPC),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Dao) Info(c context.Context, ipaddr string) (info *locmdl.Info, err error) {
|
||||
if info, err = d.locRPC.Info(c, &locmdl.ArgIP{IP: ipaddr}); err != nil {
|
||||
log.Error("%v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Dao) AuthPIDs(c context.Context, pids, ipaddr string) (res map[string]*locmdl.Auth, err error) {
|
||||
var auths map[int64]*locmdl.Auth
|
||||
if auths, err = d.locRPC.AuthPIDs(c, &locmdl.ArgPids{Pids: pids, IP: ipaddr}); err != nil {
|
||||
log.Error("%v", err)
|
||||
return
|
||||
}
|
||||
res = make(map[string]*locmdl.Auth)
|
||||
for pid, auth := range auths {
|
||||
p := strconv.FormatInt(pid, 10)
|
||||
res[p] = auth
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Dao) Archive(c context.Context, aid, mid int64, ipaddr, cndip string) (auth *locmdl.Auth, err error) {
|
||||
if auth, err = d.locRPC.Archive2(c, &locmdl.Archive{Aid: aid, Mid: mid, IP: ipaddr, CIP: cndip}); err != nil {
|
||||
log.Error("%v", err)
|
||||
}
|
||||
return
|
||||
}
|
51
app/interface/main/app-intl/dao/location/dao_test.go
Normal file
51
app/interface/main/app-intl/dao/location/dao_test.go
Normal file
@ -0,0 +1,51 @@
|
||||
package location
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func ctx() context.Context {
|
||||
return context.Background()
|
||||
}
|
||||
|
||||
func init() {
|
||||
dir, _ := filepath.Abs("../../cmd/app-intl-test.toml")
|
||||
flag.Set("conf", dir)
|
||||
conf.Init()
|
||||
d = New(conf.Conf)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
func TestInfo(t *testing.T) {
|
||||
Convey("get Info", t, func() {
|
||||
res, err := d.Info(ctx(), "127.0.0.1")
|
||||
So(res, ShouldNotBeEmpty)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAuthPIDs(t *testing.T) {
|
||||
Convey("get AuthPIDs", t, func() {
|
||||
_, err := d.AuthPIDs(ctx(), "417,1521", "127.0.0.0")
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestArchive(t *testing.T) {
|
||||
Convey("get Archive", t, func() {
|
||||
_, err := d.Archive(ctx(), 16816128, 16816128, "127.0.0.0", "127.0.0.0")
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user