diff --git a/config/build.go b/config/build.go index d76f1ba9c..8274ffe54 100644 --- a/config/build.go +++ b/config/build.go @@ -19,7 +19,7 @@ func Build() { // "dataDir" builds the directory for program files. func dataDir() { // attempts to make the data directory. - if err := os.MkdirAll(Get().DD, os.ModePerm); err != nil { + if err := os.MkdirAll(GlobalConfig().DD, os.ModePerm); err != nil { // doesn't use custom logs, because they may or may not be available at this point log.Fatalf(err.Error()) } @@ -28,7 +28,7 @@ func dataDir() { // "logsDir" builds the directory for logs. func logsDir() { // attempts to make the logs directory - if err := os.MkdirAll(Get().DD+_const.FILESEPARATOR+"logs", os.ModePerm); err != nil { + if err := os.MkdirAll(GlobalConfig().DD+_const.FILESEPARATOR+"logs", os.ModePerm); err != nil { log.Fatal(err.Error()) } } diff --git a/config/config.go b/config/config.go index 22823dbe0..527977283 100644 --- a/config/config.go +++ b/config/config.go @@ -45,7 +45,7 @@ func Init() { // built in function to parse the flags above. flag.Parse() // returns the thread safe c of the client configuration. - Get() + GlobalConfig() } // "newConfiguration() is a constructor function of the configuration type. @@ -71,8 +71,8 @@ func Print() { fmt.Println("Pocket Core Configuration:\n", string(data)) // pretty print the pocket configuration } -// "Get()" returns the configuration object in a thread safe manner. -func Get() *config { // singleton structure to return the configuration object +// "GlobalConfig()" returns the configuration object in a thread safe manner. +func GlobalConfig() *config { // singleton structure to return the configuration object once.Do(func() { // thread safety. newConfiguration() }) diff --git a/logs/methods.go b/logs/methods.go index fa6055f7c..e1e798015 100644 --- a/logs/methods.go +++ b/logs/methods.go @@ -58,7 +58,7 @@ func NewLog(message string, level LogLevel, format LogFormat) { // "Logger" prints the log to data directory func Logger(l Log) error { // open/create the new log file - f, err := os.OpenFile(config.Get().DD+_const.FILESEPARATOR+"logs"+_const.FILESEPARATOR+l.Name, os.O_WRONLY|os.O_CREATE|os.O_APPEND, os.ModePerm) + f, err := os.OpenFile(config.GlobalConfig().DD+_const.FILESEPARATOR+"logs"+_const.FILESEPARATOR+l.Name, os.O_WRONLY|os.O_CREATE|os.O_APPEND, os.ModePerm) if err != nil { return err } diff --git a/node/config.go b/node/config.go index 58967c265..389dac9b3 100644 --- a/node/config.go +++ b/node/config.go @@ -7,11 +7,11 @@ import ( func Files() { // Map.json - if err := ManualPeersFile(config.Get().PFile); err != nil { // add Map from file + if err := ManualPeersFile(config.GlobalConfig().PFile); err != nil { // add Map from file logs.NewLog(err.Error(), logs.WaringLevel, logs.JSONLogFormat) } // chains.json - if err := CFIle(config.Get().CFile); err != nil { + if err := CFIle(config.GlobalConfig().CFile); err != nil { logs.NewLog(err.Error(), logs.WaringLevel, logs.JSONLogFormat) } // whitelists for centralized dispatcher diff --git a/node/self.go b/node/self.go index 92dd83e36..2448c032b 100644 --- a/node/self.go +++ b/node/self.go @@ -19,7 +19,7 @@ func Self() *Node { if err != nil { logs.NewLog(err.Error(), logs.FatalLevel, logs.JSONLogFormat) } - self = &Node{GID: config.Get().GID, RelayPort: config.Get().RRPCPort, IP: ip} + self = &Node{GID: config.GlobalConfig().GID, RelayPort: config.GlobalConfig().RRPCPort, IP: ip} }) return self } diff --git a/node/whitelist.go b/node/whitelist.go index bb4b17fae..2243f7709 100644 --- a/node/whitelist.go +++ b/node/whitelist.go @@ -73,12 +73,12 @@ func (w *Whitelist) Count() int { // "SWLFile" builds the service white list from a file. func SWLFile() error { - return SWL().wlFile(config.Get().DWL) + return SWL().wlFile(config.GlobalConfig().DWL) } // "DWLFile" builds the develoeprs white list from a file. func DWLFile() error { - return DWL().wlFile(config.Get().SNWL) + return DWL().wlFile(config.GlobalConfig().SNWL) } // "wlFile" builds a whitelist structure from a file. diff --git a/rpc/client/routes.go b/rpc/client/routes.go index 5a3886b09..92b9a25b3 100644 --- a/rpc/client/routes.go +++ b/rpc/client/routes.go @@ -10,7 +10,7 @@ import ( // "Routes" is a function that returns all of the routes of the API. func Routes() shared.Routes { routes := shared.Routes{ - shared.Route{Name: "Routes", Method: "GET", Path: "/v1/routes", HandlerFunc: GetRoutes}, + shared.Route{Name: "Routes", Method: "GET", Path: "/v1/routes", HandlerFunc: WriteRoutes}, shared.Route{Name: "Register", Method: "POST", Path: "/v1/register", HandlerFunc: Register}, shared.Route{Name: "UnRegister", Method: "POST", Path: "/v1/unregister", HandlerFunc: UnRegister}, shared.Route{Name: "RegisterInfo", Method: "GET", Path: "/v1/register", HandlerFunc: RegisterInfo}, @@ -56,7 +56,7 @@ func Routes() shared.Routes { return routes } -// "GetRoutes" handles the localhost:/routes call. -func GetRoutes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - shared.GetRoutes(w, r, ps, Routes()) +// "WriteRoutes" handles the localhost:/routes call. +func WriteRoutes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + shared.WriteRoutes(w, r, ps, Routes()) } diff --git a/rpc/relay/routes.go b/rpc/relay/routes.go index ce47d87ed..adcce67d1 100644 --- a/rpc/relay/routes.go +++ b/rpc/relay/routes.go @@ -11,7 +11,7 @@ import ( func Routes() shared.Routes { routes := shared.Routes{ shared.Route{Name: "Version", Method: "GET", Path: "/v1", HandlerFunc: Version}, - shared.Route{Name: "GetRoutes", Method: "GET", Path: "/v1/routes", HandlerFunc: GetRoutes}, + shared.Route{Name: "WriteRoutes", Method: "GET", Path: "/v1/routes", HandlerFunc: WriteRoutes}, shared.Route{Name: "Report", Method: "POST", Path: "/v1/report", HandlerFunc: Report}, shared.Route{Name: "ReportInfo", Method: "GET", Path: "/v1/report", HandlerFunc: ReportInfo}, shared.Route{Name: "Dispatch", Method: "POST", Path: "/v1/dispatch", HandlerFunc: Dispatch}, @@ -22,7 +22,7 @@ func Routes() shared.Routes { return routes } -// "GetRoutes" handles the localhost:/routes call. -func GetRoutes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - shared.GetRoutes(w,r,ps,Routes()) +// "WriteRoutes" handles the localhost:/routes call. +func WriteRoutes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + shared.WriteRoutes(w,r,ps,Routes()) } diff --git a/rpc/server.go b/rpc/server.go index 7f82f0cd4..9eebe7c1c 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -14,11 +14,11 @@ import ( // "StartServers" executes the specified configuration for the client. func StartServers() { - if config.Get().CRPC { // if flag set - go StartClientRPC(config.Get().CRPCPort) // run the client rpc in a goroutine + if config.GlobalConfig().CRPC { // if flag set + go StartClientRPC(config.GlobalConfig().CRPCPort) // run the client rpc in a goroutine } - if config.Get().RRPC { // if flag set - go StartRelayRPC(config.Get().RRPCPort) // run the relay rpc in a goroutine + if config.GlobalConfig().RRPC { // if flag set + go StartRelayRPC(config.GlobalConfig().RRPCPort) // run the relay rpc in a goroutine } } diff --git a/rpc/shared/routes.go b/rpc/shared/routes.go index 7c8d46f9d..8d6df5c4c 100644 --- a/rpc/shared/routes.go +++ b/rpc/shared/routes.go @@ -19,8 +19,8 @@ type Route struct { // "Routes" is a slice that holds all of the routes within one structure. type Routes []Route -// "GetRoutes" handles the localhost:/routes call. -func GetRoutes(w http.ResponseWriter, r *http.Request, ps httprouter.Params, routes Routes) { +// "WriteRoutes" handles the localhost:/routes call. +func WriteRoutes(w http.ResponseWriter, r *http.Request, ps httprouter.Params, routes Routes) { var paths []string for _, v := range routes { if v.Method != "GET" { @@ -31,7 +31,7 @@ func GetRoutes(w http.ResponseWriter, r *http.Request, ps httprouter.Params, rou w.Header().Set("Access-Control-Allow-Headers", "Content-Type") j, err := json.MarshalIndent(paths, "", " ") if err != nil { - logs.NewLog("Unable to marshal GetRoutes to JSON", logs.ErrorLevel, logs.JSONLogFormat) + logs.NewLog("Unable to marshal WriteRoutes to JSON", logs.ErrorLevel, logs.JSONLogFormat) } WriteRawJSONResponse(w, j) } diff --git a/tests/config/build_test.go b/tests/config/build_test.go index 773d24d29..0993e0e06 100644 --- a/tests/config/build_test.go +++ b/tests/config/build_test.go @@ -32,7 +32,7 @@ func TestLogsDir(t *testing.T) { func TestDataDir(t *testing.T) { config.Init() config.Print() - datadir := config.Get().DD + datadir := config.GlobalConfig().DD if datadir == _const.DATADIR { t.Log(datadir) } else { diff --git a/tests/node/dispatch_test.go b/tests/node/dispatch_test.go index f7142b697..0895ffb6e 100644 --- a/tests/node/dispatch_test.go +++ b/tests/node/dispatch_test.go @@ -12,12 +12,12 @@ import ( func TestDispatchLiveness(t *testing.T) { // start API servers - go rpc.StartRelayRPC(config.Get().RRPCPort) + go rpc.StartRelayRPC(config.GlobalConfig().RRPCPort) time.Sleep(time.Second) // get peer list pl := node.PeerList() // create arbitrary nodes - self := node.Node{GID: "self", IP: "localhost", RelayPort: config.Get().RRPCPort} + self := node.Node{GID: "self", IP: "localhost", RelayPort: config.GlobalConfig().RRPCPort} dead := node.Node{GID: "deadNode", IP: "0.0.0.0", RelayPort: "0"} // add self to peerlist pl.Add(self) diff --git a/tests/rpc/dispatch_test.go b/tests/rpc/dispatch_test.go index 209404b2f..d9f6b380c 100644 --- a/tests/rpc/dispatch_test.go +++ b/tests/rpc/dispatch_test.go @@ -48,9 +48,9 @@ func TestDispatchServe(t *testing.T) { // json call string for dispatch serve requestJSON := []byte("{\"DevID\": \"foo\", \"Blockchains\": [{\"name\":\"ethereum\",\"netid\":\"1\",\"version\":\"1.0\"}]}") // start relay server - go http.ListenAndServe(":"+config.Get().RRPCPort, shared.Router(relay.Routes())) + go http.ListenAndServe(":"+config.GlobalConfig().RRPCPort, shared.Router(relay.Routes())) // url for the POST request - u := "http://localhost:" + config.Get().RRPCPort + "/v1/dispatch/" + u := "http://localhost:" + config.GlobalConfig().RRPCPort + "/v1/dispatch/" req, err := http.NewRequest("POST", u, bytes.NewBuffer(requestJSON)) if err != nil { t.Fatalf(err.Error()) diff --git a/tests/rpc/reference_test.go b/tests/rpc/reference_test.go index a83c85ff4..6247daf25 100644 --- a/tests/rpc/reference_test.go +++ b/tests/rpc/reference_test.go @@ -15,9 +15,9 @@ Unit test for APIReference */ func TestApiReference(t *testing.T) { // Start server instance - go http.ListenAndServe(":"+config.Get().RRPCPort, shared.Router(relay.Routes())) + go http.ListenAndServe(":"+config.GlobalConfig().RRPCPort, shared.Router(relay.Routes())) // @ Url - u := "http://localhost:" + config.Get().RRPCPort + "/v1/dispatch" + u := "http://localhost:" + config.GlobalConfig().RRPCPort + "/v1/dispatch" // Send get request resp, err := http.Get(u) if err != nil { diff --git a/tests/rpc/relay_test.go b/tests/rpc/relay_test.go index 8a82342f9..1f2f23eee 100644 --- a/tests/rpc/relay_test.go +++ b/tests/rpc/relay_test.go @@ -21,15 +21,15 @@ Unit test for the relay functionality func TestRelay(t *testing.T) { node.DWL().Add("DEVID1") // grab the hosted chains via file - if err := node.CFIle(config.Get().CFile); err != nil { + if err := node.CFIle(config.GlobalConfig().CFile); err != nil { t.Fatalf(err.Error()) } node.TestChains() fmt.Println(node.Chains()) // Start server instance - go http.ListenAndServe(":"+config.Get().RRPCPort, shared.Router(relay.Routes())) + go http.ListenAndServe(":"+config.GlobalConfig().RRPCPort, shared.Router(relay.Routes())) // @ Url - u := "http://localhost:" + config.Get().RRPCPort + "/v1/relay/" + u := "http://localhost:" + config.GlobalConfig().RRPCPort + "/v1/relay/" // Setup relay r := service.Relay{} // add blockchain value diff --git a/tests/rpc/report_test.go b/tests/rpc/report_test.go index 13368b046..266f124b1 100644 --- a/tests/rpc/report_test.go +++ b/tests/rpc/report_test.go @@ -19,9 +19,9 @@ import ( func TestReport(t *testing.T) { report := service.Report{GID: "test", Message: "foo"} // Start server instance - go http.ListenAndServe(":"+config.Get().RRPCPort, shared.Router(relay.Routes())) + go http.ListenAndServe(":"+config.GlobalConfig().RRPCPort, shared.Router(relay.Routes())) // @ Url - u := "http://localhost:" + config.Get().RRPCPort + "/v1/report" + u := "http://localhost:" + config.GlobalConfig().RRPCPort + "/v1/report" j, err := json.Marshal(report) if err != nil { t.Fatalf(err.Error())