📚 Official unofficial Golang bindings for Telegraph API
https://telegra.ph/api
assets | ||
v2 | ||
.editorconfig | ||
.gitignore | ||
content.go | ||
content_test.go | ||
CONTRIBUTING.md | ||
create_account.go | ||
create_account_test.go | ||
create_page.go | ||
create_page_test.go | ||
doc.go | ||
edit_account_info.go | ||
edit_account_info_test.go | ||
edit_page.go | ||
edit_page_test.go | ||
example_test.go | ||
get_account_info.go | ||
get_account_info_test.go | ||
get_page.go | ||
get_page_list.go | ||
get_page_list_test.go | ||
get_page_test.go | ||
get_views.go | ||
get_views_test.go | ||
go.mod | ||
go.sum | ||
LICENSE.md | ||
README.en.md | ||
README.ru.md | ||
revoke_access_token.go | ||
revoke_access_token_test.go | ||
telegraph.go | ||
types.go |
telegraph
A simple package with minimum official dependencies to work with Telegraph API.
Download:
$ go get -u source.toby3d.me/toby3d/telegraph/v2
Import:
import "source.toby3d.me/toby3d/telegraph/v2"
Fill commands structs and execute it:
package main
import (
"context"
"fmt"
"log"
"net/http"
"source.toby3d.me/toby3d/telegraph/v2"
)
func Must[T any](v T, err error) T {
if err != nil {
panic(err)
}
return v
}
func main() {
client := http.DefaultClient
account, err := telegraph.CreateAccount{
AuthorURL: nil,
AuthorName: Must(telegraph.NewAuthorName("Anonymous")),
ShortName: *Must(telegraph.NewShortName("Sandbox")),
}.Do(context.Background(), client)
if err != nil {
log.Fatalln("cannot create account:", err)
}
page, err := telegraph.CreatePage{
AuthorURL: nil,
AccessToken: account.AccessToken,
Title: *Must(telegraph.NewTitle("Sample Page")),
AuthorName: &account.AuthorName,
Content: []telegraph.Node{{
Element: &telegraph.NodeElement{
Tag: telegraph.P,
Children: []telegraph.Node{{Text: "Hello, World!"}},
},
}},
ReturnContent: true,
}.Do(context.Background(), client)
if err != nil {
log.Fatalln("cannot create page:", err)
}
fmt.Printf("'%s' by %s\n%s", page.Title, page.AuthorName, page.Content[0])
// 'Sample Page' by Anonymous
// <p>Hello, World!</p>
}
If you need help, email me. If you want to help me, send a donation.