Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
LC_soapi
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0c95ad35
authored
Jan 07, 2020
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修改目录结构
parent
0479eaba
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
27 deletions
routers/api/self.go → controller/self.go
main.go
pkg/app/response.go
pkg/logging/log_report.go
pkg/setting/setting.go
routers/router.go
service/self_service/self.go
routers/api
/self.go
→
controller
/self.go
View file @
0c95ad35
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
main.go
View file @
0c95ad35
...
...
@@ -2,7 +2,7 @@ package main
import
(
"LC_soapi/pkg/gredis"
"LC_soapi/pkg/logg
er
"
"LC_soapi/pkg/logg
ing
"
"LC_soapi/pkg/setting"
"LC_soapi/routers"
"fmt"
...
...
@@ -14,7 +14,7 @@ import (
func
init
()
{
setting
.
Setup
()
gredis
.
Setup
()
logg
er
.
Setup
()
logg
ing
.
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
,
...
...
pkg/app/response.go
View file @
0c95ad35
package
htt
p
package
ap
p
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
}
pkg/logging/log_report.go
View file @
0c95ad35
...
...
@@ -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
)
}
pkg/setting/setting.go
View file @
0c95ad35
...
...
@@ -8,6 +8,7 @@ import (
)
type
App
struct
{
Name
string
JwtSecret
string
PageSize
int
PrefixUrl
string
...
...
routers/router.go
View file @
0c95ad35
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
)
{
...
...
service/self_service/self.go
View file @
0c95ad35
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment