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:22:39 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
70cbee9d5ee7ae95ea2598a6295a66dbbabd4a66
70cbee9d
1 parent
018e1e7f
ADD: get item by keyword service
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
22 deletions
joongna/main.go
joongna/service/item.go
joongna/main.go
View file @
70cbee9
...
...
@@ -3,28 +3,6 @@ package main
import
"github.com/labstack/echo/v4"
func
main
()
{
//keyword := "m1 pro 맥북 프로 16인치"
//encText := url2.QueryEscape("중고나라" + keyword)
//url := "https://openapi.naver.com/v1/search/cafearticle.json?query=" + encText + "&sort=sim"
//
//req, err := http.NewRequest("GET", url, nil)
//if err != nil {
// log.Fatal(err)
//}
//req.Header.Add("X-Naver-Client-Id", config.Cfg.Secret.CLIENTID)
//req.Header.Add("X-Naver-Client-Secret", config.Cfg.Secret.CLIENTSECRET)
//
//client := &http.Client{}
//resp, err := client.Do(req)
//if err != nil {
// log.Fatal(err)
//}
//defer resp.Body.Close()
//
//bytes, _ := ioutil.ReadAll(resp.Body)
//str := string(bytes)
//fmt.Println(str)
e
:=
echo
.
New
()
e
.
Logger
.
Fatal
(
e
.
Start
(
":8080"
))
...
...
joongna/service/item.go
0 → 100644
View file @
70cbee9
package
service
import
(
"fmt"
"io/ioutil"
"joongna/config"
"joongna/model"
"log"
"net/http"
"net/url"
)
func
GetItemByKeyword
(
keyword
string
)
([]
model
.
Item
,
error
)
{
var
items
[]
model
.
Item
return
items
,
nil
}
func
GetItemInfoByKeyword
(
keyword
string
)
{
encText
:=
url
.
QueryEscape
(
"중고나라"
+
keyword
)
url
:=
"https://openapi.naver.com/v1/search/cafearticle.json?query="
+
encText
+
"&sort=sim"
req
,
err
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
req
.
Header
.
Add
(
"X-Naver-Client-Id"
,
config
.
Cfg
.
Secret
.
CLIENTID
)
req
.
Header
.
Add
(
"X-Naver-Client-Secret"
,
config
.
Cfg
.
Secret
.
CLIENTSECRET
)
client
:=
&
http
.
Client
{}
resp
,
err
:=
client
.
Do
(
req
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
defer
resp
.
Body
.
Close
()
bytes
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
str
:=
string
(
bytes
)
fmt
.
Println
(
str
)
}
Please
register
or
login
to post a comment