Implement basic server
This commit is contained in:
parent
a04a36bf90
commit
d12ace7f37
|
@ -3,6 +3,7 @@ package secondly
|
|||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
@ -37,6 +38,11 @@ func Manage(target interface{}) {
|
|||
bootstrap()
|
||||
}
|
||||
|
||||
// StartServer will start an HTTP server with web interface to edit config.
|
||||
func StartServer(host string, port int) {
|
||||
go startServer(fmt.Sprintf("%s:%d", host, port))
|
||||
}
|
||||
|
||||
// HandleSIGHUP waits a SIGHUP system call and reloads configuration when
|
||||
// receives one.
|
||||
func HandleSIGHUP() {
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package secondly
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func startServer(addr string) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/fields.json", fieldsHandler)
|
||||
|
||||
log.Println("Starting configuration server on", addr)
|
||||
go http.ListenAndServe(addr, mux)
|
||||
}
|
||||
|
||||
func fieldsHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
fields := extractFields(config, "")
|
||||
body, _ := json.Marshal(fields)
|
||||
rw.Write(body)
|
||||
}
|
Loading…
Reference in New Issue