Created
June 18, 2015 12:23
-
-
Save mrkplt/b1048ac00f31dbda276d to your computer and use it in GitHub Desktop.
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 ( | |
"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) | |
} |
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 models | |
import "encoding/json" | |
type User struct { | |
FirstName string `json:"first_name"` | |
} | |
func (u User) Json() (r []byte) { | |
r, _ = json.Marshal(&u) | |
return r | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
that's pretty nice - i'll have to play around with it.