added REST API and simple unit test - and compose starter, still WIP for integ test

This commit is contained in:
josebarn
2017-08-15 21:14:14 -03:00
parent bd8a3f2ddd
commit 5e945440d0
58 changed files with 9040 additions and 25 deletions

43
api/api.go Normal file
View File

@@ -0,0 +1,43 @@
package api
import (
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/render"
"log"
"net/http"
"time"
)
func ApiInit() {
log.Println("Initializing API server")
r := chi.NewRouter()
addMiddleware(r)
addRoutes(r)
start(r)
}
func addMiddleware(mux *chi.Mux) {
mux.Use(middleware.RequestID)
mux.Use(middleware.Logger)
mux.Use(middleware.Recoverer)
mux.Use(middleware.URLFormat)
mux.Use(render.SetContentType(render.ContentTypeJSON))
mux.Use(middleware.Timeout(60 * time.Second)) // Set a timeout
}
func addRoutes(mux *chi.Mux) {
// Add a simple resource
mux.Mount("/app", AppResource{}.Routes())
// Live a healthy life!
mux.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("yolo"))
})
}
func start(mux *chi.Mux) {
err := http.ListenAndServe(":8080", mux)
if err != nil {
log.Fatal(err)
}
}