wings/api/api.go
2017-06-26 11:07:53 +02:00

33 lines
654 B
Go

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