1
0
Fork 0
Go library for working with the Lenpaste API.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Leonid Maslakov 4a879ea09c
Update to Lenpaste API v1.2
2 months ago
LICENSE first commit 5 months ago
README.md Update to Lenpaste API v1.2 2 months ago
client.go Update to Lenpaste API v1.2 2 months ago
client_get.go Add go doc 5 months ago
client_new.go Update to Lenpaste API v1.2 2 months ago
client_server.go Add go doc 5 months ago
go.mod first commit 5 months ago

README.md

pasteapi is a Go library for working with the Lenpaste API.

Install

Add to go.mod file:

require git.lcomrade.su/root/pasteapi.go v1

Example

package main

import (
	"fmt"
	"git.lcomrade.su/root/pasteapi.go"
)

func main() {
	pasteSrv := pasteapi.NewServer("https://paste.lcomrade.su/")
	//pasteSrv.Auth("user", "pass")

	// Getting server information
	srvInfo, err := pasteSrv.GetServerInfo()
	if err != nil {
		panic(err)
	}
	fmt.Println("## Server Info ##")
	fmt.Println("URL:", pasteSrv.Server)
	fmt.Println("Version:", srvInfo.Version)
	fmt.Println("Maximum paste title length:", srvInfo.TitleMaxLen)
	fmt.Println("Maximum paste body length:", srvInfo.BodyMaxLen)
	fmt.Println("Maximum paste lifetime:", srvInfo.MaxLifeTime)
	fmt.Println("About this server:", srvInfo.ServerAbout)
	fmt.Println("Server rules:", srvInfo.ServerRules)
	fmt.Println("Server Term of Use:", srvInfo.ServerTermsOfUse)
	fmt.Println("Administrator name:", srvInfo.AdminName)
	fmt.Println("Administrator mail:", srvInfo.AdminMail)
	fmt.Println("Syntaxes:", srvInfo.Syntaxes)
	fmt.Println("UI default paste lifetime:", srvInfo.UiDefaultLifeTime)
	fmt.Println("Need auth to create pastes:", srvInfo.AuthRequired)

	// Creating a paste
	fmt.Println("\n## TEST ##")
	fmt.Println("Creating a new paste...")

	pasteID, _, _, err := pasteSrv.New(pasteapi.NewPaste{
		Title: "Test paste",
		Body: `package main

func main() {
	println("Hello world!")
}
`,
		LineEnd:    pasteapi.LineEndUnix, // LF (\n) line end
		Syntax:     "Go",
		OneUse:     false,
		Expiration: 60 * 10, // 10 minutes
		Author: "Anon",
		AuthorEmail: "me@example.org",
		AuthorURL: "example.org",
	})
	if err != nil {
		panic(err)
	}
	fmt.Println("A new paste is created:", pasteSrv.Server+"/"+pasteID)

	// Getting the paste
	fmt.Println("Obtaining the newly created paste...")
	pasteGet, err := pasteSrv.Get(pasteID, false)
	if err != nil {
		panic(err)
	}
	fmt.Println("ID:", pasteGet.ID)
	fmt.Println("Title:", pasteGet.Title)
	fmt.Println("Body:", pasteGet.Body)
	fmt.Println("Create time:", pasteGet.CreateTime)
	fmt.Println("Delete time:", pasteGet.DeleteTime)
	fmt.Println("One use:", pasteGet.OneUse)
	fmt.Println("Syntax:", pasteGet.Syntax)
	fmt.Println("Author:", pasteGet.Author)
	fmt.Println("Author email:", pasteGet.AuthorEmail)
	fmt.Println("Author URL:", pasteGet.AuthorURL)
}

Documentation

Read documentation online on pkg.go.dev. Or use go doc -all git.lcomrade.su/root/pasteapi.go to read offline.

License

This library is distributed under the MIT license.