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-11 00:45:39 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
43a3c7d9694ac4058d3e9350851703cf35abedf5
43a3c7d9
1 parent
598223dd
ADD: getItemsInfoByKeyword functions for handle api response
return apiResponse.Items slice
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
8 deletions
joongna/service/item.go
joongna/service/item.go
View file @
43a3c7d
package
service
import
(
"fmt"
"encoding/json"
"io"
"io/ioutil"
"joongna/config"
"joongna/model"
...
...
@@ -15,11 +16,11 @@ func GetItemByKeyword(keyword string) ([]model.Item, error) {
return
items
,
nil
}
func
GetItemInfoByKeyword
(
keyword
string
)
{
func
getItemsInfoByKeyword
(
keyword
string
)
[]
model
.
ApiResponseItem
{
encText
:=
url
.
QueryEscape
(
"중고나라"
+
keyword
)
u
rl
:=
"https://openapi.naver.com/v1/search/cafearticle.json?query="
+
encText
+
"&sort=sim"
apiU
rl
:=
"https://openapi.naver.com/v1/search/cafearticle.json?query="
+
encText
+
"&sort=sim"
req
,
err
:=
http
.
NewRequest
(
"GET"
,
u
rl
,
nil
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
apiU
rl
,
nil
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
...
...
@@ -31,9 +32,18 @@ func GetItemInfoByKeyword(keyword string) {
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
defer
resp
.
Body
.
Close
()
defer
func
(
Body
io
.
ReadCloser
)
{
err
:=
Body
.
Close
()
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
}(
resp
.
Body
)
bytes
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
str
:=
string
(
bytes
)
fmt
.
Println
(
str
)
response
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
var
apiResponse
model
.
ApiResponse
err
=
json
.
Unmarshal
(
response
,
&
apiResponse
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
return
apiResponse
.
Items
}
...
...
Please
register
or
login
to post a comment