This commit is contained in:
xing 2022-11-16 15:31:37 +08:00
parent 6f688b9ea5
commit db8906e239
2 changed files with 12 additions and 7 deletions

View File

@ -37,7 +37,6 @@ type Config struct {
PostCommentUrl string `yaml:"postCommentUrl"`
TrustIps []string `yaml:"trustIps"`
TrustServerNames []string `yaml:"trustServerNames"`
Port string `yaml:"port"`
}
type Mail struct {

18
main.go
View File

@ -16,16 +16,27 @@ import (
"math/rand"
"os"
"os/signal"
"regexp"
"strings"
"syscall"
"time"
)
var confPath string
var port string
var middleWareReloadFn func()
var intReg = regexp.MustCompile(`^\d`)
func init() {
flag.StringVar(&confPath, "c", "config.yaml", "config file")
flag.StringVar(&port, "p", "", "port")
flag.Parse()
if port == "" && os.Getenv("PORT") == "" {
port = "80"
}
if intReg.MatchString(port) && !strings.Contains(port, ":") {
port = ":" + port
}
rand.Seed(time.Now().UnixNano())
err := initConf(confPath)
if err != nil {
@ -117,15 +128,10 @@ func signalNotify() {
}
func main() {
c := config.Conf.Load()
if c.Port == "" {
c.Port = "80"
config.Conf.Store(c)
}
go signalNotify()
Gin, reloadFn := route.SetupRouter()
middleWareReloadFn = reloadFn
err := Gin.Run(c.Port)
err := Gin.Run(port)
if err != nil {
panic(err)
}