Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"net/http"
"github.com/mrkplt/end_point/models"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write(models.User{FirstName: "Mark"}.Json())
})
http.ListenAndServe(":8080", nil)
}
package models
import "encoding/json"
type User struct {
FirstName string `json:"first_name"`
}
func (u User) Json() (r []byte) {
r, _ = json.Marshal(&u)
return r
}
@BeerInHand

This comment has been minimized.

Show comment
Hide comment
@BeerInHand

BeerInHand Jun 19, 2015

that's pretty nice - i'll have to play around with it.

BeerInHand commented Jun 19, 2015

that's pretty nice - i'll have to play around with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment