file

package
Version: v0.0.0-...-9131a37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

README

文件檔案模組

讀取屬性的優先順序

有效順序依照下面排序,數字越小有效等級越高,如果檔案已經被找到將不會繼續往下找尋

  1. A /config subdir of the working directory.
  2. The working directory
  3. 當前執行檔所位址下面的 config 目錄
  4. 當前執行檔所在目錄

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigType

type ConfigType string
const (
	ConfigTypeYAML ConfigType = "yaml"
	ConfigTypeJSON ConfigType = "json"
)

type FileProvider

type FileProvider struct {
	OnChangedEvent OnChangedEvent
	// contains filtered or unexported fields
}

func New

func New() *FileProvider

func (*FileProvider) AddPath

func (p *FileProvider) AddPath(path string)

AddPath adds a path to look for config file. Please don't include filename. Directory only

func (*FileProvider) ConfigName

func (p *FileProvider) ConfigName() string

ConfigName return config file name. The default config file name is "app.yml"

func (*FileProvider) ConfigType

func (p *FileProvider) ConfigType() ConfigType

ConfigType set the config encoding type. Default is "YAML". `YAML`, `JSON` are supported

func (*FileProvider) Content

func (p *FileProvider) Content() string

Content return config content.

func (*FileProvider) Get

func (p *FileProvider) Get(key string) (interface{}, error)

func (*FileProvider) Load

func (p *FileProvider) Load() error

Load initialize this package. It will load config into cache and get ready to work. However, if the config file was not found, `ErrFileNotFound` will be returned

func (*FileProvider) LoadContent

func (p *FileProvider) LoadContent(content string) error

LoadContent reads the content as config file

func (*FileProvider) SetConfigName

func (p *FileProvider) SetConfigName(configName string)

SetConfigName set a config file name. The default config file name is "app.yml"

func (*FileProvider) SetConfigType

func (p *FileProvider) SetConfigType(configType ConfigType)

SetConfigType set the config encoding type. Default is "YAML". `YAML`, `JSON` are supported

func (*FileProvider) WatchConfig

func (p *FileProvider) WatchConfig() error

type OnChangedEvent

type OnChangedEvent func(oldContent string, newContent string)

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL