Documentation ¶
Overview ¶
Package goinside 는 Go로 구현한 비공식 디시인사이드 API입니다.
Feature ¶
1. 유동닉 또는 고정닉으로 글과 댓글의 작성 및 삭제
2. 추천과 비추천
3. 특정 갤러리의 특정 페이지에 있는 게시물 및 댓글 가져오기
4. 모든 일반 갤러리, 마이너 갤러리 정보 가져오기
5. 프록시 모드
6. 검색
Usage ¶
글이나 댓글을 작성하거나 삭제하려면 우선 세션을 생성해야 합니다.
유동닉 세션은 Guest 함수로 생성하며, 닉네임과 비밀번호를 인자로 받습니다. 빈 문자열을 인자로 넘길 경우 에러를 반환합니다.
s, err := goinside.Guest("ㅇㅇ", "123") if err != nil { log.Fatal(err) }
고정닉 세션은 Login 함수로 생성합니다. 디시인사이드 ID와 비밀번호를 인자로 받습니다. 로그인에 실패할 경우 에러를 반환합니다.
s, err := goinside.Login("ID", "PASSWORD") if err != nil { log.Fatal(err) }
글이나 댓글을 작성하기 위해서는 Draft를 먼저 생성해야 합니다. Draft를 생성하기 위해 NewArticleDraft, NewCommentDraft 함수가 있습니다. 해당 함수로 생성된 Draft 객체를 Wrtie 메소드로 전달하여 글을 작성합니다.
draft := NewArticleDraft("programming", "제목", "내용", "이미지 경로") if err := s.Write(draft); err != nil { log.Fatal(err) }
갤러리의 글을 가져오는 데는 세션이 필요하지 않습니다. 다음 코드는 programming 갤러리의 개념글 목록 1페이지에 있는 글들을 가져옵니다.
URL := "http://gall.dcinside.com/board/lists/?id=programming" list, err := goinside.FetchBestList(URL, 1) if err != nil { log.Fatal(err) }
다음은 가져온 목록의 첫 번째 글에 댓글을 작성하는 코드입니다.
err := goinside.Write(goinside.NewCommentDraft( list.Items[0], "내용", )) if err != nil { log.Fatal(err) }
다음은 가져온 목록의 첫 번째 글을 삭제하는 코드입니다. 삭제할 때는 해당 세션의 정보로 삭제를 시도합니다. 유동닉의 경우 닉네임과 비밀번호가 글을 작성할 때 사용했던 것과 일치해야 하며, 고정닉의 경우 해당 세션의 고정닉으로 작성했던 글이어야 삭제할 수 있습니다. 일치하지 않는 세션으로 삭제 요청을 할 경우, 오류를 반환합니다.
if err := s.Delete(list.Items[0]); err != nil { log.Fatal(err) }
가져온 글을 Write 메소드에 넘겨서 바로 재작성 할 수도 있습니다. 그러나 FetchList, FetchBestList 함수로 가져온 Item들은 아직 글의 내용을 알 수 없는 상태입니다. 이 Item이 Write 함수의 인자로 전달될 때는 글의 제목을 그대로 내용으로 쓰도록 되어있습니다.
if err := s.Write(list.Items[0]); err != nil { log.Fatal(err) }
다음은 FetchArticle 함수로 가져온 글을 재작성하는 코드입니다.
article, err := goinside.FetchArticle(URL) if err != nil { log.Fatal(err) } if err := s.Write(article); err != nil { log.Fatal(err) }
해당 세션을 프록시로 전환할 수도 있습니다. 아래 코드의 proxy 변수는 *url.URL 타입이라고 가정합니다.
s.Connection().SetTransport(proxy)
http 요청에 타임아웃을 설정할 수도 있습니다.
s.Connection().SetTimeout(time.Second * 3)
Index ¶
- type App
- type AppIDResponse
- type Article
- type ArticleDraft
- type ArticleType
- type Comment
- type CommentDraft
- type CommentType
- type Connection
- type Gall
- type GuestSession
- type ImageURLType
- type Level
- type List
- func FetchBestList(gallID string, page int) (l *List, err error)
- func FetchList(gallID string, page int) (l *List, err error)
- func Search(id, keyword string) (l *List, err error)
- func SearchByAuthor(id, keyword string) (l *List, err error)
- func SearchByContent(id, keyword string) (l *List, err error)
- func SearchBySubject(id, keyword string) (l *List, err error)
- func SearchBySubjectAndContent(id, keyword string) (l *List, err error)
- type ListInfo
- type ListItem
- type MajorGallery
- type MemberSession
- func (ms *MemberSession) Connection() *Connection
- func (ms *MemberSession) Delete(d deletable) error
- func (ms *MemberSession) Logout() (err error)
- func (ms *MemberSession) ThumbsDown(a actionable) error
- func (ms *MemberSession) ThumbsUp(a actionable) error
- func (ms *MemberSession) Write(w writable) error
- type MemberSessionDetail
- type MemberType
- type MinorGallery
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppIDResponse ¶
AppIDResponse 구조체는 appKeyVerificationAPI 요청의 응답을 정의합니다.
type Article ¶
type Article struct { *Gall URL string Subject string Content string ThumbsUp int ThumbsDown int Name string Number string Level Level IP string CommentLength int HasImage bool Hit int ArticleType ArticleType GallogID string GallogURL string IsBest bool ImageURLs []ImageURLType Comments []*Comment Date time.Time }
Article 구조체는 글의 정보를 나타냅니다. 여기에는 해당 글이 작성된 갤러리의 정보와 해당 글에 달린 댓글들을 모두 포함합니다.
func FetchArticle ¶
FetchArticle 함수는 해당 글의 정보를 가져옵니다.
type ArticleDraft ¶
ArticleDraft 구조체는 작성하기 위한 글의 초안을 나타냅니다.
func NewArticleDraft ¶
func NewArticleDraft(gallID, subject, content string, images ...string) *ArticleDraft
NewArticleDraft 함수는 글을 작성하기 위해 초안을 생성합니다. 해당 초안을 세션의 Write 함수로 전달하여 작성 요청을 보낼 수 있습니다.
type ArticleType ¶
type ArticleType int
ArticleType 은 글의 타입을 나타내는 상수입니다.
const ( UnknownArticleType ArticleType = iota TextArticleType TextBestArticleType ImageArticleType ImageBestArticleType MovieArticleType SuperBestArticleType )
글의 타입을 구분하는 상수입니다. TextArticleType은 텍스트만 있는 글, TextBestArticleType은 텍스트만 있는 개념글, ImageArticleType은 이미지만 있는 글, ImageBestArticleType은 이미지만 있는 개념글, MovieArticleType은 동영상이 있는 글, SuperBestArticleType은 초개념글입니다.
func (ArticleType) IconURL ¶
func (a ArticleType) IconURL() string
IconURL 메소드는 해당 글 타입의 IconURL을 반환합니다.
type Comment ¶
type Comment struct { *Gall Parents *Article Content string HTML string Type CommentType Name string GallogID string GallogURL string Level Level IP string Number string Date time.Time }
Comment 구조체는 댓글의 정보를 나타냅니다. 여기에는 해당 댓글이 작성된 글의 정보도 포함됩니다. HTML은 해당 댓글의 타입에 맞는 HTML 코드입니다. DCcon일 경우 img element, 보이스리플일 경우 audio element 입니다.
type CommentDraft ¶
CommentDraft 구조체는 작성하기 위한 댓글의 초안을 나타냅니다.
func NewCommentDraft ¶
func NewCommentDraft(c commentable, content string) *CommentDraft
NewCommentDraft 함수는 댓글을 작성하기 위해 초안을 생성합니다. 해당 초안을 세션의 Write 함수로 전달하여 작성 요청을 보낼 수 있습니다.
type CommentType ¶
type CommentType int
CommentType 은 댓글의 타입을 나타내는 상수입니다.
const ( UnknownCommentType CommentType = iota TextCommentType DCconCommentType VoiceCommentType )
댓글의 타입을 구분하는 상수입니다. TextCommentType은 일반 댓글, DCconCommentType은 디시콘, VoiceCommentType은 보이스 리플입니다.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection 구조체는 HTTP 통신에 필요한 정보를 나타냅니다.
func (*Connection) SetTimeout ¶
func (c *Connection) SetTimeout(time time.Duration)
SetTimeout 함수는 해당 세션의 통신에 timeout 값을 설정합니다.
func (*Connection) SetTransport ¶
func (c *Connection) SetTransport(proxy *url.URL)
SetTransport 함수는 해당 세션이 주어진 프록시를 통해 통신하도록 설정합니다. 프록시 주소는 http://84.192.54.48:8080 와 같은 형식으로 전달합니다.
type GuestSession ¶
type GuestSession struct {
// contains filtered or unexported fields
}
GuestSession 구조체는 유동닉 세션을 나타냅니다.
func (*GuestSession) Connection ¶
func (gs *GuestSession) Connection() *Connection
Connection 메소드는 해당 세션의 Connection 구조체를 반환합니다.
func (*GuestSession) Delete ¶
func (gs *GuestSession) Delete(d deletable) error
Delete 메소드는 삭제 가능한 객체를 전달받아 삭제 요청을 보냅니다.
func (*GuestSession) ThumbsDown ¶
func (gs *GuestSession) ThumbsDown(a actionable) error
ThumbsDown 메소드는 해당 글에 비추천 요청을 보냅니다.
func (*GuestSession) ThumbsUp ¶
func (gs *GuestSession) ThumbsUp(a actionable) error
ThumbsUp 메소드는 해당 글에 추천 요청을 보냅니다.
func (*GuestSession) Write ¶
func (gs *GuestSession) Write(w writable) error
Write 메소드는 쓰기 가능한 객체를 전달받아 작성 요청을 보냅니다.
type List ¶
List 구조체는 갤러리의 정보와 해당 갤러리의 특정 페이지에 있는 글의 슬라이스를 나타냅니다.
func FetchBestList ¶
FetchBestList 함수는 해당 갤러리의 해당 페이지에 있는 개념글의 목록을 가져옵니다.
func SearchByAuthor ¶
SearchByAuthor 함수는 해당 키워드와 글쓴이가 일치하는 글을 검색합니다.
func SearchByContent ¶
SearchByContent 함수는 해당 키워드와 내용이 일치하는 글을 검색합니다.
func SearchBySubject ¶
SearchBySubject 함수는 해당 키워드와 제목이 일치하는 글을 검색합니다.
func SearchBySubjectAndContent ¶
SearchBySubjectAndContent 함수는 해당 키워드와 제목이나 내용이 일치하는 글을 검색합니다.
type ListInfo ¶
ListInfo 구조체는 갤러리의 정보를 나타냅니다. 기본 정보를 나타내는 Gall을 제외한 나머지 정보들은 디시인사이드 갤러리 목록 API가 반환하는 값들입니다. CategoryName은 해당 갤러리의 카테고리 이름을 나타냅니다. FileCount와 FileSize는 정확히 무엇을 나타내는지 알 수 없습니다.
type ListItem ¶
type ListItem struct { *Gall URL string Subject string Name string Level Level HasImage bool ArticleType ArticleType ThumbsUp int IsBest bool Hit int GallogID string GallogURL string IP string CommentLength int VoiceCommentLength int Number string Date time.Time }
ListItem 구조체는 갤러리 페이지에서 확인할 수 있는 글의 정보를 나타냅니다. Article 구조체와는 다릅니다. Article 구조체는 글 본문과 댓글들을 포함하지만 ListItem 구조체는 그럴 수 없습니다. 갤러리 목록에서 확인할 수 있는 정보만을 나타냅니다.
func (*ListItem) FetchImageURLs ¶
func (i *ListItem) FetchImageURLs() (imageURLs []ImageURLType, err error)
FetchImageURLs 메소드는 해당 글의 이미지 주소의 슬라이스만을 가져옵니다.
type MajorGallery ¶
MajorGallery 구조체는 일반 갤러리의 정보를 나타냅니다.
func FetchAllMajorGallery ¶
func FetchAllMajorGallery() (mg []*MajorGallery, err error)
FetchAllMajorGallery 함수는 모든 일반 갤러리의 정보를 가져옵니다.
type MemberSession ¶
type MemberSession struct { *MemberSessionDetail // contains filtered or unexported fields }
MemberSession 구조체는 고정닉의 세션을 나타냅니다.
func (*MemberSession) Connection ¶
func (ms *MemberSession) Connection() *Connection
Connection 메소드는 해당 세션의 Connection 구조체를 반환합니다.
func (*MemberSession) Delete ¶
func (ms *MemberSession) Delete(d deletable) error
Delete 메소드는 삭제 가능한 객체를 전달받아 삭제 요청을 보냅니다.
func (*MemberSession) Logout ¶
func (ms *MemberSession) Logout() (err error)
Logout 메소드는 해당 고정닉 세션을 종료합니다.
func (*MemberSession) ThumbsDown ¶
func (ms *MemberSession) ThumbsDown(a actionable) error
ThumbsDown 메소드는 해당 글에 비추천 요청을 보냅니다.
func (*MemberSession) ThumbsUp ¶
func (ms *MemberSession) ThumbsUp(a actionable) error
ThumbsUp 메소드는 해당 글에 추천 요청을 보냅니다.
func (*MemberSession) Write ¶
func (ms *MemberSession) Write(w writable) error
Write 메소드는 글이나 댓글과 같은 쓰기 가능한 객체를 전달받아 작성 요청을 보냅니다.
type MemberSessionDetail ¶
type MemberSessionDetail struct { UserID string `json:"user_id"` UserNO string `json:"user_no"` Name string `json:"name"` Stype string `json:"stype"` }
MemberSessionDetail 구조체는 해당 세션의 세부 정보를 나타냅니다.
type MemberType ¶
type MemberType int
MemberType 은 멤버 타입을 나타내는 상수입니다.
const ( UnknownMemberType MemberType = iota FullMemberType HalfMemberType GuestMemberType )
멤버의 타입을 구분하는 상수입니다. FullMemberType은 고정닉, HalfMemberType 반고정닉, GuestMemberType은 유동닉입니다.
func (MemberType) Level ¶
func (m MemberType) Level() Level
Level 메소드는 해당 멤버 타입의 레벨을 반환합니다. HalfMemberType은 Level8, FullMemberType은 Level9, GuestMemberType은 Level10을 반환합니다. 알 수 없는 경우 UnknownLevel을 반환합니다.
type MinorGallery ¶
type MinorGallery struct { ID string Name string Number string CanWrite bool Manager string SubManagers []string }
MinorGallery 구조체는 마이너 갤러리의 정보를 나타냅니다. 마이너 갤러리는 일반 갤러리와 달리 매니저와 부매니저가 존재합니다. 부매니저는 여러 명일 수 있습니다. 해당 값들은 gallog ID 입니다.
func FetchAllMinorGallery ¶
func FetchAllMinorGallery() (mg []*MinorGallery, err error)
FetchAllMinorGallery 함수는 모든 마이너 갤러리의 정보를 가져옵니다.