telegraph

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2020 License: MIT Imports: 10 Imported by: 6

README

telegraph-go

是一个封装了 Telegraph APIGolang

APIs has achieved

  • CreatePage
Getting Started

  1. Download
go get -u github.com/MakeGolangGreat/telegraph-go
  1. test.go
package main

imoprt "github.com/MakeGolangGreat/telegraph-go"

func main(){
  page := &telegraph.Page{
    AccessToken: "......<telegraph-token>......",
		AuthorURL:   "https://github.com/MakeGolangGreat/telegraph-go",
		AuthorName:  "telegraph-go",
    Title: 			 "Title here",
    Data:				 "<h1>Put html strings here.</h1>",
	}
  
  link, err := page.CreatePage()
	if err != nil {
    fmt.Println("Create Page Failed: ", err)
  }else{
    fmt.Println(link) 
  }
}

It's a very simple sample above. You maybe want to look this archive project that using telegraph-go now.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node interface{}

Node 对应DOM中的一个Node节点,可以是字符串或者NodeElement

type NodeElement

type NodeElement struct {
	// Name of the DOM element. Available tags: a, aside, b, blockquote, br, code, em, figcaption, figure,
	// h3, h4, hr, i, iframe, img, li, ol, p, pre, s, strong, u, ul, video.
	Tag string `json:"tag"`

	// Attributes of the DOM element. Key of object represents name of attribute, value represents value
	// of attribute. Available attributes: href, src.
	Attrs map[string]string `json:"attrs,omitempty"`

	// List of child nodes for the DOM element.
	Children []Node `json:"children,omitempty"`
}

NodeElement 表示一个元素,因为Telegraph的限制,只允许这三个属性

type Page

type Page struct {
	AccessToken   string       `json:"access_token" validate:"required"`
	Title         string       `json:"title" validate:"max=10,min=1,required"`
	Content       interface{}  `json:"content" validate:"required"`
	ReturnContent string       `json:"return_content,omitempty"`
	Data          string       `json:"-"`
	Debug         bool         `json:"-"`
	AttachInfo    *NodeElement `json:"-"`
	AuthorName    string       `json:"author_name,omitempty"`
	AuthorURL     string       `json:"author_url,omitempty"`
}

Page 是创建文章时的请求类型,内含创建文章需要的请求数据

func (*Page) CreatePage added in v1.1.0

func (page *Page) CreatePage() (string, error)

CreatePage 将文本数据保存到Telegrah,并返回一个Telegraph链接。 具体实现和说明请看:CreatePageWithClient 这里只是一层简单的封装,传入一个默认的Client

func (*Page) CreatePageWithClient added in v1.1.0

func (page *Page) CreatePageWithClient(client *http.Client) (string, error)

CreatePageWithClient 将文本数据保存到Telegrah,并返回一个Telegraph链接。 由于Telegraph存在内容大小限制(64kb,utf-8),CreatePageWithClient将会把文本数据分割成多篇文章发表。 但放心,第一篇文章尾部将会存在指向第二篇文章的链接(「下一页」) 提供一个Client参数,方便调用者传入一个自定义的Client(其实就是代理,让程序可以翻墙)

func (*Page) SendPage added in v1.1.0

func (page *Page) SendPage(url string, client *http.Client) (link string, err error)

SendPage 发送文章请求

type PageResponse added in v1.1.0

type PageResponse struct {
	OK     bool
	Result struct {
		Path string
		URL  string
	}
	Error string
}

PageResponse 创建Page接口返回的数据

Jump to

Keyboard shortcuts

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