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,53 @@
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",
"video_types_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/admin/main/mcn/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"video_types.go",
],
importpath = "go-common/app/admin/main/mcn/dao/videoup",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/mcn/conf:go_default_library",
"//app/service/main/videoup/model/archive:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster: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,33 @@
package videoup
import (
"go-common/app/admin/main/mcn/conf"
"go-common/app/service/main/videoup/model/archive"
bm "go-common/library/net/http/blademaster"
)
const (
_typeURL = "/videoup/types"
)
// Dao .
type Dao struct {
c *conf.Config
client *bm.Client
videTypeURL string
videoUpTypeCache map[int]archive.Type
}
// New new a Dao and return.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
// http client
client: bm.NewClient(c.HTTPClient),
videTypeURL: c.Host.Videoup + _typeURL,
videoUpTypeCache: make(map[int]archive.Type),
}
d.refreshUpType()
go d.refreshUpTypeAsync()
return
}

View File

@@ -0,0 +1,36 @@
package videoup
import (
"flag"
"os"
"testing"
"go-common/app/admin/main/mcn/conf"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.mcn-admin")
flag.Set("conf_token", "220af473858ad67f75586b66bece0e6b")
flag.Set("tree_id", "58930")
flag.Set("conf_version", "docker-1")
flag.Set("deploy_env", "uat")
flag.Set("conf_host", "config.bilibili.co")
flag.Set("conf_path", "/tmp")
flag.Set("region", "sh")
flag.Set("zone", "sh001")
}
if os.Getenv("UT_LOCAL_TEST") != "" {
flag.Set("conf", "../../cmd/mcn-admin-test.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}

View File

@@ -0,0 +1,49 @@
package videoup
import (
"context"
"time"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/log"
)
// refreshUpTypeAsync refresh in a goroutine
func (d *Dao) refreshUpTypeAsync() {
for {
time.Sleep(1 * time.Hour)
d.refreshUpType()
}
}
// videoTypes .
func (d *Dao) refreshUpType() {
var (
err error
res struct {
Code int `json:"code"`
Data map[int]archive.Type `json:"data"`
}
)
if err = d.client.Get(context.Background(), d.videTypeURL, "", nil, &res); err != nil {
log.Error("refresh videoup types fail, err=%v", err)
return
}
if res.Code != 0 {
log.Error("videoTypes d.client.Get(%d)", res.Code)
}
d.videoUpTypeCache = res.Data
}
// GetTidName get tid name
func (d *Dao) GetTidName(tids []int64) (tpNames map[int64]string) {
tpNames = make(map[int64]string, len(tids))
for _, tid := range tids {
info, ok := d.videoUpTypeCache[int(tid)]
if !ok {
continue
}
tpNames[tid] = info.Name
}
return
}

View File

@@ -0,0 +1,31 @@
package videoup
import (
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestVideouprefreshUpType(t *testing.T) {
convey.Convey("refreshUpType", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
d.refreshUpType()
ctx.Convey("No return values", func(ctx convey.C) {
})
})
})
}
func TestVideoupGetTidName(t *testing.T) {
convey.Convey("GetTidName", t, func(ctx convey.C) {
var (
tids = []int64{22}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
tpNames := d.GetTidName(tids)
ctx.Convey("Then tpNames should not be nil.", func(ctx convey.C) {
ctx.So(tpNames, convey.ShouldNotBeNil)
})
})
})
}