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,46 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = ["card.go"],
importpath = "go-common/app/interface/main/account/service/card",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/account/conf:go_default_library",
"//app/service/main/card/api/grpc/v1: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"],
)
go_test(
name = "go_default_test",
srcs = ["card_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/account/conf:go_default_library",
"//app/service/main/card/api/grpc/v1:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,91 @@
package card
import (
"context"
"go-common/app/interface/main/account/conf"
v1 "go-common/app/service/main/card/api/grpc/v1"
)
// Service .
type Service struct {
// conf
c *conf.Config
// card service
cardRPC v1.CardClient
}
// New create service instance and return.
func New(c *conf.Config) (s *Service) {
s = &Service{
c: c,
}
cardRPC, err := v1.NewClient(c.CardClient)
if err != nil {
panic(err)
}
s.cardRPC = cardRPC
return
}
// UserCard user card info.
func (s *Service) UserCard(c context.Context, mid int64) (res *v1.ModelUserCard, err error) {
var reply *v1.UserCardReply
if reply, err = s.cardRPC.UserCard(c, &v1.UserCardReq{Mid: mid}); err != nil {
return
}
res = reply.Res
return
}
// Card get card info by id.
func (s *Service) Card(c context.Context, id int64) (res *v1.ModelCard, err error) {
var reply *v1.CardReply
if reply, err = s.cardRPC.Card(c, &v1.CardReq{Id: id}); err != nil {
return
}
res = reply.Data_0
return
}
// CardHots get all hots cards.
func (s *Service) CardHots(c context.Context) (res []*v1.ModelCard, err error) {
var reply *v1.CardHotsReply
if reply, err = s.cardRPC.CardHots(c, &v1.CardHotsReq{}); err != nil {
return
}
res = reply.Data_0
return
}
// AllGroup all group.
func (s *Service) AllGroup(c context.Context, mid int64) (res *v1.ModelAllGroupResp, err error) {
var reply *v1.AllGroupReply
if reply, err = s.cardRPC.AllGroup(c, &v1.AllGroupReq{Mid: mid}); err != nil {
return
}
res = reply.Res
return
}
// CardsByGid get cards by gid.
func (s *Service) CardsByGid(c context.Context, id int64) (res []*v1.ModelCard, err error) {
var reply *v1.CardsByGidReply
if reply, err = s.cardRPC.CardsByGid(c, &v1.CardsByGidReq{Gid: id}); err != nil {
return
}
res = reply.Data_0
return
}
// Equip card equip.
func (s *Service) Equip(c context.Context, arg *v1.ModelArgEquip) (err error) {
_, err = s.cardRPC.Equip(c, &v1.EquipReq{Arg: arg})
return
}
// Demount card demount.
func (s *Service) Demount(c context.Context, mid int64) (err error) {
_, err = s.cardRPC.DemountEquip(c, &v1.DemountEquipReq{Mid: mid})
return
}

View File

@@ -0,0 +1,90 @@
package card
import (
"context"
"flag"
"testing"
"go-common/app/interface/main/account/conf"
v1 "go-common/app/service/main/card/api/grpc/v1"
. "github.com/smartystreets/goconvey/convey"
)
var (
s *Service
c = context.Background()
)
func init() {
flag.Set("conf", "../../cmd/account-interface-example.toml")
var err error
if err = conf.Init(); err != nil {
panic(err)
}
s = New(conf.Conf)
}
// go test -test.v -test.run TestServiceUserCard
func TestServiceUserCard(t *testing.T) {
Convey("TestServiceUserCard", t, func() {
res, err := s.UserCard(c, 1)
t.Logf("%v", res)
So(err, ShouldBeNil)
})
}
// go test -test.v -test.run TestServiceCard
func TestServiceCard(t *testing.T) {
Convey("TestServiceCard", t, func() {
res, err := s.Card(c, 1)
t.Logf("%v", res)
So(err, ShouldBeNil)
})
}
// go test -test.v -test.run TestCardHots
func TestCardHots(t *testing.T) {
Convey("TestCardHots", t, func() {
res, err := s.CardHots(c)
t.Logf("%v", res)
So(err, ShouldBeNil)
})
}
// go test -test.v -test.run TestAllGroup
func TestAllGroup(t *testing.T) {
Convey("TestAllGroup", t, func() {
res, err := s.AllGroup(c, 1)
t.Logf("%v", res)
So(err, ShouldBeNil)
})
}
// go test -test.v -test.run TestCardsByGid
func TestCardsByGid(t *testing.T) {
Convey("TestCardsByGid", t, func() {
res, err := s.CardsByGid(c, 1)
t.Logf("%v", res)
So(err, ShouldBeNil)
})
}
// go test -test.v -test.run TestEquip
func TestEquip(t *testing.T) {
Convey("TestEquip", t, func() {
err := s.Equip(c, &v1.ModelArgEquip{
Mid: 2,
CardId: 1,
})
So(err, ShouldBeNil)
})
}
// go test -test.v -test.run TestDemount
func TestDemount(t *testing.T) {
Convey("TestDemount", t, func() {
err := s.Demount(c, 2)
So(err, ShouldBeNil)
})
}