util

package
v0.0.0-...-0a7bcea Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(password string, hashedPassowrd string) error

CheckPassword checks if password and hashedpassword are the same.

func HashPassword

func HashPassword(password string) (string, error)

HashPassword returns the bcrypt hash of the password and an error.

func IsSensitiveIdentifier

func IsSensitiveIdentifier(name string) bool

IsSensitiveIdentifier checks whether a column or identifier name contains restricted sensitive keywords.

func RandomEmail

func RandomEmail(n int) string

RandomEmail generates a random email address

func RandomInt

func RandomInt(min, max int64) int64

RandomInt generates a random integer between min and max

func RandomMoney

func RandomMoney() int64

RandomMoney generates a random amount of money

func RandomStr

func RandomStr(n int) string

RandomStr generates a random string of length n

func RandomUser

func RandomUser() string

RandomOwner generates a random owner name

func SanitizeSQL

func SanitizeSQL(query string) string

SanitizeSQL strips markdown code fences and trims excess whitespace that LLMs may emit.

func SanitizeSchema

func SanitizeSchema(schema map[string]map[string]string) map[string]map[string]string

SanitizeSchema returns a deep copy of a database schema map with all sensitive columns removed. This ensures LLMs (Muse, Gemini, OpenAI) never see sensitive columns in their prompt context.

func ValidQuery

func ValidQuery(query string) bool

ValidQuery checks if parsed SQL Query is a valid query a valid query in this case is a correct SQL which is also a SELECT statement. It adds extra security to ensure only SELECT queries are validated.

Types

type Config

type Config struct {
	Port                string        `json:"PORT"`
	DBDriver            string        `json:"DB_DRIVER"`
	DBUrl               string        `json:"DB_URL"`
	DBName              string        `json:"DB_NAME"`
	Environment         string        `json:"ENVIRONMENT"`
	TokenSymmetricKey   string        `json:"TOKEN_SYMMETRIC_KEY"`
	TokenSecretKey      string        `json:"TOKEN_SECRET_KEY"`
	AccessTokenDuration time.Duration `json:"ACCESS_TOKEN_DURATION"`
	ApiKey              string        `json:"API_KEY"`
	OrgId               string        `json:"ORG_ID"`
	ProjectId           string        `json:"PROJECT_ID"`
	Model               string        `json:"MODEL"`
	Temp                string        `json:"TEMP"`
	LLMType             string        `json:"LLM_TYPE"`
	LLMBaseUrl          string        `json:"LLM_BASE_URL"`
	CronSchedule        string        `json:"CRON_SCHEDULE"`
	CronBatchSize       string        `json:"CRON_BATCH_SIZE"`
	LogPath             string        `json:"LOG_PATH"`
}

func LoadConfig

func LoadConfig(path string) (config Config, err error)

type SchemaCache

type SchemaCache struct {
	Data       map[string]map[string]string
	LastUpdate time.Time
	// contains filtered or unexported fields
}

func NewSchemaCache

func NewSchemaCache() *SchemaCache

func (*SchemaCache) AutoRefresh

func (cache *SchemaCache) AutoRefresh(schema map[string]map[string]string, interval time.Duration) error

Set up a background goroutine to periodically refresh the schema.

func (*SchemaCache) CacheSchema

func (cache *SchemaCache) CacheSchema(schema map[string]map[string]string) error

Load the schema from the database and store it in the cache.

func (*SchemaCache) GetSchema

func (cache *SchemaCache) GetSchema() map[string]map[string]string

Provide thread-safe access to the cached data.

func (*SchemaCache) GetSchemaWithExpiry

func (cache *SchemaCache) GetSchemaWithExpiry(maxAge time.Duration) (map[string]map[string]string, bool)

If the schema changes infrequently, add logic to validate or expire the cache based on the LastUpdate timestamp.

func (*SchemaCache) RefreshSchema

func (cache *SchemaCache) RefreshSchema(schema map[string]map[string]string) error

Manual Refresh API: Allow manual cache refresh via an admin endpoint or CLI.

Jump to

Keyboard shortcuts

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