Toggle navigation
Toggle navigation
This project
Loading...
Sign in
방승일
/
mamuri-bot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
윤준석
2022-05-22 02:32:55 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
30455e9ee0c09a8b0aa7a5d366d5643898b8861b
30455e9e
1 parent
bcac1b53
ADD: api request concurrently
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
15 deletions
bunjang/service/item.go
bunjang/service/item.go
View file @
30455e9
...
...
@@ -11,10 +11,12 @@ import (
"net/url"
"strconv"
"strings"
"sync"
)
func
GetItemByKeyword
(
keyword
string
)
([]
model
.
Item
,
error
)
{
var
items
[]
model
.
Item
wg
:=
sync
.
WaitGroup
{}
responseItems
,
err
:=
getApiResponseItems
(
keyword
)
if
err
!=
nil
{
...
...
@@ -22,28 +24,33 @@ func GetItemByKeyword(keyword string) ([]model.Item, error) {
}
for
_
,
responseItem
:=
range
responseItems
{
extraInfo
,
err
:=
getItemExtraInfo
(
responseItem
.
Pid
)
if
err
!=
nil
{
return
nil
,
err
}
item
:=
model
.
Item
{
Platform
:
"번개장터"
,
Name
:
responseItem
.
Name
,
Price
:
priceStringToInt
(
responseItem
.
Price
),
ThumbnailUrl
:
responseItem
.
ProductImage
,
ItemUrl
:
"https://m.bunjang.co.kr/products/"
+
responseItem
.
Pid
,
ExtraInfo
:
extraInfo
,
}
items
=
append
(
items
,
item
)
wg
.
Add
(
1
)
go
func
(
responseItem
model
.
ApiResponseItem
)
{
defer
wg
.
Done
()
extraInfo
,
err
:=
getItemExtraInfo
(
responseItem
.
Pid
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
item
:=
model
.
Item
{
Platform
:
"번개장터"
,
Name
:
responseItem
.
Name
,
Price
:
priceStringToInt
(
responseItem
.
Price
),
ThumbnailUrl
:
responseItem
.
ProductImage
,
ItemUrl
:
"https://m.bunjang.co.kr/products/"
+
responseItem
.
Pid
,
ExtraInfo
:
extraInfo
,
}
items
=
append
(
items
,
item
)
}(
responseItem
)
}
wg
.
Wait
()
return
items
,
nil
}
func
getApiResponseItems
(
keyword
string
)
([]
model
.
ApiResponseItem
,
error
)
{
encText
:=
url
.
QueryEscape
(
keyword
)
apiUrl
:=
fmt
.
Sprintf
(
"https://api.bunjang.co.kr/api/1/find_v2.json?q=%s&order=score"
,
encText
)
apiUrl
:=
fmt
.
Sprintf
(
"https://api.bunjang.co.kr/api/1/find_v2.json?q=%s&order=score
&n=6
"
,
encText
)
response
,
err
:=
getResponse
(
apiUrl
)
if
err
!=
nil
{
...
...
Please
register
or
login
to post a comment