完善
This commit is contained in:
parent
6f688b9ea5
commit
db8906e239
|
@ -37,7 +37,6 @@ type Config struct {
|
||||||
PostCommentUrl string `yaml:"postCommentUrl"`
|
PostCommentUrl string `yaml:"postCommentUrl"`
|
||||||
TrustIps []string `yaml:"trustIps"`
|
TrustIps []string `yaml:"trustIps"`
|
||||||
TrustServerNames []string `yaml:"trustServerNames"`
|
TrustServerNames []string `yaml:"trustServerNames"`
|
||||||
Port string `yaml:"port"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mail struct {
|
type Mail struct {
|
||||||
|
|
18
main.go
18
main.go
|
@ -16,16 +16,27 @@ import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var confPath string
|
var confPath string
|
||||||
|
var port string
|
||||||
var middleWareReloadFn func()
|
var middleWareReloadFn func()
|
||||||
|
var intReg = regexp.MustCompile(`^\d`)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.StringVar(&confPath, "c", "config.yaml", "config file")
|
flag.StringVar(&confPath, "c", "config.yaml", "config file")
|
||||||
|
flag.StringVar(&port, "p", "", "port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
if port == "" && os.Getenv("PORT") == "" {
|
||||||
|
port = "80"
|
||||||
|
}
|
||||||
|
if intReg.MatchString(port) && !strings.Contains(port, ":") {
|
||||||
|
port = ":" + port
|
||||||
|
}
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
err := initConf(confPath)
|
err := initConf(confPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -117,15 +128,10 @@ func signalNotify() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c := config.Conf.Load()
|
|
||||||
if c.Port == "" {
|
|
||||||
c.Port = "80"
|
|
||||||
config.Conf.Store(c)
|
|
||||||
}
|
|
||||||
go signalNotify()
|
go signalNotify()
|
||||||
Gin, reloadFn := route.SetupRouter()
|
Gin, reloadFn := route.SetupRouter()
|
||||||
middleWareReloadFn = reloadFn
|
middleWareReloadFn = reloadFn
|
||||||
err := Gin.Run(c.Port)
|
err := Gin.Run(port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user