From dbeab44f400717c52f5756a2cc49c23c5f6bfa82 Mon Sep 17 00:00:00 2001 From: Naren Date: Tue, 25 Apr 2017 16:19:41 -0700 Subject: [PATCH] dubious type shit --- server.go | 16 +++++++++------- server/logger.go | 2 +- server/router.go | 3 ++- services.go | 8 ++++++-- services/services.go | 22 ++++++++++++++++++++++ 5 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 services/services.go diff --git a/server.go b/server.go index 93334a8..7c04178 100644 --- a/server.go +++ b/server.go @@ -18,9 +18,11 @@ import ( "github.com/acm-uiuc/arbor/security" "github.com/acm-uiuc/arbor/server" + "github.com/acm-uiuc/arbor/services" ) // Boot is a standard server CLI +// Provide a set of routes to serve and a port to serve on // executable [-r | --register-client client_name] [-c | --check-registration token] [-u | --unsecured] // -r | --register-client client_name // registers a client, generates a token @@ -31,17 +33,17 @@ import ( // without args // runs groot with the security layer // It will start the arbor instance, parsing the command arguments and execute the behavior -func Boot(routes RouteCollection) { +func Boot(routes RouteCollection, port uint16) { if len(os.Args) == 3 && (os.Args[1] == "--register-client" || os.Args[1] == "-r") { RegisterClient(os.Args[2]) } else if len(os.Args) == 3 && (os.Args[1] == "--check-registration" || os.Args[1] == "-c") { CheckRegistration(os.Args[2]) } else if len(os.Args) == 2 && (os.Args[1] == "--unsecured" || os.Args[1] == "-u") { - StartUnsecuredServer(routes) + StartUnsecuredServer(routes, port) } else if len(os.Args) > 1 { fmt.Println("Invalid Command") } else { - StartServer(routes) + StartServer(routes, port) } } @@ -67,11 +69,11 @@ func CheckRegistration(token string) { } // StartServer starts a secured arbor server (Token required for access) -// Provide a set of routes to service and a port to serve on +// Provide a set of routes to serve and a port to serve on func StartServer(routes RouteCollection, port uint16) { security.Init() - router := server.NewRouter(routes) + router := server.NewRouter(services.RouteCollection(routes)) log.Println("ROOTS BEING PLANTED [Server is listening on :" + fmt.Sprintf("%d", port) + "]") log.Fatal(http.ListenAndServe(":"+fmt.Sprintf("%d", port), router)) @@ -80,9 +82,9 @@ func StartServer(routes RouteCollection, port uint16) { } // StartUnsecuredServer starts an unsecured arbor server (Token required for access) -// Provide a set of routes to service and a port to serve on +// Provide a set of routes to server and a port to serve on func StartUnsecuredServer(routes RouteCollection, port uint16) { - router := server.NewRouter(routes) + router := server.NewRouter(services.RouteCollection(routes)) log.Println("ROOTS BEING PLANTED [Server is listening on :" + fmt.Sprintf("%d", port) + "]") log.Fatal(http.ListenAndServe(":"+fmt.Sprintf("%d", port), router)) diff --git a/server/logger.go b/server/logger.go index d099400..bbf4350 100644 --- a/server/logger.go +++ b/server/logger.go @@ -8,7 +8,7 @@ * this license in a file with the distribution. **/ -package arbor +package server import ( "log" diff --git a/server/router.go b/server/router.go index be0c94b..9bf6965 100644 --- a/server/router.go +++ b/server/router.go @@ -13,10 +13,11 @@ package server import ( "net/http" + "github.com/acm-uiuc/arbor/services" "github.com/gorilla/mux" ) -func NewRouter(routes RouteCollection) *mux.Router { +func NewRouter(routes services.RouteCollection) *mux.Router { router := mux.NewRouter() for _, route := range routes { diff --git a/services.go b/services.go index 7f31c27..64bee5a 100644 --- a/services.go +++ b/services.go @@ -10,7 +10,11 @@ package arbor -import "net/http" +import ( + "net/http" + + "github.com/acm-uiuc/arbor/services" +) // Route is a struct that defines a route for a microservice // Name: Name of the route @@ -26,4 +30,4 @@ type Route struct { // RouteCollection is a slice of routes that is used to represent a service (may change name here ) // Usage: The recomendation is to create a RouteCollection variable for all of you services and for each service create a specific one then in a registration function append all the service collections into the single master collection. -type RouteCollection []Route +type RouteCollection []services.Route diff --git a/services/services.go b/services/services.go new file mode 100644 index 0000000..2596d79 --- /dev/null +++ b/services/services.go @@ -0,0 +1,22 @@ +/** +* Copyright © 2017, ACM@UIUC +* +* This file is part of the Groot Project. +* +* The Groot Project is open source software, released under the University of +* Illinois/NCSA Open Source License. You should have received a copy of +* this license in a file with the distribution. +**/ + +package services + +import "net/http" + +type Route struct { + Name string + Method string + Pattern string + HandlerFunc http.HandlerFunc +} + +type RouteCollection []Route