Documentation
¶
Index ¶
- Constants
- func IsRequestError(err error) bool
- type BackupPart
- type BackupRemoteUploadResponse
- type BackupRequest
- type Client
- type ClientOption
- type InstallStatusRequest
- type InstallationScript
- type OutputLineMatcher
- type Pagination
- type ProcessConfiguration
- type ProcessStopConfiguration
- type RawServerData
- type RequestError
- type RequestErrors
- type Response
- type ServerConfigurationResponse
- type SftpAuthRequest
- type SftpAuthRequestType
- type SftpAuthResponse
- type SftpInvalidCredentialsError
Constants ¶
const ( ProcessStopCommand = "command" ProcessStopSignal = "signal" ProcessStopNativeStop = "stop" )
const ( SftpAuthPassword = SftpAuthRequestType("password") SftpAuthPublicKey = SftpAuthRequestType("public_key") )
Variables ¶
This section is empty.
Functions ¶
func IsRequestError ¶
IsRequestError 檢查指定的錯誤是否為 RequestError 型別。
Types ¶
type BackupPart ¶
type BackupRequest ¶
type BackupRequest struct {
Checksum string `json:"checksum"`
ChecksumType string `json:"checksum_type"`
Size int64 `json:"size"`
Successful bool `json:"successful"`
Parts []BackupPart `json:"parts"`
}
type Client ¶
type Client interface {
GetBackupRemoteUploadURLs(ctx context.Context, backup string, size int64) (BackupRemoteUploadResponse, error)
GetInstallationScript(ctx context.Context, uuid string) (InstallationScript, error)
GetServerConfiguration(ctx context.Context, uuid string) (ServerConfigurationResponse, error)
GetServers(context context.Context, perPage int) ([]RawServerData, error)
ResetServersState(ctx context.Context) error
SetArchiveStatus(ctx context.Context, uuid string, successful bool) error
SetBackupStatus(ctx context.Context, backup string, data BackupRequest) error
SendRestorationStatus(ctx context.Context, backup string, successful bool) error
SetInstallationStatus(ctx context.Context, uuid string, data InstallStatusRequest) error
SetTransferStatus(ctx context.Context, uuid string, successful bool) error
ValidateSftpCredentials(ctx context.Context, request SftpAuthRequest) (SftpAuthResponse, error)
SendActivityLogs(ctx context.Context, activity []models.Activity) error
}
func New ¶
func New(base string, opts ...ClientOption) Client
New 回傳一個新的 HTTP 請求用戶端,用於向此實例所依附的 Panel 發出經過驗證的請求。
type ClientOption ¶
type ClientOption func(c *client)
func WithCredentials ¶
func WithCredentials(id, token string) ClientOption
WithCredentials 設定向遠端 API 端點發出請求時所使用的憑證。
func WithHttpClient ¶
func WithHttpClient(httpClient *http.Client) ClientOption
WithHttpClient 設定向 Panel API 發出請求時所使用的底層 HTTP 用戶端實例。
type InstallStatusRequest ¶
type InstallationScript ¶
type InstallationScript struct {
ContainerImage string `json:"container_image"`
Entrypoint string `json:"entrypoint"`
Script string `json:"script"`
}
InstallationScript 定義伺服器行程的安裝腳本資訊。此結構體會在 伺服器首次安裝,以及伺服器被標記為需要重新安裝時使用。
type OutputLineMatcher ¶
type OutputLineMatcher struct {
// contains filtered or unexported fields
}
func (*OutputLineMatcher) Matches ¶
func (olm *OutputLineMatcher) Matches(s []byte) bool
Matches 判斷提供的位元組字串是否符合此比對器所指定的正規 表示式或原始字串。
func (*OutputLineMatcher) String ¶
func (olm *OutputLineMatcher) String() string
String 回傳此比對器的原始比對字串。
func (*OutputLineMatcher) UnmarshalJSON ¶
func (olm *OutputLineMatcher) UnmarshalJSON(data []byte) error
UnmarshalJSON 將啟動行反序列化為各自獨立的結構體, 以便更容易進行比對。
type Pagination ¶
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"`
}
ProcessConfiguration 定義指定伺服器實例的行程組態。這設定了 Wings 用來判斷伺服器已完成啟動的依據、停止時該做什麼, 以及應對伺服器組態檔案做哪些變更。
type ProcessStopConfiguration ¶
ProcessStopConfiguration 定義停止實例時所使用的設定。
type RawServerData ¶
type RawServerData struct {
Uuid string `json:"uuid"`
Settings json.RawMessage `json:"settings"`
ProcessConfiguration json.RawMessage `json:"process_configuration"`
}
RawServerData 是 API 針對某伺服器回傳的原始回應。
type RequestError ¶
type RequestError struct {
Code string `json:"code"`
Status string `json:"status"`
Detail string `json:"detail"`
// contains filtered or unexported fields
}
func AsRequestError ¶
func AsRequestError(err error) *RequestError
AsRequestError 若該錯誤目前確實為 RequestError,就將其轉換為 RequestError 型別,並檢查其他錯誤處理程序的包裝狀態。若該錯誤 並非 RequestError,則回傳 nil。
type RequestErrors ¶
type RequestErrors struct {
Errors []RequestError `json:"errors"`
}
type Response ¶
Response is 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) BindJSON ¶
BindJSON 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 first error message from the API call as a string. The error message will be formatted similar to the below example. If there is no error that can be parsed out of the API you'll still get a RequestError returned but the RequestError.Code will be "_MissingResponseCode".
HttpNotFoundException: The requested resource does not exist. (HTTP/404)
func (*Response) HasError ¶
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"`
}
ServerConfigurationResponse 保存從 Panel 回傳的伺服器組態資料。 當伺服器行程啟動時,Wings 會與 Panel 通訊,以取得最新的建置 資訊,以及解析指定 Egg 所需的所有詳細資料。
這代表每次伺服器有部分更新時,我們都不需要向 Wings 發出請求, 而 Panel 則隨時作為單一事實來源。這也代表若 Wings 上的組態 不慎遭到清除,只要 Wings 知道自己應該擁有哪些伺服器,就能 不費太大功夫自行復原。
type SftpAuthRequest ¶
type SftpAuthRequest struct {
Type SftpAuthRequestType `json:"type"`
User string `json:"username"`
Pass string `json:"password"`
IP string `json:"ip"`
SessionID []byte `json:"session_id"`
ClientVersion []byte `json:"client_version"`
}
SftpAuthRequest 定義判斷傳入 Wings 的憑證是否有效時,傳送給 Panel 的請求詳細資料。
type SftpAuthRequestType ¶
type SftpAuthRequestType string
type SftpAuthResponse ¶
type SftpAuthResponse struct {
Server string `json:"server"`
User string `json:"user"`
Permissions []string `json:"permissions"`
}
SftpAuthResponse 會在一組 SFTP 憑證成功驗證後由 Panel 回傳。 其中包含相符的特定伺服器,以及授予該已驗證使用者在 SFTP 子系統中的權限。
type SftpInvalidCredentialsError ¶
type SftpInvalidCredentialsError struct{}
func (SftpInvalidCredentialsError) Error ¶
func (ice SftpInvalidCredentialsError) Error() string