Documentation ¶
Overview ¶
The Configure Pool - load and manage config files
The configure information have three levels: Block, Section, Config.
The Block use curly braces to define its name, the Section use square brackets to define its name.
All lines can add comments after the line. The comments must start with #, and after # must have a space.
The enumerate config, each item is searated by a space.
The config files like this:
# a comment line {block_name} [section_name] config_key_name = config # a comment line ... [other_section_name] # a comment other_config_key_name = config ... {other_block_name} [section_name] config_key_name = config ... [other_section_name] other_config_key_name = enum1 enum2 enum3 # a enumerate config ...
Index ¶
- type Block
- func (b *Block) DecodeBlock(block BlockEncode)
- func (b *Block) DecodeSection(se SectionEncode)
- func (b *Block) EncodeBlock() (encode BlockEncode)
- func (b *Block) EncodeSection(s string) (encode SectionEncode, err error)
- func (b *Block) GetConfig(s string) (string, error)
- func (b *Block) GetEnum(s string) ([]string, error)
- func (b *Block) GetSection(s string) (*Section, error)
- func (b Block) MarshalBinary() (data []byte, err error)
- func (b *Block) RegSection(s *Section) error
- func (b *Block) SetBool(s string, v bool, n string) error
- func (b *Block) SetConfig(s, v, n string) error
- func (b *Block) SetEnum(s string, n string, v ...string) error
- func (b *Block) SetFloat(s string, v float64, n string) error
- func (b *Block) SetInt64(s string, v int64, n string) error
- func (b *Block) TranBool(s string) (bool, error)
- func (b *Block) TranFloat(s string) (float64, error)
- func (b *Block) TranInt64(s string) (int64, error)
- func (b *Block) UnmarshalBinary(data []byte) (err error)
- type BlockEncode
- type Config
- type ConfigEncode
- type ConfigPool
- func (c *ConfigPool) DecodeBlock(bl BlockEncode)
- func (c *ConfigPool) DecodePool(pool PoolEncode)
- func (c *ConfigPool) DecodeSection(blockname string, sectioncode SectionEncode)
- func (c *ConfigPool) EncodeBlock(b string) (encode BlockEncode, err error)
- func (c *ConfigPool) EncodePool() PoolEncode
- func (c *ConfigPool) EncodeSection(s string) (encode SectionEncode, err error)
- func (c *ConfigPool) GetAllBlockName() []string
- func (c *ConfigPool) GetBlock(ns string) (*Block, error)
- func (c *ConfigPool) GetConfig(s string) (string, error)
- func (c *ConfigPool) GetEnum(s string) ([]string, error)
- func (c *ConfigPool) GetSection(s string) (*Section, error)
- func (c ConfigPool) MarshalBinary() (data []byte, err error)
- func (c *ConfigPool) RegBlock(b *Block) error
- func (c *ConfigPool) RegFile(fname ...string) error
- func (c *ConfigPool) Reload() error
- func (c *ConfigPool) SetBool(s string, v bool, n string) error
- func (c *ConfigPool) SetConfig(s, v, n string) error
- func (c *ConfigPool) SetEnum(s string, n string, v ...string) error
- func (c *ConfigPool) SetFloat(s string, v float64, n string) error
- func (c *ConfigPool) SetInt64(s string, v int64, n string) error
- func (c *ConfigPool) TranBool(s string) (bool, error)
- func (c *ConfigPool) TranFloat(s string) (float64, error)
- func (c *ConfigPool) TranInt64(s string) (int64, error)
- func (c *ConfigPool) UnmarshalBinary(data []byte) (err error)
- func (c *ConfigPool) WriteTo(filename string) error
- type PoolEncode
- type Section
- func (se *Section) DecodeSection(s SectionEncode)
- func (se *Section) EncodeSection() (encode SectionEncode)
- func (se *Section) GetConfig(s string) (string, error)
- func (se *Section) GetEnum(s string) ([]string, error)
- func (s Section) MarshalBinary() (data []byte, err error)
- func (se *Section) SetBool(s string, v bool, n string) error
- func (se *Section) SetConfig(s, v, n string) error
- func (se *Section) SetEnum(s string, n string, v ...string) error
- func (se *Section) SetFloat(s string, v float64, n string) error
- func (se *Section) SetInt64(s string, v int64, n string) error
- func (se *Section) TranBool(s string) (bool, error)
- func (se *Section) TranFloat(s string) (float64, error)
- func (se *Section) TranInt64(s string) (int64, error)
- func (s *Section) UnmarshalBinary(data []byte) (err error)
- type SectionEncode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
The Block
func (*Block) DecodeBlock ¶
func (b *Block) DecodeBlock(block BlockEncode)
decode Block and store to self
func (*Block) DecodeSection ¶
func (b *Block) DecodeSection(se SectionEncode)
decode a Section and store, if the Section name is exist, cover the old one.
func (*Block) EncodeSection ¶
func (b *Block) EncodeSection(s string) (encode SectionEncode, err error)
export a Section to encode mode
func (*Block) GetEnum ¶
get a enum config, if not exist, return error. the s format is section.keyname
func (Block) MarshalBinary ¶
func (*Block) RegSection ¶
register a Section, if the Section name is exist, return err.
func (*Block) SetBool ¶
Set one config, the s format is :block|section.configkey, v is the value, n is the comment.
if the Config exist, cover the old one.
func (*Block) SetConfig ¶
Set one config, the s format is :block|section.configkey, v is the value, n is the comment.
if the Config exist, cover the old one.
func (*Block) SetEnum ¶
Set one config, the s format is :block|section.configkey, v is the value, n is the comment.
if the Config exist, cover the old one.
func (*Block) SetFloat ¶
Set one config, the s format is :block|section.configkey, v is the value, n is the comment.
if the Config exist, cover the old one.
func (*Block) SetInt64 ¶
Set one config, the s format is :block|section.configkey, v is the value, n is the comment.
if the Config exist, cover the old one.
func (*Block) TranBool ¶
get a Config, and transform to bool, if not exist return error. the s format is section.keyname
func (*Block) TranFloat ¶
get a Config, and transform to float64, if not exist return error. the s format is section.keyname
func (*Block) TranInt64 ¶
get a Config, and transform to int64, if not exist return error. the s format is section.keyname
func (*Block) UnmarshalBinary ¶
type BlockEncode ¶
type BlockEncode struct { Key string Notes string Sections map[string]SectionEncode }
The Block's encode mode
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
One Config
func (Config) MarshalBinary ¶
func (*Config) UnmarshalBinary ¶
type ConfigEncode ¶
The Config's encode mode
type ConfigPool ¶
type ConfigPool struct {
// contains filtered or unexported fields
}
The Configure Pool
func NewConfigPool ¶
func NewConfigPool(fname ...string) (*ConfigPool, error)
Create new configure pool, and analyze the config files.
func (*ConfigPool) DecodeBlock ¶
func (c *ConfigPool) DecodeBlock(bl BlockEncode)
Decode a Block and store, if the Block name is exist, cover the old one.
func (*ConfigPool) DecodePool ¶
func (c *ConfigPool) DecodePool(pool PoolEncode)
Decode the configure pool and load to self.
func (*ConfigPool) DecodeSection ¶
func (c *ConfigPool) DecodeSection(blockname string, sectioncode SectionEncode)
Decode a Section and store, if the Section name is exist, cover the old one.
func (*ConfigPool) EncodeBlock ¶
func (c *ConfigPool) EncodeBlock(b string) (encode BlockEncode, err error)
Export a Block to encode mode, if the Block not exist, return error.
func (*ConfigPool) EncodePool ¶
func (c *ConfigPool) EncodePool() PoolEncode
Export the configure pool to encode mode.
func (*ConfigPool) EncodeSection ¶
func (c *ConfigPool) EncodeSection(s string) (encode SectionEncode, err error)
Export a Section to encode mode, if the Section not exist, return error.
func (*ConfigPool) GetAllBlockName ¶
func (c *ConfigPool) GetAllBlockName() []string
Get all Block name.
func (*ConfigPool) GetBlock ¶
func (c *ConfigPool) GetBlock(ns string) (*Block, error)
Return one Block information, if not exist return error.
func (*ConfigPool) GetConfig ¶
func (c *ConfigPool) GetConfig(s string) (string, error)
Get a Config, if not exist return error, s format is: block|section.keyname
func (*ConfigPool) GetEnum ¶
func (c *ConfigPool) GetEnum(s string) ([]string, error)
Get a Config, if not exist return error, s format is: block|section.keyname
func (*ConfigPool) GetSection ¶
func (c *ConfigPool) GetSection(s string) (*Section, error)
Return the Section information, the s format is: block|section
func (ConfigPool) MarshalBinary ¶
func (c ConfigPool) MarshalBinary() (data []byte, err error)
func (*ConfigPool) RegBlock ¶
func (c *ConfigPool) RegBlock(b *Block) error
Register a Block to configure pool.
func (*ConfigPool) RegFile ¶
func (c *ConfigPool) RegFile(fname ...string) error
Register a file to configure pool
func (*ConfigPool) Reload ¶
func (c *ConfigPool) Reload() error
Reload all config files, be careful all your change will be deleted.
func (*ConfigPool) SetBool ¶
func (c *ConfigPool) SetBool(s string, v bool, n string) error
Set a Config, s format is : block|section.configkey, v is value, n is comment.
func (*ConfigPool) SetConfig ¶
func (c *ConfigPool) SetConfig(s, v, n string) error
Set a Config, s format is : block|section.configkey, v is value, n is comment.
func (*ConfigPool) SetEnum ¶
func (c *ConfigPool) SetEnum(s string, n string, v ...string) error
Set a Config, s format is : block|section.configkey, v is value, n is comment.
func (*ConfigPool) SetFloat ¶
func (c *ConfigPool) SetFloat(s string, v float64, n string) error
Set a Config, s format is : block|section.configkey, v is value, n is comment.
func (*ConfigPool) SetInt64 ¶
func (c *ConfigPool) SetInt64(s string, v int64, n string) error
Set a Config, s format is : block|section.configkey, v is value, n is comment.
func (*ConfigPool) TranBool ¶
func (c *ConfigPool) TranBool(s string) (bool, error)
Get a Config, if not exist return error, s format is: block|section.keyname
func (*ConfigPool) TranFloat ¶
func (c *ConfigPool) TranFloat(s string) (float64, error)
Get a Config, if not exist return error, s format is: block|section.keyname
func (*ConfigPool) TranInt64 ¶
func (c *ConfigPool) TranInt64(s string) (int64, error)
Get a Config, if not exist return error, s format is: block|section.keyname
func (*ConfigPool) UnmarshalBinary ¶
func (c *ConfigPool) UnmarshalBinary(data []byte) (err error)
func (*ConfigPool) WriteTo ¶
func (c *ConfigPool) WriteTo(filename string) error
Save the configure information to file, it may not be used.
type PoolEncode ¶
type PoolEncode struct {
Blocks map[string]BlockEncode
}
The Configure Pool's encode mode
type Section ¶
type Section struct {
// contains filtered or unexported fields
}
The Section
func NewSection ¶
Create a new Section, the notes is comment.
func (*Section) DecodeSection ¶
func (se *Section) DecodeSection(s SectionEncode)
Decode Section and store to self.
func (*Section) EncodeSection ¶
func (se *Section) EncodeSection() (encode SectionEncode)
Export self to encode mode.
func (Section) MarshalBinary ¶
func (*Section) SetBool ¶
Set a Config, the s is the key, v is the value, n is the comment. if not exist, create new, else cover the old one.
func (*Section) SetConfig ¶
Set a Config, the s is the key, v is the value, n is the comment. if not exist, create new, else cover the old one.
func (*Section) SetEnum ¶
Set a Config, the s is the key, v is the value, n is the comment. if not exist, create new, else cover the old one.
func (*Section) SetFloat ¶
Set a Config, the s is the key, v is the value, n is the comment. if not exist, create new, else cover the old one.
func (*Section) SetInt64 ¶
Set a Config, the s is the key, v is the value, n is the comment. if not exist, create new, else cover the old one.
func (*Section) UnmarshalBinary ¶
type SectionEncode ¶
type SectionEncode struct { Key string Notes string Configs map[string]ConfigEncode }
The Section's encode mode