Created
June 14, 2015 11:34
-
-
Save zaz600/058e2888b3593a10f8c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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