Skip to content

Instantly share code, notes, and snippets.

Created February 19, 2014 20:01
Show Gist options
  • Save anonymous/9100387 to your computer and use it in GitHub Desktop.
Save anonymous/9100387 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"github.com/BurntSushi/toml"
)
var gobbConf = `
# This section deals with various gobb-specific settings
[gobb]
site_name = "gobb"
cookie_key = "encrypt_your_cookies"
posts_per_page = 15
threads_per_page = 30
enable_signatures = true
port = 8080
# The base path is a directory that houses any custom
# gobb things (eg, templates, css modifications, etc.)
# This field is optional (disabled by default), but we
# reccommend that you set it to where your config file
# is located (keep things organized!)
#base_path = "/path/to/gobb/directory"
# This section deals with the database connection. It's
# definitely not optional, so you should fill it in now.
[database]
username = "db_username"
password = "db_password"
database = "db_name"
hostname = "localhost"
# If you have a Google Analytics account, put your information
# in this section (optional)
[googleanalytics]
tracking_id = ""
account = ""
`
type Config struct {
ConfigGobb `toml:"gobb"`
ConfigDatabase `toml:"database"`
ConfigGoogle `toml:"googleanalytics"`
}
type ConfigGobb struct {
SiteName string `toml:"site_name"`
CookieKey string `toml:"cookie_key"`
PostsPerPage int `toml:"posts_per_page"`
ThreadsPerPage int `toml:"threads_per_page"`
Signatures bool `toml:"enable_signatures"`
Port int
BasePath string `toml:"base_path"`
}
type ConfigDatabase struct {
Username string
Password string
Database string
Hostname string
}
type ConfigGoogle struct {
TrackingId string
Account string
}
func main() {
var conf Config
if _, err := toml.Decode(gobbConf, &conf); err != nil {
log.Fatal(err)
}
fmt.Printf("%#v\n", conf)
// Output:
// main.Config{
// ConfigGobb:main.ConfigGobb{SiteName:"gobb",
// CookieKey:"encrypt_your_cookies", PostsPerPage:15, ThreadsPerPage:30,
// Signatures:true, Port:8080, BasePath:""},
// ConfigDatabase:main.ConfigDatabase{Username:"db_username",
// Password:"db_password", Database:"db_name", Hostname:"localhost"},
// ConfigGoogle:main.ConfigGoogle{TrackingId:"", Account:""}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment