Showing
1 changed file
with
10 additions
and
3 deletions
... | @@ -11,10 +11,12 @@ import ( | ... | @@ -11,10 +11,12 @@ import ( |
11 | "net/url" | 11 | "net/url" |
12 | "strconv" | 12 | "strconv" |
13 | "strings" | 13 | "strings" |
14 | + "sync" | ||
14 | ) | 15 | ) |
15 | 16 | ||
16 | func GetItemByKeyword(keyword string) ([]model.Item, error) { | 17 | func GetItemByKeyword(keyword string) ([]model.Item, error) { |
17 | var items []model.Item | 18 | var items []model.Item |
19 | + wg := sync.WaitGroup{} | ||
18 | 20 | ||
19 | responseItems, err := getApiResponseItems(keyword) | 21 | responseItems, err := getApiResponseItems(keyword) |
20 | if err != nil { | 22 | if err != nil { |
... | @@ -22,9 +24,13 @@ func GetItemByKeyword(keyword string) ([]model.Item, error) { | ... | @@ -22,9 +24,13 @@ func GetItemByKeyword(keyword string) ([]model.Item, error) { |
22 | } | 24 | } |
23 | 25 | ||
24 | for _, responseItem := range responseItems { | 26 | for _, responseItem := range responseItems { |
27 | + wg.Add(1) | ||
28 | + | ||
29 | + go func(responseItem model.ApiResponseItem) { | ||
30 | + defer wg.Done() | ||
25 | extraInfo, err := getItemExtraInfo(responseItem.Pid) | 31 | extraInfo, err := getItemExtraInfo(responseItem.Pid) |
26 | if err != nil { | 32 | if err != nil { |
27 | - return nil, err | 33 | + log.Fatal(err) |
28 | } | 34 | } |
29 | item := model.Item{ | 35 | item := model.Item{ |
30 | Platform: "번개장터", | 36 | Platform: "번개장터", |
... | @@ -34,16 +40,17 @@ func GetItemByKeyword(keyword string) ([]model.Item, error) { | ... | @@ -34,16 +40,17 @@ func GetItemByKeyword(keyword string) ([]model.Item, error) { |
34 | ItemUrl: "https://m.bunjang.co.kr/products/" + responseItem.Pid, | 40 | ItemUrl: "https://m.bunjang.co.kr/products/" + responseItem.Pid, |
35 | ExtraInfo: extraInfo, | 41 | ExtraInfo: extraInfo, |
36 | } | 42 | } |
37 | - | ||
38 | items = append(items, item) | 43 | items = append(items, item) |
44 | + }(responseItem) | ||
39 | } | 45 | } |
46 | + wg.Wait() | ||
40 | 47 | ||
41 | return items, nil | 48 | return items, nil |
42 | } | 49 | } |
43 | 50 | ||
44 | func getApiResponseItems(keyword string) ([]model.ApiResponseItem, error) { | 51 | func getApiResponseItems(keyword string) ([]model.ApiResponseItem, error) { |
45 | encText := url.QueryEscape(keyword) | 52 | encText := url.QueryEscape(keyword) |
46 | - apiUrl := fmt.Sprintf("https://api.bunjang.co.kr/api/1/find_v2.json?q=%s&order=score", encText) | 53 | + apiUrl := fmt.Sprintf("https://api.bunjang.co.kr/api/1/find_v2.json?q=%s&order=score&n=6", encText) |
47 | 54 | ||
48 | response, err := getResponse(apiUrl) | 55 | response, err := getResponse(apiUrl) |
49 | if err != nil { | 56 | if err != nil { | ... | ... |
-
Please register or login to post a comment