package main import ( "net/http" "encoding/json" "fmt" "github.com/drone/routes" ) type API struct { Message string "json:message" } func Hello(w http.ResponseWriter, r *http.Request) { urlParams := r.URL.Query() name := urlParams.Get(":name") HelloMessage := "Hello, " + name message := API{Message:HelloMessage} output, err := json.Marshal(message) if err != nil { fmt.Println("Something went wrong", err) } fmt.Fprint(w, string(output)) } func main() { mux := routes.New() mux.Get("/api/:name", Hello) http.Handle("/", mux) http.ListenAndServe(":8080", nil) }