package main

import (
	"flag"
	"git.quantgroup.cn/DevOps/enoch/service"
	"git.quantgroup.cn/DevOps/enoch/service/conf"
	"git.quantgroup.cn/DevOps/enoch/service/job"
	"log"
	"net/http"
	"os"
)

func main() {

	var port string
	var quartz bool
	flag.StringVar(&port, "port", "9091", "端口")
	flag.BoolVar(&quartz, "quartz", false, "quartz")
	flag.Parse()

	file, err := os.Create("quantgroup.log")
	defer func() { _ = file.Close() }()
	if err != nil {
		log.Fatalln("create file error", err)
	}

	logger := log.New(file, "[Info]", log.LstdFlags|log.Llongfile)

	logger.Println("项目启动" + port)
	defer logger.Println("项目结束")

	//初始化redis连接池
	conf.RedisPoolInit()

	go service.Consumer()

	if quartz {
		log.Println("启动定时任务")
		job.AutoEmailPerformInfo()
	}

	http.HandleFunc("/duration", service.DurationInterface)
	http.HandleFunc("/counter", service.CounterInterface)

	err = http.ListenAndServe(":"+port, nil)
	if err != nil {
		log.Fatalln("服务启动失败", err)
	}

}
