Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"conf.go",
"license.go",
"ugc.go",
],
importpath = "go-common/app/job/main/tv/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/log: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/queue/databus: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"],
)

View File

@@ -0,0 +1,232 @@
package conf
import (
"errors"
"flag"
"go-common/library/cache/memcache"
"go-common/library/cache/redis"
"go-common/library/conf"
"go-common/library/database/sql"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/rpc"
"go-common/library/net/rpc/warden"
"go-common/library/net/trace"
"go-common/library/queue/databus"
xtime "go-common/library/time"
"github.com/BurntSushi/toml"
)
// Conf global variable.
var (
Conf = &Config{}
client *conf.Client
confPath string
)
// Config struct of conf.
type Config struct {
// base
// log
Log *log.Config
// Databus cfg
ContentSub *databus.Config
ArchiveNotifySub *databus.Config
UgcSub *databus.Config
// tracer
Tracer *trace.Config
// http
HTTPServer *bm.ServerConfig
// db
Mysql *sql.Config
// sync params
Sync *Sync
// memcache
Memcache *Memcache
// redis
Redis *Redis
// playControl related config
PlayControl *PlayControl
// HTTPClient .
HTTPClient *bm.ClientConfig
// Search Cfg
Search *Search
// UgcSync cfg
UgcSync *UgcSync
// grpc
ArcClient *warden.ClientConfig
ArchiveRPC *rpc.ClientConfig
AccClient *warden.ClientConfig
Cfg *Cfg
Report *Report
DpClient *bm.ClientConfig
Style *Style
}
// Style .
type Style struct {
LabelSpan xtime.Duration
StyleSpan xtime.Duration
}
// Report data .
type Report struct {
ReportURI string
UpDataURI string
TimeDelay string
SendDataDelay xtime.Duration
Env string
RoutineCount int
ReadSize int
Expire xtime.Duration
SeTimeSpan xtime.Duration
CronAc string
CronAd string
CronPd string
CronVe string
}
// Cfg contains various of configuration
type Cfg struct {
TitleFilter []string
LessStrategy int
PgcTypes []string // pgc types name, need to filter these ugc archives
PGCZonesID []int // all the zones' ID that need to be loaded
UgcZones map[string]*UgcType
SyncRetry *SyncRetry // sync retry
Merak *Merak
}
// Merak cfg
type Merak struct {
Host string
Key string
Secret string
Names []string
Template string
Title string
Cron string
Onlyfree bool // if true, we consider free+audited episodes, otherwise we consider only audited episodes
}
// SyncRetry def.
type SyncRetry struct {
MaxRetry int // max retry times for pgc already-passed sn & ep
RetryFre xtime.Duration
}
// UgcType def.
type UgcType struct {
TID int32
Name string
}
// Search represents the config for the search suggestion module
type Search struct {
UgcSwitch string // the Ugc search suggest Switch
SugPath string // the tvsug file local path
Md5Path string // the tvsug md5 file local path
FTP *FTP // the ftp info
PgcContPath string // the pgc content file local path
PgcContMd5Path string // the pgc content md5 file local path
UgcContPath string // the ugc content file local path
UgcContMd5Path string // the ugc content md5 file local path
Cfg *SearchCfg
}
//SearchCfg synchronize files time
type SearchCfg struct {
UploadFre xtime.Duration
}
// FTP represents the ftp login info
type FTP struct {
Pass string
User string
Host string
URL string
Timeout xtime.Duration // timeout in seconds
UseEPSV bool
RemoteFName string // file name in remote ftp server
RemoteMd5 string // md5 file name in remote ftp server
RemotePgcCont string // pgc file name in remote ftp server
RemotePgcURL string // RemotePgcURL remote search pgc url dir
RemotePgcContMd5 string // pgc md5 file name in remote ftp server
RemoteUgcCont string // ugc file name in remote ftp server
RemoteUgcURL string // RemotePgcCont remote search ugc url dir
RemoteUgcContMd5 string // ugc md5 file name in remote ftp server
}
// Redis redis
type Redis struct {
*redis.Config
Expire xtime.Duration
CronPGC string
CronUGC string
}
// PlayControl is the configuration for the play control interface, related to MC
type PlayControl struct {
ProducerCron string
PieceSize int
}
// Memcache config
type Memcache struct {
*memcache.Config
Expire xtime.Duration
ExpireMedia xtime.Duration
}
func local() (err error) {
_, err = toml.DecodeFile(confPath, &Conf)
return
}
func remote() (err error) {
if client, err = conf.New(); err != nil {
return
}
if err = load(); err != nil {
return
}
go func() {
for range client.Event() {
log.Info("config reload")
if load() != nil {
log.Error("config reload error (%v)", err)
}
}
}()
return
}
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
}
func init() {
flag.StringVar(&confPath, "conf", "", "default config path")
}
// Init int config
func Init() error {
if confPath != "" {
return local()
}
return remote()
}

View File

@@ -0,0 +1,59 @@
package conf
import xtime "go-common/library/time"
// Sync struct defines the parameters for the data sync to license owner
type Sync struct {
HTTPTimeout xtime.Duration
DialTimeout xtime.Duration
LogSize int
LConf LicenseConf // conf for the sync with License Owner
PlayURL PlayURL // playurl config
API LicenseURL // license owner url
Frequency Duration
AuditPrefix string // the prefix for audit pgc data
UGCPrefix string // the prefix for audit ugc data
Sign string
}
// LicenseConf defubes the configuration about the comm with the license owner
type LicenseConf struct {
// how many programs can be contained in one message
SizeMsg int
// cpcode recognized by License owner
CPCode string
// number of modified season to sync in one time
NbSeason int
}
// PlayURL defines the conf to have the temp play URL
type PlayURL struct {
Upsigsecret string // key of playurl
Deadline string // deadline of playurl
PlayPath string // path of playurl
API string // the api to get the playurl with CID
Qn string // quality of the video
Deadcodes []int // playurl response codes, for them we think the video is dead and delete it
}
// Duration defines the frequencies of the data sync/wait
type Duration struct {
// Modified Season sync frequency
FreModSeason xtime.Duration
// how much time wait if error
ErrorWait xtime.Duration
// unit: seconds. if it's 3600, that means when we found season is delayed ( not in DB yet ), we postpone all its eps auditing one hour
AuditDelay int64
// unit: seconds. used for rejected season case, we re-audit its content in one day
RejectWait int
// one minute for the data to sync ( avoid selecting the same data )
WaitCall int
}
// LicenseURL defines the API address of the license owner
type LicenseURL struct {
AddURL string
DelSeasonURL string
DelEPURL string
UpdateURL string
}

View File

@@ -0,0 +1,48 @@
package conf
import (
xtime "go-common/library/time"
)
// UgcSync defines the params for ugc sync
type UgcSync struct {
Frequency *UgcFre
Batch *Batch
Cfg *UgcCfg
}
// UgcCfg is for various ugc cfg
type UgcCfg struct {
Copyright string
ReportCidURL string // the url of VideoCloud for reporting Cid
BFSPrefix string
CriticalCid int64 // critical cid 12780000, under it no need to ask for transcoding
ThreadLimit int64 // thread limit
}
// Batch is for the number of data to pick each time
type Batch struct {
ManualNum int // manually added archives
ImportNum int // the number of uppers to import all his video
ArcPS int // the page size to pick the upper's archives
SyncPS int // the page size of sync message ( nb of videos )
ReportCidPS int // the page size to update cid's mark status
ProducerPS int // producer page size
ReshelfPS int // reshelf arc page size
}
// UgcFre defines the ugc sync frequencies
type UgcFre struct {
ErrorWait int // postpone the operation due to error
ManualFre xtime.Duration // re-check the manual import need frequency
ImportFre xtime.Duration // import upper's video frequency
TypesCron string // import the ugc types cron
SyncFre xtime.Duration
UpperRefresh xtime.Duration // upper refresh duration
ReportCid xtime.Duration // 1 minute to check report cid
UpInitFre xtime.Duration // pause between each page of upper's archive
UpperPause xtime.Duration // pause between each import upper
ProducerFre xtime.Duration // producer pause time
FullRefreshFre xtime.Duration // video refresh frequency
FullRefArcFre xtime.Duration // pause between each archive
}