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
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
35 additions
and
29 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
(
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
main.go
View file @
0c95ad35
...
@@ -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/logg
er
"
"LC_soapi/pkg/logg
ing
"
"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
()
logg
er
.
Setup
()
logg
ing
.
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
,
...
...
pkg/app/response.go
View file @
0c95ad35
package
htt
p
package
ap
p
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
}
pkg/logging/log_report.go
View file @
0c95ad35
...
@@ -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
)
}
}
pkg/setting/setting.go
View file @
0c95ad35
...
@@ -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
}
}
...
...
routers/router.go
View file @
0c95ad35
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
)
{
...
...
service/self_service/self.go
View file @
0c95ad35
...
@@ -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
...
...
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