Created
December 4, 2018 12:31
-
-
Save cn007b/677973fc5f9d3fc75869fffff7c22bb8 to your computer and use it in GitHub Desktop.
Plain Go vs Gin - plain go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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