|
@@ -0,0 +1,54 @@
|
|
1
|
+package main
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "github.com/gin-gonic/gin"
|
|
5
|
+ rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
|
6
|
+ "io"
|
|
7
|
+ "miads/adslib"
|
|
8
|
+ "miads/adslib/ads_redis"
|
|
9
|
+ "os"
|
|
10
|
+ "time"
|
|
11
|
+
|
|
12
|
+ log "github.com/sirupsen/logrus"
|
|
13
|
+)
|
|
14
|
+
|
|
15
|
+func setupLogger(logName string, logLevel log.Level) {
|
|
16
|
+ writer, err := rotatelogs.New(
|
|
17
|
+ logName+".%Y%m%d",
|
|
18
|
+
|
|
19
|
+ // WithLinkName为最新的日志建立软连接,以方便随着找到当前日志文件
|
|
20
|
+ rotatelogs.WithLinkName(logName),
|
|
21
|
+
|
|
22
|
+ // WithRotationTime设置日志分割的时间,这里设置为一小时分割一次
|
|
23
|
+ rotatelogs.WithRotationTime(time.Hour),
|
|
24
|
+
|
|
25
|
+ // WithMaxAge和WithRotationCount二者只能设置一个,
|
|
26
|
+ // WithMaxAge设置文件清理前的最长保存时间,
|
|
27
|
+ // WithRotationCount设置文件清理前最多保存的个数。
|
|
28
|
+ rotatelogs.WithMaxAge(time.Hour*24*3),
|
|
29
|
+ )
|
|
30
|
+
|
|
31
|
+ if err != nil {
|
|
32
|
+ log.Errorf("config local file system for logger error: %v", err)
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ log.SetReportCaller(true)
|
|
36
|
+ log.SetLevel(logLevel)
|
|
37
|
+ log.SetOutput(io.MultiWriter(writer, os.Stdout))
|
|
38
|
+}
|
|
39
|
+
|
|
40
|
+func setupRouter() *gin.Engine {
|
|
41
|
+ r := gin.Default()
|
|
42
|
+
|
|
43
|
+ r.POST("/ads", adsHandler)
|
|
44
|
+ return r
|
|
45
|
+}
|
|
46
|
+
|
|
47
|
+func main() {
|
|
48
|
+ ads_redis.Setup()
|
|
49
|
+ adslib.GetConf()
|
|
50
|
+ setupLogger(adslib.GetConf().LogPath+"/ads.log", log.TraceLevel)
|
|
51
|
+
|
|
52
|
+ r := setupRouter()
|
|
53
|
+ r.Run(":8080")
|
|
54
|
+}
|