feat(args): 1.add command args(date)

This commit is contained in:
eson 2020-12-09 10:47:19 +08:00
parent 3d00fca1db
commit a48cb45d05

16
main.go
View File

@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/json"
"flag"
"log"
"time"
@ -21,6 +22,18 @@ type CountLiveAnchors struct {
CountMap string `xorm:"count_map"`
}
func getArgsStartTime() time.Time {
date := flag.Arg(0)
if date != "" {
panic("please input date eg. '2020-11-30 16:29:17'")
}
start, err := time.ParseInLocation("2006-01-02 15:04:03", date, time.Local)
if err != nil {
panic(err)
}
return start
}
func main() {
mdb := database.NewStatisticsDB("mongodb://sg-board1.livenono.com:27018")
@ -31,7 +44,8 @@ func main() {
cla := engine.Table("count_live_anchors")
start, err := time.ParseInLocation("2006-01-02 15:04:03", "2020-11-30 16:29:17", time.Local)
start := getArgsStartTime()
// start, err := time.ParseInLocation("2006-01-02 15:04:03", "2020-11-30 16:29:17", time.Local)
if err != nil {
panic(err)
}