config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActiveClass

func ActiveClass(a, b int) string

func App

func App() *config

func Clamp

func Clamp(value, min, max int) int

func ComparePassword

func ComparePassword(hashedPassword, password string) bool

func ContainsElement

func ContainsElement(val interface{}, array interface{}) bool

ContainsElement checks if a value exists in a slice.

func ConvertStringBoolsToBool

func ConvertStringBoolsToBool(r *http.Request, columns ...string) ([]byte, error)

ConvertStringBoolsToBool converts specified string Bools in JSON data to bool

func ConvertStringIDsToInt

func ConvertStringIDsToInt(r *http.Request, columns ...string) ([]byte, error)

ConvertStringIDsToInt converts specified string IDs in JSON data to integers

func CustomCronValidate

func CustomCronValidate()

The Go Playground Validator has a “cron” validation mechanism, but it does not work correctly. So we will validate with “robfig/cron parser”.

func CustomNoEmptyValidate

func CustomNoEmptyValidate()

The Go Playground Validator package does not have a validation tag that directly checks whether slices are empty. In the case of slices, this tag checks if the slice itself exists, but does not check if the contents of the slice are empty. We have written a special validation function to check if slices are empty.

func CustomValidate

func CustomValidate()

custom validates are called in main

func DecrementRunning

func DecrementRunning()

func GenerateToken

func GenerateToken(userId int) (string, error)

GenerateToken token generate

func GetIntQuery

func GetIntQuery(r *http.Request, name string) int

func GetUserIDByToken

func GetUserIDByToken(token string) (string, error)

func HasPrefixInList

func HasPrefixInList(str string, prefixes []string) bool

HasPrefixInList is a prefix checker

func HashAndSalt

func HashAndSalt(password string) string

func IncrementRunning

func IncrementRunning()

func LoadSQLQueries

func LoadSQLQueries() (map[string]string, error)

LoadSQLQueries loads SQL queries from a file and populates the QUERY map.

func MaptoJSON

func MaptoJSON(response map[string]any) []byte

func RandomHex

func RandomHex(length int) string

func RandomString

func RandomString(length int) string

func ReadJSON

func ReadJSON(w http.ResponseWriter, r *http.Request, data any) error

func ResponseToJSON

func ResponseToJSON(response Response) []byte

func ShuttingWrapper

func ShuttingWrapper(fn func())

func StructToMap

func StructToMap(obj interface{}) map[string]any

func Validate

func Validate(structure any) error

func ValidateToken

func ValidateToken(token string) (*jwt.Token, error)

ValidateToken token validate

func WriteBody

func WriteBody(r *http.Request)

func WriteJSON

func WriteJSON(w http.ResponseWriter, httpStatus int, data Response, headers ...http.Header) error

Types

type CKey

type CKey string

context key type

type DB

type DB struct {
	*sql.DB
}

func (*DB) CloseDatabase

func (db *DB) CloseDatabase()

CloseDatabase method is closing a connection between your app and your db

func (*DB) ConnectDatabase

func (db *DB) ConnectDatabase()

ConnectDatabase is creating a new connection to our database

func (*DB) RunPrepare

func (db *DB) RunPrepare(exec any, query string, args ...any) (*sql.Stmt, error)

type ES

type ES struct {
	*elasticsearch.Client
}

type Kraft

type Kraft struct {
	// contains filtered or unexported fields
}

func (*Kraft) Close

func (k *Kraft) Close()

Close closes the Kafka producer and consumer

func (*Kraft) ConsumeMessages

func (k *Kraft) ConsumeMessages(topic string, partition int32)

ConsumeMessages consumes messages from a Kafka topic

func (*Kraft) PushMessageToQueue

func (k *Kraft) PushMessageToQueue(topic string, message []byte) error

PushMessageToQueue sends a message to a Kafka topic

type Logger

type Logger struct {
	*slog.Logger
}

func (*Logger) Debug

func (l *Logger) Debug(message ...string)

func (*Logger) Error

func (l *Logger) Error(message ...string)

func (*Logger) Info

func (l *Logger) Info(message ...string)

func (*Logger) Warn

func (l *Logger) Warn(message ...string)

type Response

type Response struct {
	Status  bool           `json:"status"`
	Message string         `json:"message"`
	Data    map[string]any `json:"data"`
}

func (*Response) SetData

func (r *Response) SetData(key string, value any) *Response

func (*Response) SetMessage

func (r *Response) SetMessage(message string) *Response

func (*Response) SetStatus

func (r *Response) SetStatus(status bool) *Response

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL