fleet/tools/mdm/migration/echo/main.go
Roberto Dip c508209e11
document migration webhooks (#13900)
This documents a few migration webhooks we have built, so I'm not the
only person that can run them.
2023-09-18 19:39:00 -03:00

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())
}
}