sdkcm

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2023 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

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())
	}
	ErrUnauthorized = func(root error, err ErrorWithKey) AppError {
		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 CurrentUser(t OAuth, u User) *currentUser

func CustomError

func CustomError(k, v string) *customError

func SetDateFormat

func SetDateFormat(layout string)

Set time format layout. Default: 2006-01-02

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 AppError struct {
	// We don't show root cause to the clients
	RootCause  error  `json:"-"`
	Code       string `json:"code"`
	Log        string `json:"log"`
	StatusCode int    `json:"status_code"`
	Message    string `json:"message"`
}

func NewAppErr

func NewAppErr(err error, statusCode int, msg string) AppError

func (AppError) Error

func (ae AppError) Error() string

AppError is error

func (AppError) RootError

func (ae AppError) RootError() error

func (AppError) WithCode

func (ae AppError) WithCode(code string) 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 ErrorWithKey interface {
	error
	Key() string
}

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) Fulfill

func (i *Image) Fulfill(domain string)

func (*Image) HideSomeInfo

func (i *Image) HideSomeInfo() *Image

func (*Image) Scan

func (i *Image) Scan(value interface{}) error

This method for scanning Image from date data type in sql

func (*Image) Value

func (i *Image) Value() (driver.Value, error)

This method for mapping Image to json data type in sql

type Images

type Images []Image

func (*Images) Scan

func (is *Images) Scan(value interface{}) error

This method for scanning Images from json array type in sql

func (*Images) Value

func (is *Images) Value() (driver.Value, error)

This method for mapping Images to json array data type in sql

type JSON

type JSON []byte

func (JSON) IsNull

func (j JSON) IsNull() bool

func (*JSON) MarshalJSON

func (j *JSON) MarshalJSON() ([]byte, error)

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

This method for scanning JSON from json data type in sql

func (*JSON) UnmarshalJSON

func (j *JSON) UnmarshalJSON(data []byte) error

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

This method for mapping JSON to json data type in sql

type JSONDate

type JSONDate time.Time

func (JSONDate) GetBSON

func (d JSONDate) GetBSON() (interface{}, error)

func (JSONDate) MarshalJSON

func (d JSONDate) MarshalJSON() ([]byte, error)

Implement method MarshalJSON to output date with in formatted

func (*JSONDate) Scan

func (d *JSONDate) Scan(value interface{}) error

This method for scanning JSONDate from date data type in sql

func (*JSONDate) UnmarshalJSON

func (d *JSONDate) UnmarshalJSON(data []byte) error

func (*JSONDate) Value

func (d *JSONDate) Value() (driver.Value, error)

This method for mapping JSONDate to date data type in sql

type JSONTime

type JSONTime time.Time

func (*JSONTime) GetBSON

func (t *JSONTime) GetBSON() (interface{}, error)

func (JSONTime) MarshalJSON

func (t JSONTime) MarshalJSON() ([]byte, error)

Implement method MarshalJSON to output time with in formatted

func (*JSONTime) Scan

func (t *JSONTime) Scan(value interface{}) error

This method for scanning JSONTime from datetime data type in sql

func (*JSONTime) SetBSON

func (t *JSONTime) SetBSON(raw bson.Raw) error

func (*JSONTime) String

func (t *JSONTime) String() string

func (*JSONTime) UnmarshalJSON

func (t *JSONTime) UnmarshalJSON(data []byte) error

func (*JSONTime) Value

func (t *JSONTime) Value() (driver.Value, error)

This method for mapping JSONTime to datetime data type in sql

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"`
}

func (*Media) Fulfill

func (i *Media) Fulfill(domain string)

func (*Media) Scan

func (i *Media) Scan(value interface{}) error

This method for scanning Media from date data type in sql

func (*Media) Value

func (i *Media) Value() (driver.Value, error)

This method for mapping Media to json data type in sql

type Medias

type Medias []Media

func (*Medias) Scan

func (i *Medias) Scan(value interface{}) error

func (*Medias) Value

func (i *Medias) Value() (driver.Value, error)

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

func (md *MgoModel) PrepareForInsert(status int)

type OAuth

type OAuth interface {
	OAuthID() string
}

type OrderBy

type OrderBy struct {
	Key    string
	IsDesc bool
}

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:"-"`
}

func (*Paging) FullFill

func (p *Paging) FullFill()

type Requester

type Requester interface {
	OAuth
	User
}

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

func NewSQLModelWithStatus(status int) *SQLModel

func (*SQLModel) GenUID

func (sm *SQLModel) GenUID(objType int, shardID uint32) *SQLModel

func (*SQLModel) ToID

func (sm *SQLModel) ToID() *SQLModel

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 DecomposeUID(s string) (UID, error)

func FromBase58

func FromBase58(s string) (UID, error)

func NewUID

func NewUID(localID uint32, objType int, shardID uint32) UID

func (*UID) GetBSON

func (uid *UID) GetBSON() (interface{}, error)

func (UID) GetLocalID

func (uid UID) GetLocalID() uint32

func (UID) GetObjectType

func (uid UID) GetObjectType() int

func (UID) GetShardID

func (uid UID) GetShardID() uint32

func (UID) MarshalJSON

func (uid UID) MarshalJSON() ([]byte, error)

func (*UID) Scan

func (uid *UID) Scan(value interface{}) error

func (*UID) SetBSON

func (uid *UID) SetBSON(raw bson.Raw) error

func (UID) String

func (uid UID) String() string

func (*UID) UnmarshalJSON

func (uid *UID) UnmarshalJSON(data []byte) error

func (*UID) Value

func (uid *UID) Value() (driver.Value, error)

type User

type User interface {
	UserID() uint32
	GetSystemRole() string
	GetUser() interface{}
}

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) Fulfill

func (i *Video) Fulfill(domain string)

func (*Video) HideSomeInfo

func (i *Video) HideSomeInfo() *Video

func (*Video) Scan

func (i *Video) Scan(value interface{}) error

This method for scanning Video from date data type in sql

func (*Video) Value

func (i *Video) Value() (driver.Value, error)

This method for mapping Video to json data type in sql

type VideoInfo

type VideoInfo struct {
	PixFormat string `json:"pix_format" bson:"pix_format,omitempty"`
	Codec     string `json:"codec" bson:"codec,omitempty"`
	Level     int    `json:"level" bson:"level,omitempty"`
	BitRate   string `json:"bit_rate" bson:"bit_rate,omitempty"`
}

type Videos

type Videos []Video

func (*Videos) Scan

func (is *Videos) Scan(value interface{}) error

This method for scanning Videos from json array type in sql

func (*Videos) Value

func (is *Videos) Value() (driver.Value, error)

This method for mapping Videos to json array data type in sql

Jump to

Keyboard shortcuts

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