Documentation ¶
Index ¶
- Constants
- func IsRequestError(err error) bool
- type BackupRemoteUploadResponse
- type BackupRequest
- type D
- type InstallationScript
- type OutputLineMatcher
- type Pagination
- type ProcessConfiguration
- type ProcessStopConfiguration
- type Q
- type RawServerData
- type Request
- func (r *Request) Client() *http.Client
- func (r *Request) Endpoint(endpoint string) string
- func (r *Request) Get(url string, data Q) (*Response, error)
- func (r *Request) GetBackupRemoteUploadURLs(backup string, size int64) (*BackupRemoteUploadResponse, error)
- func (r *Request) GetInstallationScript(uuid string) (InstallationScript, error)
- func (r *Request) GetServerConfiguration(uuid string) (ServerConfigurationResponse, error)
- func (r *Request) GetServers() ([]RawServerData, error)
- func (r *Request) Make(method, url string, body io.Reader, opts ...func(r *http.Request)) (*Response, error)
- func (r *Request) Post(url string, data interface{}) (*Response, error)
- func (r *Request) SendArchiveStatus(uuid string, successful bool) error
- func (r *Request) SendBackupStatus(backup string, data BackupRequest) error
- func (r *Request) SendInstallationStatus(uuid string, successful bool) error
- func (r *Request) SendTransferFailure(uuid string) error
- func (r *Request) SendTransferSuccess(uuid string) error
- type RequestError
- type RequestErrorBag
- type Response
- type ServerConfigurationResponse
Constants ¶
const ( ProcessStopCommand = "command" ProcessStopSignal = "signal" ProcessStopNativeStop = "stop" )
Variables ¶
This section is empty.
Functions ¶
func IsRequestError ¶
Types ¶
type BackupRequest ¶
type D ¶
type D map[string]interface{}
A generic type allowing for easy binding use when making requests to API endpoints that only expect a singular argument or something that would not benefit from being a typed struct.
Inspired by gin.H, same concept.
type InstallationScript ¶
type InstallationScript struct { ContainerImage string `json:"container_image"` Entrypoint string `json:"entrypoint"` Script string `json:"script"` }
Defines installation script information for a server process. This is used when a server is installed for the first time, and when a server is marked for re-installation.
type OutputLineMatcher ¶
type OutputLineMatcher struct {
// contains filtered or unexported fields
}
func (*OutputLineMatcher) Matches ¶
func (olm *OutputLineMatcher) Matches(s string) bool
Determine if a given string "s" matches the given line.
func (*OutputLineMatcher) String ¶
func (olm *OutputLineMatcher) String() string
Return the matcher's raw comparison string.
func (*OutputLineMatcher) UnmarshalJSON ¶
func (olm *OutputLineMatcher) UnmarshalJSON(data []byte) error
Unmarshal the startup lines into individual structs for easier matching abilities.
type Pagination ¶
type Pagination struct { CurrentPage uint `json:"current_page"` From uint `json:"from"` LastPage uint `json:"last_page"` PerPage uint `json:"per_page"` To uint `json:"to"` Total uint `json:"total"` }
A pagination struct matching the expected pagination response from the Panel API.
type ProcessConfiguration ¶
type ProcessConfiguration struct { Startup struct { Done []*OutputLineMatcher `json:"done"` UserInteraction []string `json:"user_interaction"` StripAnsi bool `json:"strip_ansi"` } `json:"startup"` Stop ProcessStopConfiguration `json:"stop"` ConfigurationFiles []parser.ConfigurationFile `json:"configs"` }
Defines the process configuration for a given server instance. This sets what the daemon is looking for to mark a server as done starting, what to do when stopping, and what changes to make to the configuration file for a server.
type RawServerData ¶
type RawServerData struct { Uuid string `json:"uuid"` Settings json.RawMessage `json:"settings"` ProcessConfiguration json.RawMessage `json:"process_configuration"` }
type Request ¶
type Request struct{}
A custom API requester struct for Claws.
func (*Request) Get ¶
Makes a GET request to the given Panel API endpoint. If any data is passed as the second argument it will be passed through on the request as URL parameters.
func (*Request) GetBackupRemoteUploadURLs ¶
func (r *Request) GetBackupRemoteUploadURLs(backup string, size int64) (*BackupRemoteUploadResponse, error)
func (*Request) GetInstallationScript ¶
func (r *Request) GetInstallationScript(uuid string) (InstallationScript, error)
Fetches installation information for the server process.
func (*Request) GetServerConfiguration ¶
func (r *Request) GetServerConfiguration(uuid string) (ServerConfigurationResponse, error)
Fetches the server configuration and returns the struct for it.
func (*Request) GetServers ¶
func (r *Request) GetServers() ([]RawServerData, error)
Fetches all of the server configurations from the Panel API. This will initially load the first 50 servers, and then check the pagination response to determine if more pages should be loaded. If so, those requests are spun-up in additional routines and the final resulting slice of all servers will be returned.
func (*Request) Make ¶
func (r *Request) Make(method, url string, body io.Reader, opts ...func(r *http.Request)) (*Response, error)
Makes a HTTP request to the given endpoint, attaching the necessary request headers from Claws to ensure that the request is properly handled by the Panel.
func (*Request) SendArchiveStatus ¶
func (*Request) SendBackupStatus ¶
func (r *Request) SendBackupStatus(backup string, data BackupRequest) error
Notifies the panel that a specific backup has been completed and is now available for a user to view and download.
func (*Request) SendInstallationStatus ¶
Marks a server as being installed successfully or unsuccessfully on the panel.
func (*Request) SendTransferFailure ¶
func (*Request) SendTransferSuccess ¶
type RequestError ¶
type RequestError struct { Code string `json:"code"` Status string `json:"status"` Detail string `json:"detail"` // contains filtered or unexported fields }
func (*RequestError) Error ¶
func (re *RequestError) Error() string
Returns the error response in a string form that can be more easily consumed.
type RequestErrorBag ¶
type RequestErrorBag struct {
Errors []RequestError `json:"errors"`
}
type Response ¶
A custom response type that allows for commonly used error handling and response parsing from the Panel API. This just embeds the normal HTTP response from Go and we attach a few helper functions to it.
func (*Response) Bind ¶
Binds a given interface with the data returned in the response. This is a shortcut for calling Read and then manually calling json.Unmarshal on the raw bytes.
func (*Response) Error ¶
Returns the error message from the API call as a string. The error message will be formatted similar to the below example:
HttpNotFoundException: The requested resource does not exist. (HTTP/404)
func (*Response) HasError ¶
Determines if the API call encountered an error. If no request has been made the response will be false. This function will evaluate to true if the response code is anything 300 or higher.
type ServerConfigurationResponse ¶
type ServerConfigurationResponse struct { Settings json.RawMessage `json:"settings"` ProcessConfiguration *ProcessConfiguration `json:"process_configuration"` }
Holds the server configuration data returned from the Panel. When a server process is started, Claws communicates with the Panel to fetch the latest build information as well as get all of the details needed to parse the given Egg.
This means we do not need to hit Claws each time part of the server is updated, and the Panel serves as the source of truth at all times. This also means if a configuration is accidentally wiped on Claws we can self-recover without too much hassle, so long as Claws is aware of what servers should exist on it.