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
Show 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) {
...
@@ -31,14 +31,10 @@ func Recommend(c *gin.Context) {
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
}
}
if
req
.
Flag
==
0
{
if
req
.
Flag
==
0
{
res
:=
common
.
BomResponse
{
common
.
Output
(
101
,
"参数不全"
,
nil
)
ErrCode
:
101
,
ErrMsg
:
"参数不全"
,
Data
:
[]
string
{},
}
c
.
JSON
(
200
,
res
)
return
return
}
}
data
:=
service
.
Recommend
(
req
)
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) {
...
@@ -132,8 +132,8 @@ func GetDataPur(c *gin.Context) {
defer
redisCon
.
Close
()
defer
redisCon
.
Close
()
for
_
,
supplier
:=
range
supplierData
{
for
_
,
supplier
:=
range
supplierData
{
if
value
,
exist
:=
temp2
[
supplier
.
ChannelUid
];
exist
{
if
value
,
exist
:=
temp2
[
supplier
.
ChannelUid
];
exist
{
res
,
err
:=
redis
.
Bool
(
redisCon
.
Do
(
"HSET"
,
"search_supplier_canaltopurchase_test"
,
supplier
.
SupplierCode
,
value
))
_
,
err
:=
redis
.
Bool
(
redisCon
.
Do
(
"HSET"
,
"search_supplier_canaltopurchase_test"
,
supplier
.
SupplierCode
,
value
))
if
err
!=
nil
||
!
res
{
if
err
!=
nil
{
c
.
String
(
200
,
"失败"
)
c
.
String
(
200
,
"失败"
)
return
return
}
}
...
...
pkg/common/response.go
View file @
d93f32be
package
common
package
common
import
(
import
(
"regexp"
"runtime"
"runtime"
"search_server/middleware"
"search_server/middleware"
"search_server/pkg/log_report"
"search_server/pkg/log_report"
"strconv"
"strconv"
"strings"
)
)
type
Response
struct
{
type
Response
struct
{
...
@@ -53,13 +53,8 @@ func Output(errCode int, errMsg string, data interface{}) {
...
@@ -53,13 +53,8 @@ func Output(errCode int, errMsg string, data interface{}) {
ctx
.
JSONP
(
200
,
response
)
ctx
.
JSONP
(
200
,
response
)
}
else
{
}
else
{
referer
:=
ctx
.
Request
.
Referer
()
referer
:=
ctx
.
Request
.
Referer
()
r
,
_
:=
regexp
.
Compile
(
`/^(\w+:\/\/)?([^\/]+)/i`
)
referer
=
strings
.
TrimRight
(
referer
,
"/"
)
var
match
string
ctx
.
Header
(
"Access-Control-Allow-Origin"
,
referer
)
matches
:=
r
.
FindStringSubmatch
(
referer
)
if
len
(
matches
)
>
0
{
match
=
matches
[
0
]
}
ctx
.
Header
(
"Access-Control-Allow-Origin"
,
match
)
ctx
.
Header
(
"Access-Control-Allow-Credentials"
,
"true"
)
ctx
.
Header
(
"Access-Control-Allow-Credentials"
,
"true"
)
//允许跨站访问的站点域名
//允许跨站访问的站点域名
//跨域请求头设置
//跨域请求头设置
...
...
service/bom_service.go
View file @
d93f32be
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"github.com/tidwall/gjson"
"github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5"
"gopkg.in/olivere/elastic.v5"
"regexp"
"regexp"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/config"
"search_server/pkg/es"
"search_server/pkg/es"
...
@@ -64,7 +65,7 @@ func getTermQuery(goodsName string) (query *elastic.BoolQuery) {
...
@@ -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
err
error
//先去请求参数,看是否是参数,如果是参数的话,需要修改请求的商品名称
//先去请求参数,看是否是参数,如果是参数的话,需要修改请求的商品名称
var
goodsName
string
var
goodsName
string
...
@@ -101,10 +102,8 @@ func Recommend(req *common.RecommendRequest) (rsp *common.BomResponse) {
...
@@ -101,10 +102,8 @@ func Recommend(req *common.RecommendRequest) (rsp *common.BomResponse) {
goodsIdList
=
append
(
goodsIdList
,
goodsId
)
goodsIdList
=
append
(
goodsIdList
,
goodsId
)
}
}
goodsIdListStr
=
strings
.
Join
(
goodsIdList
,
","
)
goodsIdListStr
=
strings
.
Join
(
goodsIdList
,
","
)
goodsList
,
err
:=
GetGoodsInfoByApi
(
goodsIdListStr
)
goodsList
,
err
=
GetGoodsInfoByApi
(
goodsIdListStr
)
response
.
Data
=
goodsList
return
goodsList
response
.
Flag
=
req
.
Flag
return
&
response
}
}
//处理recommend接口的请求参数
//处理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