Created
July 24, 2018 17:50
-
-
Save psyomn/c4c3522e7ba4a58c18a38fc8aef8dfb7 to your computer and use it in GitHub Desktop.
if you need to do quick test thingies
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" | |
"github.com/gorilla/mux" | |
) | |
type Sample struct { | |
Name string | |
Age uint | |
} | |
func One(w http.ResponseWriter, r *http.Request) { | |
var sam Sample = Sample{Name: "jon", Age: 12} | |
json.NewEncoder(w).Encode(sam) | |
} | |
func Two(w http.ResponseWriter, r *http.Request) { | |
var sams = []Sample { | |
Sample{Name: "jon", Age: 12}, | |
Sample{Name: "mary", Age: 13}, | |
} | |
json.NewEncoder(w).Encode(sams) | |
} | |
func main() { | |
router := mux.NewRouter() | |
router.HandleFunc("/one", One).Methods("GET") | |
router.HandleFunc("/two", Two).Methods("GET") | |
http.ListenAndServe(":9001", router) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment