Documentation ¶
Index ¶
- Constants
- Variables
- func CheckArrayIntNil(data []int) []int
- func CheckIntValue(data *int) int
- func CheckStringValue(data *string) string
- func CheckStringValueToPointer(data string) *string
- func CheckTimeIsZeroToPointer(t time.Time) *time.Time
- func CheckTimeIsZeroToString(t time.Time, formatDate string) string
- func CheckTimePointerToString(t *time.Time, formatDate string) string
- func CheckTimePointerValue(t *time.Time) time.Time
- func EndDate(t time.Time) time.Time
- func EndDateString(t string) time.Time
- func ErrHashPasswordFailed() error
- func ErrNewPasswordNotMatchWithConfirmPassword() error
- func ErrPasswordNotMatch() error
- func FormatValidationError(err error) error
- func GenerateRandomNumber(length int) string
- func GetHTTPRequestJSON(ctx context.Context, method string, url string, body io.Reader, ...) (res []byte, statusCode int, err error)
- func GetHTTPRequestSkipVerify(ctx context.Context, method string, url string, body io.Reader, ...) (res []byte, statusCode int, err error)
- func HashPassword(password string) (res string, err error)
- func IsValidEmail(email string) bool
- func IsValidUUID(input string) bool
- func PanicRecover(opName string)
- func ParseUTC7(timeFormat string, value string) (time.Time, error)
- func PasswordValid(h, p string) bool
- func PrettyStruct(data interface{}) (string, error)
- func QueryEscape(s string) string
- func RenderJSON(w http.ResponseWriter, statusCode int, v interface{})
- func RoundFloat(val float64, precision uint) float64
- func SafeJsonMarshal(data interface{}) ([]byte, error)
- func StartDate(t time.Time) time.Time
- func StartDateString(t string) time.Time
- func StatusCodeMapping(statusCode int, v interface{}) int
- func StatusErrorMapping(code int) int
- func StatusMapping(statusCode int) string
- func StreamToByte(stream io.Reader) []byte
- func StreamToString(stream io.Reader) string
- func TimeZoneJakarta() *time.Location
- func ToLower(input string) string
- func ToSentenceCase(input string) string
- func ToTitle(input string) string
- func ToUpper(input string) string
- func Translate(source, sourceLang, targetLang string) (string, error)
- func WriteJSON(w http.ResponseWriter, statusCode int, v interface{}) error
- type CustomConfigClientRequest
- type Meta
- type MultiLanguages
- type Pagination
- type ResponseDefault
- type ResponseError
- func ErrCannotBeMoreThan(id, en, max string) *ResponseError
- func ErrCannotHaveAccessResources() *ResponseError
- func ErrCannotHaveAccessUpdateData() *ResponseError
- func ErrCannotUpdateData() *ResponseError
- func ErrCreatedDB() *ResponseError
- func ErrDB() *ResponseError
- func ErrDataNotFound(id, en string) *ResponseError
- func ErrEmailIsVerified() *ResponseError
- func ErrEmailNotVerified() *ResponseError
- func ErrFailedSendEmail() *ResponseError
- func ErrFailedTranslateText() *ResponseError
- func ErrGenerateOtp() *ResponseError
- func ErrGetRequest() *ResponseError
- func ErrInvalid(id, en string) *ResponseError
- func ErrInvalidFormat(id, en string) *ResponseError
- func ErrIsDuplicate(id, en string) *ResponseError
- func ErrIsEmpty(id, en string) *ResponseError
- func ErrIsRequired(id, en string) *ResponseError
- func ErrMaxCharacters(id, en, max string) *ResponseError
- func ErrMinCharacters(id, en, min string) *ResponseError
- func ErrMustBeMoreThanZero(id, en string) *ResponseError
- func ErrNotAccess() *ResponseError
- func ErrNotFound() *ResponseError
- func ErrOtpExpired() *ResponseError
- func ErrOtpInvalid() *ResponseError
- func ErrReadContext() *ResponseError
- func ErrRouteNotFound() *ResponseError
- func ErrTooLong(id, en string) *ResponseError
- func ErrTooMany(id, en string) *ResponseError
- func ErrTooShort(id, en string) *ResponseError
- func ErrUnmarshalJSON() *ResponseError
- func ErrUpdatedDB() *ResponseError
- func NewError(code TypeError, err error) *ResponseError
- type ResponseErrorHttp
- type TypeError
Constants ¶
const ( // Format date time FormatDateTime = `2006-01-02 15:04:05` FormatDateHourMinutes = `2006-01-02 15:04` FormatDate = `2006-01-02` FormatDateDDMMYYYY = `02-01-2006` FormatLocalTime = `02-Jan-2006` FormatLocalTimeDDsMMsYYYY = `02 Jan 2006` FormatDateConcise = `02-Jan-06` DateMonthFormat = `02 January 2006` DateMonthFormatWithoutYear = `02 January` FormatTimeMinute = `15:04` FormatTimeMinuteSecond = `15:04:05` // Timezone country AsiaJakarta = `Asia/Jakarta` AsiaMakassar = `Asia/Makassar` AsiaJayapura = `Asia/Jayapura` // indonesia country timezone in table city GMT7 = `GMT+7:00` GMT8 = `GMT+8:00` GMT9 = `GMT+9:00` // Month January = `January` February = `February` March = `March` April = `April` May = `May` June = `June` July = `July` August = `August` September = `September` October = `October` November = `November` December = `December` )
const (
Auto = "auto"
)
Variables ¶
var ( LangID = language.Indonesian.String() LangEn = language.English.String() )
var ( // Mapping Timezone ToT imeLocation ... MappingTimezoneToTimeLocation = map[string]string{ GMT7: AsiaJakarta, GMT8: AsiaMakassar, GMT9: AsiaJayapura, } // Month to Bulan MappingMonthToBulan = map[string]string{ January: `Januari`, February: `Februari`, March: `Maret`, April: `April`, May: `Mei`, June: `Juni`, July: `Juli`, August: `Agustus`, September: `September`, October: `Oktober`, November: `November`, December: `Desember`, } )
var ( IsStatusSuccess = map[int]bool{ http.StatusOK: true, http.StatusCreated: true, } )
Functions ¶
func CheckIntValue ¶
Return 0 if data is nil, otherwise return the value of data
func CheckStringValue ¶
Return empty string if data is nil, otherwise return the value of data
func CheckStringValueToPointer ¶
Return a pointer to a string or nil if the input string is empty or only contains whitespace
func ErrHashPasswordFailed ¶
func ErrHashPasswordFailed() error
func ErrNewPasswordNotMatchWithConfirmPassword ¶
func ErrNewPasswordNotMatchWithConfirmPassword() error
func ErrPasswordNotMatch ¶
func ErrPasswordNotMatch() error
func FormatValidationError ¶
FormatValidationError function is used to format validation errors that occur during user input validation. It changes the default format of errors from github.com/go-playground/validator/v10.
This function iterates over the validation errors and constructs a formatted error message. The error message is then translated into the Indonesian language using the Translate function. The resulting error message is then returned as a ResponseError struct.
Parameters: - err: The validation errors that occurred.
Returns: - error: The formatted validation error.
func GenerateRandomNumber ¶
GenerateRandomNumber generates a random number of the specified length (length int) and returns it as a string (string).
func GetHTTPRequestJSON ¶
func GetHTTPRequestJSON(ctx context.Context, method string, url string, body io.Reader, headers ...map[string]string) (res []byte, statusCode int, err error)
GetHTTPRequestJSON ...
func GetHTTPRequestSkipVerify ¶
func GetHTTPRequestSkipVerify(ctx context.Context, method string, url string, body io.Reader, customTimeOut int, headers ...map[string]string) (res []byte, statusCode int, err error)
GetHTTPRequestSkipVerify ...
func HashPassword ¶
func IsValidEmail ¶
validation email format example here: https://go.dev/play/p/j4B4v01Qolw
func IsValidUUID ¶
func PanicRecover ¶
func PanicRecover(opName string)
func PasswordValid ¶
func PrettyStruct ¶
func RenderJSON ¶
func RenderJSON(w http.ResponseWriter, statusCode int, v interface{})
func RoundFloat ¶
Round float generator example here: https://go.dev/play/p/VmTGHhV2_WI
func SafeJsonMarshal ¶
SafeJsonMarshal safely marshals an interface{} to a []byte using json.Marshal. If there is an error during the marshal, it will re-marshal the original data and return it. It returns a []byte and an error. If there is an error during the marshal, the error will be returned. Otherwise, nil will be returned.
func StatusCodeMapping ¶
func StatusErrorMapping ¶
func StatusMapping ¶
StatusMapping maps HTTP status code to a descriptive string. It returns the descriptive string that can be used as the 'status' field in ResponseDefault.
func TimeZoneJakarta ¶
func ToSentenceCase ¶
Sentence case in a string, ex; hello world => Hello world
Types ¶
type CustomConfigClientRequest ¶
type CustomConfigClientRequest struct {
Timeout int
}
func (*CustomConfigClientRequest) SetTimeout ¶
func (c *CustomConfigClientRequest) SetTimeout(defaultTimeout int) int
type Meta ¶
type Meta struct { Page int `json:"page,omitempty"` Limit int `json:"limit,omitempty"` TotalRecords int `json:"total_records,omitempty"` TotalPages int `json:"total_pages,omitempty"` }
Meta struct
type MultiLanguages ¶
func NewResponseMultiLang ¶
func NewResponseMultiLang(languages MultiLanguages) *MultiLanguages
func (*MultiLanguages) Error ¶
func (e *MultiLanguages) Error() string
type Pagination ¶
type Pagination struct { Meta Meta Data interface{} }
type ResponseDefault ¶
type ResponseError ¶
type ResponseError struct { Status string `json:"status"` Code int `json:"code"` Err error `json:"-"` Message MultiLanguages `json:"message"` }
func ErrCannotBeMoreThan ¶
func ErrCannotBeMoreThan(id, en, max string) *ResponseError
func ErrCannotHaveAccessResources ¶
func ErrCannotHaveAccessResources() *ResponseError
func ErrCannotHaveAccessUpdateData ¶
func ErrCannotHaveAccessUpdateData() *ResponseError
func ErrCannotUpdateData ¶
func ErrCannotUpdateData() *ResponseError
func ErrCreatedDB ¶
func ErrCreatedDB() *ResponseError
func ErrDB ¶
func ErrDB() *ResponseError
func ErrDataNotFound ¶
func ErrDataNotFound(id, en string) *ResponseError
func ErrEmailIsVerified ¶
func ErrEmailIsVerified() *ResponseError
func ErrEmailNotVerified ¶
func ErrEmailNotVerified() *ResponseError
func ErrFailedSendEmail ¶
func ErrFailedSendEmail() *ResponseError
func ErrFailedTranslateText ¶
func ErrFailedTranslateText() *ResponseError
func ErrGenerateOtp ¶
func ErrGenerateOtp() *ResponseError
func ErrGetRequest ¶
func ErrGetRequest() *ResponseError
func ErrInvalid ¶
func ErrInvalid(id, en string) *ResponseError
func ErrInvalidFormat ¶
func ErrInvalidFormat(id, en string) *ResponseError
func ErrIsDuplicate ¶
func ErrIsDuplicate(id, en string) *ResponseError
func ErrIsEmpty ¶
func ErrIsEmpty(id, en string) *ResponseError
func ErrIsRequired ¶
func ErrIsRequired(id, en string) *ResponseError
func ErrMaxCharacters ¶
func ErrMaxCharacters(id, en, max string) *ResponseError
func ErrMinCharacters ¶
func ErrMinCharacters(id, en, min string) *ResponseError
func ErrMustBeMoreThanZero ¶
func ErrMustBeMoreThanZero(id, en string) *ResponseError
func ErrNotAccess ¶
func ErrNotAccess() *ResponseError
func ErrNotFound ¶
func ErrNotFound() *ResponseError
func ErrOtpExpired ¶
func ErrOtpExpired() *ResponseError
func ErrOtpInvalid ¶
func ErrOtpInvalid() *ResponseError
func ErrReadContext ¶
func ErrReadContext() *ResponseError
func ErrRouteNotFound ¶
func ErrRouteNotFound() *ResponseError
func ErrTooLong ¶
func ErrTooLong(id, en string) *ResponseError
func ErrTooMany ¶
func ErrTooMany(id, en string) *ResponseError
func ErrTooShort ¶
func ErrTooShort(id, en string) *ResponseError
func ErrUnmarshalJSON ¶
func ErrUnmarshalJSON() *ResponseError
func ErrUpdatedDB ¶
func ErrUpdatedDB() *ResponseError
func NewError ¶
func NewError(code TypeError, err error) *ResponseError
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
type ResponseErrorHttp ¶
type ResponseErrorHttp struct { Status string `json:"status"` Code int `json:"code"` Desc MultiLanguages `json:"desc"` Message MultiLanguages `json:"message"` }
unmarshal from response http
func (*ResponseErrorHttp) GetMessageEN ¶
func (m *ResponseErrorHttp) GetMessageEN() string
func (*ResponseErrorHttp) GetMessageID ¶
func (m *ResponseErrorHttp) GetMessageID() string
Source Files ¶
- error.go
- error_http.go
- general.go
- hashing.go
- json_marshal.go
- languange.go
- net.go
- number_manipulator.go
- response.go
- response_error.go
- response_error_constants.go
- response_error_db.go
- response_error_general.go
- response_error_validation.go
- response_error_validation_auth.go
- response_error_validation_invalid.go
- response_error_validation_len.go
- response_error_validation_required.go
- response_status.go
- response_type.go
- string_manipulator.go
- string_manipulator_check_value.go
- time_manipulator.go
- time_manipulator_check_value.go
- time_manipulator_var.go