unmarshal config into struct with viper for consistent access

This commit is contained in:
Jakob Schrettenbrunner
2017-06-26 11:07:53 +02:00
parent b4b0c3f9e6
commit 06055d6265
10 changed files with 128 additions and 52 deletions

View File

@@ -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))
}

1
api/auth.go Normal file
View File

@@ -0,0 +1 @@
package api

11
api/auth_test.go Normal file
View File

@@ -0,0 +1,11 @@
package api
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFunction(t *testing.T) {
assert.Equal(t, 1, 1)
}