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_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"archive.go",
"dao.go",
],
importpath = "go-common/app/job/main/tv/dao/archive",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/job/main/tv/conf:go_default_library",
"//app/service/main/archive/api:go_default_library",
"//library/cache/memcache: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"],
)
go_test(
name = "go_default_test",
srcs = [
"archive_test.go",
"dao_test.go",
],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/job/main/tv/conf:go_default_library",
"//app/service/main/archive/api:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,46 @@
package archive
import (
"context"
"strconv"
arccli "go-common/app/service/main/archive/api"
"go-common/library/cache/memcache"
"github.com/pkg/errors"
)
const (
_prefixArc = "a3p_"
_prefixView = "avp_"
)
func keyArc(aid int64) string {
return _prefixArc + strconv.FormatInt(aid, 10)
}
func keyView(aid int64) string {
return _prefixView + strconv.FormatInt(aid, 10)
}
// UpArcCache update archive cache
func (d *Dao) UpArcCache(c context.Context, a *arccli.Arc) (err error) {
conn := d.mc.Get(c)
item := &memcache.Item{Key: keyArc(a.Aid), Object: a, Flags: memcache.FlagJSON, Expiration: 0}
if err = conn.Set(item); err != nil {
err = errors.Wrapf(err, "conn.Set(%v)", item)
}
conn.Close()
return
}
// UpViewCache up all app cache .
func (d *Dao) UpViewCache(c context.Context, v *arccli.ViewReply) (err error) {
conn := d.mc.Get(c)
item := &memcache.Item{Key: keyView(v.Arc.Aid), Object: v, Flags: memcache.FlagJSON, Expiration: 0}
if err = conn.Set(item); err != nil {
err = errors.Wrapf(err, "conn.Set(%v)", item)
}
conn.Close()
return
}

View File

@@ -0,0 +1,64 @@
package archive
import (
"context"
"testing"
arccli "go-common/app/service/main/archive/api"
"github.com/smartystreets/goconvey/convey"
)
func TestArchivekeyArc(t *testing.T) {
var (
aid = int64(0)
)
convey.Convey("keyArc", t, func(ctx convey.C) {
p1 := keyArc(aid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
}
func TestArchivekeyView(t *testing.T) {
var (
aid = int64(0)
)
convey.Convey("keyView", t, func(ctx convey.C) {
p1 := keyView(aid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
}
func TestArchiveUpArcCache(t *testing.T) {
var (
c = context.Background()
a = &arccli.Arc{}
)
convey.Convey("UpArcCache", t, func(ctx convey.C) {
err := d.UpArcCache(c, a)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestArchiveUpViewCache(t *testing.T) {
var (
c = context.Background()
v = &arccli.ViewReply{
Arc: &arccli.Arc{
Aid: 123,
},
}
)
convey.Convey("UpViewCache", t, func(ctx convey.C) {
err := d.UpViewCache(c, v)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,25 @@
package archive
import (
"time"
"go-common/app/job/main/tv/conf"
"go-common/library/cache/memcache"
)
// Dao is archive dao.
type Dao struct {
// memcache
mc *memcache.Pool
expireView int32
}
// New new a archive dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
// memcache
mc: memcache.NewPool(c.Memcache.Config),
expireView: int32(time.Duration(c.Memcache.ExpireMedia) / time.Second),
}
return
}

View File

@@ -0,0 +1,34 @@
package archive
import (
"flag"
"go-common/app/job/main/tv/conf"
"os"
"testing"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.web-svr.tv-job")
flag.Set("conf_token", "ab3e9801a77c076b997de0ac5cb21775")
flag.Set("tree_id", "15260")
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")
} else {
flag.Set("conf", "../../cmd/tv-job-test.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}