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
c7672236
authored
Nov 25, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
c24da176
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
42 deletions
doc/test/h2.go
service/ly/sourceability.go
doc/test/h2.go
View file @
c7672236
...
@@ -2,29 +2,24 @@ package main
...
@@ -2,29 +2,24 @@ package main
import
(
import
(
"fmt"
"fmt"
"
sort
"
"
github.com/syyongx/php2go
"
)
)
// 按map的key排序
func
main
()
{
func
main
()
{
params
:=
make
(
map
[
string
]
interface
{})
userCount
:=
10000
ch
:=
make
(
chan
bool
,
2
)
params
[
"name"
]
=
"xxx"
for
i
:=
0
;
i
<
userCount
;
i
++
{
params
[
"age"
]
=
23
php2go
.
Time
()
params
[
"sex"
]
=
0
ch
<-
true
params
[
"level"
]
=
1
go
send
(
ch
,
i
)
// 1.取出所有的key
var
keys
[]
string
for
k
:=
range
params
{
keys
=
append
(
keys
,
k
)
}
}
// 对字符串切片排序
sort
.
Strings
(
keys
)
fmt
.
Println
(
keys
)
// 打印key, val
//time.Sleep(time.Second)
for
_
,
k
:=
range
keys
{
}
fmt
.
Printf
(
"key: %v val:%v
\n
"
,
k
,
params
[
k
])
}
func
send
(
ch
chan
bool
,
i
int
)
{
//time.Sleep(time.Second*i)
fmt
.
Println
(
php2go
.
Time
())
fmt
.
Printf
(
"go func: %d
\n
"
,
i
)
<-
ch
}
}
service/ly/sourceability.go
View file @
c7672236
...
@@ -3,9 +3,9 @@ package ly
...
@@ -3,9 +3,9 @@ package ly
import
(
import
(
"fmt"
"fmt"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"github.com/gogf/gf/util/gconv"
"github.com/iancoleman/orderedmap"
"github.com/iancoleman/orderedmap"
"github.com/imroc/req"
"github.com/imroc/req"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"github.com/tidwall/gjson"
"search_server/model"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/common"
...
@@ -80,8 +80,11 @@ func OutLinkSource(ctx *gin.Context,goodsName *string) *orderedmap.OrderedMap {
...
@@ -80,8 +80,11 @@ func OutLinkSource(ctx *gin.Context,goodsName *string) *orderedmap.OrderedMap {
return
nil
;
return
nil
;
}
}
skuRsults
:=
gjson
.
Get
(
skuIdRes
,
"results"
)
.
Array
()
skuRsults
:=
gjson
.
Get
(
skuIdRes
,
"results"
)
.
Array
()
//协程并发请求
//协程并发请求
ch
:=
make
(
chan
*
orderedmap
.
OrderedMap
)
//接收通道所有的值
A
:=
orderedmap
.
New
()
ch
:=
make
(
chan
bool
,
2
)
p
:=
0
;
p
:=
0
;
for
_
,
a
:=
range
skuRsults
{
for
_
,
a
:=
range
skuRsults
{
goods_sn
:=
a
.
Get
(
"sku"
)
.
String
()
//goods_sn
goods_sn
:=
a
.
Get
(
"sku"
)
.
String
()
//goods_sn
...
@@ -89,6 +92,7 @@ func OutLinkSource(ctx *gin.Context,goodsName *string) *orderedmap.OrderedMap {
...
@@ -89,6 +92,7 @@ func OutLinkSource(ctx *gin.Context,goodsName *string) *orderedmap.OrderedMap {
brand_name
:=
a
.
Get
(
"manufacturer"
)
.
String
()
//品牌
brand_name
:=
a
.
Get
(
"manufacturer"
)
.
String
()
//品牌
desc
:=
a
.
Get
(
"description"
)
.
String
()
//描述
desc
:=
a
.
Get
(
"description"
)
.
String
()
//描述
ch
<-
true
go
func
()
{
go
func
()
{
B
:=
orderedmap
.
New
()
B
:=
orderedmap
.
New
()
B
.
Set
(
"goods_sn"
,
goods_sn
)
B
.
Set
(
"goods_sn"
,
goods_sn
)
...
@@ -98,29 +102,28 @@ func OutLinkSource(ctx *gin.Context,goodsName *string) *orderedmap.OrderedMap {
...
@@ -98,29 +102,28 @@ func OutLinkSource(ctx *gin.Context,goodsName *string) *orderedmap.OrderedMap {
flag
:=
GetSourceInfo
(
ctx
,
B
)
flag
:=
GetSourceInfo
(
ctx
,
B
)
//res,_ := json.Marshal(A)
//res,_ := json.Marshal(A)
if
flag
{
if
flag
{
ch
<-
B
A
.
Set
(
goods_sn
,
B
)
}
else
{
ch
<-
nil
}
}
<-
ch
}()
}()
p
++
;
p
++
;
}
}
//接收通道所有的值
//接收通道所有的值
A
:=
orderedmap
.
New
();
//
A := orderedmap.New();
for
i
:=
0
;
i
<
p
;
i
++
{
//
for i := 0; i < p; i++ {
select
{
//
select {
case
x
:=
<-
ch
:
//
case x := <-ch:
if
x
==
nil
{
//
if x == nil {
continue
//
continue
}
//
}
goods_sn
,
_
:=
x
.
Get
(
"goods_sn"
)
//
goods_sn,_ := x.Get("goods_sn")
A
.
Set
(
gconv
.
String
(
goods_sn
),
x
)
//
A.Set(gconv.String(goods_sn),x)
case
<-
time
.
After
(
time
.
Second
*
2
)
:
//
case <- time.After(time.Second *2):
fmt
.
Println
(
"超时退出等待"
)
//
fmt.Println("超时退出等待")
}
//
}
}
//
}
//allRes,_ := json.Marshal(A)
//allRes,_ := json.Marshal(A)
return
A
;
return
A
;
}
}
...
@@ -130,7 +133,7 @@ func GetSourceInfo(ctx *gin.Context,B *orderedmap.OrderedMap) bool {
...
@@ -130,7 +133,7 @@ func GetSourceInfo(ctx *gin.Context,B *orderedmap.OrderedMap) bool {
goods_sn
,
_
:=
B
.
Get
(
"goods_sn"
)
goods_sn
,
_
:=
B
.
Get
(
"goods_sn"
)
skuInfo
:=
GetSourceGineData
(
ctx
,
fmt
.
Sprintf
(
SourceSkuPriceUrl
,
goods_sn
))
skuInfo
:=
GetSourceGineData
(
ctx
,
fmt
.
Sprintf
(
SourceSkuPriceUrl
,
goods_sn
))
//
fmt.Println("请求价格开始:",php2go.Time(),fmt.Sprintf(SourceSkuPriceUrl,goods_sn))
fmt
.
Println
(
"请求价格开始:"
,
php2go
.
Time
(),
fmt
.
Sprintf
(
SourceSkuPriceUrl
,
goods_sn
))
//$skuPriceRes = `{"total":3,"results":[{"offerPlatformId":"8718009643","mpq":1,"quantity":2277626,"priceTiers":[{"moq":807,"price":"0.06820"}],"deliveryDays":5,"vendor":{"type":"factory_direct"},"dateCode":null,"isDateCodeWithin2Years":true,"availabilityType":"stock","packagingType":"tube","packagingCondition":"full"},{"offerPlatformId":"8715417520","mpq":1,"quantity":1520,"priceTiers":[{"moq":709,"price":"0.07768"}],"deliveryDays":7,"vendor":{"type":"authorised_distributor"},"dateCode":null,"isDateCodeWithin2Years":true,"availabilityType":"stock","packagingType":"tape_reel","packagingCondition":"full"},{"offerPlatformId":"8715417522","mpq":1,"quantity":283206,"priceTiers":[{"moq":709,"price":"0.07768"}],"deliveryDays":167,"vendor":{"type":"authorised_distributor"},"dateCode":null,"isDateCodeWithin2Years":true,"availabilityType":"lead_time","packagingType":"tape_reel","packagingCondition":"full"}],"facets":{"vendorTypes":[{"value":"authorised_distributor","label":"authorised_distributor","count":2},{"value":"factory_direct","label":"factory_direct","count":1}],"availabilityTypes":[{"value":"lead_time","label":"lead_time","count":1},{"value":"stock","label":"stock","count":2}],"packagingConditions":[{"value":"full","label":"full","count":3}],"packagingTypes":[{"value":"tape_reel","label":"tape_reel","count":2},{"value":"tube","label":"tube","count":1}]},"_links":{"schema":{"href":"/api/schemas/part-offer-search.json"}}}`;
//$skuPriceRes = `{"total":3,"results":[{"offerPlatformId":"8718009643","mpq":1,"quantity":2277626,"priceTiers":[{"moq":807,"price":"0.06820"}],"deliveryDays":5,"vendor":{"type":"factory_direct"},"dateCode":null,"isDateCodeWithin2Years":true,"availabilityType":"stock","packagingType":"tube","packagingCondition":"full"},{"offerPlatformId":"8715417520","mpq":1,"quantity":1520,"priceTiers":[{"moq":709,"price":"0.07768"}],"deliveryDays":7,"vendor":{"type":"authorised_distributor"},"dateCode":null,"isDateCodeWithin2Years":true,"availabilityType":"stock","packagingType":"tape_reel","packagingCondition":"full"},{"offerPlatformId":"8715417522","mpq":1,"quantity":283206,"priceTiers":[{"moq":709,"price":"0.07768"}],"deliveryDays":167,"vendor":{"type":"authorised_distributor"},"dateCode":null,"isDateCodeWithin2Years":true,"availabilityType":"lead_time","packagingType":"tape_reel","packagingCondition":"full"}],"facets":{"vendorTypes":[{"value":"authorised_distributor","label":"authorised_distributor","count":2},{"value":"factory_direct","label":"factory_direct","count":1}],"availabilityTypes":[{"value":"lead_time","label":"lead_time","count":1},{"value":"stock","label":"stock","count":2}],"packagingConditions":[{"value":"full","label":"full","count":3}],"packagingTypes":[{"value":"tape_reel","label":"tape_reel","count":2},{"value":"tube","label":"tube","count":1}]},"_links":{"schema":{"href":"/api/schemas/part-offer-search.json"}}}`;
priceGoodsList
:=
gjson
.
Get
(
skuInfo
,
"results"
)
.
Array
()
priceGoodsList
:=
gjson
.
Get
(
skuInfo
,
"results"
)
.
Array
()
common
.
PrintDebugHtml
(
ctx
,
priceGoodsList
)
common
.
PrintDebugHtml
(
ctx
,
priceGoodsList
)
...
@@ -221,12 +224,12 @@ func GetSourceGineData(ctx *gin.Context,url string) string {
...
@@ -221,12 +224,12 @@ func GetSourceGineData(ctx *gin.Context,url string) string {
"Content-Type"
:
"application/json"
,
"Content-Type"
:
"application/json"
,
"Authorization"
:
"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE2MDUwMjk3ODQsInVzZXJuYW1lIjoiYWNiMjMzMmItYjQ4MC00M2UwLTgwZjYtZjQ0OTVkY2M0NjBhIn0.Bt6Aii7xxVKIfxpnttmHi4hDhvBmw0Bow47b1s08ibfDVtQxmn5ZzOAbsl0spxqMysUngZ31KfPEnos5EeD04jOtu5Y9llNHCymO15_--AYy4JdzcoDgSwUnogUw4tD4zkm4vTsRxzfTjbrN9gX2n_33BemD4S1oT4M4rPK_RRw6dJ8wYqMIK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FYH5i9J_pesJCYGdRfAZDZ_mcD9KPZUylDd17nlrMWl_D14vMOklU4_9RksBX7YsNu5lyexW-djOmCcnTFV5GMcPF1jht0i6IlvQYHgNYtEITEKNMjAGRy4AL_3kYXRjlGsq37uKJup14t4VkZe95Zt_beIqPyRvcig3TV1ol5vdPf2IW1Vt_vJXsoNno5F_uznvsv268srplyO-akqbpP-X16m-Sh9kgZhk1fDcWQ8kJXt7uqd0"
,
}
}
req
.
SetTimeout
(
3
*
time
.
Second
)
req
.
SetTimeout
(
8
*
time
.
Second
)
resp
,
err
:=
req
.
Get
(
url
,
header
)
resp
,
err
:=
req
.
Get
(
url
,
header
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
return
""
}
}
res
:=
resp
.
String
()
//请求外链拿到结果
res
:=
resp
.
String
()
//请求外链拿到结果
common
.
PrintDebugHtml
(
ctx
,
"原始数据:"
+
res
)
common
.
PrintDebugHtml
(
ctx
,
"原始数据:"
+
url
+
res
)
return
res
return
res
}
}
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