Documentation ¶
Index ¶
- Variables
- func AllSysRoles() []string
- func CurrentUser(t OAuth, u User) *currentUser
- func CustomError(k, v string) *customError
- func SetDateFormat(layout string)
- func SetTimeFormat(layout string)
- func SetTimeZone(zone int64)
- type AppError
- type AudioInfo
- type ErrorWithKey
- type Image
- type Images
- type JSON
- type JSONDate
- type JSONTime
- func (t *JSONTime) GetBSON() (interface{}, error)
- func (t JSONTime) MarshalJSON() ([]byte, error)
- func (t *JSONTime) Scan(value interface{}) error
- func (t *JSONTime) SetBSON(raw bson.Raw) error
- func (t *JSONTime) String() string
- func (t *JSONTime) UnmarshalJSON(data []byte) error
- func (t *JSONTime) Value() (driver.Value, error)
- type Media
- type Medias
- type MgoModel
- type OAuth
- type OrderBy
- type Paging
- type Requester
- type Response
- type SQLModel
- type SQLModelCreate
- type SystemRole
- type UID
- func (uid *UID) GetBSON() (interface{}, error)
- func (uid UID) GetLocalID() uint32
- func (uid UID) GetObjectType() int
- func (uid UID) GetShardID() uint32
- func (uid UID) MarshalJSON() ([]byte, error)
- func (uid *UID) Scan(value interface{}) error
- func (uid *UID) SetBSON(raw bson.Raw) error
- func (uid UID) String() string
- func (uid *UID) UnmarshalJSON(data []byte) error
- func (uid *UID) Value() (driver.Value, error)
- type User
- type Video
- type VideoInfo
- type Videos
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrRequestDataInvalid = func(s string) *customError { return CustomError("ErrRequestDataInvalid", s) } ErrNoPermission = CustomError("ErrNoPermission", "you don't have permission to access") ErrUsernamePasswordBlank = CustomError("ErrUsernamePasswordBlank", "username and password cannot be blank") ErrAccessTokenInvalid = CustomError("ErrAccessTokenInvalid", "invalid access token") ErrAccessTokenInactivated = CustomError("ErrAccessTokenInactivated", "access token is disabled") ErrUserNotFound = CustomError("ErrUserNotFound", "user not found or deactivated") ErrNoPermissionOnChatRoom = CustomError("ErrNoPermissionOnChatRoom", "you don't have permission on this chat room") ErrCreateRoomWithYourself = CustomError("ErrCreateRoomWithYourself", "you cannot create room has yourself") ErrCreateEmptyRoom = CustomError("ErrCreateEmptyRoom", "you cannot create an empty room") ErrCannotCreateRoom = CustomError("ErrCannotCreateRoom", "cannot create room") ErrRoomNotFound = CustomError("ErrRoomNotFound", "room not found") ErrFbTokenEmpty = CustomError("ErrFbTokenEmpty", "facebook token cannot be empty") ErrAKTokenEmpty = CustomError("ErrFbTokenEmpty", "AccountKit token cannot be empty") ErrAppleTokenEmpty = CustomError("ErrAppleTokenEmpty", "apple token cannot be empty") ErrCannotUpdateData = CustomError("ErrCannotUpdateData", "cannot update data") ErrCannotLoginWithFB = CustomError("ErrCannotLoginWithFB", "cannot login with Facebook") ErrCannotLoginWithApple = CustomError("ErrCannotLoginWithApple", "cannot login with Apple") ErrCannotCreateUser = CustomError("ErrCannotCreateUser", "cannot create new user") ErrCannotUploadImage = CustomError("ErrCannotUploadImage", "cannot upload image") ErrImageIsRequired = CustomError("ErrImageIsRequired", "image file is required") ErrFileIsNotImage = CustomError("ErrFileIsNotImage", "file is not image") ErrImageFileTooBig = CustomError("ErrImageFileTooBig", "image file is too big, limit 1MB") ErrCannotDoYourself = CustomError("ErrCannotDoYourself", "cannot action on yourself") ErrCannotLikeUser = CustomError("ErrCannotLikeUser", "cannot like user") ErrActionTwice = CustomError("ErrActionTwice", "you have done before") ErrCannotDislikeUser = CustomError("ErrCannotDislikeUser", "cannot dislike user") ErrTopicNotFound = CustomError("ErrTopicNotFound", "topic not found") ErrCannotCreateUserTopic = CustomError("ErrCannotCreateUserTopic", "cannot create user topic") ErrUserNameMinMaxLength = CustomError("ErrUserNameMinMaxLength", "UserName must have length greater than 3 and less than 100") ErrPasswordMinMaxLength = CustomError("ErrPasswordMinMaxLength", "Password must have length greater than 6 and less than 50") // Handler Error UserDeviceToken ErrCreateUserDeviceToken = CustomError("ErrCreateUserDeviceToken", "cannot create user device token") ErrDeleteUserDeviceToken = CustomError("ErrDeleteUserDeviceToken", "cannot delete user device token") ErrTokenLength = CustomError("ErrTokenLength", "token cannot empty") ErrInvalidUserDeviceToken = CustomError("ErrInvalidUserDeviceToken", "user device token invalid") ErrCannotProcessImage = CustomError("ErrCannotProcessImage", "cannot process image") )
View Source
var ( ErrCannotFetchData = func(err error) AppError { return NewAppErr(err, http.StatusBadRequest, "can not fetch data").WithCode("cannot_fetch_data") } ErrDB = func(err error) AppError { return NewAppErr(err, http.StatusBadRequest, "db error").WithCode("db_error") } ErrInvalidRequest = func(err error) AppError { return NewAppErr(err, http.StatusBadRequest, "invalid request").WithCode("invalid_request") } ErrInvalidRequestWithMessage = func(err error, message string) AppError { return NewAppErr(err, http.StatusBadRequest, message).WithCode("invalid_request") } ErrWithMessage = func(root error, err ErrorWithKey) AppError { if root == nil { return NewAppErr(errors.New(err.Error()), http.StatusBadRequest, err.Error()).WithCode(err.Key()) } return NewAppErr(root, http.StatusBadRequest, err.Error()).WithCode(err.Key()) } ErrCustom = func(root error, err ErrorWithKey) AppError { if root == nil { return NewAppErr(errors.New(err.Error()), http.StatusBadRequest, err.Error()).WithCode(err.Key()) } return NewAppErr(root, http.StatusBadRequest, err.Error()).WithCode(err.Key()) } if root == nil { return NewAppErr(errors.New(err.Error()), http.StatusUnauthorized, err.Error()).WithCode(err.Key()) } return NewAppErr(root, http.StatusUnauthorized, err.Error()).WithCode(err.Key()) } )
View Source
var ( SimpleSuccessResponse = func(data interface{}) Response { return newResponse(http.StatusOK, data, nil, nil) } ResponseWithPaging = func(data, param interface{}, other interface{}) Response { if v, ok := other.(Paging); ok { if v.NextCursor != "" { if !v.CursorIsUID { v.NextCursor = base58.Encode([]byte(v.NextCursor)) } } return newResponse(http.StatusOK, data, param, v) } return newResponse(http.StatusOK, data, param, other) } )
Response helpers
View Source
var ( // data not found sometime is not an error // but we need this type to decouple from db (errNotFound mongodb and gorm) ErrDataNotFound = errors.New("data not found") )
Functions ¶
func AllSysRoles ¶
func AllSysRoles() []string
func CurrentUser ¶
func CustomError ¶
func CustomError(k, v string) *customError
func SetTimeFormat ¶
func SetTimeFormat(layout string)
Set time format layout. Default: 2006-01-02T15:04:05.999999-07:00
func SetTimeZone ¶
func SetTimeZone(zone int64)
Types ¶
type AppError ¶
type AudioInfo ¶
type AudioInfo struct { Codec string `json:"codec" bson:"codec,omitempty"` BitRate string `json:"bit_rate" bson:"bit_rate,omitempty"` Frequency int `json:"frequency" bson:"frequency,omitempty"` Channels int `json:"channels" bson:"channels,omitempty"` ChannelLayout string `json:"channel_layout" bson:"channel_layout,omitempty"` }
type ErrorWithKey ¶
type Image ¶
type Image struct { ID uint32 `json:"img_id,omitempty" bson:"img_id,omitempty"` FakeID *UID `json:"id,omitempty" bson:"-"` Url string `json:"url" bson:"url"` FileName string `json:"file_name,omitempty" bson:"file_name,omitempty"` OriginWidth int `json:"org_width" bson:"org_width"` OriginHeight int `json:"org_height" bson:"org_height"` OriginUrl string `json:"org_url" bson:"org_url"` CloudName string `json:"cloud_name,omitempty" bson:"cloud_name"` CloudId string `json:"cloud_id,omitempty" bson:"cloud_id"` DominantColor string `json:"dominant_color" bson:"dominant_color"` RequestId string `json:"request_id,omitempty" bson:"-"` FileSize uint32 `json:"file_size,omitempty" bson:"-"` }
func (*Image) HideSomeInfo ¶
type Images ¶
type Images []Image
type JSON ¶
type JSON []byte
func (*JSON) MarshalJSON ¶
func (*JSON) UnmarshalJSON ¶
type JSONDate ¶
func (JSONDate) MarshalJSON ¶
Implement method MarshalJSON to output date with in formatted
func (*JSONDate) UnmarshalJSON ¶
type JSONTime ¶
func (JSONTime) MarshalJSON ¶
Implement method MarshalJSON to output time with in formatted
func (*JSONTime) UnmarshalJSON ¶
type Media ¶
type Media struct { ID uint32 `json:"img_id,omitempty" bson:"img_id,omitempty"` FakeID *UID `json:"id,omitempty" bson:"-"` Type string `json:"type" bson:"type,omitempty"` Url string `json:"url" bson:"url,omitempty"` OriginWidth int `json:"org_width" bson:"org_width,omitempty"` OriginHeight int `json:"org_height" bson:"org_height,omitempty"` OriginUrl string `json:"org_url,omitempty" bson:"org_url,omitempty"` FileName string `json:"file_name,omitempty" bson:"file_name,omitempty"` CloudName string `json:"cloud_name,omitempty" bson:"cloud_name,omitempty"` CloudId string `json:"cloud_id,omitempty" bson:"cloud_id,omitempty"` DominantColor string `json:"dominant_color,omitempty" bson:"dominant_color,omitempty"` RequestId string `json:"request_id,omitempty" bson:"-"` FileSize uint32 `json:"file_size,omitempty" bson:"-"` Format string `json:"format,omitempty" bson:"format,omitempty"` Thumbnail *Image `json:"thumbnail,omitempty" bson:"thumbnail,omitempty"` Audio *AudioInfo `json:"audio,omitempty" bson:"audio,omitempty"` Video *VideoInfo `json:"video,omitempty" bson:"video,omitempty"` FrameRate float64 `json:"frame_rate,omitempty" bson:"frame_rate,omitempty"` BitRate int `json:"bit_rate,omitempty" bson:"bit_rate,omitempty"` Duration float64 `json:"duration,omitempty" bson:"duration,omitempty"` }
type MgoModel ¶
type MgoModel struct { PK bson.ObjectId `json:"id" bson:"_id,omitempty"` Status int `json:"status" bson:"status,omitempty"` CreatedAt *JSONTime `json:"created_at" bson:"created_at,omitempty"` UpdatedAt *JSONTime `json:"updated_at" bson:"updated_at,omitempty"` DeletedAt *JSONTime `json:"deleted_at" bson:"deleted_at,omitempty"` }
func (*MgoModel) PrepareForInsert ¶
type Paging ¶
type Paging struct { Cursor *UID `json:"-" form:"-"` NextCursor string `json:"next_cursor" form:"-"` CursorStr string `json:"cursor" form:"cursor"` Limit int `json:"limit" form:"limit"` Total int `json:"total" form:"-"` Page int `json:"page" form:"page"` HasNext bool `json:"has_next" form:"-"` OrderBy string `json:"-" form:"-"` OB []OrderBy `json:"-" form:"-"` CursorIsUID bool `json:"-" form:"-"` }
type Response ¶
type Response struct { Code int `json:"code"` Data interface{} `json:"data"` Param interface{} `json:"param,omitempty"` Paging interface{} `json:"paging,omitempty"` }
type SQLModel ¶
type SQLModel struct { // Real id in db, we would't show it ID uint32 `json:"-" gorm:"id,PRIMARY_KEY"` // Fake id, we will public it FakeID UID `json:"id" gorm:"-"` Status *int `json:"status,omitempty" gorm:"column:status;default:1;"` CreatedAt *JSONTime `json:"created_at,omitempty;" gorm:"column:created_at;"` UpdatedAt *JSONTime `json:"updated_at,omitempty;" gorm:"column:updated_at;"` }
For reading
func NewSQLModelWithStatus ¶
type SQLModelCreate ¶
type SQLModelCreate struct { // Real id in db, we would't show it ID uint32 `json:"-" gorm:"id,PRIMARY_KEY"` // Fake id, we will public it FakeID UID `json:"id" gorm:"-"` Status int `json:"status,omitempty" gorm:"column:status;default:1;"` CreatedAt *JSONTime `json:"created_at,omitempty;" gorm:"column:created_at;"` UpdatedAt *JSONTime `json:"updated_at,omitempty;" gorm:"column:updated_at;"` }
For creating
func NewSQLModelCreateWithStatus ¶
func NewSQLModelCreateWithStatus(status int) SQLModelCreate
func (*SQLModelCreate) GenUID ¶
func (sm *SQLModelCreate) GenUID(objType int, shardID uint32)
type SystemRole ¶
type SystemRole int
const ( SysRoleRoot SystemRole = iota SysRoleAdmin SysRoleModerator SysRoleUser SysRoleGuest )
func ParseSystemRole ¶
func ParseSystemRole(role string) SystemRole
func (SystemRole) String ¶
func (sr SystemRole) String() string
type UID ¶
type UID struct {
// contains filtered or unexported fields
}
func DecomposeUID ¶
func FromBase58 ¶
func (UID) GetLocalID ¶
func (UID) GetObjectType ¶
func (UID) GetShardID ¶
func (UID) MarshalJSON ¶
func (*UID) UnmarshalJSON ¶
type Video ¶
type Video struct { ID uint32 `json:"img_id,omitempty" bson:"img_id,omitempty"` FakeID *UID `json:"id,omitempty" bson:"-"` Url string `json:"url" bson:"url"` OriginWidth int `json:"org_width" bson:"org_width"` OriginHeight int `json:"org_height" bson:"org_height"` OriginUrl string `json:"org_url" bson:"org_url"` CloudName string `json:"cloud_name,omitempty" bson:"cloud_name"` CloudId string `json:"cloud_id,omitempty" bson:"cloud_id"` DominantColor string `json:"dominant_color" bson:"dominant_color"` RequestId string `json:"request_id,omitempty" bson:"-"` FileSize uint32 `json:"file_size,omitempty" bson:"-"` Format string `json:"format,omitempty"` Audio AudioInfo `json:"audio"` Video VideoInfo `json:"video"` FrameRate float64 `json:"frame_rate"` BitRate int `json:"bit_rate"` Duration float64 `json:"duration"` }
func (*Video) HideSomeInfo ¶
Click to show internal directories.
Click to hide internal directories.