utils

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 7 Imported by: 0

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

func GenerateLargeHTMLFile(filePath string, sizeMB int) error

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

func GenerateLargeJSONFile(filePath string, sizeMB int) error

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

func GenerateLargeTextFile(filePath string, sizeMB int) error

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

type Pool

type Pool interface {
	// Get retrieves a connection from the pool
	Get(ctx context.Context) (interface{}, error)
	// Put returns a connection to the pool
	Put(conn interface{})
	// Close closes all connections in the pool
	Close() error
}

Pool defines the interface for connection pooling

type PoolOptions

type PoolOptions struct {
	CreateConn   func() (interface{}, error)
	ValidateConn func(interface{}) bool
	CloseConn    func(interface{}) error
	MaxIdle      int
	MaxActive    int
	IdleTimeout  time.Duration
}

PoolOptions configures the connection pool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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