Documentation
¶
Index ¶
- Constants
- func CheckFolder(folderPath string)
- func ConstructColNameAndValue(ctx context.Context, structName interface{}, isNullStruct ...bool) ([]string, []interface{})
- func ConstructColNameAndValueBulk(ctx context.Context, arrayOfData interface{}, ...) (*database.CUDConstructData, error)
- func ConstructColNameAndValueForUpdate(ctx context.Context, structName interface{}, anotherValues ...interface{}) *database.CUDConstructData
- func ConvertStructToMap(structSource interface{}) map[string]interface{}
- func GenerateFastID() string
- func GenerateFastIDCounter() string
- func GenerateFastIDCounterBytes() *[]byte
- func GenerateJWTToken(data interface{}, expireTime ...time.Duration) (string, error)
- func GeneratePublicKey(apiKey string) string
- func GenerateRandomString(length int) string
- func GenerateRandomStringWithCharset(length int, charset string) string
- func GenerateSelectCols(ctx context.Context, source interface{}, opts ...GenSelectColsOptions) []string
- func GenerateUUID() string
- func GenerateUUIDV4() string
- func GetColorUniform(hexColor string) *image.Uniform
- func GetFilePath() string
- func GetFolderAndFileName(path string) (folderPath string, fileName string)
- func GetFolderNameWithoutTmp(path string) (folderName string)
- func GetTemplate(file string, args, destStruct interface{}) error
- func GetTemplateFS(embedFS embed.FS, file string, args, destStruct interface{}) error
- func GetTmpFolderPath() (string, error)
- func ParseFileTemplate(filePath string, args interface{}, additionalBodyContent ...string) (strings.Builder, error)
- func ParseHexColor(s string) (c color.RGBA, err error)
- func ParseTemplate(embedFS embed.FS, file string, args interface{}, ...) (strings.Builder, error)
- func ParseTemplateFromPath(filePath string, data any, optionalParams ...any) (strings.Builder, error)
- func PutFastIDCounterBytes(bp *[]byte)
- func Remove(slice []interface{}, s int) []interface{}
- func SendSlackNotification(ctx context.Context, options ...SentNotifParamOptions) error
- func SliceContains(s []string, str string) bool
- func ToCamelCase(str string) string
- func ToLowerCamelCase(str string) string
- func ToSnakeCase(s string) string
- func TrimDuplicatedSpace(str string) string
- func UploadToTmp(ctx context.Context, path *string, file multipart.File, ...) error
- func VerifyAPIKey(apiKey string, publicKey string) bool
- type CUDConstructInfo
- type CloudStorageTmpUpload
- type CryptoManager
- type GenSelectColsOptionalParams
- type GenSelectColsOptions
- type SentNotifParamOptions
- type UpdateFieldPath
- type UpdateTemplateInfo
Constants ¶
const ( NotifInfoType = "info" NotifWarnType = "warn" NotifErrorType = "error" )
Variables ¶
This section is empty.
Functions ¶
func CheckFolder ¶
func CheckFolder(folderPath string)
func ConstructColNameAndValueForUpdate ¶
func ConstructColNameAndValueForUpdate(ctx context.Context, structName interface{}, anotherValues ...interface{}) *database.CUDConstructData
func ConvertStructToMap ¶ added in v2.16.0
func ConvertStructToMap(structSource interface{}) map[string]interface{}
func GenerateFastID ¶ added in v2.41.0
func GenerateFastID() string
GenerateFastID generates a random string of length 15 using a nanoid-style algorithm that is significantly faster than GenerateRandomString. It uses crypto/rand for uniform distribution and processes 8 characters per uint64. Uses sync.Pool for both entropy and result buffers to minimize allocations.
func GenerateFastIDCounter ¶ added in v2.41.0
func GenerateFastIDCounter() string
GenerateFastIDCounter generates a request ID using an atomic counter. Uses a pre-allocated buffer from sync.Pool to avoid per-call allocations. ~15ns per call with 1 allocation (the final string). Not cryptographically secure.
func GenerateFastIDCounterBytes ¶ added in v2.41.0
func GenerateFastIDCounterBytes() *[]byte
func GenerateJWTToken ¶
func GeneratePublicKey ¶ added in v2.38.0
GeneratePublicKey generates a public representation of a decrypted API key This is safe to store on the client side (encrypted or hashed)
func GenerateRandomString ¶
func GenerateSelectCols ¶
func GenerateSelectCols(ctx context.Context, source interface{}, opts ...GenSelectColsOptions) []string
func GenerateUUID ¶
func GenerateUUID() string
func GenerateUUIDV4 ¶
func GenerateUUIDV4() string
func GetColorUniform ¶
func GetFilePath ¶
func GetFilePath() string
func GetFolderAndFileName ¶
func GetFolderNameWithoutTmp ¶
func GetTemplate ¶
func GetTemplateFS ¶
func GetTmpFolderPath ¶
func ParseFileTemplate ¶
func ParseTemplate ¶
func ParseTemplateFromPath ¶ added in v2.35.0
func PutFastIDCounterBytes ¶ added in v2.41.0
func PutFastIDCounterBytes(bp *[]byte)
func SendSlackNotification ¶ added in v2.7.0
func SendSlackNotification(ctx context.Context, options ...SentNotifParamOptions) error
func SliceContains ¶ added in v2.3.12
func ToCamelCase ¶
ToCamelCase - will be convert string to camel case format
example:"AnyKind of_string" result:"AnyKindOfString"
func ToLowerCamelCase ¶
ToLowerCamelCase - will be convert string to camel case format with lower case at first letter
example:"AnyKind of_string" result:"anyKindOfString"
func ToSnakeCase ¶
ToSnakeCase - will be convert string to snake case format
example:"AnyKind of_string" result:"any_kind_of_string"
func TrimDuplicatedSpace ¶
func UploadToTmp ¶
func VerifyAPIKey ¶ added in v2.38.0
VerifyAPIKey verifies if a decrypted API key matches a public key
Types ¶
type CUDConstructInfo ¶ added in v2.41.0
CUDConstructInfo is the result of extracting update values from a struct using the cached template. It contains the same data as CUDConstructData but is produced without repeated reflection/tag lookups.
func ExtractFixedUpdateValues ¶ added in v2.41.0
func ExtractFixedUpdateValues(tmpl *UpdateTemplateInfo, structVal reflect.Value, anotherValues ...interface{}) *CUDConstructInfo
ExtractFixedUpdateValues extracts values from a struct using the FULL template — every field is included regardless of null/empty status. For null.String with Valid=false, it sends nil (SQL NULL). For nil pointers, it sends nil (SQL NULL). For empty strings, it sends "" (empty string) to avoid violating NOT NULL constraints on columns like email, name, etc.
This produces an INVARIANT query string (same SET clause every time) which means the same *sql.Stmt can be reused across calls — critical for PostgreSQL prepared statement caching where variable-length SET clauses cause a new prepare on every call.
The Values slice length always matches len(tmpl.FieldPaths) + [1 if !HaveUpdatedAt] + len(anotherValues).
func ExtractUpdateValues ¶ added in v2.41.0
func ExtractUpdateValues(tmpl *UpdateTemplateInfo, structVal reflect.Value, anotherValues ...interface{}) *CUDConstructInfo
ExtractUpdateValues uses the cached field paths to extract values from a struct instance. It returns the Cols pattern and Values for the UPDATE. Null fields (nil pointers, null.String with Valid=false) are excluded.
type CloudStorageTmpUpload ¶
type CryptoManager ¶ added in v2.38.0
type CryptoManager struct {
// contains filtered or unexported fields
}
CryptoManager handles encryption and decryption of API keys
func NewCryptoManager ¶ added in v2.38.0
func NewCryptoManager(encryptionKey string) (*CryptoManager, error)
NewCryptoManager creates a new crypto manager from an encryption key The key should be 32 bytes (256 bits) for AES-256
func NewCryptoManagerFromEnv ¶ added in v2.38.0
func NewCryptoManagerFromEnv(envVarName string) (*CryptoManager, error)
NewCryptoManagerFromEnv creates a CryptoManager from an environment variable
type GenSelectColsOptionalParams ¶ added in v2.5.3
type GenSelectColsOptionalParams struct {
// contains filtered or unexported fields
}
type GenSelectColsOptions ¶ added in v2.5.3
type GenSelectColsOptions func(*GenSelectColsOptionalParams)
func WithExcludedCols ¶ added in v2.5.3
func WithExcludedCols(excludedCols string) GenSelectColsOptions
func WithIncludedCols ¶ added in v2.5.3
func WithIncludedCols(includedCols string) GenSelectColsOptions
func WithIsEmbeddedStruct ¶ added in v2.21.0
func WithIsEmbeddedStruct(isEmbeddedStruct bool) GenSelectColsOptions
type SentNotifParamOptions ¶ added in v2.7.0
type SentNotifParamOptions func(param *sentNotifParam)
func NotifChannel ¶ added in v2.7.0
func NotifChannel(channel string) SentNotifParamOptions
func NotifData ¶ added in v2.7.0
func NotifData(data map[string]string) SentNotifParamOptions
func NotifMsgType ¶ added in v2.7.0
func NotifMsgType(msgType string) SentNotifParamOptions
func NotifTitle ¶ added in v2.7.0
func NotifTitle(title string) SentNotifParamOptions
type UpdateFieldPath ¶ added in v2.41.0
type UpdateFieldPath struct {
// IndexPath is used with reflect.Value.FieldByIndex to reach
// the leaf field (e.g. [0] for a top-level field, [2,1] for
// an embedded struct's field).
IndexPath []int
ColName string // e.g. "name", "age", "updated_at"
IsNullType bool // true if the field type contains "null." — treat nil/null specially
}
UpdateFieldPath describes how to extract a single value from a struct for an UPDATE SET clause. It handles embedded structs via FieldByIndex.
type UpdateTemplateInfo ¶ added in v2.41.0
type UpdateTemplateInfo struct {
// Cols is the list of SET clause fragments like ["name=?", "age=?", "updated_at=?"]
// This is what data.Cols will be set to.
Cols []string
// ColsInsert is the comma-joined column names like "name,age,updated_at"
ColsInsert string
// FieldPaths tells us how to extract each non-null value from the struct.
// The i-th path corresponds to the i-th "?" placeholder in Cols.
FieldPaths []UpdateFieldPath
// HaveUpdatedAt is true when the struct itself has an updated_at field.
HaveUpdatedAt bool
}
UpdateTemplateInfo holds the pre-computed UPDATE query template for a given struct type. On each call, only the values need to be extracted from the struct instance; the column layout is fixed.
func GetUpdateTemplate ¶ added in v2.41.0
func GetUpdateTemplate(t reflect.Type) *UpdateTemplateInfo
GetUpdateTemplate returns the cached update template for the given struct type, computing it on first access. The template assumes all non-null fields are present (the common case). Fields with null.String values that are valid (i.e. non-NULL in SQL) are included; null values are excluded at runtime.