Documentation
¶
Index ¶
- Constants
- type ConfigurationFile
- func (f *ConfigurationFile) IterateOverJson(data []byte) (*gabs.Container, error)
- func (f *ConfigurationFile) LookupConfigurationValue(cfr ConfigurationFileReplacement) (string, error)
- func (f *ConfigurationFile) Parse(file ufs.File) error
- func (f *ConfigurationFile) UnmarshalJSON(data []byte) error
- type ConfigurationFileReplacement
- type ConfigurationParser
- type ReplaceValue
Constants ¶
const ( File = "file" Yaml = "yaml" Properties = "properties" Ini = "ini" Json = "json" Xml = "xml" )
File 解析選項是可用於伺服器組態檔案的解析方式。
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigurationFile ¶
type ConfigurationFile struct {
FileName string `json:"file"`
Parser ConfigurationParser `json:"parser"`
Replace []ConfigurationFileReplacement `json:"replace"`
// contains filtered or unexported fields
}
ConfigurationFile 定義伺服器啟動時所需的組態檔案。系統會逐一 走訪這些檔案,並在伺服器完成開機前進行修改。
func (*ConfigurationFile) IterateOverJson ¶
func (f *ConfigurationFile) IterateOverJson(data []byte) (*gabs.Container, error)
IterateOverJson 走訪未結構化的 JSON/YAML 等介面,為組態檔案 設定所有需要的鍵/值配對。
我們需要在鍵值搜尋中支援萬用字元,這讓您能一次修改多個鍵, 對於每個世界都有多份組態的遊戲(例如 Spigot 與 Bungeecord) 特別有用,這類情境下我們需要為使用者調整綁定位址。
目前不支援巢狀的萬用字元比對。例如 foo.*.bar 是可行的, 但 foo.*.bar.*.baz 則不行,因為我們只會在第一個萬用字元處 進行分割,而不處理後續的萬用字元。
func (*ConfigurationFile) LookupConfigurationValue ¶
func (f *ConfigurationFile) LookupConfigurationValue(cfr ConfigurationFileReplacement) (string, error)
LookupConfigurationValue 依照點記法(dot-notated)語法, 在 Daemon 上查找組態值。
func (*ConfigurationFile) Parse ¶
func (f *ConfigurationFile) Parse(file ufs.File) error
Parse 解析指定的組態檔案,並依照 Panel API 回應中定義的內容 更新其中所有的值。
func (*ConfigurationFile) UnmarshalJSON ¶
func (f *ConfigurationFile) UnmarshalJSON(data []byte) error
UnmarshalJSON 是組態檔案的自訂反序列化函式。若解析替換項目時 發生錯誤,不會讓整個操作失敗,而是記錄一則全域警告,讓人能 找出問題所在,並回傳空的替換項目陣列。
type ConfigurationFileReplacement ¶
type ConfigurationFileReplacement struct {
Match string `json:"match"`
IfValue string `json:"if_value"`
ReplaceWith ReplaceValue `json:"replace_with"`
}
ConfigurationFileReplacement 定義指定伺服器組態檔案的單一 尋找/替換實例。
func (*ConfigurationFileReplacement) SetAtPathway ¶
func (cfr *ConfigurationFileReplacement) SetAtPathway(c *gabs.Container, path string, value string) error
SetAtPathway 在指定路徑設定值之前,會先檢查我們是否要尋找 特定的值。
func (*ConfigurationFileReplacement) UnmarshalJSON ¶
func (cfr *ConfigurationFileReplacement) UnmarshalJSON(data []byte) error
UnmarshalJSON 負責將 JSON 表示反序列化為能提供此功能更有用 資料的結構體。
type ConfigurationParser ¶
type ConfigurationParser string
func (ConfigurationParser) String ¶
func (cp ConfigurationParser) String() string
type ReplaceValue ¶
type ReplaceValue struct {
// contains filtered or unexported fields
}
func (*ReplaceValue) Bytes ¶
func (cv *ReplaceValue) Bytes() []byte
func (*ReplaceValue) String ¶
func (cv *ReplaceValue) String() string
String 以字串形式回傳此值。這會自動將 UTF-8 序列轉換為預期 的值,例如將以下形式互相轉換
func (*ReplaceValue) Type ¶
func (cv *ReplaceValue) Type() jsonparser.ValueType
Type 回傳 Value 欄位的底層資料型別。
func (*ReplaceValue) Value ¶
func (cv *ReplaceValue) Value() []byte
Value 回傳此替換項目的底層值。請注意,此值可能包含已轉義的 UTF-8 序列,呼叫端需自行處理,以避免不慎將無效序列注入正在 執行中的行程。
舉例來說,預期的值可能是 "§Foo",但實際處理的資料是類似 "§Foo" 這樣的轉義序列。若不解決此問題會造成使用者困擾, 因為那顯然不是他們預期使用的值。