Logging
This commit is contained in:
parent
ee13d570d8
commit
85e1af878a
8 changed files with 288 additions and 47 deletions
13
web.go
13
web.go
|
@ -3,13 +3,10 @@ package main
|
|||
import (
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
"os"
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/unrolled/render"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"encoding/json"
|
||||
"log"
|
||||
)
|
||||
|
||||
var renderer = render.New()
|
||||
|
@ -24,9 +21,9 @@ type Page struct {
|
|||
|
||||
func (provider *WebProvider) Provide(configurationChan chan<- *Configuration){
|
||||
systemRouter := mux.NewRouter()
|
||||
systemRouter.Methods("GET").PathPrefix("/web/").Handler(handlers.CombinedLoggingHandler(os.Stdout, http.HandlerFunc(GetHtmlConfigHandler)))
|
||||
systemRouter.Methods("GET").PathPrefix("/api/").Handler(handlers.CombinedLoggingHandler(os.Stdout, http.HandlerFunc(GetConfigHandler)))
|
||||
systemRouter.Methods("POST").PathPrefix("/api/").Handler(handlers.CombinedLoggingHandler(os.Stdout, http.HandlerFunc(
|
||||
systemRouter.Methods("GET").PathPrefix("/web/").Handler(http.HandlerFunc(GetHtmlConfigHandler))
|
||||
systemRouter.Methods("GET").PathPrefix("/api/").Handler(http.HandlerFunc(GetConfigHandler))
|
||||
systemRouter.Methods("POST").PathPrefix("/api/").Handler(http.HandlerFunc(
|
||||
func(rw http.ResponseWriter, r *http.Request){
|
||||
configuration := new(Configuration)
|
||||
b, _ := ioutil.ReadAll(r.Body)
|
||||
|
@ -35,10 +32,10 @@ func (provider *WebProvider) Provide(configurationChan chan<- *Configuration){
|
|||
configurationChan <- configuration
|
||||
GetConfigHandler(rw, r)
|
||||
}else{
|
||||
log.Printf("Error parsing configuration %+v\n", err)
|
||||
log.Error("Error parsing configuration %+v\n", err)
|
||||
http.Error(rw, fmt.Sprintf("%+v", err), http.StatusBadRequest)
|
||||
}
|
||||
})))
|
||||
}))
|
||||
systemRouter.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
||||
|
||||
go http.ListenAndServe(provider.Address, systemRouter)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue