Documentation
¶
Overview ¶
pkg/utils/context.go
Index ¶
- Constants
- Variables
- func Atoi(value string) int
- func BoolPtr(value bool) *bool
- func ConvertToStringIfNeeded(input interface{}) (interface{}, error)
- func FullyResponse(c *gin.Context, statusCode int, message string, errorCode interface{}, ...)
- func GenerateUserSession(c *gin.Context, userID uint64) error
- func GetUserIDFromContext(c *gin.Context) (uint64, error)
- func IsValidImageType(magic []byte) (bool, string, error)
- func SendEmail(to string, subject string, body string) error
- func ServerErrorResponse(c *gin.Context, statusCode int, message string, errorCode string, err error)
- func StrToUint64(str string) (uint64, error)
- func StrToUint64NoError(str string) uint64
- func Uint64ToStr(id uint64) string
- func Uint64ToStrPtr(id uint64) *string
- type LangLocal
Constants ¶
View Source
const ( ErrAuthenticationKeyNotFound = "authentication_key_not_found" ErrTokenExpired = "token_expired" )
Authentication errors
View Source
const ( ErrBadRequest = "bad_request" ErrUserIDNotFound = "user_id_not_found" )
Request errors
View Source
const ( ErrInvalidUsernameOrEmail = "invalid_username_or_email" ErrInvalidPassword = "invalid_password" ErrEmailAlreadyUsed = "email_already_used" ErrUsernameAlreadyUsed = "username_already_used" ErrEmailNotVerify = "email_not_verify" )
User-related errors
View Source
const ( ErrDuplicateCourseModule = "duplicate_courses_module" ErrMissingCourseID = "missing_course_id" ErrCourseNotExist = "course_not_exist" ErrImageRequired = "image_required" ErrImageTooLarge = "image_too_large" ErrOpeningImage = "opening_image_failed" ErrReadingImage = "reading_image_failed" ErrInvalidImage = "invalid_image" ErrGeneratingFilePath = "generating_file_path_failed" ErrResetFilePointer = "reset_file_pointer_failed" ErrS3UploadFailed = "s3_upload_failed" ErrRivisionNotExist = "revision_not_exist" ErrAlreadyMerged = "revision_already_merged" )
Courses-releated errors
View Source
const ( ErrSaveData = "error_save_data" ErrGetData = "error_get_data" ErrDeleteData = "error_delete_data" )
Database errors
View Source
const ( ErrHashData = "hash_data_failed" ErrParseFile = "template_parse_failed" ErrParse = "data_parse_failed" ErrUnmarshal = "data_unmarshal_failed" ErrSendEmail = "send_email_failed" ErrGenerateSession = "generate_session_failed" ErrParseData = "parse_data_failed" ErrGenerateToken = "generate_token_failed" ErrExecuteTemplate = "execute_template_failed" ErrStoreRedis = "store_redis_failed" ErrChangeType = "change_type_failed" )
Internal errors
View Source
const ( ErrCreateNewCourse = "create_new_course_failed" ErrSaveCourseFile = "save_new_course_file_failed" )
Gitea errors
Variables ¶
View Source
var ( // Unit is days CookieRefreshTokenExpires int // Unit is minutes CookieAccessTokenExpires int BackendURL string FrontendURl string GiteaORGName string GiteaCommitEmail string )
View Source
var LangList = []string{"en", "es", "zh-tw", "zh-cn"}
View Source
var (
RootPath = filepath.Join(filepath.Dir(b), "../..")
)
Functions ¶
func ConvertToStringIfNeeded ¶
func ConvertToStringIfNeeded(input interface{}) (interface{}, error)
func FullyResponse ¶
func FullyResponse(c *gin.Context, statusCode int, message string, errorCode interface{}, data interface{})
Fully response
func GenerateUserSession ¶
Generate new user access_token and refresh_token
func GetUserIDFromContext ¶
GetUserIDFromContext retrieves the user ID from the request context.
func IsValidImageType ¶
Check if the uploaded file is an image using Magic Bytes
func ServerErrorResponse ¶
func ServerErrorResponse(c *gin.Context, statusCode int, message string, errorCode string, err error)
ServerErrorResponse is a helper function to handle errors and send responses
func StrToUint64 ¶
func StrToUint64NoError ¶
func Uint64ToStr ¶
func Uint64ToStrPtr ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.