mirror of
https://github.com/fleetdm/fleet
synced 2026-05-22 08:28:52 +00:00
This documents a few migration webhooks we have built, so I'm not the only person that can run them.
40 lines
858 B
Go
40 lines
858 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
|
|
var detail string
|
|
body, err := io.ReadAll(request.Body)
|
|
if err != nil {
|
|
detail = fmt.Sprintf("| ERROR: reading request body: %s", err)
|
|
} else if len(body) != 0 {
|
|
detail = fmt.Sprintf("| BODY: %s", string(body))
|
|
}
|
|
log.Printf("%s %s %s\n", request.Method, request.URL.Path, detail)
|
|
if err := request.Write(writer); err != nil {
|
|
log.Fatalf(err.Error())
|
|
}
|
|
})
|
|
|
|
port := ":4648"
|
|
if p := os.Getenv("SERVER_PORT"); p != "" {
|
|
port = p
|
|
}
|
|
|
|
fmt.Printf("Server running at http://localhost%s\n", port)
|
|
server := &http.Server{
|
|
Addr: port,
|
|
ReadHeaderTimeout: 3 * time.Second,
|
|
}
|
|
if err := server.ListenAndServe(); err != nil {
|
|
log.Fatalf(err.Error())
|
|
}
|
|
}
|