31 lines
708 B
Go
31 lines
708 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
const (
|
|
MethodPurge = "PURGE"
|
|
)
|
|
|
|
// 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()
|
|
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() {
|
|
http.HandleFunc("/", PurgeHandler)
|
|
log.Fatal(http.ListenAndServe(":6081",nil))
|
|
}
|