utils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMoneyNullString

func CreateMoneyNullString(s string) (sql.NullString, error)

Turns a given string into SQL type NullString, so it can be inserted into possible Null fields in database - this version handles strings that will be turned into NUMERIC(16, 2) type

func CreateTextNullString

func CreateTextNullString(s string) sql.NullString

This version will handle text NullStrings

Types

type QueryService

type QueryService interface {
	ValidateParamValue(value, expectedType string) (bool, error)
	ValidateQuery(queries url.Values, rules map[string]string) (map[string]string, []QueryValidationError)
	BuildSqlQuery(queries map[string]string, accountID string) (string, []any, error)
}

URL Query service interface

type QueryValidationError

type QueryValidationError struct {
	Parameter string `json:"parameter"`
	Value     string `json:"value"`
	Message   string `json:"message"`
}

Represents an error related to query parameter validation

type Service

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

Responsible for validating query parameters based on their type. Holds map of type validators, where key is the type, and value is a function that validates the string value

func NewQueryService

func NewQueryService() *Service

Initializes new QueryValidator instance

func (*Service) BuildSqlQuery

func (qv *Service) BuildSqlQuery(queries map[string]string, accountID string) (string, []any, error)

Builds an SQL query for transactions based on optional query arguments

func (*Service) ValidateParamValue

func (qv *Service) ValidateParamValue(value, expectedType string) (bool, error)

Validates a query parameter's value based on its expected type. - value: Value of parameter to validate - expectedType: Expected data type of query parameter Returns true if value passes validation or no validator exists for expected type

func (*Service) ValidateQuery

func (qv *Service) ValidateQuery(queries url.Values, rules map[string]string) (map[string]string, []QueryValidationError)

Validates query parameters based on predefined rules. Rules is a map of expected query parameters and their expected types. Returns slice of QueryValidationError if validation fails

Jump to

Keyboard shortcuts

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