44 lines
931 B
Go
44 lines
931 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"github.com/zeromicro/go-zero/core/service"
|
|
"nova_task/internal/config"
|
|
"nova_task/internal/handler"
|
|
"nova_task/internal/job"
|
|
"nova_task/internal/pkg/errs"
|
|
"nova_task/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/conf"
|
|
"github.com/zeromicro/go-zero/rest"
|
|
)
|
|
|
|
var configFile = flag.String("f", "etc/novatask.yaml", "the config file")
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
var c config.Config
|
|
conf.MustLoad(*configFile, &c)
|
|
c.MustSetUp()
|
|
|
|
ctx := svc.NewServiceContext(c)
|
|
defer ctx.Close()
|
|
|
|
serviceGroup := service.NewServiceGroup()
|
|
defer serviceGroup.Stop()
|
|
|
|
jbs := job.BuildJobs(ctx)
|
|
for _, jb := range jbs {
|
|
serviceGroup.Add(jb)
|
|
}
|
|
|
|
httpSvr := rest.MustNewServer(c.RestConf, rest.WithCors(), errs.WithUnauthorizedCallback())
|
|
handler.RegisterHandlers(httpSvr, ctx)
|
|
serviceGroup.Add(httpSvr)
|
|
|
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
|
serviceGroup.Start()
|
|
}
|