post

package
v0.0.0-...-087e281 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2016 License: GPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

post.go Structures for rest server

Index

Constants

View Source
const API_VERSION = "1.0"

Variables

This section is empty.

Functions

func Hash

func Hash(s string) uint64

Types

type Comment

type Comment struct {
	Id            uint64    `db:"notnull, primarykey, autoincrement"`
	PostId        uint64    `db:"notnull, index:idx_foreign_key_postid, uniqueindex:idx_webcomment"` // points to post.id
	WebCommentId  string    `db:"enforcenotnull, size:32, uniqueindex:idx_webcomment"`
	WebParentId   string    `db:"size:32"`
	CommentDate   time.Time `db:"notnull"`
	User          string    `db:"size:64"`
	Score         int       `db:"notnull"`
	Body          string    `db:"name:CommentBody, type:mediumtext"` //size:16383"`
	ParseComplete bool      `db:"-"`                                 // ignore this field when storing with gorp
	Err           error     `db:"-"`                                 // ignore this field when storing with gorp
}

holds a single comment bound to a post

func NewComment

func NewComment() Comment

func (*Comment) GetCommentDate

func (c *Comment) GetCommentDate() time.Time

func (*Comment) Hash

func (c *Comment) Hash() (h uint64)

func (*Comment) SetCommentDate

func (c *Comment) SetCommentDate(commentdate string)

Set the data a post was posted - if it cannot be parsed use the current datetime

func (*Comment) String

func (c *Comment) String(tag string) (s string)

func (*Comment) X_PreUpdate

func (c *Comment) X_PreUpdate(s gorp.SqlExecutor) error

type ErrorDomain

type ErrorDomain struct {
	Domain  string `json:"domain"`
	Message string `json:"message"`
}

Item in an array of errors

type ErrorResponse

type ErrorResponse struct {
	ApiVersion  string `json:"apiVersion"`
	ErrorStruct struct {
		Code    uint32        `json:"code"`
		Message string        `json:"message"`
		XErrors []ErrorDomain `json:"errors"`
	} `json:"error"`
}

The error structure to send back as JSON

func (*ErrorResponse) Append

func (e *ErrorResponse) Append(ed ErrorDomain)

type Post

type Post struct {
	Id        uint64    `db:"notnull, PID, primarykey, autoincrement"`
	Created   time.Time `db:"notnull"`
	PostDate  time.Time `db:"notnull"`
	Site      string    `db:"name: PostSite, enforcenotnull, size:50, index:idx_site"`
	Thumbnail string    `db:"-", json:"thumbnail"`
	WebPostId string    `db:"enforcenotnull, size:32, uniqueindex:idx_webpost"`
	Score     int       `db:"notnull"`
	Title     string    `gorp:"notnull, size: 512"`
	Url       string    `db:"notnull, size:1024"`
	User      string    `db:"index:idx_user, size:64"`
	PostSub   string    `db:"index:idx_user, size:128"`
	Ignored   int       `gorp:"ignorefield"`
	UserIP    string    `db:"notnull, index:idx_user, size:16"`
	BodyType  string    `gorp:"notnull, size:64"`
	Body      string    `db:"name:PostBody, type:mediumtext"`
	Err       error     `db:"-"`               // ignore this field when storing with gorp
	Comments  []Comment `db:"relation:PostId"` // will create a table Comment as a detail table with foreignkey PostId
	// if you want a different name just issue a: table = dbmap.AddTableWithName(post.Comment{}, "comments_embedded_test")
	// after: table := dbmap.AddTableWithName(post.Post{}, "posts_embedded_test")
	// but before: dbmap.CreateTablesIfNotExists()
	CommentParseErrors []Comment `db:"-"`
	CommentCount       uint64
}

Post holds a single post You can use ether db or gorp as tag

func NewPost

func NewPost() Post

func (*Post) AddComment

func (p *Post) AddComment() *Comment

Add a new comment to the post

func (*Post) Hash

func (p *Post) Hash() (h uint64)

func (*Post) SetPostDate

func (p *Post) SetPostDate(postdate string)

Set the date a post was posted - if it cannot be parsed use the current datetime

func (*Post) SetScore

func (p *Post) SetScore(score string)

Set the score of a post or -1 if not convertable from string to int

func (*Post) String

func (p *Post) String(tag string) (s string)

func (*Post) X_PreUpdate

func (p *Post) X_PreUpdate(s gorp.SqlExecutor) error

implement the PreInsert and PreUpdate hooks

type PostSubThumbnail

type PostSubThumbnail struct {
	Id   uint64 `gorp:"notnull, primarykey, autoincrement"`
	Name string `gorp:"notnull, size: 128, uniqueindex:idx_post_thumbnail"`
	Url  string `db:"notnull, size:1024"`
}

Post sub image information struct

type Posts

type Posts struct {
	ApiVersion       string `json:"apiVersion"`
	RequestDuration  int64
	RequestErrorCode int
	RequestErrorMsg  string
	Posts            []*Post
}

Posts holds a slice of Post

type User

type User struct {
	Id        uint64 `gorp:"notnull, primarykey, autoincrement"`
	Name      string `gorp:"notnull, size: 64, uniqueindex:idx_user_name"`
	Password  string `gorp:"size: 32"`
	Level     int32
	Group     int32
	Created   time.Time `gorp:"notnull"`
	LastPost  time.Time
	LastLogin time.Time
	Activity  uint64
	Avatar    string `gorp:"size: 255"`
	Signature string `gorp:"size: 512"`
	Likes     uint32
	Hates     uint32
}

User information struct

func NewUser

func NewUser() User

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL