|
|
@ -28,30 +28,39 @@ func healthCheckHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
} |
|
|
|
|
|
|
|
func webHookHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
// Create a Bearer string by appending string access token
|
|
|
|
// Create a new request using http
|
|
|
|
req, err := http.NewRequest(os.Getenv("METHOD"), os.Getenv("ENDPOINT"), nil) |
|
|
|
token := r.URL.Query().Get("token") |
|
|
|
if token == os.Getenv("SECURE_TOKEN") || os.Getenv("SECURE_TOKEN") == "" { |
|
|
|
// Create a Bearer string by appending string access token
|
|
|
|
// Create a new request using http
|
|
|
|
req, err := http.NewRequest(os.Getenv("ENDPOINT_REQUEST_METHOD"), os.Getenv("ENDPOINT_URL"), nil) |
|
|
|
// add authorization header to the req
|
|
|
|
authToken := os.Getenv("ENDPOINT_AUTH_TOKEN") |
|
|
|
if authToken != "" { |
|
|
|
var bearer = "Bearer " + authToken |
|
|
|
req.Header.Add("Authorization", bearer) |
|
|
|
} |
|
|
|
|
|
|
|
// add authorization header to the req
|
|
|
|
authToken := os.Getenv("AUTH_TOKEN") |
|
|
|
if authToken != "" { |
|
|
|
var bearer = "Bearer " + authToken |
|
|
|
req.Header.Add("Authorization", bearer) |
|
|
|
} |
|
|
|
// Send req using http Client
|
|
|
|
client := &http.Client{} |
|
|
|
resp, err := client.Do(req) |
|
|
|
if err != nil { |
|
|
|
log.Println("Error on response.\n[ERROR] -", err) |
|
|
|
} |
|
|
|
defer resp.Body.Close() |
|
|
|
|
|
|
|
// Send req using http Client
|
|
|
|
client := &http.Client{} |
|
|
|
resp, err := client.Do(req) |
|
|
|
if err != nil { |
|
|
|
log.Println("Error on response.\n[ERROR] -", err) |
|
|
|
} |
|
|
|
defer resp.Body.Close() |
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body) |
|
|
|
if err != nil { |
|
|
|
log.Println("Error while reading the response bytes:", err) |
|
|
|
body, err := ioutil.ReadAll(resp.Body) |
|
|
|
if err != nil { |
|
|
|
w.WriteHeader(http.StatusInternalServerError) |
|
|
|
w.Write([]byte("500 - Internal Server Error!")) |
|
|
|
log.Println("Error while reading the response bytes:", err) |
|
|
|
} |
|
|
|
w.WriteHeader(http.StatusOK) |
|
|
|
w.Write([]byte("200 - Success!")) |
|
|
|
log.Println("Success: ", body) |
|
|
|
} else { |
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
|
|
|
w.Write([]byte("401 - Unauthorized!")) |
|
|
|
} |
|
|
|
log.Println(string([]byte(body))) |
|
|
|
} |
|
|
|
|
|
|
|
func main() { |
|
|
|