sdkcm

package
v1.0.15 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

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 ErrRecordNotFound = errors.New("record not found")

Functions

func AllSysRoles

func AllSysRoles() []string

func CurrentUser

func CurrentUser(t OAuth, u User) *currentUser

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 {
	StatusCode int    `json:"status_code"`
	RootErr    error  `json:"-"`
	Message    string `json:"message"`
	Log        string `json:"log"`
	Key        string `json:"error_key"`
	TraceID    string `json:"trace_id,omitempty"`
}

func CustomError

func CustomError(statusCode int, root error, msg string, key string) *AppError

func ErrCannotCreateEntity added in v1.0.3

func ErrCannotCreateEntity(entity string, err error) *AppError

func ErrCannotDeleteEntity added in v1.0.3

func ErrCannotDeleteEntity(entity string, err error) *AppError

func ErrCannotGetEntity added in v1.0.3

func ErrCannotGetEntity(entity string, err error) *AppError

func ErrCannotListEntity added in v1.0.3

func ErrCannotListEntity(entity string, err error) *AppError

func ErrCannotUpdateEntity added in v1.0.3

func ErrCannotUpdateEntity(entity string, err error) *AppError

func ErrDB

func ErrDB(err error) *AppError

func ErrEntityDeleted added in v1.0.3

func ErrEntityDeleted(entity string, err error) *AppError

func ErrEntityExisted added in v1.0.3

func ErrEntityExisted(entity string, err error) *AppError

func ErrEntityNotFound added in v1.0.3

func ErrEntityNotFound(entity string, err error) *AppError

func ErrInternal added in v1.0.3

func ErrInternal(err error) *AppError

func ErrInvalidRequest

func ErrInvalidRequest(err error) *AppError

func ErrNoPermission

func ErrNoPermission(err error) *AppError

func NewCustomError added in v1.0.3

func NewCustomError(statusCode int, root error, msg string, key string) *AppError

func NewErrorResponse added in v1.0.3

func NewErrorResponse(statusCode int, root error, msg, log, key string) *AppError

func NewFullErrorResponse added in v1.0.3

func NewFullErrorResponse(statusCode int, root error, msg, log, key string) *AppError

func NewUnauthorized added in v1.0.3

func NewUnauthorized(root error, msg, key string) *AppError

func (*AppError) Error

func (e *AppError) Error() string

func (*AppError) RootError

func (e *AppError) RootError() error

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

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