Showing
1 changed file
with
22 additions
and
15 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,28 +24,33 @@ func GetItemByKeyword(keyword string) ([]model.Item, error) { | ... | @@ -22,28 +24,33 @@ func GetItemByKeyword(keyword string) ([]model.Item, error) { |
22 | } | 24 | } |
23 | 25 | ||
24 | for _, responseItem := range responseItems { | 26 | for _, responseItem := range responseItems { |
25 | - extraInfo, err := getItemExtraInfo(responseItem.Pid) | 27 | + wg.Add(1) |
26 | - if err != nil { | 28 | + |
27 | - return nil, err | 29 | + go func(responseItem model.ApiResponseItem) { |
28 | - } | 30 | + defer wg.Done() |
29 | - item := model.Item{ | 31 | + extraInfo, err := getItemExtraInfo(responseItem.Pid) |
30 | - Platform: "번개장터", | 32 | + if err != nil { |
31 | - Name: responseItem.Name, | 33 | + log.Fatal(err) |
32 | - Price: priceStringToInt(responseItem.Price), | 34 | + } |
33 | - ThumbnailUrl: responseItem.ProductImage, | 35 | + item := model.Item{ |
34 | - ItemUrl: "https://m.bunjang.co.kr/products/" + responseItem.Pid, | 36 | + Platform: "번개장터", |
35 | - ExtraInfo: extraInfo, | 37 | + Name: responseItem.Name, |
36 | - } | 38 | + Price: priceStringToInt(responseItem.Price), |
37 | - | 39 | + ThumbnailUrl: responseItem.ProductImage, |
38 | - items = append(items, item) | 40 | + ItemUrl: "https://m.bunjang.co.kr/products/" + responseItem.Pid, |
41 | + ExtraInfo: extraInfo, | ||
42 | + } | ||
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