From 8ef58bc9e80e8d3b1f59dff67211fceb37009006 Mon Sep 17 00:00:00 2001 From: Sebastien Laithier Date: Wed, 10 May 2023 09:33:13 +0200 Subject: [PATCH] Working purge --- main.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index df87605..fcf1110 100644 --- a/main.go +++ b/main.go @@ -1,22 +1,27 @@ package main import ( + "fmt" "io" "log" "net/http" ) -// Declaring non-existing HTTP method const ( - MethodPurge = "PURGE" - VaultStgRoleId = "" - VaultStgSecretId = "" + MethodPurge = "PURGE" ) -// PurgeHandler handles PURGE request to broadcast it to all varnish instances +// PurgeHandler handles PURGE request to broadcast it to all varnish instances. func PurgeHandler(w http.ResponseWriter, r *http.Request) { + client := &http.Client{} + + // Retrieve URL sent and send an HTTP PURGE request to all varnish servers. url := r.URL.String() - io.WriteString(w, url) + req, err := http.NewRequest(MethodPurge, "http://10.13.32.1:6081" + url, nil) + resp, err := client.Do(req) + fmt.Printf("Error: %v\n", err) + fmt.Printf("Resp: %v\n", resp) + io.WriteString(w, resp.Status) } func main() {