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,52 @@
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/openplatform/ticket-item/api/grpc/v1:go_default_library",
"//app/service/openplatform/ticket-item/conf:go_default_library",
"//app/service/openplatform/ticket-item/model:go_default_library",
"//app/service/openplatform/ticket-item/service:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["server.go"],
importpath = "go-common/app/service/openplatform/ticket-item/server/grpc",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/openplatform/ticket-item/api/grpc/v1:go_default_library",
"//app/service/openplatform/ticket-item/conf:go_default_library",
"//app/service/openplatform/ticket-item/service:go_default_library",
"//library/log:go_default_library",
"//library/net/rpc/warden:go_default_library",
"@org_golang_google_grpc//: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,135 @@
package server
import (
"context"
item "go-common/app/service/openplatform/ticket-item/api/grpc/v1"
"go-common/app/service/openplatform/ticket-item/conf"
"go-common/app/service/openplatform/ticket-item/service"
"go-common/library/log"
"go-common/library/net/rpc/warden"
"google.golang.org/grpc"
)
// New 新建warden实例
func New(c *conf.Config) *warden.Server {
//server := warden.NewServer(c.RPCServer)
server := warden.NewServer(nil)
server.Use(middleware())
item.RegisterItemServer(server.Server(), service.New(c))
item.RegisterGuestServer(server.Server(), service.New(c))
item.RegisterBulletinServer(server.Server(), service.New(c))
item.RegisterVenueServer(server.Server(), service.New(c))
item.RegisterPlaceServer(server.Server(), service.New(c))
item.RegisterAreaServer(server.Server(), service.New(c))
item.RegisterSeatServer(server.Server(), service.New(c))
/**go func() {
err := server.Run(c.RPCServer.Addr)
if err != nil {
panic("run server failed!" + err.Error())
}
}()
log.Info("warden run@%s", c.RPCServer.Addr)
**/
_, err := server.Start()
if err != nil {
panic("run server failed!" + err.Error())
}
return server
}
// 拦截器作用类似于http中间件
func middleware() grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
// 记录调用方法
log.Info("method:", info.FullMethod)
// call chain
resp, err = handler(ctx, req)
return
}
}
type server struct {
is *service.ItemService
}
func (s *server) Info(ctx context.Context, in *item.InfoRequest) (*item.InfoReply, error) {
return s.is.Info(ctx, in)
}
func (s *server) Cards(ctx context.Context, in *item.CardsRequest) (*item.CardsReply, error) {
return s.is.Cards(ctx, in)
}
func (s *server) BillInfo(ctx context.Context, in *item.BillRequest) (*item.BillReply, error) {
return s.is.BillInfo(ctx, in)
}
func (s *server) GuestInfo(ctx context.Context, in *item.GuestInfoRequest) (*item.GuestInfoReply, error) {
return s.is.GuestInfo(ctx, in)
}
func (s *server) GuestStatus(ctx context.Context, in *item.GuestStatusRequest) (*item.GuestInfoReply, error) {
return s.is.GuestStatus(ctx, in)
}
func (s *server) BulletinInfo(ctx context.Context, in *item.BulletinInfoRequest) (*item.BulletinReply, error) {
return s.is.BulletinInfo(ctx, in)
}
func (s *server) BulletinCheck(ctx context.Context, in *item.BulletinCheckRequest) (*item.BulletinReply, error) {
return s.is.BulletinCheck(ctx, in)
}
func (s *server) BulletinState(ctx context.Context, in *item.BulletinStateRequest) (*item.BulletinReply, error) {
return s.is.BulletinState(ctx, in)
}
func (s *server) Wish(ctx context.Context, in *item.WishRequest) (*item.WishReply, error) {
return s.is.Wish(ctx, in)
}
func (s *server) Fav(ctx context.Context, in *item.FavRequest) (*item.FavReply, error) {
return s.is.Fav(ctx, in)
}
// VenueInfo 添加/修改场馆信息
func (s *server) VenueInfo(ctx context.Context, in *item.VenueInfoRequest) (*item.VenueInfoReply, error) {
return s.is.VenueInfo(ctx, in)
}
// PlaceInfo 添加/修改场地信息
func (s *server) PlaceInfo(ctx context.Context, in *item.PlaceInfoRequest) (*item.PlaceInfoReply, error) {
return s.is.PlaceInfo(ctx, in)
}
// AreaInfo 添加/修改区域信息
func (s *server) AreaInfo(ctx context.Context, in *item.AreaInfoRequest) (*item.AreaInfoReply, error) {
return s.is.AreaInfo(ctx, in)
}
// DeleteArea 删除区域信息
func (s *server) DeleteArea(ctx context.Context, in *item.DeleteAreaRequest) (*item.DeleteAreaReply, error) {
return s.is.DeleteArea(ctx, in)
}
// SeatInfo 添加/修改座位信息
func (s *server) SeatInfo(ctx context.Context, in *item.SeatInfoRequest) (*item.SeatInfoReply, error) {
return s.is.SeatInfo(ctx, in)
}
// SeatStock 设置座位库存
func (s *server) SeatStock(ctx context.Context, in *item.SeatStockRequest) (*item.SeatStockReply, error) {
return s.is.SeatStock(ctx, in)
}
// RemoveSeatOrders 删除坐票票价下所有座位
func (s *server) RemoveSeatOrders(ctx context.Context, in *item.RemoveSeatOrdersRequest) (*item.RemoveSeatOrdersReply, error) {
return s.is.RemoveSeatOrders(ctx, in)
}
// Version 添加/修改项目信息
func (s *server) Version(ctx context.Context, in *item.VersionRequest) (*item.VersionReply, error) {
return s.is.Version(ctx, in)
}

View File

@@ -0,0 +1,123 @@
package server
import (
"context"
"flag"
"fmt"
"path/filepath"
"testing"
item "go-common/app/service/openplatform/ticket-item/api/grpc/v1"
"go-common/app/service/openplatform/ticket-item/conf"
"go-common/app/service/openplatform/ticket-item/model"
"go-common/app/service/openplatform/ticket-item/service"
. "github.com/smartystreets/goconvey/convey"
)
var (
s *server
ctx = context.TODO()
)
func init() {
dir, _ := filepath.Abs("../../cmd/item.toml")
flag.Set("conf", dir)
if err := conf.Init(); err != nil {
panic(fmt.Sprintf("conf.Init() error(%v)", err))
}
s = &server{
is: service.New(conf.Conf),
}
}
// Test_Info
func TestInfo(t *testing.T) {
Convey("get data", t, func() {
res, err := s.Info(ctx, &item.InfoRequest{ID: model.DataID})
So(err, ShouldBeNil)
So(res, ShouldNotBeNil)
So(res, ShouldNotBeEmpty)
})
Convey("no data", t, func() {
res, err := s.Info(ctx, &item.InfoRequest{ID: model.NoDataID})
So(err, ShouldNotBeNil)
So(res, ShouldNotBeEmpty)
})
}
// Test_Cards
func TestCards(t *testing.T) {
Convey("get data", t, func() {
res, err := s.Cards(ctx, &item.CardsRequest{IDs: model.DataIDs})
So(err, ShouldBeNil)
So(res, ShouldNotBeNil)
So(res, ShouldNotBeEmpty)
})
Convey("no data", t, func() {
res, err := s.Cards(ctx, &item.CardsRequest{IDs: model.NoDataIDs})
So(err, ShouldNotBeNil)
So(res, ShouldNotBeNil)
})
}
// TestBillInfo
func TestBillInfo(t *testing.T) {
Convey("get data", t, func() {
res, err := s.BillInfo(ctx, &item.BillRequest{
IDs: model.DataIDs,
ScIDs: model.DataSIDs,
TkIDs: model.DataTIDs,
})
So(err, ShouldBeNil)
So(res, ShouldNotBeNil)
So(res, ShouldNotBeEmpty)
})
Convey("no data", t, func() {
res, err := s.BillInfo(ctx, &item.BillRequest{
IDs: model.NoDataIDs,
ScIDs: model.NoDataSIDs,
TkIDs: model.NoDataTIDs,
})
So(err, ShouldNotBeNil)
So(res, ShouldNotBeNil)
})
}
// TestWish
func TestWish(t *testing.T) {
Convey("add wish", t, func() {
res, err := s.Wish(ctx, &item.WishRequest{
ItemID: 1,
MID: 1,
Face: "",
})
So(err, ShouldBeNil)
So(res, ShouldNotBeNil)
})
}
// TestWish
func TestFav(t *testing.T) {
Convey("fav add", t, func() {
res, err := s.Fav(ctx, &item.FavRequest{
ItemID: 1,
MID: 1,
Type: 1,
Status: 1,
})
So(err, ShouldBeNil)
So(res, ShouldNotBeNil)
})
Convey("fav del", t, func() {
res, err := s.Fav(ctx, &item.FavRequest{
ItemID: 1,
MID: 1,
Type: 1,
Status: 0,
})
So(err, ShouldBeNil)
So(res, ShouldNotBeNil)
})
}