Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_server
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
d93f32be
authored
Jul 21, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
output添加跨域
parent
9444bc4b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
22 deletions
controller/bom_controller.go
controller/quote_controller.go
pkg/common/response.go
service/bom_service.go
controller/bom_controller.go
View file @
d93f32be
...
...
@@ -31,14 +31,10 @@ func Recommend(c *gin.Context) {
fmt
.
Println
(
err
)
}
if
req
.
Flag
==
0
{
res
:=
common
.
BomResponse
{
ErrCode
:
101
,
ErrMsg
:
"参数不全"
,
Data
:
[]
string
{},
}
c
.
JSON
(
200
,
res
)
common
.
Output
(
101
,
"参数不全"
,
nil
)
return
}
data
:=
service
.
Recommend
(
req
)
c
.
JSON
(
200
,
data
)
common
.
Output
(
req
.
Flag
,
""
,
data
)
return
}
controller/quote_controller.go
View file @
d93f32be
...
...
@@ -132,8 +132,8 @@ func GetDataPur(c *gin.Context) {
defer
redisCon
.
Close
()
for
_
,
supplier
:=
range
supplierData
{
if
value
,
exist
:=
temp2
[
supplier
.
ChannelUid
];
exist
{
res
,
err
:=
redis
.
Bool
(
redisCon
.
Do
(
"HSET"
,
"search_supplier_canaltopurchase_test"
,
supplier
.
SupplierCode
,
value
))
if
err
!=
nil
||
!
res
{
_
,
err
:=
redis
.
Bool
(
redisCon
.
Do
(
"HSET"
,
"search_supplier_canaltopurchase_test"
,
supplier
.
SupplierCode
,
value
))
if
err
!=
nil
{
c
.
String
(
200
,
"失败"
)
return
}
...
...
pkg/common/response.go
View file @
d93f32be
package
common
import
(
"regexp"
"runtime"
"search_server/middleware"
"search_server/pkg/log_report"
"strconv"
"strings"
)
type
Response
struct
{
...
...
@@ -53,13 +53,8 @@ func Output(errCode int, errMsg string, data interface{}) {
ctx
.
JSONP
(
200
,
response
)
}
else
{
referer
:=
ctx
.
Request
.
Referer
()
r
,
_
:=
regexp
.
Compile
(
`/^(\w+:\/\/)?([^\/]+)/i`
)
var
match
string
matches
:=
r
.
FindStringSubmatch
(
referer
)
if
len
(
matches
)
>
0
{
match
=
matches
[
0
]
}
ctx
.
Header
(
"Access-Control-Allow-Origin"
,
match
)
referer
=
strings
.
TrimRight
(
referer
,
"/"
)
ctx
.
Header
(
"Access-Control-Allow-Origin"
,
referer
)
ctx
.
Header
(
"Access-Control-Allow-Credentials"
,
"true"
)
//允许跨站访问的站点域名
//跨域请求头设置
...
...
service/bom_service.go
View file @
d93f32be
...
...
@@ -6,6 +6,7 @@ import (
"github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/es"
...
...
@@ -64,7 +65,7 @@ func getTermQuery(goodsName string) (query *elastic.BoolQuery) {
}
//推荐商品搜索
func
Recommend
(
req
*
common
.
RecommendRequest
)
(
rsp
*
common
.
BomResponse
)
{
func
Recommend
(
req
*
common
.
RecommendRequest
)
(
goodsList
[]
model
.
ApiGoods
)
{
var
err
error
//先去请求参数,看是否是参数,如果是参数的话,需要修改请求的商品名称
var
goodsName
string
...
...
@@ -101,10 +102,8 @@ func Recommend(req *common.RecommendRequest) (rsp *common.BomResponse) {
goodsIdList
=
append
(
goodsIdList
,
goodsId
)
}
goodsIdListStr
=
strings
.
Join
(
goodsIdList
,
","
)
goodsList
,
err
:=
GetGoodsInfoByApi
(
goodsIdListStr
)
response
.
Data
=
goodsList
response
.
Flag
=
req
.
Flag
return
&
response
goodsList
,
err
=
GetGoodsInfoByApi
(
goodsIdListStr
)
return
goodsList
}
//处理recommend接口的请求参数
...
...
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