Skip to content

Instantly share code, notes, and snippets.

@psyomn
Created July 24, 2018 17:50
Show Gist options
  • Save psyomn/c4c3522e7ba4a58c18a38fc8aef8dfb7 to your computer and use it in GitHub Desktop.
Save psyomn/c4c3522e7ba4a58c18a38fc8aef8dfb7 to your computer and use it in GitHub Desktop.
if you need to do quick test thingies
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