Commit 0c95ad35 by 杨树贤

修改目录结构

parent 0479eaba
package api package controller
import ( import (
"LC_soapi/pkg/app"
"LC_soapi/service/self_service" "LC_soapi/service/self_service"
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
...@@ -8,9 +9,11 @@ import ( ...@@ -8,9 +9,11 @@ import (
//Search 自营搜索 //Search 自营搜索
func Search(c *gin.Context) { func Search(c *gin.Context) {
appG := app.Gin{C: c}
//先去处理请求参数 //先去处理请求参数
params := self_service.GetSearchParams(c) params := self_service.GetSearchParams(c)
fmt.Println(params) fmt.Println(params)
c.JSON(200, nil) appG.Response(500,"错误测试",params)
} //appG.ResponseOk()
}
\ No newline at end of file
...@@ -2,7 +2,7 @@ package main ...@@ -2,7 +2,7 @@ package main
import ( import (
"LC_soapi/pkg/gredis" "LC_soapi/pkg/gredis"
"LC_soapi/pkg/logger" "LC_soapi/pkg/logging"
"LC_soapi/pkg/setting" "LC_soapi/pkg/setting"
"LC_soapi/routers" "LC_soapi/routers"
"fmt" "fmt"
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
func init() { func init() {
setting.Setup() setting.Setup()
gredis.Setup() gredis.Setup()
logger.Setup() logging.Setup()
} }
func main() { func main() {
...@@ -26,7 +26,7 @@ func main() { ...@@ -26,7 +26,7 @@ func main() {
endPoint := fmt.Sprintf(":%d", setting.ServerSetting.HttpPort) endPoint := fmt.Sprintf(":%d", setting.ServerSetting.HttpPort)
maxHeaderBytes := 1 << 20 maxHeaderBytes := 1 << 20
server := &http.Server{ server := &http.Server{
Addr: ":8000", Addr: endPoint,
Handler: routersInit, Handler: routersInit,
ReadTimeout: readTimeout, ReadTimeout: readTimeout,
WriteTimeout: writeTimeout, WriteTimeout: writeTimeout,
......
package http package app
import ( import (
"LC_soapi/pkg/logging" "LC_soapi/pkg/logging"
...@@ -10,12 +10,12 @@ type Gin struct { ...@@ -10,12 +10,12 @@ type Gin struct {
} }
type Response struct { type Response struct {
Code int `json:"code"` Code int `json:"err_code"`
Msg string `json:"msg"` Msg string `json:"err_msg"`
Data interface{} `json:"data"` Data interface{} `json:"data"`
} }
// Response setting gin.JSON //返回数据
func (g *Gin) Response(code int, msg string, data interface{}) { func (g *Gin) Response(code int, msg string, data interface{}) {
if code > 100 { if code > 100 {
...@@ -29,3 +29,13 @@ func (g *Gin) Response(code int, msg string, data interface{}) { ...@@ -29,3 +29,13 @@ func (g *Gin) Response(code int, msg string, data interface{}) {
}) })
return return
} }
//返回ok
func (g *Gin) ResponseOk() {
response := map[string]interface{}{
"err_code": 0,
"err_msg": "ok",
}
g.C.JSON(200, response)
return
}
...@@ -24,20 +24,21 @@ type ErrorLog struct { ...@@ -24,20 +24,21 @@ type ErrorLog struct {
//上报请求日志 //上报请求日志
func ReportErrorLog(code int, msg string, ip string) { func ReportErrorLog(code int, msg string, ip string) {
var errLog ErrorLog var errLog ErrorLog
//获取调用者信息 //基础信息
caller := util.GetCaller(2)
errLog.TimeStamp = int(time.Now().Unix()) errLog.TimeStamp = int(time.Now().Unix())
errLog.DateTimeStr = time.Now().Format("2006-01-02 15:04:05") errLog.DateTimeStr = time.Now().Format("2006-01-02 15:04:05")
errLog.App = setting.AppSetting.Name errLog.App = setting.AppSetting.Name
//返回信息
errLog.Code = code
errLog.Msg = msg
errLog.ServerIp = ip errLog.ServerIp = ip
//调用者信息
caller := util.GetCaller(3)
errLog.Method = caller.FunctionName errLog.Method = caller.FunctionName
errLog.FileName = caller.FileName errLog.FileName = caller.FileName
errLog.LineNo = caller.FileLine errLog.LineNo = caller.FileLine
//日志记录
logString, _ := json.Marshal(errLog) logString, _ := json.Marshal(errLog)
logger.Info(string(logString)) logger.Info(string(logString))
fmt.Println(errLog) fmt.Println(errLog)
} }
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
) )
type App struct { type App struct {
Name string
JwtSecret string JwtSecret string
PageSize int PageSize int
PrefixUrl string PrefixUrl string
...@@ -62,7 +63,7 @@ type Redis struct { ...@@ -62,7 +63,7 @@ type Redis struct {
var RedisSetting = &Redis{} var RedisSetting = &Redis{}
type Log struct { type Log struct {
LogPath string LogPath string
LogChanSize string LogChanSize string
} }
......
package routers package routers
import ( import (
"LC_soapi/controller"
"LC_soapi/pkg/setting" "LC_soapi/pkg/setting"
"LC_soapi/routers/api"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
...@@ -18,7 +17,7 @@ func InitRouter() *gin.Engine { ...@@ -18,7 +17,7 @@ func InitRouter() *gin.Engine {
{ {
//自营搜索 //自营搜索
apiSelf.GET("/search", api.Search) apiSelf.GET("/search", controller.Search)
} }
r.GET("/test", func(c *gin.Context) { r.GET("/test", func(c *gin.Context) {
......
...@@ -10,20 +10,11 @@ type Params struct { ...@@ -10,20 +10,11 @@ type Params struct {
GoodsName string `form:"goods_name/condition"` GoodsName string `form:"goods_name/condition"`
} }
//$goods_name_arr=array();
//if(isset($arr['goods_name/condition']) && C('ZIYING_BRAND_REPLACE.'.mystrupper($arr['goods_name/condition']))){
//$arr['brand_name/condition'] = C('ZIYING_BRAND_REPLACE.'.mystrupper($arr['goods_name/condition']));
//$goods_name_arr = array($arr['brand_name/condition']);
//unset($arr['goods_name/condition']);
//
//}
func GetSearchParams(c *gin.Context) (params Params) { func GetSearchParams(c *gin.Context) (params Params) {
if c.ShouldBindQuery(&params) == nil { if c.ShouldBindQuery(&params) == nil {
//商品名称的数组 //商品名称的数组
fmt.Println(params.GoodsName) fmt.Println(params.GoodsName)
} }
return params return params
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment