conf

package
v0.0.0-...-d989b54 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ConfSuffix     = []string{".conf"}
	DefaultSection = model.DefaultSection
	PathSeparator  = model.PathSeparator
)

Functions

func AddFile

func AddFile(domainName, fileName, conf, note string) error

func HasConfSuffix

func HasConfSuffix(file string) bool

func Ignore

func Ignore(name string, isDir bool) bool

IgnoreFile . 忽略以.开头的文件和目录 忽略后缀不为 ConfSuffix 的文件

Types

type ConfManager

type ConfManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ConfManager for managing configuration files and subscriptions

func InitConfManager

func InitConfManager(domainName string, withLock bool) (*ConfManager, error)

func NewConfManager

func NewConfManager(event operate.Event) (*ConfManager, error)

func NewConfManagerFromLocal

func NewConfManagerFromLocal(root string, backupPath string) (*ConfManager, error)

NewConfManager return a new ConfManager given a path

func WrapConfManager

func WrapConfManager(fs []File) (*ConfManager, error)

func (*ConfManager) Debug

func (c *ConfManager) Debug()

func (*ConfManager) Delete

func (c *ConfManager) Delete(event operate.Event) error

func (*ConfManager) FileList

func (c *ConfManager) FileList() []File

func (*ConfManager) GetFiles

func (c *ConfManager) GetFiles() *Files

func (*ConfManager) GetKeyData

func (c *ConfManager) GetKeyData() map[string]map[string]KeyData

func (*ConfManager) GetRoot

func (c *ConfManager) GetRoot() string

func (*ConfManager) NewFile

func (c *ConfManager) NewFile(event operate.Event) (*File, error)

func (*ConfManager) ParseSubscribe

func (c *ConfManager) ParseSubscribe(rawSubscriptions []string) []string

ParseSubscribe handle subscription relationship and return real subscription file

Subscription file format

  • subscribe section : /subscribe/file.conf/section
  • subscribe file : /subscribe/file.conf
  • subscribe directory : /subscribe/dir/ -> deprecated?

func (*ConfManager) Subscribe

func (c *ConfManager) Subscribe(subscriptions []string) []model.StructData

Subscribe return struct data

func (*ConfManager) Update

func (c *ConfManager) Update(event operate.Event) error

type File

type File struct {
	Name     string     `json:"name"`
	Sections []*Section `json:"sections"`
	// contains filtered or unexported fields
}

func ParseFileConf

func ParseFileConf(conf string) (*File, error)

func (*File) Debug

func (f *File) Debug()

func (*File) GetInfo

func (f *File) GetInfo() os.FileInfo

func (*File) GetKeyData

func (f *File) GetKeyData(section, key string) (model.ConfData, error)

func (*File) GetPath

func (f *File) GetPath() string

func (*File) GetSection

func (f *File) GetSection(section string) (Section, error)

func (*File) GetSections

func (f *File) GetSections() []*Section

func (*File) KeyList

func (f *File) KeyList() []model.ConfData

type Files

type Files struct {
	// contains filtered or unexported fields
}

func InitFiles

func InitFiles(domainName string, withLock bool) (*Files, error)

func NewFiles

func NewFiles(event operate.Event) (*Files, error)

func OpenPath

func OpenPath(root string) (*Files, error)

func WrapFiles

func WrapFiles(fs []File) *Files

func (*Files) Debug

func (f *Files) Debug()

func (*Files) DelKey

func (f *Files) DelKey(file, section, key string) error

func (*Files) FileList

func (f *Files) FileList() []File

func (*Files) GetExistPaths

func (f *Files) GetExistPaths(fpaths []string) (files []string)

return file paths which exist in Files

func (*Files) GetFile

func (f *Files) GetFile(fname string) (*File, error)

func (*Files) SectionKeyList

func (f *Files) SectionKeyList(fname string, section string) map[string]model.ConfData

func (*Files) SetKey

func (f *Files) SetKey(file, section, key, value string) error

func (*Files) Walk

func (f *Files) Walk(fn func(file *File) error) error

type KeyData

type KeyData struct {
	model.ConfData
	// contains filtered or unexported fields
}

func NewKeyData

func NewKeyData(file string, cfd model.ConfData) KeyData

type Section

type Section struct {
	Name string                    `json:"name"`
	Keys map[string]model.ConfData `json:"keys"`
}

func (*Section) DeleteKey

func (s *Section) DeleteKey(key string)

func (*Section) GetKeys

func (s *Section) GetKeys() map[string]model.ConfData

func (*Section) GetName

func (s *Section) GetName() string

func (*Section) Set

func (s *Section) Set(key string, cfd model.ConfData)

type SubscribeType

type SubscribeType int
const (
	SubscribeSection SubscribeType = 1
	SubscribeFile    SubscribeType = 2
	SubscribeDir     SubscribeType = 3
)

type Subscription

type Subscription string

func (Subscription) File

func (s Subscription) File() string

func (Subscription) InvolvedFilesPath

func (s Subscription) InvolvedFilesPath() (files []string)

input = "/test.conf/section" output = "/test.conf" input = "/zy/test.conf/section" output = "/test.conf" "/zy/test.conf" input - "/center.conf" output = "/center.conf" input = "/zy/center.conf" output = "/center.conf" "/zy/center.conf" inherited path include current file and parents files

func (Subscription) Section

func (s Subscription) Section() string

func (Subscription) Type

func (s Subscription) Type() SubscribeType

Jump to

Keyboard shortcuts

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