conf

package
v0.0.0-...-3a1b8ae Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(m interface{}) ([]byte, error)

func Range

func Range(m interface{}, g func(string, interface{}) bool)

func Unmarshal

func Unmarshal(b []byte, m interface{}) error
Example
configuration := `# DEVICES
UT0311-L0x.405419896.name = BOARD1
UT0311-L0x.405419896.address = 192.168.1.100:60000
UT0311-L0x.54321.name = BOARD2
UT0311-L0x.54321.address = 192.168.1.101:60000
`

config := struct {
	Devices deviceMap `conf:"/UT0311-L0x\\.([0-9]+)\\.(\\w+)/"`
}{}

err := Unmarshal([]byte(configuration), &config)
if err != nil {
	fmt.Printf("ERROR: %v", err)
	return
}

for id, d := range config.Devices {
	fmt.Printf("DEVICE: %-10d %s\n", id, d)
}
Output:

DEVICE: 405419896  BOARD1  192.168.1.100:60000
DEVICE: 54321      BOARD2  192.168.1.101:60000

Types

type Marshaler

type Marshaler interface {
	MarshalConf(tag string) ([]byte, error)
}

type Rangeable

type Rangeable interface {
	MapKV(tag string, g func(string, interface{}) bool) bool
}

type Unmarshaler

type Unmarshaler interface {
	UnmarshalConf(tag string, values map[string]string) (interface{}, error)
}

Jump to

Keyboard shortcuts

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