gospacebin

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: MIT Imports: 5 Imported by: 3

README

gospacebin

Made with :heart: by @GreatGodApollo

PkgGoDev

Spacebin GoLang API library

Built With

Usage

Import the package into your project

import "github.com/GreatGodApollo/gospacebin"

Then construct a new spacebin client that can be used to access the API

spacebin := gospacebin.NewClient("https://api.spaceb.in")

For more information on using the client read the documentation.

Licensing

This project is licensed under the MIT License

Authors

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Host string // The host that the client is connecting to.
}

Represents the Spacebin API Client

func NewClient

func NewClient(host string) *Client

NewClient creates a new Spacebin API client. The only parameter is the host the client is connecting to. The return value of this method is the new *Client.

func (*Client) CreateDocument

func (cli *Client) CreateDocument(opts *CreateDocumentOpts) (*HashDocument, error)

CreateDocument allows you to create a new document on the Spacebin. The only parameter is a *CreateDocumentOpts. The return value of this method is a *HashDocument.

func (*Client) GetDocument

func (cli *Client) GetDocument(docID string) (*Document, error)

GetDocument allows you to retrieve a document from the Spacebin. The only parameter is a string, the document ID. The return value of this method is a *Document.

type CreateDocumentOpts

type CreateDocumentOpts struct {
	Content   string `json:"content"`   // The content of the document
	Extension string `json:"extension"` // The file extension of the document
}

Information needed to create a document

func NewCreateDocumentOpts

func NewCreateDocumentOpts(content string) *CreateDocumentOpts

NewCreateDocumentOpts creates a new *CreateDocumentOpts for use in the CreateDocument method. The only parameter is the content for the *CreateDocumentOpts. It returns the new *CreateDocumentOpts.

func (*CreateDocumentOpts) Marshal

func (opts *CreateDocumentOpts) Marshal() ([]byte, error)

Turn a CreateDocumentOpts into JSON

func (*CreateDocumentOpts) SetContent

func (opts *CreateDocumentOpts) SetContent(content string) *CreateDocumentOpts

SetContent sets the content for the *CreateDocumentOpts. It returns the *CreateDocumentOpts

func (*CreateDocumentOpts) SetExtension

func (opts *CreateDocumentOpts) SetExtension(extension string) *CreateDocumentOpts

SetExtension sets the extension for the *CreateDocumentOpts. It returns the *CreateDocumentOpts.

type Document

type Document struct {
	ID        string // The document ID
	Content   string // The document content
	Extension string // The file extension of the document
	CreatedAt int    // The time the document was created
	UpdatedAt int    // The time the document was last modified
}

Returned when GETting a document

type HashDocument

type HashDocument struct {
	ID          string // The document ID
	ContentHash string // The hash of the document content
}

Returned when POSTing a document

type Payload

type Payload struct {
	Content     *string `json:"content,omitempty"`      // The document content
	ContentHash *string `json:"content_hash,omitempty"` // The hash of the document content
	Extension   *string `json:"extension,omitempty"`    // The file extension of the document
	ID          *string `json:"id,omitempty"`           // The document ID
	CreatedAt   *int    `json:"created_at,omitempty"`   // The time the document was created
	UpdatedAt   *int    `json:"updated_at,omitempty"`   // The time the document was last modified/updated
}

The main body of the response

type Response

type Response struct {
	Error   string  `json:"error,omitempty"` // The error, if one occurred
	Payload Payload `json:"payload"`         // The main body of the response
	Status  int64   `json:"status"`          // The status code of the response
}

A Spacebin API response

func UnmarshalResponse

func UnmarshalResponse(data []byte) (Response, error)

Turn JSON into a response

func (*Response) Marshal

func (r *Response) Marshal() ([]byte, error)

Turn a Response into JSON

Jump to

Keyboard shortcuts

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