github.com/cnotch/ipchub@v1.1.0/main.go (about) 1 // Copyright (c) 2019,CAOHONGJU All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "context" 9 10 "github.com/cnotch/ipchub/config" 11 "github.com/cnotch/ipchub/provider/auth" 12 "github.com/cnotch/ipchub/provider/route" 13 "github.com/cnotch/ipchub/service" 14 "github.com/cnotch/scheduler" 15 "github.com/cnotch/xlog" 16 ) 17 18 func main() { 19 // 初始化配置 20 config.InitConfig() 21 // 初始化全局计划任务 22 scheduler.SetPanicHandler(func(job *scheduler.ManagedJob, r interface{}) { 23 xlog.Errorf("scheduler task panic. tag: %v, recover: %v", job.Tag, r) 24 }) 25 26 // 初始化各类提供者 27 // 路由表提供者 28 routetableProvider := config.LoadRoutetableProvider(route.JSON) 29 route.Reset(routetableProvider.(route.Provider)) 30 31 // 用户提供者 32 userProvider := config.LoadUsersProvider(auth.JSON) 33 auth.Reset(userProvider.(auth.UserProvider)) 34 35 // Start new service 36 svc, err := service.NewService(context.Background(), xlog.L()) 37 if err != nil { 38 xlog.L().Panic(err.Error()) 39 } 40 41 // Listen and serve 42 svc.Listen() 43 }