dyndns/webapi/server.go
Torben Nehmer 01e22e2b30 Make Hello World Test URL configurable
This should not be active by default for security reasons.
2022-06-28 19:11:15 +02:00

32 lines
622 B
Go

package webapi
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
var router = mux.NewRouter()
func Server() {
router.StrictSlash(true)
if C.AllowHello {
router.HandleFunc("/hello", handleHello)
}
log.Printf("Listening to: %s", C.ListenAddress)
log.Fatal(http.ListenAndServe(C.ListenAddress, router))
}
func handleHello(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
log.Printf("handleHello %s", r.Host)
log.Println(r.URL)
log.Println(r.Form.Get("Lorem"))
log.Println(r.Form)
fmt.Fprintf(w, "<html><body><h1>Hello World</h1><p>Lorem = %s</p></body></html>", r.Form.Get("Lorem"))
}