Skip to content

Instantly share code, notes, and snippets.

@mrkplt
Created June 18, 2015 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrkplt/b1048ac00f31dbda276d to your computer and use it in GitHub Desktop.
Save mrkplt/b1048ac00f31dbda276d to your computer and use it in GitHub Desktop.
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
Copy link

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