mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-20 17:57:54 +00:00
feat: add global & logger
This commit is contained in:
+9
-13
@@ -4,22 +4,21 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"go-admin/database"
|
||||
"go-admin/global/orm"
|
||||
"go-admin/router"
|
||||
"go-admin/tools"
|
||||
config2 "go-admin/tools/config"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
|
||||
var (
|
||||
config string
|
||||
port string
|
||||
@@ -46,7 +45,7 @@ func init() {
|
||||
|
||||
func usage() {
|
||||
usageStr := `starting api server`
|
||||
fmt.Printf("%s\n", usageStr)
|
||||
log.Printf("%s\n", usageStr)
|
||||
}
|
||||
|
||||
func setup() {
|
||||
@@ -58,7 +57,6 @@ func setup() {
|
||||
//3. 初始化数据库链接
|
||||
database.Setup()
|
||||
|
||||
|
||||
}
|
||||
|
||||
func run() error {
|
||||
@@ -71,12 +69,11 @@ func run() error {
|
||||
|
||||
r := router.InitRouter()
|
||||
|
||||
defer database.Eloquent.Close()
|
||||
defer orm.Eloquent.Close()
|
||||
if port != "" {
|
||||
config2.SetConfig(config, "settings.application.port", port)
|
||||
}
|
||||
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: config2.ApplicationConfig.Host + ":" + config2.ApplicationConfig.Port,
|
||||
Handler: r,
|
||||
@@ -95,16 +92,15 @@ func run() error {
|
||||
}
|
||||
}()
|
||||
content, _ := ioutil.ReadFile("./static/go-admin.txt")
|
||||
log.Println(string(content))
|
||||
log.Println("Server Run http://127.0.0.1:" + config2.ApplicationConfig.Port + "/")
|
||||
log.Println("Swagger URL http://127.0.0.1:" + config2.ApplicationConfig.Port + "/swagger/index.html")
|
||||
|
||||
log.Println("Enter Control + C Shutdown Server")
|
||||
fmt.Println(string(content))
|
||||
fmt.Printf("%s Server Run http://127.0.0.1:%s/ \r\n", tools.GetCurrntTimeStr(), config2.ApplicationConfig.Port)
|
||||
fmt.Printf("%s Swagger URL http://127.0.0.1:%s/swagger/index.html \r\n", tools.GetCurrntTimeStr(), config2.ApplicationConfig.Port)
|
||||
fmt.Printf("%s Enter Control + C Shutdown Server \r\n", tools.GetCurrntTimeStr())
|
||||
// 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间)
|
||||
quit := make(chan os.Signal)
|
||||
signal.Notify(quit, os.Interrupt)
|
||||
<-quit
|
||||
log.Println("Shutdown Server ...")
|
||||
fmt.Printf("%s Shutdown Server ... \r\n", tools.GetCurrntTimeStr())
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
Reference in New Issue
Block a user