views

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderAccount

func RenderAccount(w http.ResponseWriter, r *http.Request, user *models.User)

RenderAccount response

func RenderBlankResponse

func RenderBlankResponse(w http.ResponseWriter, r *http.Request)

RenderBlankResponse respond a blank response

func RenderCategories

func RenderCategories(w http.ResponseWriter, r *http.Request, categories []*models.Category)

RenderCategories response sevaral categories

func RenderCategory

func RenderCategory(w http.ResponseWriter, r *http.Request, category *models.Category)

RenderCategory response a category

func RenderComment

func RenderComment(w http.ResponseWriter, r *http.Request, comment *models.Comment)

RenderComment response a comment

func RenderComments

func RenderComments(w http.ResponseWriter, r *http.Request, comments []*models.Comment)

RenderComments response a bundle of comments

func RenderErrorResponse

func RenderErrorResponse(w http.ResponseWriter, r *http.Request, err error)

RenderErrorResponse respond an error response

func RenderResponse

func RenderResponse(w http.ResponseWriter, r *http.Request, data interface{})

RenderResponse respond a special data, e.g.: Topic, Category etc.

func RenderTopic

func RenderTopic(w http.ResponseWriter, r *http.Request, topic *models.Topic)

RenderTopic response a topic

func RenderTopics

func RenderTopics(w http.ResponseWriter, r *http.Request, topics []*models.Topic)

RenderTopics response a bundle of topics

func RenderUser

func RenderUser(w http.ResponseWriter, r *http.Request, user *models.User)

RenderUser response a user

func RenderUsers

func RenderUsers(w http.ResponseWriter, r *http.Request, users []*models.User)

RenderUsers response a bundle of users

Types

type AccountView

type AccountView struct {
	UserView
	Username  string `json:"username"`
	Email     string `json:"email"`
	SessionID string `json:"session_id"`
	Role      string `json:"role"`
}

AccountView is the response body of a sign in user

type CategoryView

type CategoryView struct {
	Type        string    `json:"type"`
	CategoryID  string    `json:"category_id"`
	Name        string    `json:"name"`
	Alias       string    `json:"alias"`
	Description string    `json:"description"`
	TopicsCount int64     `json:"topics_count"`
	LastTopicID string    `json:"last_topic_id"`
	Position    int64     `json:"position"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

CategoryView is the response body of a category

type CommentView

type CommentView struct {
	CommentID string    `json:"comment_id,pk"`
	Body      string    `json:"body"`
	TopicID   string    `json:"topic_id"`
	UserID    string    `json:"user_id"`
	Score     int       `json:"score,notnull"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	User      UserView  `json:"user"`
}

CommentView is the response body of comment

type ResponseView

type ResponseView struct {
	Data  interface{} `json:"data,omitempty"`
	Error error       `json:"error,omitempty"`
}

ResponseView is the struct of response

type TopicView

type TopicView struct {
	Type          string       `json:"type"`
	TopicID       string       `json:"topic_id"`
	Title         string       `json:"title"`
	Body          string       `json:"body"`
	UserID        string       `json:"user_id"`
	CategoryID    string       `json:"category_id"`
	Score         int          `json:"score"`
	CommentsCount int64        `json:"comments_count"`
	CreatedAt     time.Time    `json:"created_at"`
	UpdatedAt     time.Time    `json:"updated_at"`
	User          UserView     `json:"user"`
	Category      CategoryView `json:"category"`
}

TopicView is the response body of topic

type UserView

type UserView struct {
	Type      string    `json:"type"`
	UserID    string    `json:"user_id"`
	Nickname  string    `json:"nickname"`
	Biography string    `json:"biography"`
	AvatarURL string    `json:"avatar_url"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

UserView is the response body of user

Jump to

Keyboard shortcuts

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