2022-9-20 #7

Merged
ptinqsey9 merged 8 commits from zimujun_branch into develop 2 years ago

@ -0,0 +1,28 @@
package main
import (
"fmt"
"log"
"net/http"
"time"
"application/routers"
)
func main() {
timeLocal, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
log.Printf("时区设置失败 %s", err)
}
time.Local = timeLocal
endPoint := fmt.Sprintf("0.0.0.0:%d", 8000)
server := &http.Server{
Addr: endPoint,
Handler: routers.InitRouter(),
}
log.Printf("[info] start http server listening %s", endPoint)
if err := server.ListenAndServe(); err != nil {
log.Printf("start http server failed %s", err)
}
}

@ -0,0 +1,24 @@
package app
import (
"github.com/gin-gonic/gin"
)
type Gin struct {
C *gin.Context
}
type Response struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}
func (g *Gin) Response(httpCode int, errMsg string, data interface{}) {
g.C.JSON(httpCode, Response{
Code: httpCode,
Msg: errMsg,
Data: data,
})
return
}

@ -0,0 +1,26 @@
package routers
import (
"net/http"
android "application/api/android"
pc "application/api/pc"
"github.com/gin-gonic/gin"
)
// InitRouter 初始化路由信息
func InitRouter() *gin.Engine {
r := gin.Default()
api := r.Group("/api")
{
api.GET("/android/hello", android.Hello)
api.POST("/android/hello", android.Hello)
api.GET("/pc/hello", pc.Hello)
api.POST("/pc/hello", pc.Hello)
}
// 静态文件路由
r.StaticFS("/web", http.Dir("./dist/"))
return r
}
Loading…
Cancel
Save