Skip to content

Commit

Permalink
New HTTP router implementation for start-api.
Browse files Browse the repository at this point in the history
This change takes a lot of the logic out of start.go for HTTP handling,
and moves it to a new, separate 'router' package.

It also moves all of the environment handling out into a separate file
(env.go and env_test.go), to make that a lot cleaner and remove
duplication. These changes makes for a much smaller start.go, with far less logic.

The new HTTP router implementation looks like this:

```
// initiate a new router
r := router.NewServerlessRouter()

// Add a AWS::Serverless::Function to it
r.AddFunction(someServerlessFunction)

// Add a AWS::Serverless::Api to it
r.AddAPI(someServerlessApi)

// Add a static files dir
r.AddStaticDir("public/", "/")

// Pass it to Go's HTTP pkg for serving
http.ListenAndServe("0.0.0.0:3000", r.Router()))
```

As the router impementation isn't a mega-method-of-doom anymore, it's
much, much easier to unit test. I've included quite a few tests already.
  • Loading branch information
PaulMaddox committed Aug 31, 2017
1 parent 70b403f commit f7c8514
Showing 1 changed file with 0 additions and 0 deletions.
Binary file added router/debug.test
Binary file not shown.

0 comments on commit f7c8514

Please sign in to comment.