Create & Init Project...
This commit is contained in:
39
app/service/main/passport-auth/rpc/client/BUILD
Normal file
39
app/service/main/passport-auth/rpc/client/BUILD
Normal file
@ -0,0 +1,39 @@
|
||||
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 = ["//vendor/github.com/smartystreets/goconvey/convey:go_default_library"],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["client.go"],
|
||||
importpath = "go-common/app/service/main/passport-auth/rpc/client",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//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"],
|
||||
)
|
44
app/service/main/passport-auth/rpc/client/client.go
Normal file
44
app/service/main/passport-auth/rpc/client/client.go
Normal file
@ -0,0 +1,44 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/library/net/rpc"
|
||||
)
|
||||
|
||||
var (
|
||||
_noRes = &struct{}{}
|
||||
)
|
||||
|
||||
const (
|
||||
// token
|
||||
_delTokenCache = "RPC.DelTokenCache"
|
||||
|
||||
// cookie
|
||||
_delCookieCache = "RPC.DelCookieCache"
|
||||
)
|
||||
|
||||
// Service is a question service.
|
||||
type Service struct {
|
||||
client *rpc.Client2
|
||||
}
|
||||
|
||||
// New new a question service.
|
||||
func New(c *rpc.ClientConfig) (s *Service) {
|
||||
s = &Service{
|
||||
client: rpc.NewDiscoveryCli("passport.service.auth", c),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DelTokenCache query token.
|
||||
func (s *Service) DelTokenCache(c context.Context, token string) (err error) {
|
||||
err = s.client.Call(c, _delTokenCache, token, &_noRes)
|
||||
return
|
||||
}
|
||||
|
||||
// DelCookieCookie del cookie.
|
||||
func (s *Service) DelCookieCookie(c context.Context, session string) (err error) {
|
||||
err = s.client.Call(c, _delCookieCache, session, &_noRes)
|
||||
return
|
||||
}
|
40
app/service/main/passport-auth/rpc/client/client_test.go
Normal file
40
app/service/main/passport-auth/rpc/client/client_test.go
Normal file
@ -0,0 +1,40 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
s *Service
|
||||
)
|
||||
|
||||
func startRPCServer() {
|
||||
s = New(nil)
|
||||
}
|
||||
|
||||
func TestClient_DelTokenCache(t *testing.T) {
|
||||
startRPCServer()
|
||||
time.Sleep(3 * time.Second)
|
||||
Convey("Test RPC client del token by token", t, func() {
|
||||
var (
|
||||
c = context.TODO()
|
||||
ak = "64294c76972aee8cf4af51566c76ed0d"
|
||||
)
|
||||
err := s.DelTokenCache(c, ak)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestClient_DelCookieCookie(t *testing.T) {
|
||||
startRPCServer()
|
||||
time.Sleep(3 * time.Second)
|
||||
Convey("Test RPC Client del cookie by cookie", t, func() {
|
||||
sd := "1d0fb9cf,1,7f9745b6"
|
||||
err := s.DelCookieCookie(context.TODO(), sd)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user