Create & Init Project...
This commit is contained in:
47
app/interface/main/app-intl/BUILD
Normal file
47
app/interface/main/app-intl/BUILD
Normal file
@ -0,0 +1,47 @@
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [
|
||||
":package-srcs",
|
||||
"//app/interface/main/app-intl/cmd:all-srcs",
|
||||
"//app/interface/main/app-intl/conf:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/account:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/archive:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/article:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/assist:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/audio:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/bangumi:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/black:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/card:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/coin:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/dm:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/favorite:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/location:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/manager:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/player:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/rank:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/recommend:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/region:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/relation:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/resource:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/search:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/tag:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/thumbup:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/ugcpay:all-srcs",
|
||||
"//app/interface/main/app-intl/dao/vip:all-srcs",
|
||||
"//app/interface/main/app-intl/http:all-srcs",
|
||||
"//app/interface/main/app-intl/model:all-srcs",
|
||||
"//app/interface/main/app-intl/service/feed:all-srcs",
|
||||
"//app/interface/main/app-intl/service/player:all-srcs",
|
||||
"//app/interface/main/app-intl/service/search:all-srcs",
|
||||
"//app/interface/main/app-intl/service/view:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
26
app/interface/main/app-intl/CHANGELOG.md
Normal file
26
app/interface/main/app-intl/CHANGELOG.md
Normal file
@ -0,0 +1,26 @@
|
||||
# v1.0.7
|
||||
> 1.删除无用的配置
|
||||
|
||||
# v1.0.6
|
||||
> 1.详情页去掉投稿数
|
||||
> 2.首页详情页支持繁体
|
||||
> 3.清晰度支持大会员
|
||||
|
||||
# v1.0.5
|
||||
> 1.搜索展示pgc卡片
|
||||
|
||||
# v1.0.4
|
||||
> 1.去掉zlimit,接入location
|
||||
|
||||
# v1.0.3
|
||||
> 1.修复搜索卡片的uri
|
||||
|
||||
# v1.0.2
|
||||
> 1.国际版feed暂时不秒开
|
||||
|
||||
# v1.0.1
|
||||
> 1.去掉详情页的开屏广告
|
||||
|
||||
|
||||
# v1.0.0
|
||||
> 1.上线国际版功能
|
10
app/interface/main/app-intl/CONTRIBUTORS.md
Normal file
10
app/interface/main/app-intl/CONTRIBUTORS.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Owner
|
||||
peiyifei
|
||||
liweijia
|
||||
renwei
|
||||
|
||||
# Author
|
||||
zhangxin
|
||||
|
||||
# Reviewer
|
||||
peiyifei
|
16
app/interface/main/app-intl/OWNERS
Normal file
16
app/interface/main/app-intl/OWNERS
Normal file
@ -0,0 +1,16 @@
|
||||
# See the OWNERS docs at https://go.k8s.io/owners
|
||||
|
||||
approvers:
|
||||
- liweijia
|
||||
- peiyifei
|
||||
- renwei
|
||||
- zhangxin
|
||||
labels:
|
||||
- interface
|
||||
- interface/main/app-intl
|
||||
- main
|
||||
options:
|
||||
no_parent_owners: true
|
||||
reviewers:
|
||||
- peiyifei
|
||||
- zhangxin
|
12
app/interface/main/app-intl/README.md
Normal file
12
app/interface/main/app-intl/README.md
Normal file
@ -0,0 +1,12 @@
|
||||
# app-intl-interface
|
||||
|
||||
# 项目简介
|
||||
1.app国际版网关
|
||||
|
||||
# 编译环境
|
||||
|
||||
|
||||
# 依赖包
|
||||
|
||||
|
||||
# 编译执行
|
44
app/interface/main/app-intl/cmd/BUILD
Normal file
44
app/interface/main/app-intl/cmd/BUILD
Normal file
@ -0,0 +1,44 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "cmd",
|
||||
embed = [":go_default_library"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["main.go"],
|
||||
data = ["app-intl-test.toml"],
|
||||
importpath = "go-common/app/interface/main/app-intl/cmd",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/interface/main/app-intl/http:go_default_library",
|
||||
"//library/ecode/tip:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/net/trace:go_default_library",
|
||||
"//library/text/translate/chinese: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"],
|
||||
)
|
375
app/interface/main/app-intl/cmd/app-intl-test.toml
Normal file
375
app/interface/main/app-intl/cmd/app-intl-test.toml
Normal file
@ -0,0 +1,375 @@
|
||||
# This is a TOML document. Boom.
|
||||
tick = "1m"
|
||||
|
||||
[xlog]
|
||||
dir = "/data/log/app-intl"
|
||||
[xlog.agent]
|
||||
family = "app-intl"
|
||||
taskID = "000053"
|
||||
proto = "unixgram"
|
||||
addr = "/var/run/lancer/collector.sock"
|
||||
chan = 10240
|
||||
|
||||
[bm]
|
||||
[bm.outer]
|
||||
addr = "0.0.0.0:8000"
|
||||
timeout = "1s"
|
||||
|
||||
[feed]
|
||||
[feed.index]
|
||||
count = 10
|
||||
iPadCount = 20
|
||||
moePosition = 6
|
||||
followPosition = 7
|
||||
[feed.cmResource]
|
||||
"iphone" = 1890
|
||||
"android" = 1897
|
||||
"ipad" = 1975
|
||||
|
||||
[search]
|
||||
seasonNum = 3
|
||||
movieNum = 3
|
||||
seasonMore = 1
|
||||
movieMore = 1
|
||||
upUserNum = 1
|
||||
uvLimit = 1
|
||||
userNum = 1
|
||||
userVideoLimit = 1
|
||||
biliUserNum = 1
|
||||
biliUserVideoLimit = 1
|
||||
operationNum = 1
|
||||
|
||||
[view]
|
||||
vipTick = "300s"
|
||||
relateCnt = 3
|
||||
|
||||
[showInfoc]
|
||||
taskID = "000027"
|
||||
proto = "tcp"
|
||||
addr = "172.19.100.20:5401"
|
||||
chanSize = 10240
|
||||
|
||||
[tagInfoc]
|
||||
taskID = "000028"
|
||||
proto = "tcp"
|
||||
addr = "172.19.100.20:5401"
|
||||
chanSize = 10240
|
||||
|
||||
[redirectInfoc]
|
||||
taskID = "000029"
|
||||
proto = "tcp"
|
||||
addr = "172.19.100.20:5401"
|
||||
chanSize = 10240
|
||||
|
||||
[coinInfoc]
|
||||
taskID = "000078"
|
||||
proto = "tcp"
|
||||
addr = "172.19.100.20:5401"
|
||||
chanSize = 1024
|
||||
|
||||
[viewInfoc]
|
||||
taskID = "000025"
|
||||
proto = "tcp"
|
||||
addr = "172.19.100.20:5401"
|
||||
chanSize = 1024
|
||||
|
||||
[relateInfoc]
|
||||
taskID = "000025"
|
||||
proto = "tcp"
|
||||
addr = "172.19.100.20:5401"
|
||||
chanSize = 1024
|
||||
|
||||
[host]
|
||||
live = "http://live.bilibili.co"
|
||||
liveApi = "http://api.live.bilibili.co"
|
||||
bangumi = "http://bangumi.bilibili.co"
|
||||
data = "http://data.bilibili.co"
|
||||
hetongzi = "http://hetongzi.bilibili.co"
|
||||
www = "http://www.bilibili.com"
|
||||
apiCo = "http://api.bilibili.co"
|
||||
api = "http://api.bilibili.com"
|
||||
ad = "http://cm.bilibili.co"
|
||||
activity = "http://matsuri.bilibili.co"
|
||||
rank = ""
|
||||
show = "http://show.bilibili.com"
|
||||
dynamic = "http://api.vc.bilibili.com"
|
||||
bigData = "http://bigdata.bilibili.co"
|
||||
search = "http://s.search.bilibili.co"
|
||||
|
||||
|
||||
[app]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
|
||||
[httpWrite]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
dial = "30ms"
|
||||
timeout = "100ms"
|
||||
keepAlive = "60s"
|
||||
timer = 128
|
||||
[httpWrite.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
|
||||
[httpClient]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
dial = "30ms"
|
||||
timeout = "100ms"
|
||||
keepAlive = "60s"
|
||||
timer = 128
|
||||
[httpClient.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[httpClientAsyn]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
dial = "1s"
|
||||
timeout = "2s"
|
||||
keepAlive = "60s"
|
||||
timer = 10
|
||||
[httpClientAsyn.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[httpData]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
dial = "30ms"
|
||||
timeout = "200ms"
|
||||
keepAlive = "60s"
|
||||
timer = 1024
|
||||
[httpData.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[httpTag]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
dial = "50ms"
|
||||
timeout = "200ms"
|
||||
keepAlive = "60s"
|
||||
timer = 10
|
||||
[httpTag.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[httpAd]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
dial = "50ms"
|
||||
timeout = "100ms"
|
||||
keepAlive = "60s"
|
||||
timer = 128
|
||||
[httpAd.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[httpActivity]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
dial = "50ms"
|
||||
timeout = "150ms"
|
||||
keepAlive = "60s"
|
||||
timer = 128
|
||||
[httpActivity.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[httpBangumi]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
dial = "50ms"
|
||||
timeout = "150ms"
|
||||
keepAlive = "60s"
|
||||
timer = 128
|
||||
[httpBangumi.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[httpDynamic]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
dial = "200ms"
|
||||
timeout = "800ms"
|
||||
keepAlive = "60s"
|
||||
timer = 128
|
||||
[httpDynamic.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[httpAudio]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
dial = "50ms"
|
||||
timeout = "150ms"
|
||||
keepAlive = "60s"
|
||||
timer = 128
|
||||
[httpAudio.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[httpShow]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
dial = "50ms"
|
||||
timeout = "150ms"
|
||||
keepAlive = "60s"
|
||||
timer = 128
|
||||
[httpShow.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[httpSearch]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
dial = "50ms"
|
||||
timeout = "150ms"
|
||||
keepAlive = "60s"
|
||||
timer = 128
|
||||
[httpSearch.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[mysql]
|
||||
[mysql.show]
|
||||
addr = "172.18.33.49:3306"
|
||||
dsn = "show:UJYgc9UkHIaGovEDUXpTU4U0rjBpZtwb@tcp(172.18.33.49:3306)/bilibili_show?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
|
||||
active = 2
|
||||
idle = 1
|
||||
queryTimeout = "1s"
|
||||
execTimeout = "1s"
|
||||
tranTimeout = "1s"
|
||||
[mysql.show.Breaker]
|
||||
window = "1s"
|
||||
sleep = "1s"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
[mysql.resource]
|
||||
addr = "172.18.33.49:3306"
|
||||
dsn = "resource:nMgVkY0JPgQr60nUVif5tEUbOTXlilXN@tcp(172.18.33.49:3306)/bilibili_resource?timeout=100ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"
|
||||
active = 2
|
||||
idle = 1
|
||||
queryTimeout = "1s"
|
||||
execTimeout = "1s"
|
||||
tranTimeout = "1s"
|
||||
[mysql.resource.Breaker]
|
||||
window = "1s"
|
||||
sleep = "1s"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
[mysql.manager]
|
||||
addr = "172.16.33.205:3308"
|
||||
dsn = "test:test@tcp(172.16.33.205:3308)/bilibili_manager?timeout=100ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"
|
||||
active = 2
|
||||
idle = 1
|
||||
queryTimeout = "1s"
|
||||
execTimeout = "1s"
|
||||
tranTimeout = "1s"
|
||||
[mysql.manager.Breaker]
|
||||
window = "1s"
|
||||
sleep = "1s"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[redis]
|
||||
[redis.feed]
|
||||
name = "app-intl/feed"
|
||||
proto = "unix"
|
||||
addr = "/tmp/uat-app-redis.sock"
|
||||
active = 5
|
||||
idle = 1
|
||||
dialTimeout = "30ms"
|
||||
readTimeout = "80ms"
|
||||
writeTimeout = "80ms"
|
||||
idleTimeout = "80s"
|
||||
expireRecommend = "1h"
|
||||
expireBlack = "16h"
|
||||
[redis.upper]
|
||||
name = "app-intl/upper"
|
||||
proto = "unix"
|
||||
addr = "/tmp/uat-app-redis.sock"
|
||||
active = 5
|
||||
idle = 1
|
||||
dialTimeout = "30ms"
|
||||
readTimeout = "50ms"
|
||||
writeTimeout = "50ms"
|
||||
idleTimeout = "80s"
|
||||
expireUpper = "96h"
|
||||
|
||||
[memcache]
|
||||
[memcache.feed]
|
||||
name = "app-intl/feed"
|
||||
proto = "unix"
|
||||
addr = "/tmp/uat-app-mc.sock"
|
||||
active = 5
|
||||
idle = 1
|
||||
dialTimeout = "30ms"
|
||||
readTimeout = "150ms"
|
||||
writeTimeout = "150ms"
|
||||
idleTimeout = "80s"
|
||||
expire = "24h"
|
||||
[memcache.cache]
|
||||
name = "app-intl/cache"
|
||||
proto = "unix"
|
||||
addr = "/tmp/uat-app-mc.sock"
|
||||
active = 5
|
||||
idle = 1
|
||||
dialTimeout = "30ms"
|
||||
readTimeout = "150ms"
|
||||
writeTimeout = "150ms"
|
||||
idleTimeout = "80s"
|
||||
expire = "24h"
|
||||
[memcache.archive]
|
||||
name = "app-view/archive"
|
||||
proto = "unix"
|
||||
addr = "172.18.33.61:11221"
|
||||
active = 5
|
||||
idle = 1
|
||||
dialTimeout = "30ms"
|
||||
readTimeout = "200ms"
|
||||
writeTimeout = "200ms"
|
||||
idleTimeout = "80s"
|
||||
relateExpire = "5m"
|
53
app/interface/main/app-intl/cmd/main.go
Normal file
53
app/interface/main/app-intl/cmd/main.go
Normal file
@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"go-common/app/interface/main/app-intl/http"
|
||||
ecode "go-common/library/ecode/tip"
|
||||
"go-common/library/log"
|
||||
"go-common/library/net/trace"
|
||||
"go-common/library/text/translate/chinese"
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
log.Error("conf.Init() error(%v)", err)
|
||||
panic(err)
|
||||
}
|
||||
// init log
|
||||
log.Init(conf.Conf.XLog)
|
||||
defer log.Close()
|
||||
// init chinese
|
||||
chinese.Init()
|
||||
log.Info("app-intl start")
|
||||
// init trace
|
||||
trace.Init(conf.Conf.Tracer)
|
||||
defer trace.Close()
|
||||
// ecode init
|
||||
ecode.Init(conf.Conf.Ecode)
|
||||
// service init
|
||||
http.Init(conf.Conf)
|
||||
// init pprof conf.Conf.Perf
|
||||
// init signal
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
||||
for {
|
||||
s := <-c
|
||||
log.Info("app-intl get a signal %s", s.String())
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
|
||||
log.Info("app-intl exit")
|
||||
return
|
||||
case syscall.SIGHUP:
|
||||
// TODO reload
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
43
app/interface/main/app-intl/conf/BUILD
Normal file
43
app/interface/main/app-intl/conf/BUILD
Normal file
@ -0,0 +1,43 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["conf.go"],
|
||||
importpath = "go-common/app/interface/main/app-intl/conf",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//library/cache/memcache:go_default_library",
|
||||
"//library/cache/redis:go_default_library",
|
||||
"//library/conf:go_default_library",
|
||||
"//library/database/sql:go_default_library",
|
||||
"//library/ecode/tip:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/log/infoc:go_default_library",
|
||||
"//library/net/http/blademaster:go_default_library",
|
||||
"//library/net/rpc:go_default_library",
|
||||
"//library/net/rpc/warden:go_default_library",
|
||||
"//library/net/trace:go_default_library",
|
||||
"//library/time:go_default_library",
|
||||
"//vendor/github.com/BurntSushi/toml: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"],
|
||||
)
|
248
app/interface/main/app-intl/conf/conf.go
Normal file
248
app/interface/main/app-intl/conf/conf.go
Normal file
@ -0,0 +1,248 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
|
||||
"go-common/library/cache/memcache"
|
||||
"go-common/library/cache/redis"
|
||||
"go-common/library/conf"
|
||||
"go-common/library/database/sql"
|
||||
ecode "go-common/library/ecode/tip"
|
||||
"go-common/library/log"
|
||||
"go-common/library/log/infoc"
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/rpc"
|
||||
"go-common/library/net/rpc/warden"
|
||||
"go-common/library/net/trace"
|
||||
xtime "go-common/library/time"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
var (
|
||||
// confPath is.
|
||||
confPath string
|
||||
// Conf is.
|
||||
Conf = &Config{}
|
||||
// client is.
|
||||
client *conf.Client
|
||||
)
|
||||
|
||||
// Config struct
|
||||
type Config struct {
|
||||
ShowInfoc *infoc.Config
|
||||
TagInfoc *infoc.Config
|
||||
RedirectInfoc *infoc.Config
|
||||
CoinInfoc *infoc.Config
|
||||
ViewInfoc *infoc.Config
|
||||
RelateInfoc *infoc.Config
|
||||
// show XLog
|
||||
XLog *log.Config
|
||||
// tick time
|
||||
Tick xtime.Duration
|
||||
// tracer
|
||||
Tracer *trace.Config
|
||||
// httpClinet
|
||||
HTTPClient *bm.ClientConfig
|
||||
// httpAsyn
|
||||
HTTPClientAsyn *bm.ClientConfig
|
||||
// httpData
|
||||
HTTPData *bm.ClientConfig
|
||||
// httpTag
|
||||
HTTPTag *bm.ClientConfig
|
||||
// httpBangumi
|
||||
HTTPBangumi *bm.ClientConfig
|
||||
// HTTPSearch
|
||||
HTTPSearch *bm.ClientConfig
|
||||
// HTTPAudio
|
||||
HTTPAudio *bm.ClientConfig
|
||||
// HTTPWrite
|
||||
HTTPWrite *bm.ClientConfig
|
||||
// http
|
||||
BM *HTTPServers
|
||||
// host
|
||||
Host *Host
|
||||
// db
|
||||
MySQL *MySQL
|
||||
// redis
|
||||
Redis *Redis
|
||||
// mc
|
||||
Memcache *Memcache
|
||||
// rpc client
|
||||
AccountRPC *rpc.ClientConfig
|
||||
RelationRPC *rpc.ClientConfig
|
||||
ArchiveRPC *rpc.ClientConfig
|
||||
ArchiveRPC2 *rpc.ClientConfig
|
||||
TagRPC *rpc.ClientConfig
|
||||
FavoriteRPC *rpc.ClientConfig
|
||||
CoinRPC *rpc.ClientConfig
|
||||
AssistRPC *rpc.ClientConfig
|
||||
ThumbupRPC *rpc.ClientConfig
|
||||
DMRPC *rpc.ClientConfig
|
||||
ResourceRPC *rpc.ClientConfig
|
||||
HisRPC *rpc.ClientConfig
|
||||
ArticleRPC *rpc.ClientConfig
|
||||
LocationRPC *rpc.ClientConfig
|
||||
// BroadcastRPC grpc
|
||||
PGCRPC *warden.ClientConfig
|
||||
UGCpayClient *warden.ClientConfig
|
||||
// ecode
|
||||
Ecode *ecode.Config
|
||||
// feed
|
||||
Feed *Feed
|
||||
// view
|
||||
View *View
|
||||
// search
|
||||
Search *Search
|
||||
}
|
||||
|
||||
// HTTPServers Http Servers
|
||||
type HTTPServers struct {
|
||||
Outer *bm.ServerConfig
|
||||
}
|
||||
|
||||
// Host struct
|
||||
type Host struct {
|
||||
Bangumi string
|
||||
Data string
|
||||
Hetongzi string
|
||||
APICo string
|
||||
Rank string
|
||||
BigData string
|
||||
Search string
|
||||
AI string
|
||||
Bvcvod string
|
||||
VIP string
|
||||
Playurl string
|
||||
PlayurlBk string
|
||||
}
|
||||
|
||||
// MySQL struct
|
||||
type MySQL struct {
|
||||
Show *sql.Config
|
||||
Manager *sql.Config
|
||||
}
|
||||
|
||||
// Redis struct
|
||||
type Redis struct {
|
||||
Feed *struct {
|
||||
*redis.Config
|
||||
ExpireRecommend xtime.Duration
|
||||
ExpireBlack xtime.Duration
|
||||
}
|
||||
}
|
||||
|
||||
// Memcache struct
|
||||
type Memcache struct {
|
||||
Feed *struct {
|
||||
*memcache.Config
|
||||
Expire xtime.Duration
|
||||
}
|
||||
Cache *struct {
|
||||
*memcache.Config
|
||||
Expire xtime.Duration
|
||||
}
|
||||
Archive *struct {
|
||||
*memcache.Config
|
||||
RelateExpire xtime.Duration
|
||||
}
|
||||
}
|
||||
|
||||
// Feed struct
|
||||
type Feed struct {
|
||||
// index
|
||||
Index *Index
|
||||
// ad
|
||||
CMResource map[string]int64
|
||||
}
|
||||
|
||||
// Index struct
|
||||
type Index struct {
|
||||
Count int
|
||||
IPadCount int
|
||||
MoePosition int
|
||||
FollowPosition int
|
||||
// only archive for data disaster recovery
|
||||
Abnormal bool
|
||||
}
|
||||
|
||||
// View struct
|
||||
type View struct {
|
||||
VipTick xtime.Duration
|
||||
// 相关推荐秒开个数
|
||||
RelateCnt int
|
||||
}
|
||||
|
||||
// Search struct
|
||||
type Search struct {
|
||||
SeasonNum int
|
||||
MovieNum int
|
||||
SeasonMore int
|
||||
MovieMore int
|
||||
UpUserNum int
|
||||
UVLimit int
|
||||
UserNum int
|
||||
UserVideoLimit int
|
||||
BiliUserNum int
|
||||
BiliUserVideoLimit int
|
||||
OperationNum int
|
||||
IPadSearchBangumi int
|
||||
IPadSearchFt int
|
||||
}
|
||||
|
||||
// init is.
|
||||
func init() {
|
||||
flag.StringVar(&confPath, "conf", "", "default config path")
|
||||
}
|
||||
|
||||
// Init init conf
|
||||
func Init() error {
|
||||
if confPath != "" {
|
||||
return local()
|
||||
}
|
||||
return remote()
|
||||
}
|
||||
|
||||
// local is.
|
||||
func local() (err error) {
|
||||
_, err = toml.DecodeFile(confPath, &Conf)
|
||||
return
|
||||
}
|
||||
|
||||
// reomte is.
|
||||
func remote() (err error) {
|
||||
if client, err = conf.New(); err != nil {
|
||||
return
|
||||
}
|
||||
if err = load(); err != nil {
|
||||
return
|
||||
}
|
||||
client.Watch("app-intl.toml")
|
||||
go func() {
|
||||
for range client.Event() {
|
||||
log.Info("config reload")
|
||||
if load() != nil {
|
||||
log.Error("config reload error (%v)", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
// load is.
|
||||
func load() (err error) {
|
||||
var (
|
||||
s string
|
||||
ok bool
|
||||
tmpConf *Config
|
||||
)
|
||||
if s, ok = client.Toml2(); !ok {
|
||||
return errors.New("load config center error")
|
||||
}
|
||||
if _, err = toml.Decode(s, &tmpConf); err != nil {
|
||||
return errors.New("could not decode config")
|
||||
}
|
||||
*Conf = *tmpConf
|
||||
return
|
||||
}
|
48
app/interface/main/app-intl/dao/account/BUILD
Normal file
48
app/interface/main/app-intl/dao/account/BUILD
Normal file
@ -0,0 +1,48 @@
|
||||
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-intl/conf: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-intl/dao/account",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/service/main/account/model:go_default_library",
|
||||
"//app/service/main/account/rpc/client: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"],
|
||||
)
|
118
app/interface/main/app-intl/dao/account/dao.go
Normal file
118
app/interface/main/app-intl/dao/account/dao.go
Normal file
@ -0,0 +1,118 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
account "go-common/app/service/main/account/model"
|
||||
accrpc "go-common/app/service/main/account/rpc/client"
|
||||
"go-common/library/log"
|
||||
"go-common/library/net/metadata"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Dao is archive dao.
|
||||
type Dao struct {
|
||||
// rpc
|
||||
accRPC *accrpc.Service3
|
||||
}
|
||||
|
||||
// New new a archive dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
// rpc
|
||||
accRPC: accrpc.New3(c.AccountRPC),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Relations3 relatons
|
||||
func (d *Dao) Relations3(c context.Context, owners []int64, mid int64) (follows map[int64]bool) {
|
||||
if len(owners) == 0 {
|
||||
return nil
|
||||
}
|
||||
follows = make(map[int64]bool, len(owners))
|
||||
for _, owner := range owners {
|
||||
follows[owner] = false
|
||||
}
|
||||
var (
|
||||
am map[int64]*account.Relation
|
||||
err error
|
||||
)
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &account.ArgRelations{Owners: owners, Mid: mid, RealIP: ip}
|
||||
if am, err = d.accRPC.Relations3(c, arg); err != nil {
|
||||
log.Error("%+v", err)
|
||||
return
|
||||
}
|
||||
for i, a := range am {
|
||||
if _, ok := follows[i]; ok {
|
||||
follows[i] = a.Following
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IsAttention is
|
||||
func (d *Dao) IsAttention(c context.Context, owners []int64, mid int64) (isAtten map[int64]int8) {
|
||||
if len(owners) == 0 || mid == 0 {
|
||||
return
|
||||
}
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &account.ArgRelations{Owners: owners, Mid: mid, RealIP: ip}
|
||||
res, err := d.accRPC.Relations3(c, arg)
|
||||
if err != nil {
|
||||
log.Error("%+v", err)
|
||||
return
|
||||
}
|
||||
isAtten = make(map[int64]int8, len(res))
|
||||
for mid, rel := range res {
|
||||
if rel.Following {
|
||||
isAtten[mid] = 1
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Card3 get card info by mid
|
||||
func (d *Dao) Card3(c context.Context, mid int64) (res *account.Card, err error) {
|
||||
arg := &account.ArgMid{Mid: mid}
|
||||
if res, err = d.accRPC.Card3(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Cards3 get cards info by mids
|
||||
func (d *Dao) Cards3(c context.Context, mids []int64) (res map[int64]*account.Card, err error) {
|
||||
arg := &account.ArgMids{Mids: mids}
|
||||
if res, err = d.accRPC.Cards3(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Following3 following.
|
||||
func (d *Dao) Following3(c context.Context, mid, owner int64) (follow bool, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &account.ArgRelation{Mid: mid, Owner: owner, RealIP: ip}
|
||||
rl, err := d.accRPC.Relation3(c, arg)
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
return
|
||||
}
|
||||
if rl != nil {
|
||||
follow = rl.Following
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Infos3 rpc info get by mids .
|
||||
func (d *Dao) Infos3(c context.Context, mids []int64) (res map[int64]*account.Info, err error) {
|
||||
arg := &account.ArgMids{Mids: mids}
|
||||
if res, err = d.accRPC.Infos3(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
93
app/interface/main/app-intl/dao/account/dao_test.go
Normal file
93
app/interface/main/app-intl/dao/account/dao_test.go
Normal file
@ -0,0 +1,93 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestRelations3(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
d.Relations3(context.Background(), []int64{112}, 123)
|
||||
})
|
||||
}
|
||||
|
||||
func TestIsAttention(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
d.IsAttention(context.Background(), []int64{12}, 23)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCard3(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Card3(context.Background(), 12)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCards3(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Cards3(context.Background(), []int64{1})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFollowing3(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Following3(context.Background(), 12, 13)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestInfos3(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Infos3(context.Background(), []int64{12})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
70
app/interface/main/app-intl/dao/archive/BUILD
Normal file
70
app/interface/main/app-intl/dao/archive/BUILD
Normal file
@ -0,0 +1,70 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_test",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"api_test.go",
|
||||
"dao_test.go",
|
||||
"memcache_test.go",
|
||||
"stat_test.go",
|
||||
"view_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
rundir = ".",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"api.go",
|
||||
"dao.go",
|
||||
"memcache.go",
|
||||
"stat.go",
|
||||
"view.go",
|
||||
],
|
||||
importpath = "go-common/app/interface/main/app-intl/dao/archive",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/interface/main/app-intl/model/player/archive:go_default_library",
|
||||
"//app/interface/main/app-intl/model/view:go_default_library",
|
||||
"//app/interface/main/history/model:go_default_library",
|
||||
"//app/interface/main/history/rpc/client:go_default_library",
|
||||
"//app/service/main/archive/api:go_default_library",
|
||||
"//app/service/main/archive/api/gorpc:go_default_library",
|
||||
"//app/service/main/archive/model/archive:go_default_library",
|
||||
"//library/cache/memcache:go_default_library",
|
||||
"//library/ecode:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/net/http/blademaster:go_default_library",
|
||||
"//library/net/metadata:go_default_library",
|
||||
"//library/sync/errgroup:go_default_library",
|
||||
"//library/xstr: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"],
|
||||
)
|
133
app/interface/main/app-intl/dao/archive/api.go
Normal file
133
app/interface/main/app-intl/dao/archive/api.go
Normal file
@ -0,0 +1,133 @@
|
||||
package archive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"go-common/app/interface/main/app-intl/model/view"
|
||||
"go-common/app/service/main/archive/model/archive"
|
||||
"go-common/library/ecode"
|
||||
"go-common/library/net/metadata"
|
||||
"go-common/library/xstr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
_realteURL = "/recsys/related"
|
||||
_commercialURL = "/x/internal/creative/arc/commercial"
|
||||
_relateRecURL = "/recommand"
|
||||
_playURL = "/playurl/batch"
|
||||
)
|
||||
|
||||
// RelateAids get relate by aid
|
||||
func (d *Dao) RelateAids(c context.Context, aid int64) (aids []int64, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
params := url.Values{}
|
||||
params.Set("key", strconv.FormatInt(aid, 10))
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data []*struct {
|
||||
Value string `json:"value"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, d.realteURL, ip, params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.realteURL+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
if len(res.Data) != 0 {
|
||||
if aids, err = xstr.SplitInts(res.Data[0].Value); err != nil {
|
||||
err = errors.Wrap(err, res.Data[0].Value)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Commercial is
|
||||
func (d *Dao) Commercial(c context.Context, aid int64) (gameID int64, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
params := url.Values{}
|
||||
params.Set("aid", strconv.FormatInt(aid, 10))
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data *struct {
|
||||
GameID int64 `json:"game_id"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, d.commercialURL, ip, params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.commercialURL+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
if res.Data != nil {
|
||||
gameID = res.Data.GameID
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// NewRelateAids relate online recommend 在线实时推荐
|
||||
func (d *Dao) NewRelateAids(c context.Context, aid, mid int64, build int, buvid, from string, plat int8) (rec []*view.NewRelateRec, userFeature, returnCode string, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
params := url.Values{}
|
||||
params.Set("mid", strconv.FormatInt(mid, 10))
|
||||
params.Set("from", "2")
|
||||
params.Set("cmd", "related")
|
||||
params.Set("timeout", "100")
|
||||
params.Set("plat", strconv.Itoa(int(plat)))
|
||||
params.Set("build", strconv.Itoa(build))
|
||||
params.Set("buvid", buvid)
|
||||
params.Set("from_av", strconv.FormatInt(aid, 10))
|
||||
params.Set("request_cnt", "40")
|
||||
params.Set("source_page", from)
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data []*view.NewRelateRec `json:"data"`
|
||||
UserFeature string `json:"user_feature"`
|
||||
}
|
||||
if err = d.client.Get(c, d.relateRecURL, ip, params, &res); err != nil {
|
||||
returnCode = "500"
|
||||
return
|
||||
}
|
||||
returnCode = strconv.Itoa(res.Code)
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.relateRecURL+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
userFeature = res.UserFeature
|
||||
rec = res.Data
|
||||
return
|
||||
}
|
||||
|
||||
// PlayerInfos cid with player info
|
||||
func (d *Dao) PlayerInfos(c context.Context, cids []int64, qn int, platform string, fnver, fnval int) (pm map[uint32]*archive.BvcVideoItem, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
params := url.Values{}
|
||||
params.Set("cid", xstr.JoinInts(cids))
|
||||
params.Set("qn", strconv.Itoa(qn))
|
||||
params.Set("platform", platform)
|
||||
params.Set("uip", ip)
|
||||
params.Set("layout", "pb")
|
||||
params.Set("fnver", strconv.Itoa(fnver))
|
||||
params.Set("fnval", strconv.Itoa(fnval))
|
||||
var req *http.Request
|
||||
if req, err = d.client.NewRequest("GET", d.playURL, ip, params); err != nil {
|
||||
return
|
||||
}
|
||||
res := new(archive.BvcResponseMsg)
|
||||
if err = d.client.PB(c, req, res); err != nil {
|
||||
return
|
||||
}
|
||||
if int(res.Code) != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(int(res.Code)), d.playURL+params.Encode())
|
||||
return
|
||||
}
|
||||
pm = res.Data
|
||||
return
|
||||
}
|
52
app/interface/main/app-intl/dao/archive/api_test.go
Normal file
52
app/interface/main/app-intl/dao/archive/api_test.go
Normal file
@ -0,0 +1,52 @@
|
||||
package archive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestRelateAids(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.RelateAids(context.Background(), 1)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCommercial(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Commercial(context.Background(), 12)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestNewRelateAids(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, _, _, err := d.NewRelateAids(context.Background(), 12, 12, 0, "", "", 1)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPlayerInfos(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.PlayerInfos(context.Background(), []int64{12}, 1, "", 0, 2)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
254
app/interface/main/app-intl/dao/archive/dao.go
Normal file
254
app/interface/main/app-intl/dao/archive/dao.go
Normal file
@ -0,0 +1,254 @@
|
||||
package archive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
arcmdl "go-common/app/interface/main/app-intl/model/player/archive"
|
||||
"go-common/app/interface/main/app-intl/model/view"
|
||||
history "go-common/app/interface/main/history/model"
|
||||
hisrpc "go-common/app/interface/main/history/rpc/client"
|
||||
"go-common/app/service/main/archive/api"
|
||||
arcrpc "go-common/app/service/main/archive/api/gorpc"
|
||||
"go-common/app/service/main/archive/model/archive"
|
||||
"go-common/library/cache/memcache"
|
||||
"go-common/library/ecode"
|
||||
"go-common/library/log"
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/metadata"
|
||||
"go-common/library/sync/errgroup"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Dao is archive dao.
|
||||
type Dao struct {
|
||||
// http client
|
||||
client *bm.Client
|
||||
realteURL string
|
||||
commercialURL string
|
||||
relateRecURL string
|
||||
playURL string
|
||||
// rpc
|
||||
arcRPC *arcrpc.Service2
|
||||
arcRPC2 *arcrpc.Service2
|
||||
hisRPC *hisrpc.Service
|
||||
// mc
|
||||
mc *memcache.Pool
|
||||
expireMc int32
|
||||
expireRlt int32
|
||||
// chan
|
||||
mCh chan func()
|
||||
}
|
||||
|
||||
// New new a archive dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
// http client
|
||||
client: bm.NewClient(c.HTTPWrite),
|
||||
realteURL: c.Host.Data + _realteURL,
|
||||
commercialURL: c.Host.APICo + _commercialURL,
|
||||
relateRecURL: c.Host.Data + _relateRecURL,
|
||||
playURL: c.Host.Bvcvod + _playURL,
|
||||
// rpc
|
||||
arcRPC: arcrpc.New2(c.ArchiveRPC),
|
||||
arcRPC2: arcrpc.New2(c.ArchiveRPC2),
|
||||
hisRPC: hisrpc.New(c.HisRPC),
|
||||
// mc
|
||||
mc: memcache.NewPool(c.Memcache.Feed.Config),
|
||||
expireMc: int32(time.Duration(c.Memcache.Feed.Expire) / time.Second),
|
||||
expireRlt: int32(time.Duration(c.Memcache.Archive.RelateExpire) / time.Second),
|
||||
// mc proc
|
||||
mCh: make(chan func(), 10240),
|
||||
}
|
||||
for i := 0; i < runtime.NumCPU()*2; i++ {
|
||||
go d.cacheproc()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Ping ping check memcache connection
|
||||
func (d *Dao) Ping(c context.Context) (err error) {
|
||||
return d.pingMC(c)
|
||||
}
|
||||
|
||||
// Archives multi get archives.
|
||||
func (d *Dao) Archives(c context.Context, aids []int64) (am map[int64]*api.Arc, err error) {
|
||||
if len(aids) == 0 {
|
||||
return
|
||||
}
|
||||
g, ctx := errgroup.WithContext(c)
|
||||
g.Go(func() (err error) {
|
||||
var missed []int64
|
||||
if am, missed, err = d.arcsCache(ctx, aids); err != nil {
|
||||
missed = aids
|
||||
log.Error("%+v", err)
|
||||
err = nil
|
||||
}
|
||||
if len(missed) == 0 {
|
||||
return
|
||||
}
|
||||
var tmp map[int64]*api.Arc
|
||||
arg := &archive.ArgAids2{Aids: missed}
|
||||
if tmp, err = d.arcRPC.Archives3(ctx, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
return
|
||||
}
|
||||
for aid, a := range tmp {
|
||||
am[aid] = a
|
||||
}
|
||||
return
|
||||
})
|
||||
var stm map[int64]*api.Stat
|
||||
g.Go(func() (err error) {
|
||||
var missed []int64
|
||||
if stm, missed, err = d.statsCache(ctx, aids); err != nil {
|
||||
missed = aids
|
||||
log.Error("%+v", err)
|
||||
err = nil
|
||||
}
|
||||
if len(missed) == 0 {
|
||||
return
|
||||
}
|
||||
tmp, err := d.arcRPC.Stats3(ctx, &archive.ArgAids2{Aids: missed})
|
||||
if err != nil {
|
||||
log.Error("%+v", err)
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
for _, st := range tmp {
|
||||
stm[st.Aid] = st
|
||||
}
|
||||
return
|
||||
})
|
||||
if err = g.Wait(); err != nil {
|
||||
return
|
||||
}
|
||||
for aid, arc := range am {
|
||||
if st, ok := stm[aid]; ok {
|
||||
arc.Stat = *st
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ArchivesWithPlayer archives witch player
|
||||
func (d *Dao) ArchivesWithPlayer(c context.Context, aids []int64, qn int, platform string, fnver, fnval int) (res map[int64]*archive.ArchiveWithPlayer, err error) {
|
||||
if len(aids) == 0 {
|
||||
return
|
||||
}
|
||||
// 国际版暂时不秒开
|
||||
// ip := metadata.String(c, metadata.RemoteIP)
|
||||
ip := ""
|
||||
arg := &archive.ArgPlayer{Aids: aids, Qn: qn, Platform: platform, Fnval: fnval, Fnver: fnver, RealIP: ip}
|
||||
if res, err = d.arcRPC.ArchivesWithPlayer(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Archive get archive mc->rpc.
|
||||
func (d *Dao) Archive(c context.Context, aid int64) (a *api.Arc, err error) {
|
||||
if a, err = d.arcCache(c, aid); err != nil {
|
||||
log.Error("%+v", err)
|
||||
} else if a != nil {
|
||||
return
|
||||
}
|
||||
arg := &archive.ArgAid2{Aid: aid}
|
||||
if a, err = d.arcRPC.Archive3(c, arg); err != nil {
|
||||
log.Error("d.arcRPC.Archive3(%v) error(%v)", arg, err)
|
||||
if a, err = d.arcRPC2.Archive3(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Archive3 get archive.
|
||||
func (d *Dao) Archive3(c context.Context, aid int64) (a *api.Arc, err error) {
|
||||
arg := &archive.ArgAid2{Aid: aid}
|
||||
if a, err = d.arcRPC.Archive3(c, arg); err != nil {
|
||||
log.Error("d.arcRPC.Archive3(%v) error(%+v)", arg, err)
|
||||
if a, err = d.arcRPC2.Archive3(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "d.arcRPC2.Archive3(%v)", arg)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Progress is archive plays progress .
|
||||
func (d *Dao) Progress(c context.Context, aid, mid int64) (h *view.History, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &history.ArgPro{Mid: mid, Aids: []int64{aid}, RealIP: ip}
|
||||
his, err := d.hisRPC.Progress(c, arg)
|
||||
if err != nil {
|
||||
log.Error("d.hisRPC.Progress(%v) error(%v)", arg, err)
|
||||
return
|
||||
}
|
||||
if his[aid] != nil {
|
||||
h = &view.History{Cid: his[aid].Cid, Progress: his[aid].Pro}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// UpCount2 get upper count.
|
||||
func (d *Dao) UpCount2(c context.Context, mid int64) (cnt int, err error) {
|
||||
arg := &archive.ArgUpCount2{Mid: mid}
|
||||
if cnt, err = d.arcRPC.UpCount2(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ArchiveCache is
|
||||
func (d *Dao) ArchiveCache(c context.Context, aid int64) (arc *arcmdl.Info, err error) {
|
||||
var (
|
||||
vp *archive.View3
|
||||
cids []int64
|
||||
)
|
||||
if vp, err = d.ViewCache(c, aid); err != nil {
|
||||
log.Error("%+v", err)
|
||||
}
|
||||
if vp == nil || vp.Archive3 == nil || len(vp.Pages) == 0 || vp.AttrVal(archive.AttrBitIsMovie) == archive.AttrYes {
|
||||
if vp, err = d.View3(c, aid); err != nil {
|
||||
log.Error("%+v", err)
|
||||
err = ecode.NothingFound
|
||||
return
|
||||
}
|
||||
}
|
||||
if vp == nil || vp.Archive3 == nil || len(vp.Pages) == 0 {
|
||||
err = ecode.NothingFound
|
||||
return
|
||||
}
|
||||
for _, p := range vp.Pages {
|
||||
cids = append(cids, p.Cid)
|
||||
}
|
||||
arc = &arcmdl.Info{
|
||||
Aid: vp.Aid,
|
||||
State: vp.State,
|
||||
Mid: vp.Author.Mid,
|
||||
Cids: cids,
|
||||
Attribute: vp.Attribute,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// addCache add archive to mc or redis
|
||||
func (d *Dao) addCache(f func()) {
|
||||
select {
|
||||
case d.mCh <- f:
|
||||
default:
|
||||
log.Warn("cacheproc chan full")
|
||||
}
|
||||
}
|
||||
|
||||
// cacheproc write memcache and stat redis use goroutine
|
||||
func (d *Dao) cacheproc() {
|
||||
for {
|
||||
f := <-d.mCh
|
||||
f()
|
||||
}
|
||||
}
|
104
app/interface/main/app-intl/dao/archive/dao_test.go
Normal file
104
app/interface/main/app-intl/dao/archive/dao_test.go
Normal file
@ -0,0 +1,104 @@
|
||||
package archive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestArchives(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Archives(context.Background(), []int64{1, 2})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestArchivesWithPlayer(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.ArchivesWithPlayer(context.Background(), []int64{1, 2}, 1, "", 1, 2)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestArchive(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Archive(context.Background(), 122)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestArchive3(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Archive3(context.Background(), 122)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestProgress(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Progress(context.Background(), 12, 133)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpCount2(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.UpCount2(context.Background(), 122)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
258
app/interface/main/app-intl/dao/archive/memcache.go
Normal file
258
app/interface/main/app-intl/dao/archive/memcache.go
Normal file
@ -0,0 +1,258 @@
|
||||
package archive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"go-common/app/interface/main/app-intl/model/view"
|
||||
"go-common/app/service/main/archive/api"
|
||||
"go-common/app/service/main/archive/model/archive"
|
||||
|
||||
"go-common/library/cache/memcache"
|
||||
"go-common/library/log"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
_prefixRelate = "al_"
|
||||
_prefix = "a3p_"
|
||||
_prxfixSt = "stp_"
|
||||
_prefixViewStatic = "avp_"
|
||||
_prefixViewContribute = "avpc_"
|
||||
)
|
||||
|
||||
// keyArc is.
|
||||
func keyArc(aid int64) string {
|
||||
return _prefix + strconv.FormatInt(aid, 10)
|
||||
}
|
||||
|
||||
// keySt is.
|
||||
func keySt(aid int64) string {
|
||||
return _prxfixSt + strconv.FormatInt(aid, 10)
|
||||
}
|
||||
|
||||
// keyView is.
|
||||
func keyView(aid int64) string {
|
||||
return _prefixViewStatic + strconv.FormatInt(aid, 10)
|
||||
}
|
||||
|
||||
// keyRl is.
|
||||
func keyRl(aid int64) string {
|
||||
return _prefixRelate + strconv.FormatInt(aid, 10)
|
||||
}
|
||||
|
||||
// keyViewContribute is.
|
||||
func keyViewContribute(mid int64) string {
|
||||
return _prefixViewContribute + strconv.FormatInt(mid, 10)
|
||||
}
|
||||
|
||||
// pingMC is.
|
||||
func (d *Dao) pingMC(c context.Context) (err error) {
|
||||
conn := d.mc.Get(c)
|
||||
err = conn.Set(&memcache.Item{Key: "ping", Object: []byte{1}, Flags: memcache.FlagJSON, Expiration: 0})
|
||||
conn.Close()
|
||||
return
|
||||
}
|
||||
|
||||
// statsCache get stat cache by aids
|
||||
func (d *Dao) statsCache(c context.Context, aids []int64) (cached map[int64]*api.Stat, missed []int64, err error) {
|
||||
cached = make(map[int64]*api.Stat, len(aids))
|
||||
var (
|
||||
conn = d.mc.Get(c)
|
||||
keys = make([]string, 0, len(aids))
|
||||
rs map[string]*memcache.Item
|
||||
)
|
||||
defer conn.Close()
|
||||
for _, aid := range aids {
|
||||
keys = append(keys, keySt(aid))
|
||||
}
|
||||
if rs, err = conn.GetMulti(keys); err != nil {
|
||||
err = errors.Wrapf(err, "%v", keys)
|
||||
return
|
||||
}
|
||||
for _, item := range rs {
|
||||
var st = &api.Stat{}
|
||||
if err = conn.Scan(item, st); err != nil {
|
||||
log.Error("conn.Scan(%s) error(%v)", item.Value, err)
|
||||
err = nil
|
||||
continue
|
||||
}
|
||||
cached[st.Aid] = st
|
||||
}
|
||||
if len(cached) == len(aids) {
|
||||
return
|
||||
}
|
||||
for _, aid := range aids {
|
||||
if _, ok := cached[aid]; !ok {
|
||||
missed = append(missed, aid)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// arcsCache get archives cache.
|
||||
func (d *Dao) arcsCache(c context.Context, aids []int64) (cached map[int64]*api.Arc, missed []int64, err error) {
|
||||
var (
|
||||
keys = make([]string, 0, len(aids))
|
||||
conn = d.mc.Get(c)
|
||||
aidmap = make(map[string]int64, len(aids))
|
||||
rs map[string]*memcache.Item
|
||||
a *api.Arc
|
||||
)
|
||||
cached = make(map[int64]*api.Arc, len(aids))
|
||||
defer conn.Close()
|
||||
for _, aid := range aids {
|
||||
k := keyArc(aid)
|
||||
if _, ok := aidmap[k]; !ok {
|
||||
keys = append(keys, k)
|
||||
aidmap[k] = aid
|
||||
}
|
||||
}
|
||||
if rs, err = conn.GetMulti(keys); err != nil {
|
||||
err = errors.Wrapf(err, "%v", keys)
|
||||
return
|
||||
}
|
||||
for k, r := range rs {
|
||||
a = &api.Arc{}
|
||||
if err = conn.Scan(r, a); err != nil {
|
||||
log.Error("conn.Scan(%s) error(%v)", r.Value, err)
|
||||
err = nil
|
||||
continue
|
||||
}
|
||||
cached[aidmap[k]] = a
|
||||
// delete hit key
|
||||
delete(aidmap, k)
|
||||
}
|
||||
// missed key
|
||||
missed = make([]int64, 0, len(aidmap))
|
||||
for _, aid := range aidmap {
|
||||
missed = append(missed, aid)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// arcCache get archive cache.
|
||||
func (d *Dao) arcCache(c context.Context, aid int64) (a *api.Arc, err error) {
|
||||
conn := d.mc.Get(c)
|
||||
key := keyArc(aid)
|
||||
defer conn.Close()
|
||||
r, err := conn.Get(key)
|
||||
if err != nil {
|
||||
if err == memcache.ErrNotFound {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
err = errors.Wrapf(err, "conn.Get(%s)", key)
|
||||
return
|
||||
}
|
||||
a = &api.Arc{}
|
||||
if err = conn.Scan(r, a); err != nil {
|
||||
a = nil
|
||||
err = errors.Wrapf(err, "conn.Scan(%s)", r.Value)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// viewCache get view cache from remote memecache .
|
||||
func (d *Dao) viewCache(c context.Context, aid int64) (vs *archive.View3, err error) {
|
||||
conn := d.mc.Get(c)
|
||||
key := keyView(aid)
|
||||
defer conn.Close()
|
||||
r, err := conn.Get(key)
|
||||
if err != nil {
|
||||
if err == memcache.ErrNotFound {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
err = errors.Wrapf(err, "conn.Get(%s)", key)
|
||||
return
|
||||
}
|
||||
vs = &archive.View3{Archive3: &archive.Archive3{}}
|
||||
if err = conn.Scan(r, vs); err != nil {
|
||||
vs = nil
|
||||
err = errors.Wrapf(err, "conn.Scan(%s)", r.Value)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// statCache get a archive stat from cache.
|
||||
func (d *Dao) statCache(c context.Context, aid int64) (st *api.Stat, err error) {
|
||||
conn := d.mc.Get(c)
|
||||
key := keySt(aid)
|
||||
defer conn.Close()
|
||||
r, err := conn.Get(key)
|
||||
if err != nil {
|
||||
if err == memcache.ErrNotFound {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
err = errors.Wrapf(err, "conn.Get(%s)", key)
|
||||
return
|
||||
}
|
||||
st = &api.Stat{}
|
||||
if err = conn.Scan(r, st); err != nil {
|
||||
st = nil
|
||||
err = errors.Wrapf(err, "conn.Scan(%s)", r.Value)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// RelatesCache get relates.
|
||||
func (d *Dao) RelatesCache(c context.Context, aid int64) (rls []*view.Relate, err error) {
|
||||
conn := d.mc.Get(c)
|
||||
key := keyRl(aid)
|
||||
defer conn.Close()
|
||||
r, err := conn.Get(key)
|
||||
if err != nil {
|
||||
if err == memcache.ErrNotFound {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
err = errors.Wrapf(err, "conn.Get(%s)", key)
|
||||
return
|
||||
}
|
||||
if err = conn.Scan(r, &rls); err != nil {
|
||||
err = errors.Wrapf(err, "conn.Scan(%s)", r.Value)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AddRelatesCache add relates
|
||||
func (d *Dao) AddRelatesCache(aid int64, rls []*view.Relate) {
|
||||
d.addCache(func() {
|
||||
d.addRelatesCache(context.Background(), aid, rls)
|
||||
})
|
||||
}
|
||||
|
||||
// addRelatesCache add relates cache.
|
||||
func (d *Dao) addRelatesCache(c context.Context, aid int64, rls []*view.Relate) (err error) {
|
||||
conn := d.mc.Get(c)
|
||||
key := keyRl(aid)
|
||||
item := &memcache.Item{Key: key, Object: rls, Flags: memcache.FlagJSON, Expiration: d.expireRlt}
|
||||
if err = conn.Set(item); err != nil {
|
||||
err = errors.Wrapf(err, "conn.Set(%s,%v,%d)", key, rls, d.expireRlt)
|
||||
}
|
||||
conn.Close()
|
||||
return
|
||||
}
|
||||
|
||||
// ViewContributeCache get archive cache.
|
||||
func (d *Dao) ViewContributeCache(c context.Context, mid int64) (aids []int64, err error) {
|
||||
conn := d.mc.Get(c)
|
||||
key := keyViewContribute(mid)
|
||||
defer conn.Close()
|
||||
r, err := conn.Get(key)
|
||||
if err != nil {
|
||||
if err == memcache.ErrNotFound {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
err = errors.Wrapf(err, "conn.Get(%s)", key)
|
||||
return
|
||||
}
|
||||
if err = conn.Scan(r, &aids); err != nil {
|
||||
err = errors.Wrapf(err, "conn.Scan(%s)", r.Value)
|
||||
}
|
||||
return
|
||||
}
|
75
app/interface/main/app-intl/dao/archive/memcache_test.go
Normal file
75
app/interface/main/app-intl/dao/archive/memcache_test.go
Normal file
@ -0,0 +1,75 @@
|
||||
package archive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestStatsCache(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, _, err := d.statsCache(context.Background(), []int64{1, 2, 3, 4})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestArcsCache(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, _, err := d.arcsCache(context.Background(), []int64{1, 2, 3, 4})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestArcCache(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.arcCache(context.Background(), 123)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestStatCache(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.statCache(context.Background(), 123)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRelatesCache(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.RelatesCache(context.Background(), 123)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestViewContributeCache(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.ViewContributeCache(context.Background(), 12)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
28
app/interface/main/app-intl/dao/archive/stat.go
Normal file
28
app/interface/main/app-intl/dao/archive/stat.go
Normal file
@ -0,0 +1,28 @@
|
||||
package archive
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/service/main/archive/api"
|
||||
"go-common/app/service/main/archive/model/archive"
|
||||
"go-common/library/log"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Stat get a archive stat.
|
||||
func (d *Dao) Stat(c context.Context, aid int64) (st *api.Stat, err error) {
|
||||
if st, err = d.statCache(c, aid); err != nil {
|
||||
log.Error("%+v", err)
|
||||
} else if st != nil {
|
||||
return
|
||||
}
|
||||
arg := &archive.ArgAid2{Aid: aid}
|
||||
if st, err = d.arcRPC.Stat3(c, arg); err != nil {
|
||||
log.Error("d.arcRPC.Stat3(%v) error(%v)", arg, err)
|
||||
if st, err = d.arcRPC2.Stat3(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
19
app/interface/main/app-intl/dao/archive/stat_test.go
Normal file
19
app/interface/main/app-intl/dao/archive/stat_test.go
Normal file
@ -0,0 +1,19 @@
|
||||
package archive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestStat(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Stat(context.Background(), 2)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
71
app/interface/main/app-intl/dao/archive/view.go
Normal file
71
app/interface/main/app-intl/dao/archive/view.go
Normal file
@ -0,0 +1,71 @@
|
||||
package archive
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/service/main/archive/api"
|
||||
"go-common/app/service/main/archive/model/archive"
|
||||
"go-common/library/ecode"
|
||||
"go-common/library/log"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// View3 view archive with pages pb.
|
||||
func (d *Dao) View3(c context.Context, aid int64) (v *archive.View3, err error) {
|
||||
arg := &archive.ArgAid2{Aid: aid}
|
||||
if v, err = d.arcRPC.View3(c, arg); err != nil {
|
||||
log.Error("d.arcRPC.View3(%v) error(%+v)", arg, err)
|
||||
if ecode.Cause(err) == ecode.NothingFound {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
if v, err = d.arcRPC2.View3(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ViewCache get view static data from cache if cache missed from rpc.
|
||||
func (d *Dao) ViewCache(c context.Context, aid int64) (vs *archive.View3, err error) {
|
||||
if aid == 0 {
|
||||
return
|
||||
}
|
||||
if vs, err = d.viewCache(c, aid); err != nil {
|
||||
return
|
||||
}
|
||||
if vs != nil && vs.Archive3 != nil && len(vs.Pages) != 0 {
|
||||
var st *api.Stat
|
||||
if st, err = d.Stat(c, aid); err != nil {
|
||||
log.Error("%+v", err)
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
if st != nil {
|
||||
vs.Archive3.Stat = archive.Stat3{
|
||||
Aid: st.Aid,
|
||||
View: st.View,
|
||||
Danmaku: st.Danmaku,
|
||||
Reply: st.Reply,
|
||||
Fav: st.Fav,
|
||||
Coin: st.Coin,
|
||||
Share: st.Share,
|
||||
NowRank: st.NowRank,
|
||||
HisRank: st.HisRank,
|
||||
Like: st.Like,
|
||||
DisLike: st.DisLike,
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Description get archive description by aid.
|
||||
func (d *Dao) Description(c context.Context, aid int64) (desc string, err error) {
|
||||
arg := &archive.ArgAid{Aid: aid}
|
||||
if desc, err = d.arcRPC.Description2(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
26
app/interface/main/app-intl/dao/archive/view_test.go
Normal file
26
app/interface/main/app-intl/dao/archive/view_test.go
Normal file
@ -0,0 +1,26 @@
|
||||
package archive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestView3(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
d.View3(context.Background(), 1)
|
||||
})
|
||||
}
|
||||
|
||||
func TestViewCache(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
d.ViewCache(context.Background(), 1)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDescription(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
d.Description(context.Background(), 2)
|
||||
})
|
||||
}
|
48
app/interface/main/app-intl/dao/article/BUILD
Normal file
48
app/interface/main/app-intl/dao/article/BUILD
Normal file
@ -0,0 +1,48 @@
|
||||
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-intl/conf: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-intl/dao/article",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/interface/openplatform/article/model:go_default_library",
|
||||
"//app/interface/openplatform/article/rpc/client: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"],
|
||||
)
|
79
app/interface/main/app-intl/dao/article/dao.go
Normal file
79
app/interface/main/app-intl/dao/article/dao.go
Normal file
@ -0,0 +1,79 @@
|
||||
package article
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
article "go-common/app/interface/openplatform/article/model"
|
||||
artrpc "go-common/app/interface/openplatform/article/rpc/client"
|
||||
"go-common/library/net/metadata"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Dao is atticle dao
|
||||
type Dao struct {
|
||||
artRPC *artrpc.Service
|
||||
}
|
||||
|
||||
// New initial tag dao
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
artRPC: artrpc.New(c.ArticleRPC),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// UpArticles get article data from api.
|
||||
func (d *Dao) UpArticles(c context.Context, mid int64, pn, ps int) (ams []*article.Meta, count int, err error) {
|
||||
var (
|
||||
res *article.UpArtMetas
|
||||
ip = metadata.String(c, metadata.RemoteIP)
|
||||
)
|
||||
arg := &article.ArgUpArts{Mid: mid, Pn: pn, Ps: ps, RealIP: ip}
|
||||
if res, err = d.artRPC.UpArtMetas(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
return
|
||||
}
|
||||
if res != nil {
|
||||
ams = res.Articles
|
||||
count = res.Count
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Favorites get article data from api.
|
||||
func (d *Dao) Favorites(c context.Context, mid int64, pn, ps int) (res []*article.Favorite, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &article.ArgFav{Mid: mid, Pn: pn, Ps: ps, RealIP: ip}
|
||||
if res, err = d.artRPC.Favorites(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Articles is.
|
||||
func (d *Dao) Articles(c context.Context, aids []int64) (res map[int64]*article.Meta, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &article.ArgAids{Aids: aids, RealIP: ip}
|
||||
if res, err = d.artRPC.ArticleMetas(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// UpLists is.
|
||||
func (d *Dao) UpLists(c context.Context, mid int64) (lists []*article.List, count int, err error) {
|
||||
var (
|
||||
res article.UpLists
|
||||
ip = metadata.String(c, metadata.RemoteIP)
|
||||
)
|
||||
arg := &article.ArgMid{Mid: mid, RealIP: ip}
|
||||
if res, err = d.artRPC.UpLists(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%+v", arg)
|
||||
return
|
||||
}
|
||||
lists = res.Lists
|
||||
count = res.Total
|
||||
return
|
||||
}
|
44
app/interface/main/app-intl/dao/article/dao_test.go
Normal file
44
app/interface/main/app-intl/dao/article/dao_test.go
Normal file
@ -0,0 +1,44 @@
|
||||
package article
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestUpArticles(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
d.UpArticles(context.Background(), 1, 1, 1)
|
||||
})
|
||||
}
|
46
app/interface/main/app-intl/dao/assist/BUILD
Normal file
46
app/interface/main/app-intl/dao/assist/BUILD
Normal file
@ -0,0 +1,46 @@
|
||||
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-intl/conf: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-intl/dao/assist",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/service/main/assist/model/assist:go_default_library",
|
||||
"//app/service/main/assist/rpc/client: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"],
|
||||
)
|
33
app/interface/main/app-intl/dao/assist/dao.go
Normal file
33
app/interface/main/app-intl/dao/assist/dao.go
Normal file
@ -0,0 +1,33 @@
|
||||
package assist
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"go-common/app/service/main/assist/model/assist"
|
||||
assistrpc "go-common/app/service/main/assist/rpc/client"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Dao is assist dao
|
||||
type Dao struct {
|
||||
assistRPC *assistrpc.Service
|
||||
}
|
||||
|
||||
// New initial assist dao
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
assistRPC: assistrpc.New(c.AssistRPC),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Assist get assists data from api.
|
||||
func (d *Dao) Assist(c context.Context, upMid int64) (asss []int64, err error) {
|
||||
arg := &assist.ArgAssists{Mid: upMid}
|
||||
if asss, err = d.assistRPC.AssistIDs(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
49
app/interface/main/app-intl/dao/assist/dao_test.go
Normal file
49
app/interface/main/app-intl/dao/assist/dao_test.go
Normal file
@ -0,0 +1,49 @@
|
||||
package assist
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestAssist(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Assist(context.Background(), 1)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
49
app/interface/main/app-intl/dao/audio/BUILD
Normal file
49
app/interface/main/app-intl/dao/audio/BUILD
Normal 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-intl/conf: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-intl/dao/audio",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/interface/main/app-intl/model/view:go_default_library",
|
||||
"//library/ecode:go_default_library",
|
||||
"//library/net/http/blademaster:go_default_library",
|
||||
"//library/net/metadata:go_default_library",
|
||||
"//library/xstr: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"],
|
||||
)
|
56
app/interface/main/app-intl/dao/audio/dao.go
Normal file
56
app/interface/main/app-intl/dao/audio/dao.go
Normal file
@ -0,0 +1,56 @@
|
||||
package audio
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"go-common/library/ecode"
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/metadata"
|
||||
"net/url"
|
||||
|
||||
"go-common/app/interface/main/app-intl/model/view"
|
||||
"go-common/library/xstr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
_audioByCids = "/audio/music-service-c/internal/songs-by-cids"
|
||||
)
|
||||
|
||||
// Dao is archive dao.
|
||||
type Dao struct {
|
||||
// http client
|
||||
client *bm.Client
|
||||
audioByCidsURL string
|
||||
}
|
||||
|
||||
// New new a archive dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
// http client
|
||||
client: bm.NewClient(c.HTTPAudio),
|
||||
audioByCidsURL: c.Host.APICo + _audioByCids,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AudioByCids is.
|
||||
func (d *Dao) AudioByCids(c context.Context, cids []int64) (vam map[int64]*view.Audio, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
params := url.Values{}
|
||||
params.Set("cids", xstr.JoinInts(cids))
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data map[int64]*view.Audio `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, d.audioByCidsURL, ip, params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.audioByCidsURL+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
vam = res.Data
|
||||
return
|
||||
}
|
49
app/interface/main/app-intl/dao/audio/dao_test.go
Normal file
49
app/interface/main/app-intl/dao/audio/dao_test.go
Normal file
@ -0,0 +1,49 @@
|
||||
package audio
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestAudioByCids(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.AudioByCids(context.Background(), []int64{1})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
53
app/interface/main/app-intl/dao/bangumi/BUILD
Normal file
53
app/interface/main/app-intl/dao/bangumi/BUILD
Normal 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"],
|
||||
embed = [":go_default_library"],
|
||||
rundir = ".",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"dao.go",
|
||||
"grpc.go",
|
||||
],
|
||||
importpath = "go-common/app/interface/main/app-intl/dao/bangumi",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/interface/main/app-intl/model/bangumi:go_default_library",
|
||||
"//app/service/openplatform/pgc-season/api/grpc/season/v1:go_default_library",
|
||||
"//library/ecode:go_default_library",
|
||||
"//library/net/http/blademaster:go_default_library",
|
||||
"//library/net/metadata:go_default_library",
|
||||
"//library/xstr: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"],
|
||||
)
|
145
app/interface/main/app-intl/dao/bangumi/dao.go
Normal file
145
app/interface/main/app-intl/dao/bangumi/dao.go
Normal file
@ -0,0 +1,145 @@
|
||||
package bangumi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"go-common/app/interface/main/app-intl/model/bangumi"
|
||||
seasongrpc "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
|
||||
"go-common/library/ecode"
|
||||
httpx "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/metadata"
|
||||
"go-common/library/xstr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
_pgc = "/pgc/internal/season/appview"
|
||||
_movie = "/internal_api/movie_aid_info"
|
||||
_seasonidAidURL = "/api/inner/archive/seasonid2aid"
|
||||
_card = "/pgc/internal/season/search/card"
|
||||
)
|
||||
|
||||
// Dao is bangumi dao
|
||||
type Dao struct {
|
||||
client *httpx.Client
|
||||
pgc string
|
||||
movie string
|
||||
seasonidAidURL string
|
||||
card string
|
||||
// grpc
|
||||
rpcClient seasongrpc.SeasonClient
|
||||
}
|
||||
|
||||
// New bangumi dao
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
client: httpx.NewClient(c.HTTPBangumi),
|
||||
pgc: c.Host.APICo + _pgc,
|
||||
movie: c.Host.Bangumi + _movie,
|
||||
seasonidAidURL: c.Host.Bangumi + _seasonidAidURL,
|
||||
card: c.Host.APICo + _card,
|
||||
}
|
||||
var err error
|
||||
if d.rpcClient, err = seasongrpc.NewClient(nil); err != nil {
|
||||
panic(errors.WithMessage(err, "panic by seasongrpc"))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PGC bangumi Season .
|
||||
func (d *Dao) PGC(c context.Context, aid, mid int64, build int, mobiApp, device string) (s *bangumi.Season, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
params := url.Values{}
|
||||
params.Set("aid", strconv.FormatInt(aid, 10))
|
||||
params.Set("mid", strconv.FormatInt(mid, 10))
|
||||
params.Set("build", strconv.Itoa(build))
|
||||
params.Set("device", device)
|
||||
params.Set("mobi_app", mobiApp)
|
||||
params.Set("platform", "Golang")
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Result *bangumi.Season `json:"result"`
|
||||
}
|
||||
if err = d.client.Get(c, d.pgc, ip, params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.pgc+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
s = res.Result
|
||||
return
|
||||
}
|
||||
|
||||
// Movie bangumi Movie
|
||||
func (d *Dao) Movie(c context.Context, aid, mid int64, build int, mobiApp, device string) (m *bangumi.Movie, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
params := url.Values{}
|
||||
params.Set("id", strconv.FormatInt(aid, 10))
|
||||
params.Set("mid", strconv.FormatInt(mid, 10))
|
||||
params.Set("build", strconv.Itoa(build))
|
||||
params.Set("device", device)
|
||||
params.Set("mobi_app", mobiApp)
|
||||
params.Set("platform", "Golang")
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Result *bangumi.Movie `json:"result"`
|
||||
}
|
||||
if err = d.client.Get(c, d.movie, ip, params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.movie+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
m = res.Result
|
||||
return
|
||||
}
|
||||
|
||||
// SeasonidAid moive_id by aid
|
||||
func (d *Dao) SeasonidAid(c context.Context, moiveID int64, now time.Time) (data map[int64]int64, err error) {
|
||||
params := url.Values{}
|
||||
params.Set("build", "app-api")
|
||||
params.Set("platform", "Golang")
|
||||
params.Set("season_id", strconv.FormatInt(moiveID, 10))
|
||||
params.Set("season_type", "2")
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Result map[int64]int64 `json:"result"`
|
||||
}
|
||||
if err = d.client.Get(c, d.seasonidAidURL, "", params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.seasonidAidURL+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
data = res.Result
|
||||
return
|
||||
}
|
||||
|
||||
// Card bangumi card.
|
||||
func (d *Dao) Card(c context.Context, mid int64, sids []int64) (s map[string]*bangumi.Card, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
params := url.Values{}
|
||||
params.Set("mid", strconv.FormatInt(mid, 10))
|
||||
params.Set("season_ids", xstr.JoinInts(sids))
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Result map[string]*bangumi.Card `json:"result"`
|
||||
}
|
||||
if err = d.client.Get(c, d.card, ip, params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.card+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
s = res.Result
|
||||
return
|
||||
}
|
72
app/interface/main/app-intl/dao/bangumi/dao_test.go
Normal file
72
app/interface/main/app-intl/dao/bangumi/dao_test.go
Normal file
@ -0,0 +1,72 @@
|
||||
package bangumi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestMovie(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Movie(context.Background(), 1, 1, 1, "iphone", "phone")
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPGC(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.PGC(context.Background(), 1, 1, 1, "iphone", "phone")
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSeasonidAid(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.SeasonidAid(context.Background(), 1, time.Now())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
21
app/interface/main/app-intl/dao/bangumi/grpc.go
Normal file
21
app/interface/main/app-intl/dao/bangumi/grpc.go
Normal file
@ -0,0 +1,21 @@
|
||||
package bangumi
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
seasongrpc "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// CardsInfoReply pgc cards info
|
||||
func (d *Dao) CardsInfoReply(c context.Context, seasonIds []int32) (res map[int32]*seasongrpc.CardInfoProto, err error) {
|
||||
arg := &seasongrpc.SeasonInfoReq{SeasonIds: seasonIds}
|
||||
info, err := d.rpcClient.Cards(c, arg)
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
return
|
||||
}
|
||||
res = info.Cards
|
||||
return
|
||||
}
|
51
app/interface/main/app-intl/dao/black/BUILD
Normal file
51
app/interface/main/app-intl/dao/black/BUILD
Normal file
@ -0,0 +1,51 @@
|
||||
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-intl/conf:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"api.go",
|
||||
"dao.go",
|
||||
"redis.go",
|
||||
],
|
||||
importpath = "go-common/app/interface/main/app-intl/dao/black",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//library/cache/redis:go_default_library",
|
||||
"//library/log: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"],
|
||||
)
|
25
app/interface/main/app-intl/dao/black/api.go
Normal file
25
app/interface/main/app-intl/dao/black/api.go
Normal file
@ -0,0 +1,25 @@
|
||||
package black
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const (
|
||||
_blackURL = "http://172.18.7.208/privatedata/reco-deny-arcs.json"
|
||||
)
|
||||
|
||||
// Black returns blacklist of aids
|
||||
func (d *Dao) Black(c context.Context) (black map[int64]struct{}, err error) {
|
||||
var res []int64
|
||||
if err = d.clientAsyn.Get(c, _blackURL, "", nil, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if len(res) == 0 {
|
||||
return
|
||||
}
|
||||
black = make(map[int64]struct{}, len(res))
|
||||
for _, aid := range res {
|
||||
black[aid] = struct{}{}
|
||||
}
|
||||
return
|
||||
}
|
90
app/interface/main/app-intl/dao/black/dao.go
Normal file
90
app/interface/main/app-intl/dao/black/dao.go
Normal file
@ -0,0 +1,90 @@
|
||||
package black
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"go-common/library/cache/redis"
|
||||
"go-common/library/log"
|
||||
httpx "go-common/library/net/http/blademaster"
|
||||
)
|
||||
|
||||
// Dao is black dao.
|
||||
type Dao struct {
|
||||
// http clientAsyn
|
||||
clientAsyn *httpx.Client
|
||||
// redis
|
||||
redis *redis.Pool
|
||||
expireRds int32
|
||||
aCh chan func()
|
||||
}
|
||||
|
||||
// New new a black dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
// http client
|
||||
clientAsyn: httpx.NewClient(c.HTTPClientAsyn),
|
||||
// redis init
|
||||
redis: redis.NewPool(c.Redis.Feed.Config),
|
||||
expireRds: int32(time.Duration(c.Redis.Feed.ExpireBlack) / time.Second),
|
||||
aCh: make(chan func(), 1024),
|
||||
}
|
||||
go d.cacheproc()
|
||||
return
|
||||
}
|
||||
|
||||
// Ping Ping check redis connection
|
||||
func (d *Dao) Ping(c context.Context) (err error) {
|
||||
connRedis := d.redis.Get(c)
|
||||
_, err = connRedis.Do("SET", "PING", "PONG")
|
||||
connRedis.Close()
|
||||
return
|
||||
}
|
||||
|
||||
// AddBlacklist is.
|
||||
func (d *Dao) AddBlacklist(mid, aid int64) {
|
||||
d.addCache(func() {
|
||||
d.addBlackCache(context.Background(), mid, aid)
|
||||
})
|
||||
}
|
||||
|
||||
// DelBlacklist is.
|
||||
func (d *Dao) DelBlacklist(mid, aid int64) {
|
||||
d.addCache(func() {
|
||||
d.delBlackCache(context.Background(), mid, aid)
|
||||
})
|
||||
}
|
||||
|
||||
// BlackList is.
|
||||
func (d *Dao) BlackList(c context.Context, mid int64) (aidm map[int64]struct{}, err error) {
|
||||
var ok bool
|
||||
if ok, err = d.expireBlackCache(c, mid); err != nil {
|
||||
return
|
||||
}
|
||||
if ok {
|
||||
aidm, err = d.blackCache(c, mid)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// addCache add cache to mc by goroutine
|
||||
func (d *Dao) addCache(i func()) {
|
||||
select {
|
||||
case d.aCh <- i:
|
||||
default:
|
||||
log.Warn("cacheproc chan full")
|
||||
}
|
||||
}
|
||||
|
||||
// cacheproc cache proc
|
||||
func (d *Dao) cacheproc() {
|
||||
for {
|
||||
f, ok := <-d.aCh
|
||||
if !ok {
|
||||
log.Warn("cache proc exit")
|
||||
return
|
||||
}
|
||||
f()
|
||||
}
|
||||
}
|
55
app/interface/main/app-intl/dao/black/dao_test.go
Normal file
55
app/interface/main/app-intl/dao/black/dao_test.go
Normal file
@ -0,0 +1,55 @@
|
||||
package black
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestDelBlacklist(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
d.DelBlacklist(12, 12)
|
||||
})
|
||||
}
|
||||
|
||||
func TestBlackList(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.BlackList(context.Background(), 12)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
86
app/interface/main/app-intl/dao/black/redis.go
Normal file
86
app/interface/main/app-intl/dao/black/redis.go
Normal file
@ -0,0 +1,86 @@
|
||||
package black
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"go-common/library/cache/redis"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
_prefixBlack = "b_"
|
||||
)
|
||||
|
||||
// keyBlack is.
|
||||
func keyBlack(mid int64) string {
|
||||
return _prefixBlack + strconv.FormatInt(mid, 10)
|
||||
}
|
||||
|
||||
func (d *Dao) blackCache(c context.Context, mid int64) (aidm map[int64]struct{}, err error) {
|
||||
var aids []int64
|
||||
conn := d.redis.Get(c)
|
||||
key := keyBlack(mid)
|
||||
defer conn.Close()
|
||||
if aids, err = redis.Int64s(conn.Do("ZREVRANGE", key, 0, -1)); err != nil {
|
||||
err = errors.Wrapf(err, "conn.Do(ZREVRANGE,%s,0,-1)", key)
|
||||
return
|
||||
}
|
||||
aidm = make(map[int64]struct{}, len(aids))
|
||||
for _, aid := range aids {
|
||||
aidm[aid] = struct{}{}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// addBlackCache is.
|
||||
func (d *Dao) addBlackCache(c context.Context, mid int64, aids ...int64) (err error) {
|
||||
if len(aids) == 0 {
|
||||
return
|
||||
}
|
||||
key := keyBlack(mid)
|
||||
conn := d.redis.Get(c)
|
||||
defer conn.Close()
|
||||
for _, aid := range aids {
|
||||
if err = conn.Send("ZADD", key, aid, aid); err != nil {
|
||||
err = errors.Wrapf(err, "conn.Send(ZADD,%s,%d,%d)", key, aid, aid)
|
||||
return
|
||||
}
|
||||
}
|
||||
if err = conn.Send("EXPIRE", key, d.expireRds); err != nil {
|
||||
err = errors.Wrapf(err, "conn.Send(EXPIRE,%s,%d)", key, d.expireRds)
|
||||
return
|
||||
}
|
||||
if err = conn.Flush(); err != nil {
|
||||
return
|
||||
}
|
||||
for i := 0; i < len(aids)+1; i++ {
|
||||
if _, err = conn.Receive(); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// delBlackCache is.
|
||||
func (d *Dao) delBlackCache(c context.Context, mid, aid int64) (err error) {
|
||||
key := keyBlack(mid)
|
||||
conn := d.redis.Get(c)
|
||||
defer conn.Close()
|
||||
if _, err = conn.Do("ZREM", key, aid); err != nil {
|
||||
err = errors.Wrapf(err, "conn.Do(ZREM,%s,%d)", key, aid)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// expireBlackCache is.
|
||||
func (d *Dao) expireBlackCache(c context.Context, mid int64) (ok bool, err error) {
|
||||
key := keyBlack(mid)
|
||||
conn := d.redis.Get(c)
|
||||
defer conn.Close()
|
||||
if ok, err = redis.Bool(conn.Do("EXPIRE", key, d.expireRds)); err != nil {
|
||||
err = errors.Wrapf(err, "conn.Do(EXPIRE,%s,%d)", key, d.expireRds)
|
||||
}
|
||||
return
|
||||
}
|
46
app/interface/main/app-intl/dao/card/BUILD
Normal file
46
app/interface/main/app-intl/dao/card/BUILD
Normal file
@ -0,0 +1,46 @@
|
||||
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-intl/conf: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-intl/dao/card",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/app-card/model/card/operate:go_default_library",
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//library/database/sql: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"],
|
||||
)
|
48
app/interface/main/app-intl/dao/card/dao.go
Normal file
48
app/interface/main/app-intl/dao/card/dao.go
Normal file
@ -0,0 +1,48 @@
|
||||
package card
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-card/model/card/operate"
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"go-common/library/database/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
_followSQL = "SELECT `id`,`type`,`long_title`,`content` FROM `card_follow` WHERE `deleted`=0"
|
||||
)
|
||||
|
||||
// Dao is dao
|
||||
type Dao struct {
|
||||
db *sql.DB
|
||||
followGet *sql.Stmt
|
||||
}
|
||||
|
||||
// New new dao
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
db: sql.NewMySQL(c.MySQL.Show),
|
||||
}
|
||||
// prepare
|
||||
d.followGet = d.db.Prepared(_followSQL)
|
||||
return
|
||||
}
|
||||
|
||||
// Follow is.
|
||||
func (d *Dao) Follow(c context.Context) (cm map[int64]*operate.Follow, err error) {
|
||||
var rows *sql.Rows
|
||||
if rows, err = d.followGet.Query(c); err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
cm = make(map[int64]*operate.Follow)
|
||||
for rows.Next() {
|
||||
c := &operate.Follow{}
|
||||
if err = rows.Scan(&c.ID, &c.Type, &c.Title, &c.Content); err != nil {
|
||||
return
|
||||
}
|
||||
c.Change()
|
||||
cm[c.ID] = c
|
||||
}
|
||||
return
|
||||
}
|
49
app/interface/main/app-intl/dao/card/dao_test.go
Normal file
49
app/interface/main/app-intl/dao/card/dao_test.go
Normal file
@ -0,0 +1,49 @@
|
||||
package card
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestDao_Follow(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Follow(context.Background())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
47
app/interface/main/app-intl/dao/coin/BUILD
Normal file
47
app/interface/main/app-intl/dao/coin/BUILD
Normal file
@ -0,0 +1,47 @@
|
||||
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-intl/conf: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-intl/dao/coin",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/service/main/coin/api/gorpc:go_default_library",
|
||||
"//app/service/main/coin/model: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"],
|
||||
)
|
52
app/interface/main/app-intl/dao/coin/dao.go
Normal file
52
app/interface/main/app-intl/dao/coin/dao.go
Normal file
@ -0,0 +1,52 @@
|
||||
package coin
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
coinrpc "go-common/app/service/main/coin/api/gorpc"
|
||||
"go-common/app/service/main/coin/model"
|
||||
"go-common/library/net/metadata"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Dao is coin dao
|
||||
type Dao struct {
|
||||
coinRPC *coinrpc.Service
|
||||
}
|
||||
|
||||
// New initial coin dao
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
coinRPC: coinrpc.New(c.CoinRPC),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AddCoins add coin to upper.
|
||||
func (d *Dao) AddCoins(c context.Context, aid, mid, upID, maxCoin, avtype, multiply int64, typeID int16, pubTime int64) (err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &model.ArgAddCoin{Mid: mid, UpMid: upID, MaxCoin: maxCoin, Aid: aid, AvType: avtype, Multiply: multiply, RealIP: ip, TypeID: typeID, PubTime: pubTime}
|
||||
return d.coinRPC.AddCoins(c, arg)
|
||||
}
|
||||
|
||||
// ArchiveUserCoins .
|
||||
func (d *Dao) ArchiveUserCoins(c context.Context, aid, mid, avType int64) (res *model.ArchiveUserCoins, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &model.ArgCoinInfo{Mid: mid, Aid: aid, AvType: avType, RealIP: ip}
|
||||
if res, err = d.coinRPC.ArchiveUserCoins(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// UserCoins get user coins
|
||||
func (d *Dao) UserCoins(c context.Context, mid int64) (count float64, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &model.ArgCoinInfo{Mid: mid, RealIP: ip}
|
||||
if count, err = d.coinRPC.UserCoins(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
49
app/interface/main/app-intl/dao/coin/dao_test.go
Normal file
49
app/interface/main/app-intl/dao/coin/dao_test.go
Normal file
@ -0,0 +1,49 @@
|
||||
package coin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestAddCoins(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
err := d.AddCoins(context.Background(), 1, 1, 1, 1, 1, 1, 1, 0)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
47
app/interface/main/app-intl/dao/dm/BUILD
Normal file
47
app/interface/main/app-intl/dao/dm/BUILD
Normal file
@ -0,0 +1,47 @@
|
||||
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-intl/conf: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-intl/dao/dm",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/interface/main/dm2/model:go_default_library",
|
||||
"//app/interface/main/dm2/rpc/client: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"],
|
||||
)
|
33
app/interface/main/app-intl/dao/dm/dao.go
Normal file
33
app/interface/main/app-intl/dao/dm/dao.go
Normal file
@ -0,0 +1,33 @@
|
||||
package dm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
dm "go-common/app/interface/main/dm2/model"
|
||||
dmrpc "go-common/app/interface/main/dm2/rpc/client"
|
||||
"go-common/library/net/metadata"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Dao struct
|
||||
type Dao struct {
|
||||
dmRPC *dmrpc.Service
|
||||
}
|
||||
|
||||
// New a dao
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
return &Dao{
|
||||
dmRPC: dmrpc.New(c.DMRPC),
|
||||
}
|
||||
}
|
||||
|
||||
// SubjectInfos is.
|
||||
func (d *Dao) SubjectInfos(c context.Context, typ int32, plat int8, oids ...int64) (res map[int64]*dm.SubjectInfo, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &dm.ArgOids{Type: typ, Plat: plat, Oids: oids, RealIP: ip}
|
||||
if res, err = d.dmRPC.SubjectInfos(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
49
app/interface/main/app-intl/dao/dm/dao_test.go
Normal file
49
app/interface/main/app-intl/dao/dm/dao_test.go
Normal file
@ -0,0 +1,49 @@
|
||||
package dm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestSubjectInfos(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.SubjectInfos(context.Background(), 1, 1, 12)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
55
app/interface/main/app-intl/dao/favorite/BUILD
Normal file
55
app/interface/main/app-intl/dao/favorite/BUILD
Normal file
@ -0,0 +1,55 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_test",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"api_test.go",
|
||||
"dao_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
rundir = ".",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"api.go",
|
||||
"dao.go",
|
||||
],
|
||||
importpath = "go-common/app/interface/main/app-intl/dao/favorite",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/service/main/favorite/api/gorpc:go_default_library",
|
||||
"//app/service/main/favorite/model:go_default_library",
|
||||
"//library/ecode:go_default_library",
|
||||
"//library/net/http/blademaster: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"],
|
||||
)
|
77
app/interface/main/app-intl/dao/favorite/api.go
Normal file
77
app/interface/main/app-intl/dao/favorite/api.go
Normal file
@ -0,0 +1,77 @@
|
||||
package favorite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"go-common/library/ecode"
|
||||
"go-common/library/net/metadata"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// IsFavDefault faorite count
|
||||
func (d *Dao) IsFavDefault(c context.Context, mid, aid int64) (is bool, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
params := url.Values{}
|
||||
params.Set("mid", strconv.FormatInt(mid, 10))
|
||||
params.Set("aid", strconv.FormatInt(aid, 10))
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data struct {
|
||||
Default bool `json:"default"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, d.isFavDef, ip, params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.isFavDef+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
is = res.Data.Default
|
||||
return
|
||||
}
|
||||
|
||||
// IsFav is
|
||||
func (d *Dao) IsFav(c context.Context, mid, aid int64) (is bool, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
params := url.Values{}
|
||||
params.Set("mid", strconv.FormatInt(mid, 10))
|
||||
params.Set("aid", strconv.FormatInt(aid, 10))
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data struct {
|
||||
Favorite bool `json:"favoured"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, d.isFav, ip, params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.isFav+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
is = res.Data.Favorite
|
||||
return
|
||||
}
|
||||
|
||||
// AddFav add fav video
|
||||
func (d *Dao) AddFav(c context.Context, mid, aid int64) (err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
params := url.Values{}
|
||||
params.Set("mid", strconv.FormatInt(mid, 10))
|
||||
params.Set("aid", strconv.FormatInt(aid, 10))
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
}
|
||||
if err = d.client.Post(c, d.addFav, ip, params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.isFav+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
30
app/interface/main/app-intl/dao/favorite/api_test.go
Normal file
30
app/interface/main/app-intl/dao/favorite/api_test.go
Normal file
@ -0,0 +1,30 @@
|
||||
package favorite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestIsFavDefault(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.IsFavDefault(context.Background(), 1, 1)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestIsFav(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.IsFav(context.Background(), 1, 1)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
43
app/interface/main/app-intl/dao/favorite/dao.go
Normal file
43
app/interface/main/app-intl/dao/favorite/dao.go
Normal file
@ -0,0 +1,43 @@
|
||||
package favorite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
favrpc "go-common/app/service/main/favorite/api/gorpc"
|
||||
fav "go-common/app/service/main/favorite/model"
|
||||
httpx "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
_isFavDef = "/x/internal/v2/fav/video/default"
|
||||
_isFav = "/x/internal/v2/fav/video/favoured"
|
||||
_addFav = "/x/internal/v2/fav/video/add"
|
||||
)
|
||||
|
||||
// Dao is favorite dao
|
||||
type Dao struct {
|
||||
client *httpx.Client
|
||||
isFavDef string
|
||||
isFav string
|
||||
addFav string
|
||||
favRPC *favrpc.Service
|
||||
}
|
||||
|
||||
// New initial favorite dao
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
client: httpx.NewClient(c.HTTPClient),
|
||||
isFavDef: c.Host.APICo + _isFavDef,
|
||||
isFav: c.Host.APICo + _isFav,
|
||||
addFav: c.Host.APICo + _addFav,
|
||||
favRPC: favrpc.New2(c.FavoriteRPC),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AddVideo add favorite
|
||||
func (d *Dao) AddVideo(c context.Context, mid int64, fids []int64, aid int64, ak string) error {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
return d.favRPC.AddVideo(c, &fav.ArgAddVideo{Mid: mid, Fids: fids, Aid: aid, AccessKey: ak, RealIP: ip})
|
||||
}
|
52
app/interface/main/app-intl/dao/favorite/dao_test.go
Normal file
52
app/interface/main/app-intl/dao/favorite/dao_test.go
Normal file
@ -0,0 +1,52 @@
|
||||
package favorite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestAddVideo(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
err := d.AddVideo(context.Background(), 1, []int64{1}, 1, "")
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
46
app/interface/main/app-intl/dao/location/BUILD
Normal file
46
app/interface/main/app-intl/dao/location/BUILD
Normal file
@ -0,0 +1,46 @@
|
||||
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"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf: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-intl/dao/location",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/service/main/location/model:go_default_library",
|
||||
"//app/service/main/location/rpc/client:go_default_library",
|
||||
"//library/log: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"],
|
||||
)
|
54
app/interface/main/app-intl/dao/location/dao.go
Normal file
54
app/interface/main/app-intl/dao/location/dao.go
Normal file
@ -0,0 +1,54 @@
|
||||
package location
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
locmdl "go-common/app/service/main/location/model"
|
||||
locrpc "go-common/app/service/main/location/rpc/client"
|
||||
"go-common/library/log"
|
||||
)
|
||||
|
||||
// Dao is location dao.
|
||||
type Dao struct {
|
||||
// rpc
|
||||
locRPC *locrpc.Service
|
||||
}
|
||||
|
||||
// New new a location dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
// rpc
|
||||
locRPC: locrpc.New(c.LocationRPC),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Dao) Info(c context.Context, ipaddr string) (info *locmdl.Info, err error) {
|
||||
if info, err = d.locRPC.Info(c, &locmdl.ArgIP{IP: ipaddr}); err != nil {
|
||||
log.Error("%v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Dao) AuthPIDs(c context.Context, pids, ipaddr string) (res map[string]*locmdl.Auth, err error) {
|
||||
var auths map[int64]*locmdl.Auth
|
||||
if auths, err = d.locRPC.AuthPIDs(c, &locmdl.ArgPids{Pids: pids, IP: ipaddr}); err != nil {
|
||||
log.Error("%v", err)
|
||||
return
|
||||
}
|
||||
res = make(map[string]*locmdl.Auth)
|
||||
for pid, auth := range auths {
|
||||
p := strconv.FormatInt(pid, 10)
|
||||
res[p] = auth
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Dao) Archive(c context.Context, aid, mid int64, ipaddr, cndip string) (auth *locmdl.Auth, err error) {
|
||||
if auth, err = d.locRPC.Archive2(c, &locmdl.Archive{Aid: aid, Mid: mid, IP: ipaddr, CIP: cndip}); err != nil {
|
||||
log.Error("%v", err)
|
||||
}
|
||||
return
|
||||
}
|
51
app/interface/main/app-intl/dao/location/dao_test.go
Normal file
51
app/interface/main/app-intl/dao/location/dao_test.go
Normal file
@ -0,0 +1,51 @@
|
||||
package location
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func ctx() context.Context {
|
||||
return context.Background()
|
||||
}
|
||||
|
||||
func init() {
|
||||
dir, _ := filepath.Abs("../../cmd/app-intl-test.toml")
|
||||
flag.Set("conf", dir)
|
||||
conf.Init()
|
||||
d = New(conf.Conf)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
func TestInfo(t *testing.T) {
|
||||
Convey("get Info", t, func() {
|
||||
res, err := d.Info(ctx(), "127.0.0.1")
|
||||
So(res, ShouldNotBeEmpty)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAuthPIDs(t *testing.T) {
|
||||
Convey("get AuthPIDs", t, func() {
|
||||
_, err := d.AuthPIDs(ctx(), "417,1521", "127.0.0.0")
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestArchive(t *testing.T) {
|
||||
Convey("get Archive", t, func() {
|
||||
_, err := d.Archive(ctx(), 16816128, 16816128, "127.0.0.0", "127.0.0.0")
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
45
app/interface/main/app-intl/dao/manager/BUILD
Normal file
45
app/interface/main/app-intl/dao/manager/BUILD
Normal file
@ -0,0 +1,45 @@
|
||||
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-intl/conf: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-intl/dao/manager",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/interface/main/app-intl/model/manager:go_default_library",
|
||||
"//library/database/sql: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"],
|
||||
)
|
54
app/interface/main/app-intl/dao/manager/dao.go
Normal file
54
app/interface/main/app-intl/dao/manager/dao.go
Normal file
@ -0,0 +1,54 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"go-common/app/interface/main/app-intl/model/manager"
|
||||
xsql "go-common/library/database/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
_relateSQL = "SELECT `id`,`param`,`goto`,`title`,`resource_ids`,`tag_ids`,`archive_ids`,`rec_reason`,`position`,`plat_ver`, `stime`,`etime` FROM app_rcmd_pos WHERE `state`=1"
|
||||
)
|
||||
|
||||
// Dao struct
|
||||
type Dao struct {
|
||||
db *xsql.DB
|
||||
get *xsql.Stmt
|
||||
}
|
||||
|
||||
// New a dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
db: xsql.NewMySQL(c.MySQL.Show),
|
||||
}
|
||||
// prepare
|
||||
d.get = d.db.Prepared(_relateSQL)
|
||||
return
|
||||
}
|
||||
|
||||
// Relate get all relate rec.
|
||||
func (d *Dao) Relate(c context.Context) (rs []*manager.Relate, err error) {
|
||||
rows, err := d.get.Query(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
r := &manager.Relate{}
|
||||
if err = rows.Scan(&r.ID, &r.Param, &r.Goto, &r.Title, &r.ResourceIDs, &r.TagIDs, &r.ArchiveIDs, &r.RecReason, &r.Position, &r.PlatVer, &r.STime, &r.ETime); err != nil {
|
||||
return
|
||||
}
|
||||
r.Change()
|
||||
rs = append(rs, r)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Close close db resource.
|
||||
func (d *Dao) Close() {
|
||||
if d.db != nil {
|
||||
d.db.Close()
|
||||
}
|
||||
}
|
49
app/interface/main/app-intl/dao/manager/dao_test.go
Normal file
49
app/interface/main/app-intl/dao/manager/dao_test.go
Normal file
@ -0,0 +1,49 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestAddVideo(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Relate(context.Background())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
48
app/interface/main/app-intl/dao/player/BUILD
Normal file
48
app/interface/main/app-intl/dao/player/BUILD
Normal file
@ -0,0 +1,48 @@
|
||||
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-intl/conf: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-intl/dao/player",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/interface/main/app-intl/model/player:go_default_library",
|
||||
"//library/net/http/blademaster: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"],
|
||||
)
|
71
app/interface/main/app-intl/dao/player/dao.go
Normal file
71
app/interface/main/app-intl/dao/player/dao.go
Normal file
@ -0,0 +1,71 @@
|
||||
package player
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"go-common/app/interface/main/app-intl/model/player"
|
||||
httpx "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/metadata"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Dao is
|
||||
type Dao struct {
|
||||
client *httpx.Client
|
||||
}
|
||||
|
||||
// New elec dao
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
client: httpx.NewClient(c.HTTPClient),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Playurl is
|
||||
func (d *Dao) Playurl(c context.Context, mid, aid, cid, qn int64, npcybs, fnver, fnval, forceHost int, otype, mobiApp, buvid, fp, session, reqURL string) (playurl *player.Playurl, code int, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
params := url.Values{}
|
||||
params.Set("otype", otype)
|
||||
params.Set("buvid", buvid)
|
||||
params.Set("platform", mobiApp)
|
||||
params.Set("mid", strconv.FormatInt(mid, 10))
|
||||
params.Set("cid", strconv.FormatInt(cid, 10))
|
||||
params.Set("session", session)
|
||||
params.Set("force_host", strconv.Itoa(forceHost))
|
||||
if aid > 0 {
|
||||
params.Set("avid", strconv.FormatInt(aid, 10))
|
||||
}
|
||||
params.Set("fnver", strconv.Itoa(fnver))
|
||||
params.Set("fnval", strconv.Itoa(fnval))
|
||||
if qn != 0 {
|
||||
params.Set("qn", strconv.FormatInt(qn, 10))
|
||||
}
|
||||
if npcybs != 0 {
|
||||
params.Set("npcybs", strconv.Itoa(npcybs))
|
||||
}
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
*player.Playurl
|
||||
}
|
||||
var req *http.Request
|
||||
if req, err = d.client.NewRequest(http.MethodGet, reqURL, ip, params); err != nil {
|
||||
err = errors.Wrap(err, "d.client.NewRequest error")
|
||||
return
|
||||
}
|
||||
if fp != "" {
|
||||
req.Header.Set("X-BVC-FINGERPRINT", fp)
|
||||
}
|
||||
if err = d.client.Do(c, req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
playurl = res.Playurl
|
||||
playurl.FormatDash()
|
||||
code = res.Code
|
||||
return
|
||||
}
|
49
app/interface/main/app-intl/dao/player/dao_test.go
Normal file
49
app/interface/main/app-intl/dao/player/dao_test.go
Normal file
@ -0,0 +1,49 @@
|
||||
package player
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
m.Run()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func TestPlayurl(t *testing.T) {
|
||||
var (
|
||||
c = context.TODO()
|
||||
)
|
||||
convey.Convey("Playurl", t, func(ctx convey.C) {
|
||||
_, _, err := d.Playurl(c, 0, 1, 10109227, 32, 0, 0, 0, 0, "json", "android", "dajskldasjkl", "", "", "")
|
||||
ctx.Convey("Then err should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
}
|
47
app/interface/main/app-intl/dao/rank/BUILD
Normal file
47
app/interface/main/app-intl/dao/rank/BUILD
Normal file
@ -0,0 +1,47 @@
|
||||
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-intl/conf: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-intl/dao/rank",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-card/model/card/rank:go_default_library",
|
||||
"//app/interface/main/app-intl/conf: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"],
|
||||
)
|
51
app/interface/main/app-intl/dao/rank/dao.go
Normal file
51
app/interface/main/app-intl/dao/rank/dao.go
Normal file
@ -0,0 +1,51 @@
|
||||
package rank
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-card/model/card/rank"
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"go-common/library/ecode"
|
||||
httpx "go-common/library/net/http/blademaster"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
_allRank = "/data/rank/recent_all-app.json"
|
||||
)
|
||||
|
||||
// Dao is rank dao.
|
||||
type Dao struct {
|
||||
// http client
|
||||
clientAsyn *httpx.Client
|
||||
// all rank
|
||||
allRank string
|
||||
}
|
||||
|
||||
// New new a rank dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
// http client
|
||||
clientAsyn: httpx.NewClient(c.HTTPClientAsyn),
|
||||
allRank: c.Host.Rank + _allRank,
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// AllRank is.
|
||||
func (d *Dao) AllRank(c context.Context) (ranks []*rank.Rank, err error) {
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
List []*rank.Rank `json:"list"`
|
||||
}
|
||||
if err = d.clientAsyn.Get(c, d.allRank, "", nil, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(err, d.allRank)
|
||||
return
|
||||
}
|
||||
ranks = res.List
|
||||
return
|
||||
}
|
49
app/interface/main/app-intl/dao/rank/dao_test.go
Normal file
49
app/interface/main/app-intl/dao/rank/dao_test.go
Normal file
@ -0,0 +1,49 @@
|
||||
package rank
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestAllRank(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.AllRank(context.Background())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
61
app/interface/main/app-intl/dao/recommend/BUILD
Normal file
61
app/interface/main/app-intl/dao/recommend/BUILD
Normal file
@ -0,0 +1,61 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_test",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"api_test.go",
|
||||
"dao_test.go",
|
||||
"memcache_test.go",
|
||||
"redis_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
rundir = ".",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"api.go",
|
||||
"dao.go",
|
||||
"memcache.go",
|
||||
"redis.go",
|
||||
],
|
||||
importpath = "go-common/app/interface/main/app-intl/dao/recommend",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-card/model:go_default_library",
|
||||
"//app/interface/main/app-card/model/card/ai:go_default_library",
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//library/cache/memcache:go_default_library",
|
||||
"//library/cache/redis:go_default_library",
|
||||
"//library/ecode:go_default_library",
|
||||
"//library/net/http/blademaster: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"],
|
||||
)
|
124
app/interface/main/app-intl/dao/recommend/api.go
Normal file
124
app/interface/main/app-intl/dao/recommend/api.go
Normal file
@ -0,0 +1,124 @@
|
||||
package recommend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"go-common/app/interface/main/app-card/model"
|
||||
"go-common/app/interface/main/app-card/model/card/ai"
|
||||
"go-common/library/ecode"
|
||||
"go-common/library/net/metadata"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
_rcmd = "/pegasus/feed/%d"
|
||||
_hot = "/data/rank/reco-tmzb.json"
|
||||
_group = "/group_changes/pegasus.json"
|
||||
_top = "/feed/tag/top"
|
||||
)
|
||||
|
||||
// Recommend is.
|
||||
func (d *Dao) Recommend(c context.Context, plat int8, buvid string, mid int64, build, loginEvent int, zoneID int64, group int, interest, network string, style int, column model.ColumnStatus, flush int, autoplay string, now time.Time) (rs []*ai.Item, userFeature json.RawMessage, respCode int, newUser bool, err error) {
|
||||
if mid == 0 && buvid == "" {
|
||||
return
|
||||
}
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
uri := fmt.Sprintf(d.rcmd, group)
|
||||
params := url.Values{}
|
||||
params.Set("mid", strconv.FormatInt(mid, 10))
|
||||
params.Set("buvid", buvid)
|
||||
params.Set("plat", strconv.Itoa(int(plat)))
|
||||
params.Set("build", strconv.Itoa(build))
|
||||
params.Set("login_event", strconv.Itoa(loginEvent))
|
||||
params.Set("zone_id", strconv.FormatInt(zoneID, 10))
|
||||
params.Set("interest", interest)
|
||||
params.Set("network", network)
|
||||
if column > -1 {
|
||||
params.Set("column", strconv.Itoa(int(column)))
|
||||
}
|
||||
params.Set("style", strconv.Itoa(style))
|
||||
params.Set("flush", strconv.Itoa(flush))
|
||||
params.Set("autoplay_card", autoplay)
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
NewUser bool `json:"new_user"`
|
||||
UserFeature json.RawMessage `json:"user_feature"`
|
||||
Data []*ai.Item `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, uri, ip, params, &res); err != nil {
|
||||
respCode = ecode.ServerErr.Code()
|
||||
return
|
||||
}
|
||||
code := ecode.Int(res.Code)
|
||||
if !code.Equal(ecode.OK) {
|
||||
respCode = res.Code
|
||||
err = errors.Wrapf(code, "%s", uri+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
rs = res.Data
|
||||
userFeature = res.UserFeature
|
||||
newUser = res.NewUser
|
||||
return
|
||||
}
|
||||
|
||||
// Hots is.
|
||||
func (d *Dao) Hots(c context.Context) (aids []int64, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
List []struct {
|
||||
Aid int64 `json:"aid"`
|
||||
} `json:"list"`
|
||||
}
|
||||
if err = d.clientAsyn.Get(c, d.hot, ip, nil, &res); err != nil {
|
||||
return
|
||||
}
|
||||
code := ecode.Int(res.Code)
|
||||
if !code.Equal(ecode.OK) {
|
||||
err = errors.Wrapf(code, "%s", d.hot)
|
||||
return
|
||||
}
|
||||
for _, list := range res.List {
|
||||
if list.Aid != 0 {
|
||||
aids = append(aids, list.Aid)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// TagTop is.
|
||||
func (d *Dao) TagTop(c context.Context, mid, tid int64, rn int) (aids []int64, err error) {
|
||||
params := url.Values{}
|
||||
params.Set("src", "2")
|
||||
params.Set("pn", "1")
|
||||
params.Set("mid", strconv.FormatInt(mid, 10))
|
||||
params.Set("tag", strconv.FormatInt(tid, 10))
|
||||
params.Set("rn", strconv.Itoa(rn))
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data []int64 `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, d.top, "", params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
code := ecode.Int(res.Code)
|
||||
if !code.Equal(ecode.OK) {
|
||||
err = errors.Wrapf(code, "%s", d.top+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
aids = res.Data
|
||||
return
|
||||
}
|
||||
|
||||
// Group is.
|
||||
func (d *Dao) Group(c context.Context) (gm map[int64]int, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
err = d.clientAsyn.Get(c, d.group, ip, nil, &gm)
|
||||
return
|
||||
}
|
65
app/interface/main/app-intl/dao/recommend/api_test.go
Normal file
65
app/interface/main/app-intl/dao/recommend/api_test.go
Normal file
@ -0,0 +1,65 @@
|
||||
package recommend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestRecommend(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, _, _, _, err := d.Recommend(context.Background(), 1, "", 12, 123232, 2, 0, 2, "", "", 0, 1, 1, "", time.Now())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestHots(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Hots(context.Background())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestTagTop(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.TagTop(context.Background(), 12, 12, 12)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGroup(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Group(context.Background())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
61
app/interface/main/app-intl/dao/recommend/dao.go
Normal file
61
app/interface/main/app-intl/dao/recommend/dao.go
Normal file
@ -0,0 +1,61 @@
|
||||
package recommend
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"go-common/library/cache/memcache"
|
||||
"go-common/library/cache/redis"
|
||||
httpx "go-common/library/net/http/blademaster"
|
||||
)
|
||||
|
||||
// Dao is show dao.
|
||||
type Dao struct {
|
||||
// http client
|
||||
client *httpx.Client
|
||||
clientAsyn *httpx.Client
|
||||
// hetongzi
|
||||
hot string
|
||||
// bigdata
|
||||
rcmd string
|
||||
group string
|
||||
top string
|
||||
// redis
|
||||
redis *redis.Pool
|
||||
expireRds int
|
||||
// mc
|
||||
mc *memcache.Pool
|
||||
expireMc int32
|
||||
}
|
||||
|
||||
// New new a show dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
// http client
|
||||
client: httpx.NewClient(c.HTTPData),
|
||||
clientAsyn: httpx.NewClient(c.HTTPClientAsyn),
|
||||
// hetongzi
|
||||
hot: c.Host.Hetongzi + _hot,
|
||||
// bigdata
|
||||
rcmd: c.Host.Data + _rcmd,
|
||||
group: c.Host.BigData + _group,
|
||||
top: c.Host.Data + _top,
|
||||
// redis
|
||||
redis: redis.NewPool(c.Redis.Feed.Config),
|
||||
expireRds: int(time.Duration(c.Redis.Feed.ExpireRecommend) / time.Second),
|
||||
// mc
|
||||
mc: memcache.NewPool(c.Memcache.Cache.Config),
|
||||
expireMc: int32(time.Duration(c.Memcache.Cache.Expire) / time.Second),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Close close resource.
|
||||
func (d *Dao) Close() {
|
||||
if d.redis != nil {
|
||||
d.redis.Close()
|
||||
}
|
||||
if d.mc != nil {
|
||||
d.mc.Close()
|
||||
}
|
||||
}
|
41
app/interface/main/app-intl/dao/recommend/dao_test.go
Normal file
41
app/interface/main/app-intl/dao/recommend/dao_test.go
Normal file
@ -0,0 +1,41 @@
|
||||
package recommend
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
func TestClose(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
d.Close()
|
||||
})
|
||||
}
|
87
app/interface/main/app-intl/dao/recommend/memcache.go
Normal file
87
app/interface/main/app-intl/dao/recommend/memcache.go
Normal file
@ -0,0 +1,87 @@
|
||||
package recommend
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-card/model/card/ai"
|
||||
"go-common/library/cache/memcache"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
_prefixRcmdAids = "rc"
|
||||
_prefixRcmd = "rc2"
|
||||
)
|
||||
|
||||
func keyRcmdAids() string {
|
||||
return _prefixRcmdAids
|
||||
}
|
||||
|
||||
func keyRcmd() string {
|
||||
return _prefixRcmd
|
||||
}
|
||||
|
||||
// AddRcmdAidsCache add ai into cahce.
|
||||
func (d *Dao) AddRcmdAidsCache(c context.Context, aids []int64) (err error) {
|
||||
conn := d.mc.Get(c)
|
||||
key := keyRcmdAids()
|
||||
item := &memcache.Item{Key: key, Object: aids, Flags: memcache.FlagJSON, Expiration: d.expireMc}
|
||||
if err = conn.Set(item); err != nil {
|
||||
err = errors.Wrapf(err, "%v", aids)
|
||||
}
|
||||
conn.Close()
|
||||
return
|
||||
}
|
||||
|
||||
// RcmdAidsCache get ai cache data from cache
|
||||
func (d *Dao) RcmdAidsCache(c context.Context) (aids []int64, err error) {
|
||||
var r *memcache.Item
|
||||
conn := d.mc.Get(c)
|
||||
key := keyRcmdAids()
|
||||
defer conn.Close()
|
||||
if r, err = conn.Get(key); err != nil {
|
||||
if err == memcache.ErrNotFound {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
err = errors.Wrap(err, key)
|
||||
return
|
||||
}
|
||||
if err = conn.Scan(r, &aids); err != nil {
|
||||
err = errors.Wrapf(err, "%s", r.Value)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AddRcmdCache add ai into cahce.
|
||||
func (d *Dao) AddRcmdCache(c context.Context, is []*ai.Item) (err error) {
|
||||
conn := d.mc.Get(c)
|
||||
key := keyRcmd()
|
||||
item := &memcache.Item{Key: key, Object: is, Flags: memcache.FlagJSON, Expiration: d.expireMc}
|
||||
if err = conn.Set(item); err != nil {
|
||||
err = errors.Wrap(err, key)
|
||||
}
|
||||
conn.Close()
|
||||
return
|
||||
}
|
||||
|
||||
// RcmdCache get ai cache data from cache
|
||||
func (d *Dao) RcmdCache(c context.Context) (is []*ai.Item, err error) {
|
||||
var r *memcache.Item
|
||||
conn := d.mc.Get(c)
|
||||
key := keyRcmd()
|
||||
defer conn.Close()
|
||||
if r, err = conn.Get(key); err != nil {
|
||||
if err == memcache.ErrNotFound {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
err = errors.Wrap(err, key)
|
||||
return
|
||||
}
|
||||
if err = conn.Scan(r, &is); err != nil {
|
||||
err = errors.Wrapf(err, "%s", r.Value)
|
||||
}
|
||||
return
|
||||
}
|
41
app/interface/main/app-intl/dao/recommend/memcache_test.go
Normal file
41
app/interface/main/app-intl/dao/recommend/memcache_test.go
Normal file
@ -0,0 +1,41 @@
|
||||
package recommend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestAddRcmdAidsCache(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
err := d.AddRcmdAidsCache(context.Background(), []int64{12})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRcmdAidsCache(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.RcmdAidsCache(context.Background())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRcmdCache(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.RcmdCache(context.Background())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
50
app/interface/main/app-intl/dao/recommend/redis.go
Normal file
50
app/interface/main/app-intl/dao/recommend/redis.go
Normal file
@ -0,0 +1,50 @@
|
||||
package recommend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"go-common/library/cache/redis"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
// _prefixPos is.
|
||||
_prefixPos = "p_"
|
||||
)
|
||||
|
||||
// keyPos is.
|
||||
func keyPos(mid int64) string {
|
||||
return _prefixPos + strconv.FormatInt(mid%100000, 10)
|
||||
}
|
||||
|
||||
// PositionCache is.
|
||||
func (d *Dao) PositionCache(c context.Context, mid int64) (pos int, err error) {
|
||||
var (
|
||||
key = keyPos(mid)
|
||||
conn = d.redis.Get(c)
|
||||
)
|
||||
defer conn.Close()
|
||||
if pos, err = redis.Int(conn.Do("HGET", key, mid)); err != nil {
|
||||
if err == redis.ErrNil {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
err = errors.Wrapf(err, "conn.Do(HGET,%s,%d)", key, mid)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AddPositionCache is.
|
||||
func (d *Dao) AddPositionCache(c context.Context, mid int64, pos int) (err error) {
|
||||
var (
|
||||
key = keyPos(mid)
|
||||
conn = d.redis.Get(c)
|
||||
)
|
||||
defer conn.Close()
|
||||
if _, err = conn.Do("HSET", key, mid, pos); err != nil {
|
||||
err = errors.Wrapf(err, "conn.Do(HSET,%s,%d,%d)", key, mid, pos)
|
||||
}
|
||||
return
|
||||
}
|
30
app/interface/main/app-intl/dao/recommend/redis_test.go
Normal file
30
app/interface/main/app-intl/dao/recommend/redis_test.go
Normal file
@ -0,0 +1,30 @@
|
||||
package recommend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestPositionCache(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.PositionCache(context.Background(), 12)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAddPositionCache(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
err := d.AddPositionCache(context.Background(), 12, 1)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
45
app/interface/main/app-intl/dao/region/BUILD
Normal file
45
app/interface/main/app-intl/dao/region/BUILD
Normal file
@ -0,0 +1,45 @@
|
||||
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-intl/conf: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-intl/dao/region",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/interface/main/app-intl/model/region:go_default_library",
|
||||
"//library/database/sql: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"],
|
||||
)
|
59
app/interface/main/app-intl/dao/region/dao.go
Normal file
59
app/interface/main/app-intl/dao/region/dao.go
Normal file
@ -0,0 +1,59 @@
|
||||
package region
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"go-common/app/interface/main/app-intl/model/region"
|
||||
xsql "go-common/library/database/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// region
|
||||
_secSQL = "SELECT rid,name,logo,rank,goto,param,plat,area,build,conditions FROM region WHERE state=1 AND reid!=0"
|
||||
)
|
||||
|
||||
// Dao is.
|
||||
type Dao struct {
|
||||
db *xsql.DB
|
||||
get *xsql.Stmt
|
||||
}
|
||||
|
||||
// New a dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
db: xsql.NewMySQL(c.MySQL.Show),
|
||||
}
|
||||
// prepare
|
||||
d.get = d.db.Prepared(_secSQL)
|
||||
return
|
||||
}
|
||||
|
||||
// Seconds get all second region.
|
||||
func (d *Dao) Seconds(c context.Context) (rm map[int8]map[int16]*region.Region, err error) {
|
||||
rows, err := d.get.Query(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
rm = map[int8]map[int16]*region.Region{}
|
||||
for rows.Next() {
|
||||
a := ®ion.Region{}
|
||||
if err = rows.Scan(&a.Rid, &a.Name, &a.Logo, &a.Rank, &a.Goto, &a.Param, &a.Plat, &a.Area, &a.Build, &a.Condition); err != nil {
|
||||
return
|
||||
}
|
||||
if rs, ok := rm[a.Plat]; ok {
|
||||
rs[a.Rid] = a
|
||||
} else {
|
||||
rm[a.Plat] = map[int16]*region.Region{a.Rid: a}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Close close db resource.
|
||||
func (d *Dao) Close() {
|
||||
if d.db != nil {
|
||||
d.db.Close()
|
||||
}
|
||||
}
|
49
app/interface/main/app-intl/dao/region/dao_test.go
Normal file
49
app/interface/main/app-intl/dao/region/dao_test.go
Normal file
@ -0,0 +1,49 @@
|
||||
package region
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestSeconds(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Seconds(context.Background())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
47
app/interface/main/app-intl/dao/relation/BUILD
Normal file
47
app/interface/main/app-intl/dao/relation/BUILD
Normal file
@ -0,0 +1,47 @@
|
||||
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-intl/conf: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-intl/dao/relation",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/service/main/relation/model:go_default_library",
|
||||
"//app/service/main/relation/rpc/client: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"],
|
||||
)
|
43
app/interface/main/app-intl/dao/relation/dao.go
Normal file
43
app/interface/main/app-intl/dao/relation/dao.go
Normal file
@ -0,0 +1,43 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
relation "go-common/app/service/main/relation/model"
|
||||
relrpc "go-common/app/service/main/relation/rpc/client"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Dao is rpc dao.
|
||||
type Dao struct {
|
||||
// relation rpc
|
||||
relRPC *relrpc.Service
|
||||
}
|
||||
|
||||
// New new a relation dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
// relation rpc
|
||||
relRPC: relrpc.New(c.RelationRPC),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Stats fids stats
|
||||
func (d *Dao) Stats(c context.Context, mids []int64) (res map[int64]*relation.Stat, err error) {
|
||||
arg := &relation.ArgMids{Mids: mids}
|
||||
if res, err = d.relRPC.Stats(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Stat stat
|
||||
func (d *Dao) Stat(c context.Context, mid int64) (stat *relation.Stat, err error) {
|
||||
if stat, err = d.relRPC.Stat(c, &relation.ArgMid{Mid: mid}); err != nil {
|
||||
err = errors.Wrapf(err, "%v", mid)
|
||||
}
|
||||
return
|
||||
}
|
49
app/interface/main/app-intl/dao/relation/dao_test.go
Normal file
49
app/interface/main/app-intl/dao/relation/dao_test.go
Normal file
@ -0,0 +1,49 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestStats(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.Stats(context.Background(), []int64{1, 2, 3})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
46
app/interface/main/app-intl/dao/resource/BUILD
Normal file
46
app/interface/main/app-intl/dao/resource/BUILD
Normal file
@ -0,0 +1,46 @@
|
||||
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-intl/conf: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-intl/dao/resource",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/service/main/resource/model:go_default_library",
|
||||
"//app/service/main/resource/rpc/client:go_default_library",
|
||||
"//library/ecode: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"],
|
||||
)
|
40
app/interface/main/app-intl/dao/resource/dao.go
Normal file
40
app/interface/main/app-intl/dao/resource/dao.go
Normal file
@ -0,0 +1,40 @@
|
||||
package resource
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
"go-common/app/service/main/resource/model"
|
||||
rscrpc "go-common/app/service/main/resource/rpc/client"
|
||||
"go-common/library/ecode"
|
||||
)
|
||||
|
||||
// Dao is archive dao.
|
||||
type Dao struct {
|
||||
// rpc
|
||||
rscRPC *rscrpc.Service
|
||||
}
|
||||
|
||||
// New new a archive dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
// rpc
|
||||
rscRPC: rscrpc.New(c.ResourceRPC),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PlayerIcon is.
|
||||
func (d *Dao) PlayerIcon(c context.Context) (res *model.PlayerIcon, err error) {
|
||||
if res, err = d.rscRPC.PlayerIcon(c); err != nil {
|
||||
if ecode.Cause(err) == ecode.NothingFound {
|
||||
res, err = nil, nil
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PasterCID get all paster cid.
|
||||
func (d *Dao) PasterCID(c context.Context) (cids map[int64]int64, err error) {
|
||||
return d.rscRPC.PasterCID(c)
|
||||
}
|
57
app/interface/main/app-intl/dao/resource/dao_test.go
Normal file
57
app/interface/main/app-intl/dao/resource/dao_test.go
Normal file
@ -0,0 +1,57 @@
|
||||
package resource
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestPlayerIcon(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.PlayerIcon(context.Background())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPasterCID(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.PasterCID(context.Background())
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
56
app/interface/main/app-intl/dao/search/BUILD
Normal file
56
app/interface/main/app-intl/dao/search/BUILD
Normal 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 = ["dao_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
rundir = ".",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf: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-intl/dao/search",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/interface/main/app-intl/dao/archive:go_default_library",
|
||||
"//app/interface/main/app-intl/dao/bangumi:go_default_library",
|
||||
"//app/interface/main/app-intl/model:go_default_library",
|
||||
"//app/interface/main/app-intl/model/bangumi:go_default_library",
|
||||
"//app/interface/main/app-intl/model/search:go_default_library",
|
||||
"//app/service/main/archive/api:go_default_library",
|
||||
"//library/ecode:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/net/http/blademaster:go_default_library",
|
||||
"//library/net/metadata:go_default_library",
|
||||
"//library/sync/errgroup: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"],
|
||||
)
|
443
app/interface/main/app-intl/dao/search/dao.go
Normal file
443
app/interface/main/app-intl/dao/search/dao.go
Normal file
@ -0,0 +1,443 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
arcdao "go-common/app/interface/main/app-intl/dao/archive"
|
||||
bgmdao "go-common/app/interface/main/app-intl/dao/bangumi"
|
||||
"go-common/app/interface/main/app-intl/model"
|
||||
"go-common/app/interface/main/app-intl/model/bangumi"
|
||||
"go-common/app/interface/main/app-intl/model/search"
|
||||
"go-common/app/service/main/archive/api"
|
||||
"go-common/library/ecode"
|
||||
"go-common/library/log"
|
||||
httpx "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/metadata"
|
||||
"go-common/library/sync/errgroup"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
_main = "/main/search"
|
||||
_suggest3 = "/main/suggest/new"
|
||||
)
|
||||
|
||||
// Dao is search dao
|
||||
type Dao struct {
|
||||
client *httpx.Client
|
||||
arcDao *arcdao.Dao
|
||||
bgmDao *bgmdao.Dao
|
||||
main string
|
||||
suggest3 string
|
||||
}
|
||||
|
||||
// New initial search dao
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
client: httpx.NewClient(c.HTTPSearch),
|
||||
arcDao: arcdao.New(c),
|
||||
bgmDao: bgmdao.New(c),
|
||||
main: c.Host.Search + _main,
|
||||
suggest3: c.Host.Search + _suggest3,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Search app all search .
|
||||
func (d *Dao) Search(c context.Context, mid, zoneid int64, mobiApp, device, platform, buvid, keyword, duration, order, filtered, fromSource, recommend string, plat int8, seasonNum, movieNum, upUserNum, uvLimit, userNum, userVideoLimit, biliUserNum, biliUserVideoLimit, rid, highlight, build, pn, ps int, now time.Time) (res *search.Search, code int, err error) {
|
||||
var (
|
||||
req *http.Request
|
||||
ip = metadata.String(c, metadata.RemoteIP)
|
||||
)
|
||||
res = &search.Search{}
|
||||
params := url.Values{}
|
||||
params.Set("build", strconv.Itoa(build))
|
||||
params.Set("keyword", keyword)
|
||||
params.Set("main_ver", "v3")
|
||||
params.Set("highlight", strconv.Itoa(highlight))
|
||||
params.Set("mobi_app", mobiApp)
|
||||
params.Set("device", device)
|
||||
params.Set("userid", strconv.FormatInt(mid, 10))
|
||||
params.Set("tids", strconv.Itoa(rid))
|
||||
params.Set("page", strconv.Itoa(pn))
|
||||
params.Set("pagesize", strconv.Itoa(ps))
|
||||
params.Set("media_bangumi_num", strconv.Itoa(seasonNum))
|
||||
params.Set("bili_user_num", strconv.Itoa(biliUserNum))
|
||||
params.Set("bili_user_vl", strconv.Itoa(biliUserVideoLimit))
|
||||
params.Set("user_num", strconv.Itoa(userNum))
|
||||
params.Set("user_video_limit", strconv.Itoa(userVideoLimit))
|
||||
params.Set("query_rec_need", recommend)
|
||||
params.Set("platform", platform)
|
||||
params.Set("duration", duration)
|
||||
params.Set("order", order)
|
||||
params.Set("search_type", "all")
|
||||
params.Set("from_source", fromSource)
|
||||
if filtered == "1" {
|
||||
params.Set("filtered", filtered)
|
||||
}
|
||||
params.Set("zone_id", strconv.FormatInt(zoneid, 10))
|
||||
params.Set("media_ft_num", strconv.Itoa(movieNum))
|
||||
params.Set("is_new_pgc", "1")
|
||||
params.Set("is_internation", "1")
|
||||
params.Set("no_display_default", "game,live_room")
|
||||
params.Set("flow_need", "1")
|
||||
params.Set("app_highlight", "media_bangumi,media_ft")
|
||||
// new request
|
||||
if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Set("Buvid", buvid)
|
||||
if err = d.client.Do(c, req, res); err != nil {
|
||||
return
|
||||
}
|
||||
b, _ := json.Marshal(res)
|
||||
log.Error("wocao----%s---%s---%s", d.main+"?"+params.Encode(), buvid, b)
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
|
||||
}
|
||||
for _, flow := range res.FlowResult {
|
||||
flow.Change()
|
||||
}
|
||||
code = res.Code
|
||||
return
|
||||
}
|
||||
|
||||
// Season2 search new season data.
|
||||
func (d *Dao) Season2(c context.Context, mid int64, keyword, mobiApp, device, platform, buvid string, highlight, build, pn, ps int) (st *search.TypeSearch, err error) {
|
||||
var (
|
||||
req *http.Request
|
||||
ip = metadata.String(c, metadata.RemoteIP)
|
||||
seasonIDs []int64
|
||||
bangumis map[string]*bangumi.Card
|
||||
)
|
||||
params := url.Values{}
|
||||
params.Set("main_ver", "v3")
|
||||
params.Set("platform", platform)
|
||||
params.Set("build", strconv.Itoa(build))
|
||||
params.Set("keyword", keyword)
|
||||
params.Set("userid", strconv.FormatInt(mid, 10))
|
||||
params.Set("mobi_app", mobiApp)
|
||||
params.Set("device", device)
|
||||
params.Set("page", strconv.Itoa(pn))
|
||||
params.Set("pagesize", strconv.Itoa(ps))
|
||||
params.Set("search_type", "media_bangumi")
|
||||
params.Set("order", "totalrank")
|
||||
params.Set("highlight", strconv.Itoa(highlight))
|
||||
params.Set("app_highlight", "media_bangumi")
|
||||
params.Set("is_pgc_all", "1")
|
||||
if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Set("Buvid", buvid)
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
SeID string `json:"seid"`
|
||||
Total int `json:"numResults"`
|
||||
Pages int `json:"numPages"`
|
||||
List []*search.Media `json:"result"`
|
||||
}
|
||||
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.main+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
for _, v := range res.List {
|
||||
seasonIDs = append(seasonIDs, v.SeasonID)
|
||||
}
|
||||
if len(seasonIDs) > 0 {
|
||||
if bangumis, err = d.bgmDao.Card(c, mid, seasonIDs); err != nil {
|
||||
log.Error("%+v", err)
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
items := make([]*search.Item, 0, len(res.List))
|
||||
for _, v := range res.List {
|
||||
si := &search.Item{}
|
||||
si.FromMedia(v, "", model.GotoBangumi, bangumis)
|
||||
items = append(items, si)
|
||||
}
|
||||
st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Total: res.Total, Items: items}
|
||||
return
|
||||
}
|
||||
|
||||
// MovieByType2 search new movie data from api .
|
||||
func (d *Dao) MovieByType2(c context.Context, mid int64, keyword, mobiApp, device, platform, buvid string, highlight, build, pn, ps int) (st *search.TypeSearch, err error) {
|
||||
var (
|
||||
req *http.Request
|
||||
ip = metadata.String(c, metadata.RemoteIP)
|
||||
seasonIDs []int64
|
||||
bangumis map[string]*bangumi.Card
|
||||
)
|
||||
params := url.Values{}
|
||||
params.Set("keyword", keyword)
|
||||
params.Set("mobi_app", mobiApp)
|
||||
params.Set("device", device)
|
||||
params.Set("platform", platform)
|
||||
params.Set("userid", strconv.FormatInt(mid, 10))
|
||||
params.Set("build", strconv.Itoa(build))
|
||||
params.Set("main_ver", "v3")
|
||||
params.Set("search_type", "media_ft")
|
||||
params.Set("page", strconv.Itoa(pn))
|
||||
params.Set("pagesize", strconv.Itoa(ps))
|
||||
params.Set("order", "totalrank")
|
||||
params.Set("highlight", strconv.Itoa(highlight))
|
||||
params.Set("app_highlight", "media_ft")
|
||||
params.Set("is_pgc_all", "1")
|
||||
if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Set("Buvid", buvid)
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
SeID string `json:"seid"`
|
||||
Total int `json:"numResults"`
|
||||
Pages int `json:"numPages"`
|
||||
List []*search.Media `json:"result"`
|
||||
}
|
||||
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.main+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
for _, v := range res.List {
|
||||
seasonIDs = append(seasonIDs, v.SeasonID)
|
||||
}
|
||||
if len(seasonIDs) > 0 {
|
||||
if bangumis, err = d.bgmDao.Card(c, mid, seasonIDs); err != nil {
|
||||
log.Error("%+v", err)
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
items := make([]*search.Item, 0, len(res.List))
|
||||
for _, v := range res.List {
|
||||
si := &search.Item{}
|
||||
si.FromMedia(v, "", model.GotoMovie, bangumis)
|
||||
items = append(items, si)
|
||||
}
|
||||
st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Total: res.Total, Items: items}
|
||||
return
|
||||
}
|
||||
|
||||
// Upper search upper data.
|
||||
func (d *Dao) Upper(c context.Context, mid int64, keyword, mobiApp, device, platform, buvid, filtered, order string, biliUserVL, highlight, build, userType, orderSort, pn, ps int, now time.Time) (st *search.TypeSearch, err error) {
|
||||
var (
|
||||
req *http.Request
|
||||
avids []int64
|
||||
avm map[int64]*api.Arc
|
||||
ip = metadata.String(c, metadata.RemoteIP)
|
||||
)
|
||||
params := url.Values{}
|
||||
params.Set("main_ver", "v3")
|
||||
params.Set("keyword", keyword)
|
||||
params.Set("userid", strconv.FormatInt(mid, 10))
|
||||
params.Set("highlight", strconv.Itoa(highlight))
|
||||
params.Set("mobi_app", mobiApp)
|
||||
params.Set("device", device)
|
||||
params.Set("func", "search")
|
||||
params.Set("page", strconv.Itoa(pn))
|
||||
params.Set("pagesize", strconv.Itoa(ps))
|
||||
params.Set("smerge", "1")
|
||||
params.Set("platform", platform)
|
||||
params.Set("build", strconv.Itoa(build))
|
||||
params.Set("search_type", "bili_user")
|
||||
params.Set("bili_user_vl", strconv.Itoa(biliUserVL))
|
||||
params.Set("user_type", strconv.Itoa(userType))
|
||||
params.Set("order_sort", strconv.Itoa(orderSort))
|
||||
params.Set("order", order)
|
||||
params.Set("source_type", "0")
|
||||
if filtered == "1" {
|
||||
params.Set("filtered", filtered)
|
||||
}
|
||||
// new request
|
||||
if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Set("Buvid", buvid)
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
SeID string `json:"seid"`
|
||||
Pages int `json:"numPages"`
|
||||
List []*search.User `json:"result"`
|
||||
}
|
||||
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.main+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
items := make([]*search.Item, 0, len(res.List))
|
||||
for _, v := range res.List {
|
||||
for _, vr := range v.Res {
|
||||
avids = append(avids, vr.Aid)
|
||||
}
|
||||
}
|
||||
g, ctx := errgroup.WithContext(c)
|
||||
if len(avids) != 0 {
|
||||
g.Go(func() (err error) {
|
||||
if avm, err = d.arcDao.Archives(ctx, avids); err != nil {
|
||||
log.Error("Upper %+v", err)
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
})
|
||||
}
|
||||
if err = g.Wait(); err != nil {
|
||||
log.Error("%+v", err)
|
||||
return
|
||||
}
|
||||
for _, v := range res.List {
|
||||
si := &search.Item{}
|
||||
si.FromUpUser(v, avm)
|
||||
items = append(items, si)
|
||||
}
|
||||
st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Items: items}
|
||||
return
|
||||
}
|
||||
|
||||
// ArticleByType search article.
|
||||
func (d *Dao) ArticleByType(c context.Context, mid, zoneid int64, keyword, mobiApp, device, platform, buvid, filtered, order, sType string, plat int8, categoryID, build, highlight, pn, ps int, now time.Time) (st *search.TypeSearch, err error) {
|
||||
var (
|
||||
req *http.Request
|
||||
ip = metadata.String(c, metadata.RemoteIP)
|
||||
)
|
||||
params := url.Values{}
|
||||
params.Set("keyword", keyword)
|
||||
params.Set("mobi_app", mobiApp)
|
||||
params.Set("device", device)
|
||||
params.Set("platform", platform)
|
||||
params.Set("userid", strconv.FormatInt(mid, 10))
|
||||
params.Set("build", strconv.Itoa(build))
|
||||
params.Set("main_ver", "v3")
|
||||
params.Set("highlight", strconv.Itoa(highlight))
|
||||
params.Set("search_type", sType)
|
||||
params.Set("category_id", strconv.Itoa(categoryID))
|
||||
params.Set("page", strconv.Itoa(pn))
|
||||
params.Set("pagesize", strconv.Itoa(ps))
|
||||
params.Set("order", order)
|
||||
if filtered == "1" {
|
||||
params.Set("filtered", filtered)
|
||||
}
|
||||
if model.IsOverseas(plat) {
|
||||
params.Set("use_area", "1")
|
||||
params.Set("zone_id", strconv.FormatInt(zoneid, 10))
|
||||
}
|
||||
if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Set("Buvid", buvid)
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
SeID string `json:"seid"`
|
||||
Pages int `json:"numPages"`
|
||||
List []*search.Article `json:"result"`
|
||||
}
|
||||
if err = d.client.Do(c, req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != ecode.OK.Code() {
|
||||
if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
|
||||
}
|
||||
return
|
||||
}
|
||||
items := make([]*search.Item, 0, len(res.List))
|
||||
for _, v := range res.List {
|
||||
si := &search.Item{}
|
||||
si.FromArticle(v)
|
||||
items = append(items, si)
|
||||
}
|
||||
st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Items: items}
|
||||
return
|
||||
}
|
||||
|
||||
// Channel for search channel
|
||||
func (d *Dao) Channel(c context.Context, mid int64, keyword, mobiApp, platform, buvid, device, order, sType string, build, pn, ps, highlight int) (st *search.TypeSearch, err error) {
|
||||
var (
|
||||
req *http.Request
|
||||
ip = metadata.String(c, metadata.RemoteIP)
|
||||
)
|
||||
params := url.Values{}
|
||||
params.Set("keyword", keyword)
|
||||
params.Set("mobi_app", mobiApp)
|
||||
params.Set("platform", platform)
|
||||
params.Set("userid", strconv.FormatInt(mid, 10))
|
||||
params.Set("build", strconv.Itoa(build))
|
||||
params.Set("main_ver", "v3")
|
||||
params.Set("search_type", sType)
|
||||
params.Set("page", strconv.Itoa(pn))
|
||||
params.Set("pagesize", strconv.Itoa(ps))
|
||||
params.Set("device", device)
|
||||
params.Set("order", order)
|
||||
params.Set("highlight", strconv.Itoa(highlight))
|
||||
// new request
|
||||
if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Set("Buvid", buvid)
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
SeID string `json:"seid"`
|
||||
Pages int `json:"numPages"`
|
||||
List []*search.Channel `json:"result"`
|
||||
}
|
||||
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.main+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
items := make([]*search.Item, 0, len(res.List))
|
||||
for _, v := range res.List {
|
||||
si := &search.Item{}
|
||||
si.FromChannel(v)
|
||||
items = append(items, si)
|
||||
}
|
||||
st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Items: items}
|
||||
return
|
||||
}
|
||||
|
||||
// Suggest3 suggest data.
|
||||
func (d *Dao) Suggest3(c context.Context, mid int64, platform, buvid, term string, build, highlight int, mobiApp string, now time.Time) (res *search.Suggest3, err error) {
|
||||
var (
|
||||
req *http.Request
|
||||
ip = metadata.String(c, metadata.RemoteIP)
|
||||
)
|
||||
params := url.Values{}
|
||||
params.Set("suggest_type", "accurate")
|
||||
params.Set("platform", platform)
|
||||
params.Set("mobi_app", mobiApp)
|
||||
params.Set("clientip", ip)
|
||||
params.Set("highlight", strconv.Itoa(highlight))
|
||||
params.Set("build", strconv.Itoa(build))
|
||||
if mid != 0 {
|
||||
params.Set("userid", strconv.FormatInt(mid, 10))
|
||||
}
|
||||
params.Set("term", term)
|
||||
params.Set("sug_num", "10")
|
||||
params.Set("buvid", buvid)
|
||||
if req, err = d.client.NewRequest("GET", d.suggest3, ip, params); err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Set("Buvid", buvid)
|
||||
res = &search.Suggest3{}
|
||||
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.suggest3+"?"+params.Encode())
|
||||
}
|
||||
return
|
||||
}
|
87
app/interface/main/app-intl/dao/search/dao_test.go
Normal file
87
app/interface/main/app-intl/dao/search/dao_test.go
Normal file
@ -0,0 +1,87 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestSearch(t *testing.T) {
|
||||
Convey("get Search", t, func() {
|
||||
res, _, err := d.Search(context.Background(), 1, 2, "iphone", "phone", "1", "6E657F43-A770-4F7B-A6AE-FDFFCA8ED46216837infoc", "123", "0", "1", "1", "1", "1", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 8160, 1, 20, time.Now())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
So(res, ShouldNotBeEmpty)
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpper(t *testing.T) {
|
||||
Convey("get Upper", t, func() {
|
||||
res, err := d.Upper(context.Background(), 1, "iphone", "phone", "1", "6E657F43-A770-4F7B-A6AE-FDFFCA8ED46216837infoc", "123", "0", "1", 1, 2, 3, 4, 5, 1, 20, time.Now())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
So(res, ShouldNotBeEmpty)
|
||||
})
|
||||
}
|
||||
|
||||
func TestArticleByType(t *testing.T) {
|
||||
Convey("get ArticleByType", t, func() {
|
||||
res, err := d.ArticleByType(context.Background(), 1, 12313, "iphone", "phone", "1", "6E657F43-A770-4F7B-A6AE-FDFFCA8ED46216837infoc", "123", "0", "1", "2", int8(1), 1, 8190, 1, 1, 20, time.Now())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
So(res, ShouldNotBeEmpty)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSuggest3(t *testing.T) {
|
||||
Convey("get Suggest3", t, func() {
|
||||
res, err := d.Suggest3(context.Background(), 12313, "ios", "6E657F43-A770-4F7B-A6AE-FDFFCA8ED46216837infoc", "123", 8190, 1, "iphone", time.Now())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
So(res, ShouldNotBeEmpty)
|
||||
})
|
||||
}
|
58
app/interface/main/app-intl/dao/tag/BUILD
Normal file
58
app/interface/main/app-intl/dao/tag/BUILD
Normal file
@ -0,0 +1,58 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_test",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"api_test.go",
|
||||
"dao_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
rundir = ".",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"api.go",
|
||||
"dao.go",
|
||||
],
|
||||
importpath = "go-common/app/interface/main/app-intl/dao/tag",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-interface/model/tag:go_default_library",
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/interface/main/app-intl/model/tag:go_default_library",
|
||||
"//app/interface/main/tag/model:go_default_library",
|
||||
"//app/interface/main/tag/rpc/client:go_default_library",
|
||||
"//library/ecode:go_default_library",
|
||||
"//library/net/http/blademaster:go_default_library",
|
||||
"//library/net/metadata:go_default_library",
|
||||
"//library/xstr: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"],
|
||||
)
|
39
app/interface/main/app-intl/dao/tag/api.go
Normal file
39
app/interface/main/app-intl/dao/tag/api.go
Normal file
@ -0,0 +1,39 @@
|
||||
package tag
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
tagmdl "go-common/app/interface/main/app-interface/model/tag"
|
||||
"go-common/library/ecode"
|
||||
"go-common/library/net/metadata"
|
||||
"go-common/library/xstr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
_mInfo = "/x/internal/tag/minfo"
|
||||
)
|
||||
|
||||
// TagInfos get tag infos by tagIds
|
||||
func (d *Dao) TagInfos(c context.Context, tags []int64, mid int64) (tagMyInfo []*tagmdl.Tag, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
params := url.Values{}
|
||||
params.Set("tag_id", xstr.JoinInts(tags))
|
||||
params.Set("mid", strconv.FormatInt(mid, 10))
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data []*tagmdl.Tag `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, d.mInfo, ip, params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != ecode.OK.Code() {
|
||||
err = errors.Wrap(ecode.Int(res.Code), d.mInfo+"?"+params.Encode())
|
||||
return
|
||||
}
|
||||
tagMyInfo = res.Data
|
||||
return
|
||||
}
|
19
app/interface/main/app-intl/dao/tag/api_test.go
Normal file
19
app/interface/main/app-intl/dao/tag/api_test.go
Normal file
@ -0,0 +1,19 @@
|
||||
package tag
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestTagInfos(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.TagInfos(context.Background(), []int64{1, 2}, 1)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
73
app/interface/main/app-intl/dao/tag/dao.go
Normal file
73
app/interface/main/app-intl/dao/tag/dao.go
Normal file
@ -0,0 +1,73 @@
|
||||
package tag
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
tagmdl "go-common/app/interface/main/app-intl/model/tag"
|
||||
tag "go-common/app/interface/main/tag/model"
|
||||
tagrpc "go-common/app/interface/main/tag/rpc/client"
|
||||
"go-common/library/ecode"
|
||||
httpx "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/metadata"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Dao struct
|
||||
type Dao struct {
|
||||
// conf
|
||||
// http client
|
||||
mInfo string
|
||||
client *httpx.Client
|
||||
tagRPC *tagrpc.Service
|
||||
}
|
||||
|
||||
// New a dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
client: httpx.NewClient(c.HTTPTag),
|
||||
mInfo: c.Host.APICo + _mInfo,
|
||||
tagRPC: tagrpc.New2(c.TagRPC),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// InfoByIDs is.
|
||||
func (d *Dao) InfoByIDs(c context.Context, mid int64, tids []int64) (tm map[int64]*tag.Tag, err error) {
|
||||
var ts []*tag.Tag
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &tag.ArgIDs{IDs: tids, Mid: mid, RealIP: ip}
|
||||
if ts, err = d.tagRPC.InfoByIDs(c, arg); err != nil {
|
||||
if err == ecode.NothingFound {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
return
|
||||
}
|
||||
tm = make(map[int64]*tag.Tag, len(ts))
|
||||
for _, t := range ts {
|
||||
tm[t.ID] = t
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ArcTags get tags data from api.
|
||||
func (d *Dao) ArcTags(c context.Context, aid, mid int64) (tags []*tagmdl.Tag, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &tag.ArgAid{Aid: aid, Mid: mid, RealIP: ip}
|
||||
res, err := d.tagRPC.ArcTags(c, arg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(res) == 0 {
|
||||
return
|
||||
}
|
||||
tags = make([]*tagmdl.Tag, 0, len(res))
|
||||
for _, t := range res {
|
||||
tag := &tagmdl.Tag{ID: t.ID, Name: t.Name, Cover: t.Cover, Likes: t.Likes, Hates: t.Hates, Liked: t.Liked, Hated: t.Hated, Attribute: t.Attribute}
|
||||
tags = append(tags, tag)
|
||||
}
|
||||
return
|
||||
}
|
60
app/interface/main/app-intl/dao/tag/dao_test.go
Normal file
60
app/interface/main/app-intl/dao/tag/dao_test.go
Normal file
@ -0,0 +1,60 @@
|
||||
package tag
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestInfoByIDs(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.InfoByIDs(context.Background(), 12, []int64{12})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestArcTags(t *testing.T) {
|
||||
Convey(t.Name(), t, func() {
|
||||
_, err := d.ArcTags(context.Background(), 1, 2)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
err = nil
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
47
app/interface/main/app-intl/dao/thumbup/BUILD
Normal file
47
app/interface/main/app-intl/dao/thumbup/BUILD
Normal file
@ -0,0 +1,47 @@
|
||||
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"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf: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-intl/dao/thumbup",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/service/main/thumbup/model:go_default_library",
|
||||
"//app/service/main/thumbup/rpc/client: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"],
|
||||
)
|
59
app/interface/main/app-intl/dao/thumbup/dao.go
Normal file
59
app/interface/main/app-intl/dao/thumbup/dao.go
Normal file
@ -0,0 +1,59 @@
|
||||
package thumbup
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
thumbup "go-common/app/service/main/thumbup/model"
|
||||
thumbuprpc "go-common/app/service/main/thumbup/rpc/client"
|
||||
"go-common/library/net/metadata"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Dao is tag dao
|
||||
type Dao struct {
|
||||
thumbupRPC *thumbuprpc.Service
|
||||
}
|
||||
|
||||
// New initial tag dao
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
thumbupRPC: thumbuprpc.New(c.ThumbupRPC),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Like is like view.
|
||||
func (d *Dao) Like(c context.Context, mid, upMid int64, business string, messageID int64, typ int8) (err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &thumbup.ArgLike{Mid: mid, UpMid: upMid, Business: business, MessageID: messageID, Type: typ, RealIP: ip}
|
||||
return d.thumbupRPC.Like(c, arg)
|
||||
}
|
||||
|
||||
// LikeWithStat is like with stat.
|
||||
func (d *Dao) LikeWithStat(c context.Context, mid, upMid int64, business string, messageID int64, typ int8) (stat *thumbup.Stats, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &thumbup.ArgLike{Mid: mid, UpMid: upMid, Business: business, MessageID: messageID, Type: typ, RealIP: ip}
|
||||
return d.thumbupRPC.LikeWithStats(c, arg)
|
||||
}
|
||||
|
||||
// HasLike user has like
|
||||
func (d *Dao) HasLike(c context.Context, mid int64, business string, messageIDs []int64) (res map[int64]int8, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &thumbup.ArgHasLike{Mid: mid, MessageIDs: messageIDs, Business: business, RealIP: ip}
|
||||
if res, err = d.thumbupRPC.HasLike(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Stat is
|
||||
func (d *Dao) Stat(c context.Context, mid int64, business string, messageIDs []int64) (res map[int64]*thumbup.Stats, err error) {
|
||||
ip := metadata.String(c, metadata.RemoteIP)
|
||||
arg := &thumbup.ArgStats{Business: business, MessageIDs: messageIDs, RealIP: ip}
|
||||
if res, err = d.thumbupRPC.Stats(c, arg); err != nil {
|
||||
err = errors.Wrapf(err, "%v", arg)
|
||||
}
|
||||
return
|
||||
}
|
61
app/interface/main/app-intl/dao/thumbup/dao_test.go
Normal file
61
app/interface/main/app-intl/dao/thumbup/dao_test.go
Normal file
@ -0,0 +1,61 @@
|
||||
package thumbup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "02007e8d0f77d31baee89acb5ce6d3ac")
|
||||
flag.Set("tree_id", "64518")
|
||||
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/app-intl-test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestLike(t *testing.T) {
|
||||
Convey("TestLike", t, func(ctx C) {
|
||||
err := d.Like(context.Background(), 27833317, 96070394, "", 33552993, 1)
|
||||
ctx.So(err, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestLikeWithStat(t *testing.T) {
|
||||
Convey("TestLikeWithStat", t, func(ctx C) {
|
||||
gotStat, err := d.LikeWithStat(context.Background(), 27833317, 96070394, "", 33552993, 1)
|
||||
ctx.So(gotStat, ShouldBeNil)
|
||||
ctx.So(err, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestHasLike(t *testing.T) {
|
||||
Convey("TestHasLike", t, func(ctx C) {
|
||||
gotRes, err := d.HasLike(context.Background(), 27833317, "", []int64{33552993})
|
||||
ctx.So(gotRes, ShouldBeEmpty)
|
||||
ctx.So(err, ShouldNotBeNil)
|
||||
})
|
||||
}
|
46
app/interface/main/app-intl/dao/ugcpay/BUILD
Normal file
46
app/interface/main/app-intl/dao/ugcpay/BUILD
Normal file
@ -0,0 +1,46 @@
|
||||
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-intl/conf: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-intl/dao/ugcpay",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/app-intl/conf:go_default_library",
|
||||
"//app/service/main/ugcpay/api/grpc/v1:go_default_library",
|
||||
"//library/log: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"],
|
||||
)
|
36
app/interface/main/app-intl/dao/ugcpay/dao.go
Normal file
36
app/interface/main/app-intl/dao/ugcpay/dao.go
Normal file
@ -0,0 +1,36 @@
|
||||
package ugcpay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
ugcpay "go-common/app/service/main/ugcpay/api/grpc/v1"
|
||||
"go-common/library/log"
|
||||
)
|
||||
|
||||
// Dao is ugcpay dao.
|
||||
type Dao struct {
|
||||
// rpc
|
||||
ugcpayRPC ugcpay.UGCPayClient
|
||||
}
|
||||
|
||||
// New new a archive dao.
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{}
|
||||
var err error
|
||||
d.ugcpayRPC, err = ugcpay.NewClient(c.UGCpayClient)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("ugcpay NewClient error(%v)", err))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AssetRelation is
|
||||
func (d *Dao) AssetRelation(c context.Context, aid, mid int64) (relation *ugcpay.AssetRelationResp, err error) {
|
||||
if relation, err = d.ugcpayRPC.AssetRelation(c, &ugcpay.AssetRelationReq{Oid: aid, Mid: mid, Otype: "archive"}); err != nil {
|
||||
log.Error("d.ugcpayRPC.AssetRelationDetail(%d) error(%+v)", aid, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
51
app/interface/main/app-intl/dao/ugcpay/dao_test.go
Normal file
51
app/interface/main/app-intl/dao/ugcpay/dao_test.go
Normal file
@ -0,0 +1,51 @@
|
||||
package ugcpay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go-common/app/interface/main/app-intl/conf"
|
||||
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.app-svr.app-intl")
|
||||
flag.Set("conf_token", "e477d98a7c5689623eca4f32f6af735c")
|
||||
flag.Set("tree_id", "52581")
|
||||
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")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
m.Run()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func TestAssetRelation(t *testing.T) {
|
||||
var (
|
||||
c = context.Background()
|
||||
aid = int64(10110670)
|
||||
mid = int64(2)
|
||||
)
|
||||
convey.Convey("AssetRelation", t, func(ctx convey.C) {
|
||||
_, err := d.AssetRelation(c, aid, mid)
|
||||
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
})
|
||||
})
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user