56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
func readDataStream(resp http.ResponseWriter, request *http.Request) {
|
|
reqBody, _ := io.ReadAll(request.Body)
|
|
|
|
// var jsonBody = json.NewDecoder(request.Body)
|
|
fmt.Println(string(reqBody))
|
|
}
|
|
|
|
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)
|
|
|
|
fmt.Println(http.StatusOK, MessageText)
|
|
resp.WriteHeader(http.StatusOK)
|
|
resp.Write([]byte(MessageText))
|
|
}
|
|
|
|
func CatchError(resp http.ResponseWriter, request *http.Request) {
|
|
var LogText = "got bad request from " + request.RemoteAddr + ". Method: " + request.Method
|
|
fmt.Println(http.StatusBadRequest, LogText)
|
|
var MessageText = "Invalid Request, please read the docs..."
|
|
resp.WriteHeader(http.StatusBadRequest)
|
|
resp.Write([]byte(MessageText))
|
|
|
|
}
|
|
|
|
func handleRequests() {
|
|
// Start new Mux router
|
|
mainrouter := mux.NewRouter().StrictSlash(true)
|
|
|
|
mainrouter.HandleFunc("/", readDataStream).Methods("POST")
|
|
mainrouter.HandleFunc("/healthcheck", HealthCheck).Methods("GET")
|
|
mainrouter.HandleFunc("/", CatchError)
|
|
|
|
log.Fatal(http.ListenAndServe(":10000", mainrouter))
|
|
|
|
}
|
|
|
|
func main() {
|
|
var t = time.Now().String()
|
|
fmt.Println("MPE x Egnyte x PowerApps - Mux Router starting: " + t)
|
|
handleRequests()
|
|
}
|