goinside

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2019 License: GPL-3.0 Imports: 19 Imported by: 1

README

goinside

Build Status Go Report Card GoDoc

이 라이브러리는 디시인사이드 비공식 API 입니다. API에 대한 설명은 godoc에서 보실 수 있습니다.

Install

go get -u github.com/geeksbaek/goinside/...

See also

Special thanks to

goinside는 아래 라이브러리들의 코드를 일부 참고하였습니다.

Warning

현재 개발 중이며 언제든지 API 구조가 변경될 수 있습니다.

Jongyeol Baek geeksbaek@gmail.com

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App added in v1.1.0

type App struct {
	Token string
	ID    string
}

App 구조체는 AppKey와 AppId를 구성합니다.

type AppIDResponse

type AppIDResponse []struct {
	Result bool   `json:"result"`
	AppID  string `json:"app_id"`
}

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

func FetchArticle(URL string) (a *Article, err error)

FetchArticle 함수는 해당 글의 정보를 가져옵니다.

type ArticleDraft

type ArticleDraft struct {
	GallID  string
	Subject string
	Content string
	Images  []string
}

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

type CommentDraft struct {
	TargetGallID        string
	TargetArticleNumber string
	Content             string
}

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 Gall

type Gall struct {
	ID  string
	URL string
}

Gall 구조체는 갤러리의 가장 기본적인 정보, ID와 이름을 나타냅니다.

type GuestSession

type GuestSession struct {
	// contains filtered or unexported fields
}

GuestSession 구조체는 유동닉 세션을 나타냅니다.

func Guest

func Guest(id, pw string) (gs *GuestSession, err error)

Guest 함수는 유동닉 세션을 반환합니다.

func RandomGuest

func RandomGuest() *GuestSession

RandomGuest 함수는 임의의 유동닉 세션을 반환합니다.

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 ImageURLType

type ImageURLType string

ImageURLType 은 이미지 URL을 나타내는 문자열입니다.

func (ImageURLType) Fetch

func (i ImageURLType) Fetch() (data []byte, filename string, err error)

Fetch 메소드는 해당 이미지 주소를 참조하여 이미지의 []byte와 filename을 반환합니다.

type Level

type Level string

Level 은 멤버 레벨을 나타내는 문자열입니다.

const (
	UnknownLevel Level = ""
	Level8       Level = "8"
	Level9       Level = "9"
	Level10      Level = "10"
)

디시인사이드에서 회원의 단계를 구분하는데 사용되는 값입니다.

func (Level) IconURL

func (lv Level) IconURL() string

IconURL 메소드는 해당 레벨의 멤버 아이콘 URL을 반환합니다.

func (Level) Type

func (lv Level) Type() MemberType

Type 메소드는 해당 레벨의 멤버 타입을 반환합니다.

type List

type List struct {
	Info  *ListInfo
	Items []*ListItem
}

List 구조체는 갤러리의 정보와 해당 갤러리의 특정 페이지에 있는 글의 슬라이스를 나타냅니다.

func FetchBestList

func FetchBestList(gallID string, page int) (l *List, err error)

FetchBestList 함수는 해당 갤러리의 해당 페이지에 있는 개념글의 목록을 가져옵니다.

func FetchList

func FetchList(gallID string, page int) (l *List, err error)

FetchList 함수는 해당 갤러리의 해당 페이지에 있는 글의 목록을 가져옵니다.

func Search(id, keyword string) (l *List, err error)

Search 함수는 해당 키워드와 제목이나 내용, 혹은 글쓴이가 일치하는 글을 검색합니다.

func SearchByAuthor

func SearchByAuthor(id, keyword string) (l *List, err error)

SearchByAuthor 함수는 해당 키워드와 글쓴이가 일치하는 글을 검색합니다.

func SearchByContent

func SearchByContent(id, keyword string) (l *List, err error)

SearchByContent 함수는 해당 키워드와 내용이 일치하는 글을 검색합니다.

func SearchBySubject

func SearchBySubject(id, keyword string) (l *List, err error)

SearchBySubject 함수는 해당 키워드와 제목이 일치하는 글을 검색합니다.

func SearchBySubjectAndContent

func SearchBySubjectAndContent(id, keyword string) (l *List, err error)

SearchBySubjectAndContent 함수는 해당 키워드와 제목이나 내용이 일치하는 글을 검색합니다.

type ListInfo

type ListInfo struct {
	*Gall
	CategoryName string
	FileCount    string
	FileSize     string
}

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) Fetch

func (i *ListItem) Fetch() (*Article, error)

Fetch 메소드는 해당 글의 세부 정보(본문, 이미지 주소, 댓글)를 가져옵니다.

func (*ListItem) FetchImageURLs

func (i *ListItem) FetchImageURLs() (imageURLs []ImageURLType, err error)

FetchImageURLs 메소드는 해당 글의 이미지 주소의 슬라이스만을 가져옵니다.

type MajorGallery

type MajorGallery struct {
	ID       string
	Name     string
	Number   string
	CanWrite bool
}

MajorGallery 구조체는 일반 갤러리의 정보를 나타냅니다.

func FetchAllMajorGallery

func FetchAllMajorGallery() (mg []*MajorGallery, err error)

FetchAllMajorGallery 함수는 모든 일반 갤러리의 정보를 가져옵니다.

type MemberSession

type MemberSession struct {
	*MemberSessionDetail
	// contains filtered or unexported fields
}

MemberSession 구조체는 고정닉의 세션을 나타냅니다.

func Login

func Login(id, pw string) (ms *MemberSession, err error)

Login 함수는 고정닉 세션을 반환합니다.

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 함수는 모든 마이너 갤러리의 정보를 가져옵니다.

Directories

Path Synopsis
Package gallog 는 디시인사이드 갤로그 관련 API를 제공합니다.
Package gallog 는 디시인사이드 갤로그 관련 API를 제공합니다.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL