Documentation
¶
Overview ¶
Package utils provides utility functions and components for GoRAG
This package contains various utility components including: - Connection pooling - File generation utilities - Other helper functions
Example:
// Create a connection pool
pool := utils.NewConnectionPool(utils.PoolOptions{
CreateConn: func() (interface{}, error) {
return createConnection()
},
ValidateConn: func(conn interface{}) bool {
return validateConnection(conn)
},
CloseConn: func(conn interface{}) error {
return closeConnection(conn)
},
MaxIdle: 10,
MaxActive: 50,
IdleTimeout: 30 * time.Minute,
})
// Get a connection
conn, err := pool.Get(ctx)
if err != nil {
log.Fatal(err)
}
defer pool.Put(conn)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateLargeHTMLFile ¶ added in v0.6.0
GenerateLargeHTMLFile generates a large HTML file with the specified size in MB
This function generates a large HTML file by writing repetitive HTML sections until it reaches the specified size.
Parameters: - filePath: Path to the output file - sizeMB: Size of the file in megabytes
Returns: - error: Error if file generation fails
Example:
err := utils.GenerateLargeHTMLFile("test.html", 25) // Generate 25MB HTML file
if err != nil {
log.Fatal(err)
}
func GenerateLargeJSONFile ¶ added in v0.6.0
GenerateLargeJSONFile generates a large JSON file with the specified size in MB
This function generates a large JSON file by writing repetitive JSON objects until it reaches the specified size.
Parameters: - filePath: Path to the output file - sizeMB: Size of the file in megabytes
Returns: - error: Error if file generation fails
Example:
err := utils.GenerateLargeJSONFile("test.json", 50) // Generate 50MB JSON file
if err != nil {
log.Fatal(err)
}
func GenerateLargeTextFile ¶ added in v0.6.0
GenerateLargeTextFile generates a large text file with the specified size in MB
This function generates a large text file by writing repetitive content until it reaches the specified size.
Parameters: - filePath: Path to the output file - sizeMB: Size of the file in megabytes
Returns: - error: Error if file generation fails
Example:
err := utils.GenerateLargeTextFile("test.txt", 100) // Generate 100MB file
if err != nil {
log.Fatal(err)
}
Types ¶
type ConnectionPool ¶
type ConnectionPool struct {
// contains filtered or unexported fields
}
ConnectionPool implements a generic connection pool
func NewConnectionPool ¶
func NewConnectionPool(opts PoolOptions) *ConnectionPool
NewConnectionPool creates a new connection pool
func (*ConnectionPool) Close ¶
func (p *ConnectionPool) Close() error
Close closes all connections in the pool
func (*ConnectionPool) Get ¶
func (p *ConnectionPool) Get(ctx context.Context) (interface{}, error)
Get retrieves a connection from the pool
func (*ConnectionPool) Put ¶
func (p *ConnectionPool) Put(conn interface{})
Put returns a connection to the pool