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,49 @@
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"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/app-view/conf:go_default_library",
"//app/interface/main/app-view/model/game: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-view/dao/game",
tags = ["automanaged"],
deps = [
"//app/interface/main/app-view/conf:go_default_library",
"//app/interface/main/app-view/model:go_default_library",
"//app/interface/main/app-view/model/game:go_default_library",
"//library/ecode:go_default_library",
"//library/net/http/blademaster: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,76 @@
package game
import (
"context"
"crypto/md5"
"encoding/hex"
"net/http"
"net/url"
"strconv"
"time"
"go-common/app/interface/main/app-view/conf"
"go-common/app/interface/main/app-view/model"
"go-common/app/interface/main/app-view/model/game"
"go-common/library/ecode"
httpx "go-common/library/net/http/blademaster"
"github.com/pkg/errors"
)
const (
_infoURL = "/game/info"
)
type Dao struct {
client *httpx.Client
infoURL string
key string
secret string
}
func New(c *conf.Config) (d *Dao) {
d = &Dao{
client: httpx.NewClient(c.HTTPGame),
infoURL: c.Host.Game + _infoURL,
key: c.HTTPGame.Key,
secret: c.HTTPGame.Secret,
}
return
}
func (d *Dao) Info(c context.Context, gameID int64, plat int8) (info *game.Info, err error) {
var platType int
if model.IsAndroid(plat) {
platType = 1
} else if model.IsIOS(plat) {
platType = 2
}
if platType == 0 {
return
}
var req *http.Request
params := url.Values{}
params.Set("appkey", d.key)
params.Set("game_base_id", strconv.FormatInt(gameID, 10))
params.Set("platform_type", strconv.Itoa(platType))
params.Set("ts", strconv.FormatInt(time.Now().UnixNano()/1e6, 10))
mh := md5.Sum([]byte(params.Encode() + d.secret))
params.Set("sign", hex.EncodeToString(mh[:]))
if req, err = d.client.NewRequest("GET", d.infoURL, "", params); err != nil {
return
}
var res struct {
Code int `json:"code"`
Data *game.Info `json:"data"`
}
if err = d.client.Do(c, req, &res); err != nil {
return
}
if res.Code != ecode.OK.Code() {
err = errors.Wrap(ecode.Int(res.Code), d.infoURL+"?"+params.Encode())
return
}
info = res.Data
return
}

View File

@@ -0,0 +1,68 @@
package game
import (
"context"
"flag"
"path/filepath"
"reflect"
"testing"
"go-common/app/interface/main/app-view/conf"
"go-common/app/interface/main/app-view/model/game"
. "github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func init() {
dir, _ := filepath.Abs("../../cmd/app-view-test.toml")
flag.Set("conf", dir)
conf.Init()
d = New(conf.Conf)
}
func TestNew(t *testing.T) {
type args struct {
c *conf.Config
}
tests := []struct {
name string
args args
wantD *Dao
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotD := New(tt.args.c); !reflect.DeepEqual(gotD, tt.wantD) {
t.Errorf("New() = %v, want %v", gotD, tt.wantD)
}
})
}
}
func TestDao_Info(t *testing.T) {
type args struct {
c context.Context
gameID int64
plat int8
}
tests := []struct {
name string
args args
wantInfo *game.Info
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
Convey(tt.name, t, func() {
gotInfo, err := d.Info(tt.args.c, tt.args.gameID, tt.args.plat)
So(err, ShouldEqual, tt.wantErr)
So(gotInfo, ShouldResemble, tt.wantInfo)
})
}
}