Skip to content

Instantly share code, notes, and snippets.

@cn007b
Created December 4, 2018 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cn007b/677973fc5f9d3fc75869fffff7c22bb8 to your computer and use it in GitHub Desktop.
Save cn007b/677973fc5f9d3fc75869fffff7c22bb8 to your computer and use it in GitHub Desktop.
Plain Go vs Gin - plain go
package main
import (
"encoding/json"
"net/http"
"strings"
)
func main() {
http.HandleFunc("/v1/id/", func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
pos := strings.LastIndex(path, "/") + 1
id := path[pos:]
e := json.NewEncoder(w)
e.Encode(map[string]string{"id": id})
})
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment