Documentation
¶
Index ¶
- Constants
- Variables
- func AppRecover()
- func ContextWithRequester(ctx context.Context, requester Requester) context.Context
- func GenSalt(length int) string
- func GetLocalIDFromBase58(s string) (int, error)
- func GetServerAddress() (string, error)
- func NewConfig() *config
- func NewRequester(sub, tid string) *requesterData
- func NewSha256Hash() *sha256Hash
- func ResponseData(data interface{}) *successResponse
- func SuccessResponse(data, paging, extra interface{}) *successResponse
- func WriteErrorResponse(c *gin.Context, err error)
- type AppContext
- type BaseFilter
- type BaseModel
- type Config
- type DebugCarrier
- type DefaultError
- func (e DefaultError) Debug() string
- func (e DefaultError) Details() map[string]interface{}
- func (e DefaultError) Error() string
- func (e DefaultError) Format(s fmt.State, verb rune)
- func (e DefaultError) ID() string
- func (e DefaultError) Is(err error) bool
- func (e DefaultError) Reason() string
- func (e DefaultError) RequestID() string
- func (e *DefaultError) StackTrace() (trace errors.StackTrace)
- func (e DefaultError) Status() string
- func (e DefaultError) StatusCode() int
- func (e DefaultError) String() string
- func (e DefaultError) Unwrap() error
- func (e DefaultError) WithDebug(debug string) *DefaultError
- func (e DefaultError) WithDebugf(debug string, args ...interface{}) *DefaultError
- func (e DefaultError) WithDetail(key string, detail interface{}) *DefaultError
- func (e DefaultError) WithDetailf(key string, message string, args ...interface{}) *DefaultError
- func (e DefaultError) WithError(message string) *DefaultError
- func (e DefaultError) WithErrorf(message string, args ...interface{}) *DefaultError
- func (e DefaultError) WithID(id string) *DefaultError
- func (e DefaultError) WithReason(reason string) *DefaultError
- func (e DefaultError) WithReasonf(reason string, args ...interface{}) *DefaultError
- func (e *DefaultError) WithTrace(err error) *DefaultError
- func (e DefaultError) WithWrap(err error) *DefaultError
- func (e *DefaultError) Wrap(err error)
- type DetailsCarrier
- type File
- type Files
- type GINComponent
- type GormComponent
- type IDCarrier
- type Image
- type Images
- type JWTProvider
- type Paging
- type ReasonCarrier
- type RedisComponent
- type RequestIDCarrier
- type Requester
- type StatusCarrier
- type StatusCodeCarrier
- type StreamState
- type UID
- 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) String() string
- func (uid *UID) UnmarshalJSON(data []byte) error
- func (uid *UID) Value() (driver.Value, error)
- type UIDS
Constants ¶
const ( DbTypeUser = iota DbTypeAuth DbTypeStream DbTypeCategory DbTypeChannel DbTypeSystemSetting )
const ( KeyCompMySQL = "mysql" KeyCompGIN = "gin" KeyCompJWT = "jwt" KeyCompConf = "config" KeyCompRabbitMQ = "rabbitmq" KeyRedis = "redis" KeyS3 = "s3" )
const ( TopicCreateChannel = "TopicCreateChannel" TopicStreamCreate = "TopicStreamCreate" TopicStreamStart = "TopicStreamStart" TopicStreamEnded = "TopicStreamEnded" TopicStreamError = "TopicStreamError" TopicUpdateStreamViewCount = "TopicUpdateStreamViewCount" TopicUpdateUserName = "TopicUpdateUserName" TopicForgotPassword = "TopicForgotPassword" TopicUpdateChannelImage = "TopicUpdateChannelImage" )
const KeyRequester = "requester"
const StreamDomain = "stream"
Variables ¶
var ErrBadRequest = DefaultError{ StatusField: http.StatusText(http.StatusBadRequest), ErrorField: "The request was malformed or contained invalid parameters", CodeField: http.StatusBadRequest, }
var ErrConflict = DefaultError{ StatusField: http.StatusText(http.StatusConflict), ErrorField: "The resource could not be created due to a conflict", CodeField: http.StatusConflict, }
var ErrForbidden = DefaultError{ StatusField: http.StatusText(http.StatusForbidden), ErrorField: "The requested action was forbidden", CodeField: http.StatusForbidden, }
var ErrInternalServerError = DefaultError{ StatusField: http.StatusText(http.StatusInternalServerError), ErrorField: "An internal server error occurred, please contact the system administrator", CodeField: http.StatusInternalServerError, }
var ErrInvalidInput = func(field string) DefaultError { return DefaultError{ StatusField: http.StatusText(http.StatusBadRequest), ErrorField: fmt.Sprintf("Invalid %s", field), CodeField: http.StatusBadRequest, } }
var ErrNotFound = DefaultError{ StatusField: http.StatusText(http.StatusNotFound), ErrorField: "The requested resource could not be found", CodeField: http.StatusNotFound, }
var ErrRecordNotFound = errors.New("record not found")
ErrRecordNotFound is used to make our application logic independent of other libraries errors
http.StatusText(http.StatusUnauthorized), ErrorField: "The request could not be authorized", CodeField: http.StatusUnauthorized, }StatusField:
var ErrUnsupportedMediaType = DefaultError{ StatusField: http.StatusText(http.StatusUnsupportedMediaType), ErrorField: "The request is using an unknown content type", CodeField: http.StatusUnsupportedMediaType, }
var Validator = &validate{
validator.New(),
}
Functions ¶
func ContextWithRequester ¶
func GenSalt ¶
GenSalt function generates a random string of a specified length using the randSequence function. If the provided length is less than 0, it defaults to a length of 50. This function is typically used to generate a salt for cryptographic operations
func GetLocalIDFromBase58 ¶
func GetServerAddress ¶
func NewRequester ¶
func NewRequester(sub, tid string) *requesterData
func NewSha256Hash ¶
func NewSha256Hash() *sha256Hash
func ResponseData ¶
func ResponseData(data interface{}) *successResponse
func SuccessResponse ¶
func SuccessResponse(data, paging, extra interface{}) *successResponse
func WriteErrorResponse ¶
Types ¶
type AppContext ¶
type BaseFilter ¶
type BaseFilter struct { GtCreatedAt *time.Time `json:"gtCreatedAt,omitempty" form:"gtCreatedAt,omitempty"` GtUpdatedAt *time.Time `json:"gtUpdatedAt,omitempty" form:"gtUpdatedAt,omitempty"` LtCreatedAt *time.Time `json:"ltCreatedAt,omitempty" form:"ltCreatedAt,omitempty"` LtUpdatedAt *time.Time `json:"ltUpdatedAt,omitempty" form:"ltUpdatedAt,omitempty"` }
type BaseModel ¶
type BaseModel struct { Id int `json:"-" gorm:"column:id;" ` Uid *UID `json:"id" gorm:"-"` CreatedAt *time.Time `json:"createdAt,omitempty" gorm:"column:created_at;" ` UpdatedAt *time.Time `json:"updatedAt,omitempty" gorm:"column:updated_at;" ` }
func NewBaseModel ¶
func NewBaseModel() BaseModel
type DebugCarrier ¶
type DebugCarrier interface { // Debug returns debugging information for the error, if applicable. Debug() string }
DebugCarrier can be implemented by an error to support error contexts.
type DefaultError ¶
type DefaultError struct { // The error ID // // Useful when trying to identify various errors in application logic. IDField string `json:"id,omitempty"` // The status code // // example: 404 CodeField int `json:"code,omitempty"` // The status description // // example: Not Found StatusField string `json:"status,omitempty"` // The request ID // // The request ID is often exposed internally in order to trace // errors across service architectures. This is often a UUID. // // example: d7ef54b1-ec15-46e6-bccb-524b82c035e6 RIDField string `json:"request,omitempty"` // A human-readable reason for the error // // example: User with ID 1234 does not exist. ReasonField string `json:"reason,omitempty"` // Debug information // // This field is often not exposed to protect against leaking // sensitive information. // // example: SQL field "foo" is not a bool. DebugField string `json:"debug,omitempty"` // Error message // // The error's message. // // example: The resource could not be found // required: true ErrorField string `json:"message"` // Further error details DetailsField map[string]interface{} `json:"details,omitempty"` // contains filtered or unexported fields }
func ToDefaultError ¶
func ToDefaultError(err error, requestID string) *DefaultError
func (DefaultError) Debug ¶
func (e DefaultError) Debug() string
func (DefaultError) Details ¶
func (e DefaultError) Details() map[string]interface{}
func (DefaultError) Error ¶
func (e DefaultError) Error() string
func (DefaultError) ID ¶
func (e DefaultError) ID() string
func (DefaultError) Is ¶
func (e DefaultError) Is(err error) bool
func (DefaultError) Reason ¶
func (e DefaultError) Reason() string
func (DefaultError) RequestID ¶
func (e DefaultError) RequestID() string
func (*DefaultError) StackTrace ¶
func (e *DefaultError) StackTrace() (trace errors.StackTrace)
StackTrace returns the error's stack trace.
func (DefaultError) Status ¶
func (e DefaultError) Status() string
func (DefaultError) StatusCode ¶
func (e DefaultError) StatusCode() int
func (DefaultError) String ¶
func (e DefaultError) String() string
func (DefaultError) Unwrap ¶
func (e DefaultError) Unwrap() error
func (DefaultError) WithDebug ¶
func (e DefaultError) WithDebug(debug string) *DefaultError
func (DefaultError) WithDebugf ¶
func (e DefaultError) WithDebugf(debug string, args ...interface{}) *DefaultError
func (DefaultError) WithDetail ¶
func (e DefaultError) WithDetail(key string, detail interface{}) *DefaultError
func (DefaultError) WithDetailf ¶
func (e DefaultError) WithDetailf(key string, message string, args ...interface{}) *DefaultError
func (DefaultError) WithError ¶
func (e DefaultError) WithError(message string) *DefaultError
func (DefaultError) WithErrorf ¶
func (e DefaultError) WithErrorf(message string, args ...interface{}) *DefaultError
func (DefaultError) WithID ¶
func (e DefaultError) WithID(id string) *DefaultError
func (DefaultError) WithReason ¶
func (e DefaultError) WithReason(reason string) *DefaultError
func (DefaultError) WithReasonf ¶
func (e DefaultError) WithReasonf(reason string, args ...interface{}) *DefaultError
func (*DefaultError) WithTrace ¶
func (e *DefaultError) WithTrace(err error) *DefaultError
func (DefaultError) WithWrap ¶
func (e DefaultError) WithWrap(err error) *DefaultError
func (*DefaultError) Wrap ¶
func (e *DefaultError) Wrap(err error)
type DetailsCarrier ¶
type DetailsCarrier interface { // Details returns details on the error, if applicable. Details() map[string]interface{} }
DetailsCarrier can be implemented by an error to support error contexts.
type File ¶
type File struct { Id int `json:"id" gorm:"column:id"` Url string `json:"url" gorm:"column:url"` CloudName string `json:"cloud_name,omitempty" gorm:"-"` Extension string `json:"extension,omitempty" gorm:"-"` }
type GINComponent ¶
type GormComponent ¶
type IDCarrier ¶
type IDCarrier interface { // ID returns application error ID on the error, if applicable. ID() string }
IDCarrier can be implemented by an error to support error contexts.
type Image ¶
type Image struct { Id int `json:"id" gorm:"column:id"` Url string `json:"url" gorm:"column:url"` Width int `json:"width" gorm:"column:width"` Height int `json:"height" gorm:"column:height"` CloudName string `json:"cloud_name,omitempty" gorm:"-"` Extension string `json:"extension,omitempty" gorm:"-"` }
type JWTProvider ¶
type Paging ¶
type ReasonCarrier ¶
type ReasonCarrier interface { // Reason returns the reason for the error, if applicable. Reason() string }
ReasonCarrier can be implemented by an error to support error contexts.
type RedisComponent ¶
type RedisComponent interface {
GetClient() *redis.Client
}
type RequestIDCarrier ¶
type RequestIDCarrier interface { // RequestID returns the ID of the request that caused the error, if applicable. RequestID() string }
RequestIDCarrier can be implemented by an error to support error contexts.
type Requester ¶
type Requester interface { GetSubject() string GetTokenId() string GetUserId() int GetRole() string SetRole(string) }
func GetRequester ¶
type StatusCarrier ¶
type StatusCarrier interface { // ID returns the error id, if applicable. Status() string }
StatusCarrier can be implemented by an error to support error contexts.
type StatusCodeCarrier ¶
type StatusCodeCarrier interface { // StatusCode returns the status code of this error. StatusCode() int }
StatusCodeCarrier can be implemented by an error to support setting status codes in the error itself.
type StreamState ¶
type UID ¶
type UID struct {
// contains filtered or unexported fields
}
UID is method to generate a virtual unique identifier for whole system its structure contains 62 bits: LocalID - ObjectType - ShareID 32 bits for Local ID, max (2^32) - 1 10 bits for Object Type 18 bits for Shard ID