52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"api/config"
|
|
"api/initialization"
|
|
"api/middleware"
|
|
"api/utils"
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
initialization.InitSystem()
|
|
|
|
app := gin.Default()
|
|
|
|
app.Use(middleware.OpenTracing())
|
|
|
|
ipStr := strings.Join(utils.GetIps(), ",")
|
|
|
|
group := app.Group(fmt.Sprintf("/%v", config.AppInfo.AppName))
|
|
|
|
group.GET("/hello", func(context *gin.Context) {
|
|
name := context.Query("name")
|
|
context.String(http.StatusBadGateway, fmt.Sprintf("[GET]-[%v]-[latest]\n%v\n%v", config.AppInfo.AppName, ipStr, name))
|
|
})
|
|
|
|
group.POST("/hello", func(context *gin.Context) {
|
|
type param struct {
|
|
User string `json:"user"`
|
|
Age int `json:"age"`
|
|
}
|
|
p := param{}
|
|
err := context.ShouldBindJSON(&p)
|
|
if err != nil {
|
|
context.String(http.StatusInternalServerError, "服务异常")
|
|
return
|
|
}
|
|
context.String(http.StatusOK, fmt.Sprintf("[GET]-[%v]-[latest]\n%v\n%v", config.AppInfo.AppName, ipStr, p.User))
|
|
})
|
|
|
|
group.GET("/ip", func(context *gin.Context) {
|
|
time.Sleep(1 * time.Second)
|
|
context.String(http.StatusOK, fmt.Sprintf("[%v]\n%v", config.AppInfo.AppName, ipStr))
|
|
})
|
|
|
|
app.Run(fmt.Sprintf(":%v", config.AppInfo.Port))
|
|
}
|