Example #1
0
File: main.go Project: nzai/lottery
func main() {

	//	当前目录
	rootDir := filepath.Dir(os.Args[0])

	//	设置配置文件
	err := config.SetRootDir(rootDir)
	if err != nil {
		log.Fatal(err)
		return
	}

	//	启动定时任务
	job.Start()

	//	http监听端口
	port := config.Int("http", "port", 9000)
	serverAddress := fmt.Sprintf(":%d", port)

	r := gin.New()
	r.Use(gin.Logger())

	//	注册路由
	RegisterRoute(r)

	r.Run(serverAddress) // listen and serve on 0.0.0.0:8080
}
Example #2
0
File: job.go Project: nzai/lottery
func Start() {

	//	同步时间间隔
	intervalSeconds := config.Int("job", "intervalSeconds", 600)
	go func() {
		//	启动定时器
		ticker := time.NewTicker(time.Second * time.Duration(intervalSeconds))
		for _ = range ticker.C {
			sync()
		}
	}()

	// 立即执行一次
	sync()
}