Documentation ¶
Overview ¶
Package neocities is a wrapper around the NeoCities API to perform various functions related to managing a NeoCities site, as well as obtaining information about NeoCities sites.
Index ¶
- Variables
- func MakeMIMEMultipartFile(f io.Reader, name string) (*bytes.Buffer, string, error)
- func ReadFile(filename string) (string, error)
- func SetLogger(l *log.Logger)
- type API
- type APIClient
- type APIError
- type NeoTime
- type Site
- func (s *Site) DeleteFiles(c *APIClient, files ...string) error
- func (s *Site) GetInfo(c *APIClient) (*Site, error)
- func (s *Site) List(path string, c *APIClient) ([]SiteFile, error)
- func (s *Site) NewAPIClient(api API) (*APIClient, error)
- func (s *Site) Push(dir string, c *APIClient) error
- func (s *Site) UploadFile(file string, name string, c *APIClient) error
- type SiteFile
Constants ¶
This section is empty.
Variables ¶
var ( NoAPI = errors.New("no API supplied to APIClient") NoKey = errors.New("no key supplied, required for this operation") SiteError = errors.New("an error occurred during API call") MissingReq = errors.New("a required variable is missing") )
var Verbose bool
Verbose toggles the verbosity of the library when it is performing actions. Toggling it will automatically print any relevant information to a logger.
Functions ¶
func MakeMIMEMultipartFile ¶
MakeMIMEMultipartFile makes a MIME multipart body based on the Reader given to it, and the name given to it for the file name.
Types ¶
type APIClient ¶
type APIClient struct { API API // contains filtered or unexported fields }
APIClient represents an API client.
type APIError ¶
type APIError struct { Result string `json:"result"` ErrorType string `json:"error_type"` Message string `json:"message"` }
APIError represents an error message returned by the NeoCities API.
func NewAPIError ¶
NewAPIError takes a reader containing JSON related to an error, and returns a struct containing the error type and message.
type NeoTime ¶
NeoTime represents the time value used by NeoCities for unmarshalling via encoding/json.
func (*NeoTime) UnmarshalJSON ¶
type Site ¶
type Site struct { SiteName string Key string Info struct { Hits int `json:"hits"` Updated NeoTime `json:"last_updated"` Domain string `json:"domain"` Tags []string `json:"tags"` } `json:"info"` }
Site represents a NeoCities site - both in authentication, and in information grabbing. Info is only used to be filled in by the info API endpoint.
Some API calls require the Key field to be filled - others do not. If an API call requires an authentication key, and there is no key in the Key field, the NoKey error will be passed from NewAPIClient to the calling function.
func (*Site) DeleteFiles ¶
DeleteFiles deletes a set of files from a NeoCities website.
func (*Site) GetInfo ¶
GetInfo encodes the site information into the recieving Site struct. If c is nil, an API client will be made with the given info.
func (*Site) List ¶
List grabs the files from path into an array of SiteFiles. Requires an API key. If c is nil, a new client is created.
func (*Site) NewAPIClient ¶
NewAPIClient returns a struct containing everything you need to perform RESTful API actions with NeoCities.
If a key is not supplied, a NoKey error will be returned, but the API client will still be ready to be used. This is meant for API calls that require authentication.
func (*Site) Push ¶
Push pushes an entire directory and its subdirectories to the website in the given directory. If c is nil, a new client is created.
Be CAREFUL when using this - Push will automatically upload all directories recursively.
Attempts to upload all files to the NeoCities site, and only halts if the site key was not passed.
func (*Site) UploadFile ¶
UploadFile uploads a file using the information provided by Site. If c is nil, a new client is created - otherwise, an existing API client is used. If name is nil, the base of the path provided by file (file can be a singular string) is used.
File cannot be an empty string.