Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) BulkDeletePastes(pastes []string) error
- func (c *Client) CreatePaste(createInfo PasteCreateInfo) (paste *Paste, err error)
- func (c *Client) DeleteClient()
- func (c *Client) DeletePaste(pasteId string) error
- func (c *Client) EditPaste(paste *Paste) (*Paste, error)
- func (c *Client) ExpiresInToUnixTime(createdAt uint64, expires ExpiresIn) (uint64, error)
- func (c *Client) GetLanguageByExtension(extension string) (language *Language, err error)
- func (c *Client) GetLanguageByName(name string) (language *Language, err error)
- func (c *Client) GetPaste(pasteId string) (paste *Paste, err error)
- func (c *Client) GetSelfPasteIds() (pastes []string, err error)
- func (c *Client) GetSelfPasteIdsByAmount(amount uint) (pastes []string, err error)
- func (c *Client) GetSelfPastes() (pastes []*Paste, err error)
- func (c *Client) GetSelfPastesByAmount(amount uint) (pastes []*Paste, err error)
- func (c *Client) GetSelfUser() (user *User, err error)
- func (c *Client) GetUser(username string) (user *User, err error)
- func (c *Client) IsAuthorized() bool
- func (c *Client) PasteExists(pasteId string) bool
- func (c *Client) TryBulkDeletePastes(pastes []string) bool
- func (c *Client) TryCreatePaste(createInfo PasteCreateInfo) (paste *Paste, ok bool)
- func (c *Client) TryDeletePaste(pasteId string) bool
- func (c *Client) TryEditPaste(paste *Paste) (*Paste, bool)
- func (c *Client) TryGetLanguageByExtension(extension string) (language *Language, ok bool)
- func (c *Client) TryGetLanguageByName(name string) (language *Language, ok bool)
- func (c *Client) TryGetPaste(pasteId string) (paste *Paste, ok bool)
- func (c *Client) TryGetSelfPasteIds() (pastes []string, ok bool)
- func (c *Client) TryGetSelfPasteIdsByAmount(amount uint) (pastes []string, ok bool)
- func (c *Client) TryGetSelfPastes() (pastes []*Paste, ok bool)
- func (c *Client) TryGetSelfPastesByAmount(amount uint) (pastes []*Paste, ok bool)
- func (c *Client) TryGetSelfUser() (user *User, ok bool)
- func (c *Client) TryGetUser(username string) (*User, bool)
- func (c *Client) UserExists(username string) (bool, error)
- type Edit
- type ExpiresIn
- type Language
- type Paste
- type PasteCreateInfo
- type Pasty
- type PastyCreateInfo
- type RequestMethod
- type User
- Bugs
Constants ¶
const ( EndpointBase = "https://paste.myst.rs/api/v2/" EndpointData = EndpointBase + "data/" // Value: https://paste.myst.rs/api/v2/data/ EndpointTime = EndpointBase + "time/" // Value: https://paste.myst.rs/api/v2/time/ EndpointUser = EndpointBase + "user/" // Value: https://paste.myst.rs/api/v2/user/ EndpointSelfUser = EndpointUser + "self/" // Value: https://paste.myst.rs/api/v2/user/self/ EndpointSelfUserPastes = EndpointSelfUser + "pastes" // Value: https://paste.myst.rs/api/v2/user/self/pastes )
All the pastemyst API endpoints that can be accessed
Variables ¶
var ( // EndpointPaste - Value: https://paste.myst.rs/api/v2/paste/{pasteId} EndpointPaste = func(pasteId string) string { return fmt.Sprintf("%spaste/%s", EndpointBase, pasteId) } // DataLanguageByName - Value: // https://paste.myst.rs/api/v2/data/language?name={name} DataLanguageByName = func(name string) string { return fmt.Sprintf("%slanguage?name=%s", EndpointData, url.QueryEscape(name)) } // DataLanguageByExt - Value: // https://paste.myst.rs/api/v2/data/languageExt?extension={extension} DataLanguageByExt = func(extension string) string { return fmt.Sprintf("%slanguageExt?extension=%s", EndpointData, url.QueryEscape(extension)) } // TimeExpiresInToUnix - Value: // https://paste.myst.rs/api/v2/time/expiresInToUnixTime/?createdAt={createdAt}&expiresIn={expiresIn} TimeExpiresInToUnix = func(createdAt uint64, expires string) string { return fmt.Sprintf("%sexpiresInToUnixTime?createdAt=%d&expiresIn=%s", EndpointTime, createdAt, expires) } )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Token *string
}
Client represents a backend client with a token used for registration of a new context
func NewClient ¶
NewClient registers a new Client to use in the backend for API operations.
Returns:
(*Client)
func (*Client) BulkDeletePastes ¶
BulkDeletePastes deletes X amount of pastes with a given string array of paste Ids. you must specify an account token -- mandatory
You can only delete pastes that are on your account ¶
Params:
(pastes []string)
Returns:
(error)
func (*Client) CreatePaste ¶
func (c *Client) CreatePaste(createInfo PasteCreateInfo) (paste *Paste, err error)
CreatePaste creates a new paste with the given PasteCreateInfo
Posts new pastes to (https://paste.myst.rs/api/v2/paste)
Params:
(createInfo PasteCreateInfo)
Returns:
(*Paste, error)
func (*Client) DeleteClient ¶
func (c *Client) DeleteClient()
DeleteClient marks a Client for deletion by assigning it to nil, allowing it to be handled by the Garbage Collector.
Params:
(client *Client)
Remarks: This function should be called when you're done using the client, ensure that cleanup is executed.
func (*Client) DeletePaste ¶
DeletePaste deletes a paste with a specified account token -- mandatory
You can only delete pastes on the account of the token that has been passed.
A token is required for deleting a paste because this is an account feature.
This action is irreversible.
Params:
(pasteId string)
Returns:
(error)
func (*Client) EditPaste ¶
EditPaste edits a paste with a specified account token -- mandatory
You can only edit pastes on the account of the token that has been passed.
A token is required for editing a paste because this is an account feature.
To edit values of a paste you must send back the exact same paste except with the adjusted values, you cannot edit expiration date, any result will have no effect.
Params:
(paste *Paste)
Returns:
(*Paste, error)
func (*Client) ExpiresInToUnixTime ¶
ExpiresInToUnixTime returns the created at time in unix format. Will error out and return 0 if the request was malformed.
Params:
(createdAt uint64, expires ExpiresIn)
Returns:
(uint64, error)
func (*Client) GetLanguageByExtension ¶
GetLanguageByExtension gets a language based on its extension
Params:
(extension string)
Returns:
(*Language, error)
BUG(r): Some languages will not return properly, and will error out.
func (*Client) GetLanguageByName ¶
GetLanguageByName gets a language based on its pretty name
Uses url encoding to convert it into a url friendly value returns a Language and error if applicable.
Language will be nil if error is returned.
Params:
(name string)
Returns:
(*Language, error)
BUG(r): Some languages will not return properly, and will error out.
func (*Client) GetPaste ¶
GetPaste gets a paste based on Id, a token is mandatory for accessing private pastes
Params:
(pasteId string)
Returns:
(*Paste, error)
func (*Client) GetSelfPasteIds ¶
GetSelfPasteIds gets all of the currently logged in users paste Ids, this function is not available if no token is available
Returns:
([]string, error)
Remarks: this will return ALL paste ids, use with caution.
func (*Client) GetSelfPasteIdsByAmount ¶
GetSelfPasteIdsByAmount gets a specific amount of the currently logged in user paste ids, this function is not available if no token is available
Params:
(amount uint)
Returns:
([]string, error)
Remarks: this is a HEAVY function depending on the amount of pastes you specify, use with caution, you will be rate-limited.
Addendum: uint parameter because there will never be negative pastes on your account
func (*Client) GetSelfPastes ¶
GetSelfPastes gets all of the currently logged in users pastes, this function is not available if no token is available
Returns:
([]*Paste, error)
Remarks: this is a HEAVY function depending on the amount of pastes you have on your account, it will fetch all the paste ids, and convert them into actual paste objects. use with caution, you will be rate-limited.
func (*Client) GetSelfPastesByAmount ¶
GetSelfPastesByAmount gets a specific amount of the currently logged in users pastes, this function is not available if no token is available
Params:
(amount uint)
Returns:
([]*Paste, error)
Remarks: this is a HEAVY function depending on the amount of pastes you specify, use with caution, you will be rate-limited.
Addendum: uint parameter because there will never be negative pastes on your account
func (*Client) GetSelfUser ¶
GetSelfUser gets the currently logged in user, this function is not available if no token is available
Returns:
(*User, error)
func (*Client) GetUser ¶
GetUser gets a user by their username
User will be nil if they don't have a public profile.
Params:
(username string)
Returns:
(*User, error)
func (*Client) IsAuthorized ¶
func (*Client) PasteExists ¶
PasteExists checks to see if a given paste exists from a pasteId
Params:
(pasteId string)
Returns:
(bool)
func (*Client) TryBulkDeletePastes ¶
TryBulkDeletePastes attempts to delete X amount of pastes with a given string array of paste Ids. you must specify an account token -- mandatory
You can only delete pastes that are on your account ¶
Params:
(pastes []string)
Returns:
(bool)
func (*Client) TryCreatePaste ¶
func (c *Client) TryCreatePaste(createInfo PasteCreateInfo) (paste *Paste, ok bool)
TryCreatePaste attempts to create a new paste with the given PasteCreateInfo
Posts new pastes to (https://paste.myst.rs/api/v2/paste)
Params:
(createInfo PasteCreateInfo)
Returns:
(*Paste, bool)
func (*Client) TryDeletePaste ¶
TryDeletePaste attempts to delete a paste with a specified account token -- mandatory
You can only delete pastes on the account of the token that has been passed.
A token is required for deleting a paste because this is an account feature.
This action is irreversible.
Params:
(pasteId string)
Returns:
(bool)
func (*Client) TryEditPaste ¶
TryEditPaste attempts to edit a paste with a specified account token -- mandatory
You can only edit pastes on the account of the token that has been passed.
A token is required for editing a paste because this is an account feature.
To edit values of a paste you must send back the exact same paste except with the adjusted values, you cannot edit expiration date, any result will have no effect.
Params:
(paste *Paste)
Returns:
(*Paste, bool)
func (*Client) TryGetLanguageByExtension ¶
TryGetLanguageByExtension attempts to get a language based on its extension
Params:
(extension string)
Returns:
(*Language, error)
BUG(r): Some languages will not return properly, and will error out.
func (*Client) TryGetLanguageByName ¶
TryGetLanguageByName attempts to get a language based on its pretty name
Uses url encoding to convert it into a url friendly value returns a Language and error if applicable.
Language will be nil if error is returned.
Params:
(name string)
Returns:
(*Language, error)
BUG(r): Some languages will not return properly, and will error out.
func (*Client) TryGetPaste ¶
TryGetPaste attempts to get a paste based on Id, a token is mandatory for accessing private pastes.
Params:
(pasteId string)
Returns:
(*Paste, bool)
func (*Client) TryGetSelfPasteIds ¶
TryGetSelfPasteIds attempts to get all of the currently logged in users paste Ids, this function is not available if no token is available
Returns:
([]string, bool)
Remarks: this will return ALL paste ids, use with caution.
func (*Client) TryGetSelfPasteIdsByAmount ¶
TryGetSelfPasteIdsByAmount attempts to get a specific amount of the currently logged in user paste ids, this function is not available if no token is available
Params:
(amount uint)
Returns:
([]string, bool)
Remarks: this is a HEAVY function depending on the amount of pastes you specify, use with caution, you will be rate-limited.
Addendum: uint parameter because there will never be negative pastes on your account
func (*Client) TryGetSelfPastes ¶
TryGetSelfPastes attempts to get all of the currently logged in users pastes, this function is not available if no token is available
Returns:
([]*Paste, bool)
Remarks: this is a HEAVY function depending on the amount of pastes you have on your account, it will fetch all the paste ids, and convert them into actual paste objects. use with caution, you will be rate-limited.
func (*Client) TryGetSelfPastesByAmount ¶
TryGetSelfPastesByAmount attempts to get a specific amount of the currently logged in users pastes, this function is not available if no token is available
Params:
(amount uint)
Returns:
([]*Paste, error)
Remarks: this is a HEAVY function depending on the amount of pastes you specify, use with caution, you will be rate-limited.
Addendum: uint parameter because there will never be negative pastes on your account
func (*Client) TryGetSelfUser ¶
TryGetSelfUser attempts to get the currently logged in user, this function is not available if no token is available
Returns:
(*User, bool)
func (*Client) TryGetUser ¶
TryGetUser attempts to get a user by their username
User will be nil if they don't have a public profile.
Params:
(username string)
Returns:
(*User, bool)
func (*Client) UserExists ¶
UserExists checks if a given user exists based on a username
Params:
(username string)
Returns:
(bool, error)
Remarks: the user account MUST be public, or you must be accessing your own account while signed in with your API token.
type Edit ¶
type Edit struct { // Unique id of the edit Id string `json:"_id"` // Edit id, multiple edits can share the same id // to show that multiple properties were edited // at the same time EditId uint64 `json:"editId"` // Type of edit (incomplete) EditType uint64 `json:"editType"` // Various metadata, most used case - storing which pasty was edited Metadata []string `json:"metadata"` // The actual data of the edit, typically stores old data Edit string `json:"edit"` // Unix time of when the edit was executed EditedAt uint64 `json:"editedAt"` }
Edit holds information about a given edit based in 'id'.
You can only edit pastes on your account, so you must provide the Authorization header.
type ExpiresIn ¶
type ExpiresIn int
ExpiresIn represents all the possible time formats for when a paste will expire.
const ( Never ExpiresIn = iota // string form -> "never" OneHour // string form -> "1h" TwoHours // string form -> "2h" TenHours // string form -> "10h" OneDay // string form -> "1d" TwoDays // string form -> "2d" OneWeek // string form -> "1w" OneMonth // string form -> "1m" OneYear // string form -> "1y" )
type Language ¶
type Language struct { // Name represents the name of the language Name string `json:"name"` // Language represents the language mode for the online editor (codemirror) Mode string `json:"mode"` // Mimes represents all supported mimes in a slice Mimes []string `json:"mimes"` // Extensions represents all extensions for a language with a given name Extensions []string `json:"ext,omitempty"` // Color represents the color language, not guaranteed for every language, // Default will be #FFFFFF if the language doesn't have one. Color string `json:"color,omitempty"` }
Language represents a language request
type Paste ¶
type Paste struct { // Paste Id Id string `json:"_id"` // Owner of the paste, if none then will be " " OwnerId string `json:"ownerId"` // Title of the paste Title string `json:"title,omitempty"` // Date in unix time when the paste was created CreatedAt uint64 `json:"createdAt"` // When the paste expires ExpiresIn string `json:"expiresIn,omitempty"` // Date in unix time when the paste will be deleted DeletesAt uint64 `json:"deletesAt"` // Amount of stars the paste has Stars uint64 `json:"stars"` // Is the paste private? IsPrivate bool `json:"isPrivate,omitempty"` // Is the paste public? IsPublic bool `json:"isPublic,omitempty"` // Is the paste encrypted? IsEncrypted bool `json:"encrypted"` // Slices of all tags for this paste Tags []string `json:"tags,omitempty"` // Slice of all the pasties on the paste Pasties []Pasty `json:"pasties"` // Slice of all edits Edits []Edit `json:"edits"` }
Paste represents a single paste, containing all edits and pasties attached.
If you're accessing a private paste you need to provide the Authorization header.
type PasteCreateInfo ¶
type PasteCreateInfo struct { // Title represents the title of the paste -- optional Title string `json:"title,omitempty"` // ExpiresIn represents when the paste will expire -- optional ExpiresIn string `json:"expiresIn,omitempty"` // IsPrivate represents if it is accessible by the owner -- optional IsPrivate bool `json:"isPrivate,omitempty"` // IsPublic represents if it is displayed on the owners public profile -- optional IsPublic bool `json:"isPublic,omitempty"` // Tags represents comma separated paste tags -- optional Tags string `json:"tags,omitempty"` // Pasties represents a slice of pasties -- mandatory Pasties []PastyCreateInfo `json:"pasties"` }
PasteCreateInfo represents the information needed to create a new paste
type Pasty ¶
type Pasty struct { // Id of the pasty Id string `json:"_id"` // Title of the pasty Title string `json:"title"` // Language of the pasty Language string `json:"language"` // Code of the pasty Code string `json:"code"` }
Pasty represents a single pasty, could also be perceived as a "file" on the PasteMyst website, contains language, code, and title.
type PastyCreateInfo ¶
type PastyCreateInfo struct { // Title represents the title of a pasty Title string `json:"title"` // Language represents the language of the pasty, // stores the name of the language, not the mode or MIME type. Language string `json:"language"` // Code represents the code of the pasty Code string `json:"code"` }
PastyCreateInfo represents the information needed to created a new pasty
type User ¶
type User struct { // Id of the user Id string `json:"_id"` // Username of the user Username string `json:"username"` // Url of the avatar AvatarUrl string `json:"avatarUrl"` // The users default language DefaultLang string `json:"defaultLang"` // Specifies if their profile is public PublicProfile bool `json:"publicProfile"` // Specifies how long the user has been a support for, 0 if not a supporter SupporterLength uint64 `json:"supporterLength"` // Specifies if the user is a contributor IsContributor bool `json:"contributor"` // Stars represents a list of paste ids the user has starred Stars []string `json:"stars,omitempty"` // ServiceIds represents user ids of the service the user used to create an account ServiceIds map[string]string `json:"serviceIds,omitempty"` }
User represents a single pastemyst user
Notes ¶
Bugs ¶
Some languages will not return properly, and will error out.
Some languages will not return properly, and will error out.
Some languages will not return properly, and will error out.
Some languages will not return properly, and will error out.