This file contains hidden or 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 ( | |
"fmt" | |
"net/http" | |
) | |
func main() { | |
mux := http.NewServeMux() |
This file contains hidden or 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
mux := http.NewServeMux() | |
// Map a route to handle requests to the root path ("/") | |
mux.HandleFunc("GET 127.0.0.1/", func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprint(w, "Hello") | |
}) | |
mux.HandleFunc("GET localhost/", func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprint(w, "Bonjour") | |
}) |
This file contains hidden or 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
message := "Hello World" | |
r := gin.Default() | |
r.GET("/", func(c *gin.Context){ | |
c.JSON(...) | |
}) |
This file contains hidden or 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
message := "Hello World" | |
// Map a route to handle requests to the root path ("/") | |
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
switch r.Method { | |
case http.MethodGet: | |
// get code | |
fmt.Fprint(w, message) | |
case http.MethodPost: | |
// patch Code |
NewerOlder