pastebin

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: MIT Imports: 8 Imported by: 0

README

Pastebin Go Client

This is a Go client library for interacting with the Pastebin API. It allows users to authenticate, create pastes, delete them, access raw content and retrieve user pastes.


Features

  • Authenticate using Pastebin credentials
  • Create pastes (public, unlisted, or private)
  • Fetch all pastes for a user
  • Delete a paste
  • Retrieve raw content from a user's or public paste
  • Fetch user details

Getting Started

Installation
go get github.com/MarioNaise/pastebin-go

Usage

Importing
import "github.com/MarioNaise/pastebin-go"

Initialize Client
client, err := pastebin.NewClient("your_username", "your_password", "your_dev_key")
if err != nil {
 log.Fatal(err)
}

Create a Paste
pasteKey, err := client.CreatePaste(&pastebin.CreatePasteRequest{
  Content:           "Hello, Pastebin!", // required
  Name:              "HelloWorld",       // optional
  Format:            "text",             // optional
  Folder:            "hello",            // optional
  Expiration:        pastebin.OneHour,   // optional
  Visibility:        pastebin.Unlisted,  // optional
  CreatePasteAsUser: true,               // optional
})
if err != nil {
 log.Fatal(err)
}
fmt.Println("Paste Key:", pasteKey)

Get User Pastes
pastes, err := client.GetUserPastes()
if err != nil {
 log.Fatal(err)
}
for _, p := range pastes {
 fmt.Println(p)
}

Delete a Paste
err := client.DeletePaste("paste_key")
if err != nil {
 log.Fatal(err)
}

Get Raw Paste Content
For User Authenticated Pastes
content, err := client.GetRawUserPasteContent("paste_key")
if err != nil {
 log.Fatal(err)
}
fmt.Println(content)
For Public or Unlisted Pastes
content, err := client.GetRawPublicPasteContent("public_or_unlisted_paste_key")
if err != nil {
 log.Fatal(err)
}
fmt.Println(content)

Get User Details
user, err := client.GetUserDetails()
if err != nil {
 log.Fatal(err)
}
fmt.Printf("User: %s, Type: %s\n", user.UserName, user.AccountType)

Visibility Options

pastebin.Public   // 0
pastebin.Unlisted // 1
pastebin.Private  // 2

Expiration Options

pastebin.Never
pastebin.TenMinutes
pastebin.OneHour
pastebin.OneDay
pastebin.OneWeek
pastebin.TwoWeeks
pastebin.OneMonth
pastebin.SixMonths
pastebin.OneYear

License

MIT License

Documentation

Index

Constants

View Source
const (
	BaseUrl      = "https://pastebin.com"
	LoginUrl     = "https://pastebin.com/api/api_login.php"
	PostUrl      = "https://pastebin.com/api/api_post.php"
	RawUrl       = "https://pastebin.com/api/api_raw.php"
	RawPublicUrl = "https://pastebin.com/raw"
)

Base URLs and API endpoints for Pastebin.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountType

type AccountType int

AccountType represents a user account type on Pastebin. normal User = 0, pro User = 1

See https://pastebin.com/doc_api#12

const (
	NormalUser AccountType = iota
	ProUser
)

NormalUser is a free Pastebin account. ProUser is a paid Pastebin account.

See https://pastebin.com/doc_api#12

func (AccountType) String

func (acc AccountType) String() string

String returns the string representation of an AccountType.

type Client

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

Client is the Pastebin API client.

func NewClient

func NewClient(userName, password, devKey string) (*Client, error)

NewClient creates a new Pastebin API client. If a username is provided, it logs the user in to obtain a user API key.

See https://pastebin.com/doc_api#9

func (*Client) CreatePaste

func (c *Client) CreatePaste(req *CreatePasteRequest) (string, error)

CreatePaste creates a new paste using the given request parameters.

func (*Client) DeletePaste

func (c *Client) DeletePaste(key string) error

DeletePaste deletes a paste by its unique key.

func (*Client) GetRawPublicPasteContent

func (c *Client) GetRawPublicPasteContent(key string) (string, error)

GetRawPublicPasteContent fetches the raw content of a public or unlisted paste.

func (*Client) GetRawUserPasteContent

func (c *Client) GetRawUserPasteContent(key string) (string, error)

GetRawUserPasteContent retrieves the raw content of a user-owned paste.

func (*Client) GetUserDetails

func (c *Client) GetUserDetails() (*User, error)

GetUserDetails retrieves account details of the authenticated user.

func (*Client) GetUserPastes

func (c *Client) GetUserPastes() ([]*Paste, error)

GetUserPastes retrieves the list of pastes created by the authenticated user.

type CreatePasteRequest

type CreatePasteRequest struct {
	// required.
	// this is the text that will be written inside your paste.
	Content string

	// optional.
	// this will be the name / title of your paste.
	Name string

	// optional.
	// this will be the syntax highlighting value.
	//
	// See https://pastebin.com/doc_api#5
	Format string

	// optional.
	// this sets the key of the folder of your paste.
	//
	// See https://pastebin.com/doc_api#5
	Folder string

	// optional.
	// this sets the expiration date of your paste.
	// default value: "N" (Never)
	//
	// See https://pastebin.com/doc_api#6
	Expiration Expiration

	// optional.
	// this makes a paste public, unlisted or private.
	// Public = 0, Unlisted = 1, Private = 2
	//
	// See https://pastebin.com/doc_api#7
	Visibility Visibility

	// optional.
	// if true, this will create the paste as the currently logged in user.
	// otherwise it will create the paste as a guest.
	CreatePasteAsUser bool
}

CreatePasteRequest holds the parameters to create a new paste.

See https://pastebin.com/doc_api#2

type Expiration

type Expiration string

Expiration defines the duration before a paste expires.

const (
	Never      Expiration = "N"
	TenMinutes Expiration = "10M"
	OneHour    Expiration = "1H"
	OneDay     Expiration = "1D"
	OneWeek    Expiration = "1W"
	TwoWeeks   Expiration = "2W"
	OneMonth   Expiration = "1M"
	SixMonths  Expiration = "6M"
	OneYear    Expiration = "1Y"
)

Predefined expiration times for pastes.

See https://pastebin.com/doc_api#6

type Paste

type Paste struct {
	Key         string
	Title       string
	URL         string
	Hits        int
	Size        int
	CreatedAt   time.Time
	ExpireDate  time.Time
	Visibility  Visibility
	FormatLong  string
	FormatShort string
}

Paste represents a Pastebin paste entry.

func (*Paste) String

func (p *Paste) String() string

String returns a formatted string of the paste data.

type User

type User struct {
	UserName    string      `xml:"user_name"`
	Expiration  Expiration  `xml:"user_expiration"`
	Visibility  Visibility  `xml:"user_private"`
	Avatar      string      `xml:"user_avatar_url"`
	Website     string      `xml:"user_website"`
	Email       string      `xml:"user_email"`
	Location    string      `xml:"user_location"`
	AccountType AccountType `xml:"user_account_type"`
}

User contains information about the logged in Pastebin user.

func (User) String

func (u User) String() string

String returns a formatted string of the user data.

type Visibility

type Visibility int

Visibility defines the visibility level of a paste. Public = 0, Unlisted = 1, Private = 2.

See https://pastebin.com/doc_api#7

const (
	Public Visibility = iota
	Unlisted
	Private
)

Public = 0, Unlisted = 1, Private = 2.

See https://pastebin.com/doc_api#7

func (Visibility) String

func (v Visibility) String() string

String returns the string representation of a Visibility.

Jump to

Keyboard shortcuts

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