Skip to content

Commit

Permalink
dubious type shit
Browse files Browse the repository at this point in the history
  • Loading branch information
narendasan committed Apr 25, 2017
1 parent efe8f88 commit dbeab44
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
16 changes: 9 additions & 7 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}

Expand All @@ -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))
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion server/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* this license in a file with the distribution.
**/

package arbor
package server

import (
"log"
Expand Down
3 changes: 2 additions & 1 deletion server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
22 changes: 22 additions & 0 deletions services/services.go
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dbeab44

Please sign in to comment.