unmarshal config into struct with viper for consistent access
This commit is contained in:
31
api/api.go
31
api/api.go
@@ -1 +1,32 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html"
|
||||
"net/http"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
||||
"github.com/schrej/wings.go/config"
|
||||
)
|
||||
|
||||
// API is a grouping struct for the api
|
||||
type API struct {
|
||||
}
|
||||
|
||||
// NewAPI creates a new Api object
|
||||
func NewAPI() API {
|
||||
return API{}
|
||||
}
|
||||
|
||||
// Listen starts the api http server
|
||||
func (api *API) Listen() {
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
||||
})
|
||||
|
||||
listenString := fmt.Sprintf("%s:%d", config.Get().Web.ListenHost, config.Get().Web.ListenPort)
|
||||
|
||||
log.Info("Now listening on %s", listenString)
|
||||
log.Fatal(http.ListenAndServe(listenString, nil))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user