Documentation
¶
Index ¶
Constants ¶
const ( LineEndUnix = "LF" LineEndDos = "CRLF" LineEndOldMac = "CR" )
Variables ¶
var ( ErrBadRequest = errors.New("lenpaste: 400 bad request") // HTTP code 400; This API method exists on the server, but you passed the wrong arguments for it. ErrNotFoundID = errors.New("lenpaste: 404 could not find ID") // HTTP code 404; There is no paste with this ID. ErrNotFound = errors.New("lenpaste: 404 not found") // HTTP code 404; There is no such API method. ErrMethodNotAllowed = errors.New("lenpaste: 405 method not allowed") // HTTP code 405; You made a mistake with HTTP request (example: you made POST instead of GET). ErrInternalServerError = errors.New("lenpaste: 500 internal server error") // HTTP code 500; There was a failure on the server. )
Functions ¶
This section is empty.
Types ¶
type NewPaste ¶
type NewPaste struct { Title string // Paste title (may not be set). Body string // Paste content. LineEnd string // Paste line end (default: LF) Syntax string // Web interface syntax highlighting (default: plaintext). OneUse bool // If set to "true", the paste can be viewed once (default: false). Expiration int64 // The time in seconds that the paste will live (default: unlimited). Author string // Author name (may not be set). AuthorEmail string // Author email (may not be set). AuthorURL string // Author URL (may not be set). }
type Paste ¶
type Paste struct { ID string `json:"id"` // Unique paste ID. Title string `json:"title"` // Paste title (can be blank). Body string `json:"body"` // Paste content. CreateTime int64 `json:"createTime"` // Paste creation time (UNIX time in seconds). DeleteTime int64 `json:"deleteTime"` // The time after which the paste will be removed. If set to "0", the paste has no expiration date. OneUse bool `json:"oneUse"` // If set to "true", the paste can be viewed once. Syntax string `json:"syntax"` // Web interface syntax highlighting. If set to "plaintext", syntax highlighting is disabled. Author string `json:"author"` // Author name (can be blank). AuthorEmail string `json:"authorEmail"` // Author email (can be blank). AuthorURL string `json:"authorURL"` // Author URL (can be blank). }
type Server ¶
type Server struct { // Example: https://paste.lcomrade.su // Warning: If you add / to the end of the address, it will cause an error! Server string // If the user or password is blank, no authorization will be performed. AuthUser string AuthPass string }
func NewServer ¶ added in v1.1.0
NewServer is intended to replace the manual filling of fields in the Server structure. For example, if there are errors in the server address, NewServer will try to fix them.
func (*Server) Auth ¶ added in v1.2.0
Auth remembers the user and password for authorization on the server requesting it.
The correctness of the data entered is not checked. If the user or password is blank, no authorization will be performed.
func (Server) Get ¶
Get gets the paste from the server by its ID.
1. If the "openOneUse" parameter is set to "true" and the paste is intended for a single use, the function will return the entire paste, and the paste will be deleted from the server.
2. If the "openOneUse" parameter is set to "false" and the paste is intended for a single use, the function will return only the "ID" and "OneUse" fields and the paste will NOT be deleted from the server.
3. If the paste is not destroyed after reading the "openOneUse" parameter does not affect anything.
func (Server) GetServerInfo ¶
func (server Server) GetServerInfo() (ServerInfo, error)
GetServerInfo returns information about the server in use (including header and body length limits and maximum possible lifetime).
func (Server) New ¶
New creates a new paste and returns its ID, create time, delete time. If the delete time is 0, then the paste will exist forever.
Remember that you observe the limits on header length, body length, and maximum lifetime on your own. If this function returns ErrBadRequest, the problem is probably not respecting the limits.
type ServerInfo ¶
type ServerInfo struct { Version string `json:"version"` // Version of Lenpaste installed on server. TitleMaxLen int `json:"titleMaxlength"` // Maximum length paste title can have. If 0 disable title, if -1 disable length limit. BodyMaxLen int `json:"bodyMaxlength"` // Maximum length paste body can have. If -1 disable length limit. Can't be -1. MaxLifeTime int64 `json:"maxLifeTime"` // Maximum "Expiration" value. ServerAbout string `json:"serverAbout"` // Server description (can be blank). ServerRules string `json:"serverRules"` // Server rules (can be blank). ServerTermsOfUse string `json:"serverTermsOfUse"` // Server Terms of Use (can be blank). AdminName string `json:"adminName"` // Server administrator name (can be blank). AdminMail string `json:"adminMail"` // Server administrator email (can be blank). Syntaxes []string `json:"syntaxes"` // Syntaxes that this server can highlight in the web interface. For example: "plaintext", "Go", "C", and so on. UiDefaultLifeTime string `json:"uiDefaultLifeTime"` // Default lifetime of paste selected in UI. Possible values: 10min, 1h, 1d, 2w, 6mon, 1y. AuthRequired bool `json:"authRequired"` // If true, authorization is required to create paste. }