cpool

package
v0.0.0-...-2e4edee Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: LGPL-3.0 Imports: 12 Imported by: 0

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

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 NewBlock

func NewBlock(name, notes string) *Block

Create a new 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) EncodeBlock

func (b *Block) EncodeBlock() (encode BlockEncode)

Encode self

func (*Block) EncodeSection

func (b *Block) EncodeSection(s string) (encode SectionEncode, err error)

export a Section to encode mode

func (*Block) GetConfig

func (b *Block) GetConfig(s string) (string, error)

get a Config, if not exist, return error, s format is section.keyname

func (*Block) GetEnum

func (b *Block) GetEnum(s string) ([]string, error)

get a enum config, if not exist, return error. the s format is section.keyname

func (*Block) GetSection

func (b *Block) GetSection(s string) (*Section, error)

Get a Section

func (Block) MarshalBinary

func (b Block) MarshalBinary() (data []byte, err error)

func (*Block) RegSection

func (b *Block) RegSection(s *Section) error

register a Section, if the Section name is exist, return err.

func (*Block) SetBool

func (b *Block) SetBool(s string, v bool, n string) error

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

func (b *Block) SetConfig(s, v, n string) error

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

func (b *Block) SetEnum(s string, n string, v ...string) error

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

func (b *Block) SetFloat(s string, v float64, n string) error

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

func (b *Block) SetInt64(s string, v int64, n string) error

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

func (b *Block) TranBool(s string) (bool, error)

get a Config, and transform to bool, if not exist return error. the s format is section.keyname

func (*Block) TranFloat

func (b *Block) TranFloat(s string) (float64, error)

get a Config, and transform to float64, if not exist return error. the s format is section.keyname

func (*Block) TranInt64

func (b *Block) TranInt64(s string) (int64, error)

get a Config, and transform to int64, if not exist return error. the s format is section.keyname

func (*Block) UnmarshalBinary

func (b *Block) UnmarshalBinary(data []byte) (err error)

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 (c Config) MarshalBinary() (data []byte, err error)

func (*Config) UnmarshalBinary

func (c *Config) UnmarshalBinary(data []byte) (err error)

type ConfigEncode

type ConfigEncode struct {
	Key   string
	Value string
	Enum  []string
	Notes string
}

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 NewConfigPoolNoFile

func NewConfigPoolNoFile() *ConfigPool

Create a new empty configure pool

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

func NewSection(name, notes string) *Section

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

func (se *Section) GetConfig(s string) (string, error)

Get a Config, if not exist return error

func (*Section) GetEnum

func (se *Section) GetEnum(s string) ([]string, error)

Get a Config, if not exist return error

func (Section) MarshalBinary

func (s Section) MarshalBinary() (data []byte, err error)

func (*Section) SetBool

func (se *Section) SetBool(s string, v bool, n string) error

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

func (se *Section) SetConfig(s, v, n string) error

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

func (se *Section) SetEnum(s string, n string, v ...string) error

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

func (se *Section) SetFloat(s string, v float64, n string) error

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

func (se *Section) SetInt64(s string, v int64, n string) error

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

func (se *Section) TranBool(s string) (bool, error)

Get a Config, if not exist return error

func (*Section) TranFloat

func (se *Section) TranFloat(s string) (float64, error)

Get a Config, if not exist return error

func (*Section) TranInt64

func (se *Section) TranInt64(s string) (int64, error)

Get a Config, if not exist return error

func (*Section) UnmarshalBinary

func (s *Section) UnmarshalBinary(data []byte) (err error)

type SectionEncode

type SectionEncode struct {
	Key     string
	Notes   string
	Configs map[string]ConfigEncode
}

The Section's encode mode

Jump to

Keyboard shortcuts

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