Skip to content

Instantly share code, notes, and snippets.

@MggMuggins
Last active April 19, 2024 03:26
Show Gist options
  • Save MggMuggins/43eaca212402a5c4bb4aed34d6a0afa4 to your computer and use it in GitHub Desktop.
Save MggMuggins/43eaca212402a5c4bb4aed34d6a0afa4 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"net/http"
"time"
"github.com/gorilla/mux"
)
func clusterName(w http.ResponseWriter, r *http.Request) {
fmt.Printf("clusterName: %q\n", r)
w.WriteHeader(http.StatusOK)
}
func clusterName3(w http.ResponseWriter, r *http.Request) {
fmt.Printf("clusterName3: %q\n", r)
w.WriteHeader(http.StatusOK)
}
func main() {
r := mux.NewRouter()
r.HandleFunc("/cluster/{name}", clusterName)
r.HandleFunc("/cluster/{name}/3", clusterName3)
r.UseEncodedPath()
s := &http.Server{
Addr: "localhost:8080",
Handler: r,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
fmt.Println("Starting server...")
go s.ListenAndServe()
fmt.Println("Sleeping...")
time.Sleep(5 * time.Second)
fmt.Println("Making req")
resp, err := http.Get("http://localhost:8080/cluster/c%2F3")
fmt.Printf("Resp: %s\n", resp)
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment