Skip to content

Instantly share code, notes, and snippets.

@zaz600
Created June 14, 2015 11:34
Show Gist options
  • Save zaz600/058e2888b3593a10f8c7 to your computer and use it in GitHub Desktop.
Save zaz600/058e2888b3593a10f8c7 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
)
type Config struct {
Src_dir string `json:"src_dir"`
Dst_dir string `json:"dst_dir"`
Timeout int `json:"timeout"`
IfExists string `json:"ifexists"`
User string `json:"user"`
Password string `json:"password"`
}
type Global_config struct {
Dirs []Config `json:"dirs"`
}
func readconfig() (x *Global_config, err error) {
var file []byte
if file, err = ioutil.ReadFile("gotosser.json"); err != nil {
return nil, err
}
x = new(Global_config)
if err = json.Unmarshal(file, &x); err != nil {
return nil, err
}
return x, nil
}
func main() {
cfg, err := readconfig()
if err != nil {
log.Println("readconfig:", err)
os.Exit(-1)
}
for _, c := range cfg.Dirs {
log.Println(c.Src_dir)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment