mirror of http://gitlab.batiao8.com/yic/film.git
79 lines
1.6 KiB
Go
79 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"film/config"
|
|
"film/model"
|
|
"film/worker"
|
|
"fmt"
|
|
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
|
"github.com/rifflock/lfshook"
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/smbrave/goutil"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
func initLog() {
|
|
cfg := config.GetConfig()
|
|
logfile := "log/server.log"
|
|
writer, err := rotatelogs.New(
|
|
logfile+".%Y%m%d",
|
|
rotatelogs.WithLinkName(logfile),
|
|
rotatelogs.WithMaxAge(time.Duration(86400*7)*time.Second),
|
|
rotatelogs.WithRotationTime(time.Duration(86400)*time.Second),
|
|
)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
pathMap := lfshook.WriterMap{
|
|
log.TraceLevel: writer,
|
|
log.DebugLevel: writer,
|
|
log.InfoLevel: writer,
|
|
log.WarnLevel: writer,
|
|
log.ErrorLevel: writer,
|
|
log.FatalLevel: writer,
|
|
log.PanicLevel: writer,
|
|
}
|
|
|
|
log.AddHook(lfshook.NewHook(pathMap, new(goutil.LogFile)))
|
|
|
|
log.SetOutput(os.Stdout)
|
|
log.SetReportCaller(true)
|
|
log.SetFormatter(new(goutil.LogFile))
|
|
log.SetLevel(log.Level(cfg.Server.LogLevel))
|
|
}
|
|
|
|
func main() {
|
|
config.LoadServerConfig()
|
|
initLog()
|
|
cfg := config.GetConfig()
|
|
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", cfg.Mysql.User,
|
|
cfg.Mysql.Pass, cfg.Mysql.Host, cfg.Mysql.Port, cfg.Mysql.Db)
|
|
_, err := model.Init(dsn)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
dadiProcessor := &worker.Dadi{
|
|
Token: cfg.Film.DadiToken,
|
|
}
|
|
if err := dadiProcessor.Init(); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
orderWorker := &worker.Orders{
|
|
Token: config.GetConfig().Film.HahaToken,
|
|
Dadi: dadiProcessor,
|
|
}
|
|
|
|
if err := orderWorker.Init(); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
order, _ := model.GetOrder(582589)
|
|
|
|
dadiProcessor.NewOrder(order)
|
|
select {}
|
|
}
|