@@ -5,6 +5,7 @@ import "github.com/samuel/go-zookeeper/zk"
55import (
66 "bytes"
77 "encoding/json"
8+ "flag"
89 "fmt"
910 "io/ioutil"
1011 "strings"
@@ -19,9 +20,9 @@ type Configuration struct {
1920 Root string `json:"root"`
2021 } `json:"zookeeper"`
2122 ServerConfig struct {
22- WebsiteHost string `json:"websitehost"`
23- CenterHost string `json:"centerhost"`
24- StorageDriver map [string ]interface {} `json:"storagedriver"`
23+ WebsiteHost string `json:"websitehost"`
24+ CenterHost string `json:"centerhost"`
25+ StorageDriver map [string ]interface {} `json:"storagedriver"`
2526 } `json:"serverconfig"`
2627}
2728
@@ -71,9 +72,9 @@ func initServerConfigData(conf *Configuration) (string, []byte, error) {
7172 return serverConfigPath , data , nil
7273}
7374
74- func readConfiguration () (* Configuration , error ) {
75+ func readConfiguration (configFile string ) (* Configuration , error ) {
7576
76- data , err := ioutil .ReadFile ("./ServerConfig.json" )
77+ data , err := ioutil .ReadFile (configFile )
7778 if err != nil {
7879 return nil , err
7980 }
@@ -88,9 +89,13 @@ func readConfiguration() (*Configuration, error) {
8889
8990func main () {
9091
91- conf , err := readConfiguration ()
92+ var configFile string
93+ flag .StringVar (& configFile , "f" , "./ServerConfig.json" , "server config file path." )
94+ flag .Parse ()
95+
96+ conf , err := readConfiguration (configFile )
9297 if err != nil {
93- fmt .Printf ("ServerConfig.json invalid, %s" , err )
98+ fmt .Printf ("server config file invalid, %s" , err )
9499 return
95100 }
96101
0 commit comments