34 lines
463 B
Go
34 lines
463 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
var (
|
|
ListenPort = "8080"
|
|
)
|
|
|
|
func server() {
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
p := viper.GetString("Server.Port")
|
|
if p != "" {
|
|
ListenPort = p
|
|
}
|
|
|
|
r := gin.Default()
|
|
r.GET("/", helloWorld)
|
|
|
|
r.Run(":" + ListenPort)
|
|
}
|
|
|
|
func helloWorld(c *gin.Context) {
|
|
ua := c.Request.UserAgent()
|
|
message := fmt.Sprintf("Hello %v!\n", ua)
|
|
c.String(http.StatusOK, message)
|
|
}
|