Commit 0c95ad35 by 杨树贤

修改目录结构

parent 0479eaba
package api
package controller
import (
"LC_soapi/pkg/app"
"LC_soapi/service/self_service"
"fmt"
"github.com/gin-gonic/gin"
......@@ -8,9 +9,11 @@ import (
//Search 自营搜索
func Search(c *gin.Context) {
appG := app.Gin{C: c}
//先去处理请求参数
params := self_service.GetSearchParams(c)
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
import (
"LC_soapi/pkg/gredis"
"LC_soapi/pkg/logger"
"LC_soapi/pkg/logging"
"LC_soapi/pkg/setting"
"LC_soapi/routers"
"fmt"
......@@ -14,7 +14,7 @@ import (
func init() {
setting.Setup()
gredis.Setup()
logger.Setup()
logging.Setup()
}
func main() {
......@@ -26,7 +26,7 @@ func main() {
endPoint := fmt.Sprintf(":%d", setting.ServerSetting.HttpPort)
maxHeaderBytes := 1 << 20
server := &http.Server{
Addr: ":8000",
Addr: endPoint,
Handler: routersInit,
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
......
package http
package app
import (
"LC_soapi/pkg/logging"
......@@ -10,12 +10,12 @@ type Gin struct {
}
type Response struct {
Code int `json:"code"`
Msg string `json:"msg"`
Code int `json:"err_code"`
Msg string `json:"err_msg"`
Data interface{} `json:"data"`
}
// Response setting gin.JSON
//返回数据
func (g *Gin) Response(code int, msg string, data interface{}) {
if code > 100 {
......@@ -29,3 +29,13 @@ func (g *Gin) Response(code int, msg string, data interface{}) {
})
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 {
//上报请求日志
func ReportErrorLog(code int, msg string, ip string) {
var errLog ErrorLog
//获取调用者信息
caller := util.GetCaller(2)
//基础信息
errLog.TimeStamp = int(time.Now().Unix())
errLog.DateTimeStr = time.Now().Format("2006-01-02 15:04:05")
errLog.App = setting.AppSetting.Name
//返回信息
errLog.Code = code
errLog.Msg = msg
errLog.ServerIp = ip
//调用者信息
caller := util.GetCaller(3)
errLog.Method = caller.FunctionName
errLog.FileName = caller.FileName
errLog.LineNo = caller.FileLine
//日志记录
logString, _ := json.Marshal(errLog)
logger.Info(string(logString))
fmt.Println(errLog)
}
......@@ -8,6 +8,7 @@ import (
)
type App struct {
Name string
JwtSecret string
PageSize int
PrefixUrl string
......@@ -62,7 +63,7 @@ type Redis struct {
var RedisSetting = &Redis{}
type Log struct {
LogPath string
LogPath string
LogChanSize string
}
......
package routers
import (
"LC_soapi/controller"
"LC_soapi/pkg/setting"
"LC_soapi/routers/api"
"github.com/gin-gonic/gin"
)
......@@ -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) {
......
......@@ -10,20 +10,11 @@ type Params struct {
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) {
if c.ShouldBindQuery(&params) == nil {
//商品名称的数组
fmt.Println(params.GoodsName)
}
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