Skip to content

Instantly share code, notes, and snippets.

@jochasinga
Last active August 29, 2015 14:16
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 jochasinga/52a7c7c86507c91e4ab3 to your computer and use it in GitHub Desktop.
Save jochasinga/52a7c7c86507c91e4ab3 to your computer and use it in GitHub Desktop.
Simple struct models for a blog post
package main
import "time"
// User
type User struct {
Id int `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
}
// Comment
type Comment struct {
Id int `json:"id"`
User User `json:"user"`
Text string `json:"text"`
Timestamp time.Time `json:"timestamp"`
}
// Post
type Post struct {
Id int `json:"id"`
User User `json:"user"`
Topic string `json:"topic"`
Text string `json:"text"`
Comment Comment `json:"comment"`
Timestamp time.Time `json:"timestamp"`
}
type Posts []Post
type Comments []Comment
type Users []User
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment