file

package
v0.0.0-...-37e343e Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2023 License: Apache-2.0 Imports: 15 Imported by: 1

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 {
	// 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

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) NotifyChange

func (p *FileProvider) NotifyChange() chan bool

NotifyChange return a channel and notify you when file be changed.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL