Add some conifguration and logging for the hub
This commit is contained in:
14
appconfig/endpoints.go
Normal file
14
appconfig/endpoints.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package appconfig
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func handleAuthzConfig(w http.ResponseWriter, req *http.Request) {
|
||||
headers := w.Header()
|
||||
headers.Set("content-type", "text/plain")
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, "hello, world")
|
||||
}
|
||||
33
appconfig/log.go
Normal file
33
appconfig/log.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package appconfig
|
||||
|
||||
import "fmt"
|
||||
|
||||
type logger interface {
|
||||
Output(int, string) error
|
||||
}
|
||||
|
||||
type ilogger interface {
|
||||
logger
|
||||
Print(...interface{})
|
||||
Printf(string, ...interface{})
|
||||
Println(...interface{})
|
||||
}
|
||||
|
||||
type internalLog struct {
|
||||
logger
|
||||
}
|
||||
|
||||
// Println replicates the behaviour of the standard logger.
|
||||
func (t internalLog) Println(v ...interface{}) {
|
||||
t.Output(2, fmt.Sprintln(v...))
|
||||
}
|
||||
|
||||
// Printf replicates the behaviour of the standard logger.
|
||||
func (t internalLog) Printf(format string, v ...interface{}) {
|
||||
t.Output(2, fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
// Print replicates the behaviour of the standard logger.
|
||||
func (t internalLog) Print(v ...interface{}) {
|
||||
t.Output(2, fmt.Sprint(v...))
|
||||
}
|
||||
31
appconfig/provider.go
Normal file
31
appconfig/provider.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package appconfig
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Provider struct {
|
||||
handler http.Handler
|
||||
log ilogger
|
||||
}
|
||||
|
||||
func NewProvider() Provider {
|
||||
return Provider{
|
||||
handler: router(),
|
||||
log: log.New(os.Stderr, "servicedemon/appconfig - ", log.LstdFlags|log.Lshortfile),
|
||||
}
|
||||
}
|
||||
|
||||
func (p Provider) Handler() http.Handler {
|
||||
return p.handler
|
||||
}
|
||||
|
||||
func router() *http.ServeMux {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.HandleFunc("/config/authz", handleAuthzConfig)
|
||||
|
||||
return mux
|
||||
}
|
||||
Reference in New Issue
Block a user