Browse Source

0.0.3

master
Atridad Lahiji 1 month ago
parent
commit
16c0d700f6
  1. 7
      .env.example
  2. 51
      main.go

7
.env.example

@ -1,3 +1,4 @@
ENDPOINT="https://google.com"
AUTH_TOKEN=
METHOD=POST
ENDPOINT_URL="https://google.com"
ENDPOINT_AUTH_TOKEN=
ENDPOINT_REQUST_METHOD=POST
SECURE_TOKEN=

51
main.go

@ -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() {

Loading…
Cancel
Save