Make Hello World Test URL configurable
This should not be active by default for security reasons.
This commit is contained in:
parent
9b29d9213c
commit
01e22e2b30
@ -6,4 +6,5 @@ service:
|
||||
configdir: users/
|
||||
statedir: state/
|
||||
webapi:
|
||||
allowhello: false
|
||||
listenaddress: :8080
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
|
||||
type config struct {
|
||||
ListenAddress string
|
||||
AllowHello bool
|
||||
}
|
||||
|
||||
var C config
|
||||
@ -19,6 +20,7 @@ func init() {
|
||||
|
||||
func SetConfigDefaults() {
|
||||
viper.SetDefault("WebAPI.ListenAddress", ":8080")
|
||||
viper.SetDefault("WebAPI.AllowHello", false)
|
||||
}
|
||||
|
||||
func LoadConfig() {
|
||||
@ -27,6 +29,7 @@ func LoadConfig() {
|
||||
// https://github.com/spf13/viper/issues/309
|
||||
// viper.UnmarshalKey("WebAPI", &C)
|
||||
C.ListenAddress = viper.GetString("WebAPI.ListenAddress")
|
||||
C.AllowHello = viper.GetBool("WebAPI.AllowHello")
|
||||
}
|
||||
|
||||
func (obj *config) PrettyPrint() string {
|
||||
|
@ -13,10 +13,12 @@ var router = mux.NewRouter()
|
||||
func Server() {
|
||||
router.StrictSlash(true)
|
||||
|
||||
router.HandleFunc("/hello", handleHello)
|
||||
if C.AllowHello {
|
||||
router.HandleFunc("/hello", handleHello)
|
||||
}
|
||||
|
||||
log.Printf("Listening to: %s", C.ListenAddress)
|
||||
go log.Fatal(http.ListenAndServe(C.ListenAddress, router))
|
||||
log.Fatal(http.ListenAndServe(C.ListenAddress, router))
|
||||
}
|
||||
|
||||
func handleHello(w http.ResponseWriter, r *http.Request) {
|
||||
@ -25,5 +27,5 @@ func handleHello(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println(r.URL)
|
||||
log.Println(r.Form.Get("Lorem"))
|
||||
log.Println(r.Form)
|
||||
fmt.Fprint(w, "<html><body><p>Hello World</p></body></html>")
|
||||
fmt.Fprintf(w, "<html><body><h1>Hello World</h1><p>Lorem = %s</p></body></html>", r.Form.Get("Lorem"))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user