File: main.go

package info (click to toggle)
golang-github-influxdata-toml 0.0~git20160905.0.ad49a5c-1
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 256 kB
  • ctags: 349
  • sloc: makefile: 14
file content (55 lines) | stat: -rw-r--r-- 794 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main

import (
	"io/ioutil"
	"os"
	"time"

	"github.com/influxdata/toml"
)

type tomlConfig struct {
	Title string
	Owner struct {
		Name string
		Org  string `toml:"organization"`
		Bio  string
		Dob  time.Time
	}
	Database struct {
		Server        string
		Ports         []int
		ConnectionMax uint
		Enabled       bool
	}
	Servers struct {
		Alpha Server
		Beta  Server
	}
	Clients struct {
		Data  [][]interface{}
		Hosts []string
	}
}

type Server struct {
	IP string
	DC string
}

func main() {
	f, err := os.Open("example.toml")
	if err != nil {
		panic(err)
	}
	defer f.Close()
	buf, err := ioutil.ReadAll(f)
	if err != nil {
		panic(err)
	}
	var config tomlConfig
	if err := toml.Unmarshal(buf, &config); err != nil {
		panic(err)
	}
	// then to use the unmarshaled config...
}