You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"git.ouxuan.net/3136352472/go-service-template/govue"
|
|
"git.ouxuan.net/3136352472/go-service-template/pool"
|
|
"github.com/gin-gonic/gin"
|
|
"mime"
|
|
"path/filepath"
|
|
"runtime"
|
|
)
|
|
|
|
func main() {
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
r := gin.Default()
|
|
|
|
govue.SetPoolConfig(pool.Config{
|
|
MinIdle: 100,
|
|
})
|
|
|
|
gv, err := govue.NewGoVueDefaultConfig()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
r.NoRoute(func(context *gin.Context) {
|
|
raw, err := gv.LoadStaticResources(context.Request)
|
|
|
|
if err != nil {
|
|
context.Writer.Write([]byte(fmt.Sprintln("服务器错误", err.Error())))
|
|
return
|
|
}
|
|
mime.TypeByExtension(filepath.Ext(context.Request.URL.Path))
|
|
context.Writer.Header().Set("Content-Type", mime.TypeByExtension(filepath.Ext(context.Request.URL.Path)))
|
|
context.Writer.WriteHeader(200)
|
|
_, _ = context.Writer.Write(raw)
|
|
})
|
|
|
|
r.Use(func(context *gin.Context) {
|
|
context.Header("Access-Control-Allow-Origin", "*")
|
|
context.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
|
context.Header("Access-Control-Allow-Headers", "Action, Module, X-PINGOTHER, Content-Type, Content-Disposition")
|
|
})
|
|
r.GET("/test", func(context *gin.Context) {
|
|
context.JSON(200, map[string]interface{}{
|
|
"code": 0,
|
|
"data": map[string]string{
|
|
"method": context.Request.Method,
|
|
"query": context.Request.URL.Query().Encode(),
|
|
},
|
|
})
|
|
})
|
|
|
|
gv.StartPoolLog()
|
|
|
|
r.Run("127.0.0.1:8080")
|
|
|
|
}
|