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,56 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["service_test.go"],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/interface/live/live-demo/api/http/v2:go_default_library",
"//app/interface/live/live-demo/conf:go_default_library",
"//app/interface/live/live-demo/dao:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"foo.go",
"foo2.go",
],
importpath = "go-common/app/interface/live/live-demo/service/v2",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/live/live-demo/api/http/v2:go_default_library",
"//app/interface/live/live-demo/conf:go_default_library",
"//app/interface/live/live-demo/dao:go_default_library",
"//app/service/live/room/api/liverpc/v2:go_default_library",
"//library/ecode:go_default_library",
"//library/ecode/pb:go_default_library",
"//library/log:go_default_library",
"//library/net/metadata:go_default_library",
"//vendor/github.com/pkg/errors: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,103 @@
package v2
import (
"context"
v2pb "go-common/app/interface/live/live-demo/api/http/v2"
"go-common/app/interface/live/live-demo/conf"
"go-common/app/interface/live/live-demo/dao"
"go-common/app/service/live/room/api/liverpc/v2"
"go-common/library/ecode"
"go-common/library/ecode/pb"
"go-common/library/log"
"go-common/library/net/metadata"
"github.com/pkg/errors"
)
// FooService struct
type FooService struct {
conf *conf.Config
// optionally add other properties here, such as dao
// dao *dao.Dao
}
//NewFooService init
func NewFooService(c *conf.Config) (s *FooService) {
s = &FooService{
conf: c,
}
return s
}
// Foo 相关服务
// UnameByUid implementation
// 根据uid得到uname
// `method:"post" midware:"auth,verify"`
//
// 这是详细说明
func (s *FooService) UnameByUid(ctx context.Context, req *v2pb.Bar1Req) (resp *v2pb.Bar1Resp, err error) {
resp = &v2pb.Bar1Resp{}
return
}
// GetInfo implementation
// 获取房间信息
func (s *FooService) GetInfo(ctx context.Context, req *v2pb.GetInfoReq) (resp *v2pb.GetInfoResp, err error) {
//msg = "hello"
reply, err := dao.RoomAPI.V2Room.GetByIds(ctx, &v2.RoomGetByIdsReq{Ids: []int64{int64(req.RoomId)}})
if err != nil {
err = errors.Wrap(&pb.Error{ErrCode: 1, ErrMessage: "call room error"}, err.Error())
//msg = "Call Room Err"
return
}
log.Info("req is %v\n", req.RoomId)
room, ok := reply.Data[req.RoomId]
if !ok {
err = ecode.RoomNotFound
return
}
resp = &v2pb.GetInfoResp{}
resp.Roomid = room.Roomid
resp.Uname = room.Uname
resp.Amap = map[int32]string{123: "world"}
mid, _ := metadata.Value(ctx, "mid").(int64)
resp.Mid = mid
//resp.LiveTime = room.LiveTime
return
}
// UnameByUid3 implementation
// 根据uid得到uname v3
func (s *FooService) UnameByUid3(ctx context.Context, req *v2pb.Bar1Req) (resp *v2pb.Bar1Resp, err error) {
resp = &v2pb.Bar1Resp{}
return
}
// UnameByUid4 implementation
// test comment
func (s *FooService) UnameByUid4(ctx context.Context, req *v2pb.Bar1Req) (resp *v2pb.Bar1Resp, err error) {
resp = &v2pb.Bar1Resp{}
return
}
// GetDynamic implementation
// `dynamic_resp:"true"`
func (s *FooService) GetDynamic(ctx context.Context, req *v2pb.Bar1Req) (resp interface{}, err error) {
resp = &v2pb.Bar1Resp{Uname: "hehe"}
return
}
// Nointerface implementation
// `dynamic:"true"`
func (s *FooService) Nointerface(ctx context.Context, req *v2pb.Bar1Req) (resp *v2pb.Bar1Resp, err error) {
resp = &v2pb.Bar1Resp{}
return
}
// JsonReq implementation
func (s *FooService) JsonReq(ctx context.Context, req *v2pb.JsonReq) (resp *v2pb.JsonResp, err error) {
resp = &v2pb.JsonResp{P1: req.P1}
return
}

View File

@@ -0,0 +1,29 @@
package v2
import (
"context"
v2pb "go-common/app/interface/live/live-demo/api/http/v2"
"go-common/app/interface/live/live-demo/conf"
)
// Foo2Service struct
type Foo2Service struct {
conf *conf.Config
// optionally add other properties here, such as dao
// dao *dao.Dao
}
//NewFoo2Service init
func NewFoo2Service(c *conf.Config) (s *Foo2Service) {
s = &Foo2Service{
conf: c,
}
return s
}
// Hello implementation
func (s *Foo2Service) Hello(ctx context.Context, req *v2pb.Bar1Req) (resp *v2pb.Bar1Resp, err error) {
resp = &v2pb.Bar1Resp{}
return
}

View File

@@ -0,0 +1,36 @@
package v2
import (
"context"
"flag"
"testing"
foo "go-common/app/interface/live/live-demo/api/http/v2"
"go-common/app/interface/live/live-demo/conf"
"go-common/app/interface/live/live-demo/dao"
. "github.com/smartystreets/goconvey/convey"
)
var (
s *FooService
)
func init() {
flag.Set("conf", "../../cmd/test.toml")
var err error
if err = conf.Init(); err != nil {
panic(err)
}
s = NewFooService(conf.Conf)
dao.InitAPI()
}
// go test -test.v -test.run TestService_GetInfo
func TestService_GetInfo(t *testing.T) {
Convey("TestService_GetInfo", t, func() {
res, err := s.GetInfo(context.TODO(), &foo.GetInfoReq{RoomId: 10002})
t.Logf("%v msg", res)
So(err, ShouldBeNil)
})
}