Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CSVConfig ¶
type CSVConfig struct {
// HasHeader indicates if first line is header
// true: first line has column names
// false: fixed format (instance_id, cloud, account, region)
HasHeader bool
// Delimiter column separator character (default: comma)
Delimiter rune
// RequiredFields list of required fields in CSV
// Parser will validate these fields exist and are not empty
RequiredFields []string
// CloudDefault default value for cloud if column doesn't exist
// Useful for legacy CSVs that didn't have cloud column
CloudDefault string
}
CSVConfig defines CSV parser configurations. Allows customizing parser behavior.
func DefaultCSVConfig ¶
func DefaultCSVConfig() CSVConfig
DefaultCSVConfig returns default configuration. Format: instance_id,account,region (with header, comma, aws default)
type CSVRecord ¶
type CSVRecord struct {
InstanceID string // Instance ID (required)
Cloud string // Provider: aws, azure, gcp (default: aws)
Account string // Account/Subscription/Project (required)
Region string // Instance region (required)
Extra map[string]string // Optional extra columns (environment, team, etc)
}
CSVRecord represents a row from the instances CSV file. Each CSV line becomes a CSVRecord.
func (*CSVRecord) ToInstance ¶
ToInstance converts CSVRecord to cloud.Instance. This decouples CSV format from internal structure.
type ParseError ¶
type ParseError struct {
Line int // Line number where error occurred
Column string // Column name with problem (if applicable)
Message string // Error message
Err error // Original error (if any)
}
ParseError represents error during CSV parsing
func (*ParseError) Unwrap ¶
func (pe *ParseError) Unwrap() error
Unwrap allows using errors.Is() and errors.As()
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses CSV files containing instance information. Supports flexible formats with/without headers and extra columns.
func NewParser ¶
NewParser creates a new CSV parser with given configuration. If config is empty, uses DefaultCSVConfig().
func (*Parser) ParseFile ¶
ParseFile reads CSV file and returns list of instances. Validates required fields and converts each row to cloud.Instance.
CSV Format Examples:
With header:
instance_id,account,region,environment i-123,111111111111,us-east-1,prod
Without header (fixed order):
i-123,111111111111,us-east-1
Returns ParseError with line/column information if validation fails.