2023-12-04 08:37:53 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
2023-12-04 15:03:40 -07:00
|
|
|
"time"
|
2023-12-04 08:37:53 -07:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
|
|
|
func readDataStream(resp http.ResponseWriter, request *http.Request) {
|
|
|
|
reqBody, _ := io.ReadAll(request.Body)
|
|
|
|
|
|
|
|
// var jsonBody = json.NewDecoder(request.Body)
|
2023-12-04 15:03:40 -07:00
|
|
|
fmt.Println(string(reqBody))
|
2023-12-04 08:37:53 -07:00
|
|
|
}
|
|
|
|
|
2023-12-04 15:03:40 -07:00
|
|
|
func HealthCheck(resp http.ResponseWriter, request *http.Request) {
|
|
|
|
var t = time.Now().String()
|
|
|
|
var MessageText = t + ": Health Check from " + request.RemoteAddr
|
|
|
|
// reqBody, _ := io.ReadAll(request.Body)
|
2023-12-04 08:37:53 -07:00
|
|
|
|
2023-12-04 15:03:40 -07:00
|
|
|
fmt.Println(http.StatusOK, MessageText)
|
|
|
|
resp.WriteHeader(http.StatusOK)
|
|
|
|
resp.Write([]byte(MessageText))
|
2023-12-04 08:37:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func handleRequests() {
|
|
|
|
// Start new Mux router
|
|
|
|
mainrouter := mux.NewRouter().StrictSlash(true)
|
|
|
|
|
|
|
|
mainrouter.HandleFunc("/", readDataStream).Methods("POST")
|
2023-12-04 15:03:40 -07:00
|
|
|
mainrouter.HandleFunc("/healthcheck", HealthCheck).Methods("GET")
|
2023-12-04 08:37:53 -07:00
|
|
|
|
|
|
|
log.Fatal(http.ListenAndServe(":10000", mainrouter))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
fmt.Println("MPE x Egnyte x PowerApps - Mux Router")
|
|
|
|
handleRequests()
|
|
|
|
}
|