config

package
v0.5.0-beta Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package config provides the configuration for the generation of dynamic structs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDstructConfigBuilder

func NewDstructConfigBuilder() *dstructConfigBuilder

NewDstructConfigBuilder is a constructor for DstructConfigBuilder.

Types

type Config

type Config interface {
	// Number returns the number configuration.
	Number() NumberRangeConfig

	// Slice returns the slice configuration.
	Slice() SliceConfig

	// Date returns the date configuration.
	Date() DateRangeConfig

	// SetSliceLength sets the length range for the slice.
	SetSliceLength(min, max int) Config

	// SetIntRange sets the range for int values.
	SetIntRange(min, max int) Config

	// SetInt8Range sets the range for int8 values.
	SetInt8Range(min, max int8) Config

	// SetInt16Range sets the range for int16 values.
	SetInt16Range(min, max int16) Config

	// SetInt32Range sets the range for int32 values.
	SetInt32Range(min, max int32) Config

	// SetInt64Range sets the range for int64 values.
	SetInt64Range(min, max int64) Config

	// SetFloat32Range sets the range for float32 values.
	SetFloat32Range(min, max float32) Config

	// SetFloat64Range sets the range for float64 values.
	SetFloat64Range(min, max float64) Config

	// SetUIntRange sets the range for uint values.
	SetUIntRange(min, max uint) Config

	// SetUInt8Range sets the range for uint8 values.
	SetUInt8Range(min, max uint8) Config

	// SetUInt16Range sets the range for uint16 values.
	SetUInt16Range(min, max uint16) Config

	// SetUInt32Range sets the range for uint32 values.
	SetUInt32Range(min, max uint32) Config

	// SetUInt64Range sets the range for the uint64 value.
	SetUInt64Range(min, max uint64) Config

	// SetUIntPtrRange sets the range for the uintptr value.
	SetUIntPtr(min, max uintptr) Config

	// Copy returns a copy of the configuration.
	Copy() Config

	// SetFrom sets the configuration from another configuration.
	SetFrom(cfg Config)
}

Config represents the generation config for a dynamic struct.

type ConfigType

type ConfigType uint

type DateRangeConfig

type DateRangeConfig interface {

	// SetDateFormat sets the date format.
	SetDateFormat(format string)

	// GetDateFormat returns the date format.
	GetDateFormat() string

	// SetDateRange sets the date range.
	SetDateRange(start time.Time, end time.Time)

	// SetStartDate sets the start date for the date range.
	SetStartDate(start time.Time)

	// GetStartDate returns the start date for the date range.
	GetStartDate() time.Time

	// SetEndDate sets the end date for the date range.
	SetEndDate(end time.Time)

	// GetEndDate returns the end date for the date range.
	GetEndDate() time.Time
}

DateRangeConfig defines the configuration for a date range for a dynamic struct.

type DstructConfig

type DstructConfig struct {
	SliceConfig  SliceConfig
	NumberConfig NumberRangeConfig
	DateConfig   DateRangeConfig
}

DstructConfig defines the configuration for a dynamic struct.

func NewDstructConfig

func NewDstructConfig() *DstructConfig

NewDstructConfig is a constructor for DstructConfig.

func (*DstructConfig) Copy

func (c *DstructConfig) Copy() Config

Copy implements Config.

func (*DstructConfig) Date

func (c *DstructConfig) Date() DateRangeConfig

Date implements Config.Date.

func (*DstructConfig) Number

func (c *DstructConfig) Number() NumberRangeConfig

Number implements Config.Number.

func (*DstructConfig) SetFloat32Range

func (c *DstructConfig) SetFloat32Range(min, max float32) Config

SetFloat32Range implements Config.SetFloat32Range.

func (*DstructConfig) SetFloat64Range

func (c *DstructConfig) SetFloat64Range(min, max float64) Config

SetFloat64Range implements Config.SetFloat64Range.

func (*DstructConfig) SetFrom

func (c *DstructConfig) SetFrom(cfg Config)

SetFrom implements Config.

func (*DstructConfig) SetInt16Range

func (c *DstructConfig) SetInt16Range(min, max int16) Config

SetInt16Range implements Config.SetInt16Range.

func (*DstructConfig) SetInt32Range

func (c *DstructConfig) SetInt32Range(min, max int32) Config

SetInt32Range implements Config.SetInt32Range.

func (*DstructConfig) SetInt64Range

func (c *DstructConfig) SetInt64Range(min, max int64) Config

SetInt64Range implements Config.SetInt64Range.

func (*DstructConfig) SetInt8Range

func (c *DstructConfig) SetInt8Range(min, max int8) Config

SetInt8Range implements Config.SetInt8Range.

func (*DstructConfig) SetIntRange

func (c *DstructConfig) SetIntRange(min, max int) Config

SetIntRange implements Config.SetIntRange.

func (*DstructConfig) SetSliceLength

func (c *DstructConfig) SetSliceLength(min, max int) Config

SetSliceLength implements Config.SetSliceLength.

func (*DstructConfig) SetUInt16Range

func (c *DstructConfig) SetUInt16Range(min, max uint16) Config

SetUInt16Range implements Config.SetUInt16Range.

func (*DstructConfig) SetUInt32Range

func (c *DstructConfig) SetUInt32Range(min, max uint32) Config

SetUInt32Range implements Config.SetUInt32Range.

func (*DstructConfig) SetUInt64Range

func (c *DstructConfig) SetUInt64Range(min, max uint64) Config

SetUInt64Range implements Config.SetUInt64Range.

func (*DstructConfig) SetUInt8Range

func (c *DstructConfig) SetUInt8Range(min, max uint8) Config

SetUInt8Range implements Config.SetUInt8Range.

func (*DstructConfig) SetUIntPtr

func (c *DstructConfig) SetUIntPtr(min, max uintptr) Config

SetUIntPtrRange implements Config.SetUIntPtrRange.

func (*DstructConfig) SetUIntRange

func (c *DstructConfig) SetUIntRange(min, max uint) Config

SetUIntRange implements Config.SetUIntRange.

func (*DstructConfig) Slice

func (c *DstructConfig) Slice() SliceConfig

Slice implements Config.Slice.

type DstructConfigBuilder

type DstructConfigBuilder interface {

	// WithNumberConfig sets the NumberConfig in the builder.
	WithNumberConfig(numberConfig NumberRangeConfig) DstructConfigBuilder

	// WithSliceConfig sets the SliceConfig in the builder.
	WithSliceConfig(sliceConfig SliceConfig) DstructConfigBuilder

	// WithDateRangeConfig sets the DateConfig in the builder.
	WithDateRangeConfig(DateRangeConfig DateRangeConfig) DstructConfigBuilder

	// Build builds the configuration object
	Build() *DstructConfig
}

ConfigBuilder is an interface of a DstructConfig builder.

type DstructDateRangeConfig

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

DstructDateRangeConfig implements the DateRangeConfig interface.

func NewDstructDateRangeConfig

func NewDstructDateRangeConfig() *DstructDateRangeConfig

NewDstructDateRangeConfig is a constructor for DstructDateRangeConfig. It initializes the date format to RFC3339, the start date to the current date truncated to the day and the end date to the next day.

func (*DstructDateRangeConfig) GetDateFormat

func (dc *DstructDateRangeConfig) GetDateFormat() string

GetDateFormat implements DateConfig.GetDateFormat.

func (*DstructDateRangeConfig) GetEndDate

func (dc *DstructDateRangeConfig) GetEndDate() time.Time

GetEndDate implements DateConfig.GetEndDate.

func (*DstructDateRangeConfig) GetStartDate

func (dc *DstructDateRangeConfig) GetStartDate() time.Time

GetStartDate implements DateConfig.GetStartDate.

func (*DstructDateRangeConfig) SetDateFormat

func (dc *DstructDateRangeConfig) SetDateFormat(format string)

SetDateFormat implements DateConfig.SetDateFormat.

func (*DstructDateRangeConfig) SetDateRange

func (dc *DstructDateRangeConfig) SetDateRange(start time.Time, end time.Time)

SetDateRange implements DateConfig.SetDateRange.

func (*DstructDateRangeConfig) SetEndDate

func (dc *DstructDateRangeConfig) SetEndDate(end time.Time)

SetEndDate implements DateConfig.SetEndDate.

func (*DstructDateRangeConfig) SetStartDate

func (dc *DstructDateRangeConfig) SetStartDate(start time.Time)

SetStartDate implements DateConfig.SetStartDate.

type DstructNumberRangeConfig

type DstructNumberRangeConfig struct {
	IntConfig     NumberRange[int]
	Int8Config    NumberRange[int8]
	Int16Config   NumberRange[int16]
	Int32Config   NumberRange[int32]
	Int64Config   NumberRange[int64]
	Float32Config NumberRange[float32]
	Float64Config NumberRange[float64]
	UIntConfig    NumberRange[uint]
	UInt8Config   NumberRange[uint8]
	UInt16Config  NumberRange[uint16]
	UInt32Config  NumberRange[uint32]
	UInt64Config  NumberRange[uint64]
	UIntPtrConfig NumberRange[uintptr]
}

DstructNumberRangeConfig implements NumberRangeConfig.

func NewNumberRangeConfig

func NewNumberRangeConfig() *DstructNumberRangeConfig

NewNumberRangeConfig is a constructor for DstructNumberRangeConfig.

func (*DstructNumberRangeConfig) Copy

Copy implements NumberConfig.Copy.

func (*DstructNumberRangeConfig) Float32

Float32 implements NumberConfig.Float32.

func (*DstructNumberRangeConfig) Float64

Float64 implements NumberConfig.Float64.

func (*DstructNumberRangeConfig) Int

Int implements NumberConfig.Int.

func (*DstructNumberRangeConfig) Int16

Int16 implements NumberConfig.Int16.

func (*DstructNumberRangeConfig) Int32

Int32 implements NumberConfig.Int32.

func (*DstructNumberRangeConfig) Int64

Int64 implements NumberConfig.Int64.

func (*DstructNumberRangeConfig) Int8

Int8 implements NumberConfig.Int8.

func (*DstructNumberRangeConfig) SetFrom

func (*DstructNumberRangeConfig) UInt

UInt implements NumberConfig.UInt.

func (*DstructNumberRangeConfig) UInt16

UInt16 implements NumberConfig.UInt16.

func (*DstructNumberRangeConfig) UInt32

UInt32 implements NumberConfig.UInt32,

func (*DstructNumberRangeConfig) UInt64

UInt64 implements NumberConfig.UInt64.

func (*DstructNumberRangeConfig) UInt8

UInt8 implements NumberConfig.UInt8.

func (*DstructNumberRangeConfig) UIntPtr

UIntptr implements NumberConfig.UIntPtr.

type DstructSliceConfig

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

DstructSliceConfig implements SliceConfig.

func NewSliceConfig

func NewSliceConfig() *DstructSliceConfig

NewSliceConfig is a constructor for DstructSliceConfig.

func (*DstructSliceConfig) Copy

func (sc *DstructSliceConfig) Copy() SliceConfig

Copy implements SliceConfig.Copy.

func (*DstructSliceConfig) MaxLength

func (sc *DstructSliceConfig) MaxLength() int

MaxLength implements SliceConfig.MaxLength.

func (*DstructSliceConfig) MinLength

func (sc *DstructSliceConfig) MinLength() int

MinLength implements SliceConfig.MinLength.

func (*DstructSliceConfig) SetLengthRange

func (sc *DstructSliceConfig) SetLengthRange(min, max int) SliceConfig

SetLengthRange implements SliceConfig.SetLengthRange.

type GenerationSettings

type GenerationSettings struct {
	ValueGenerationType  ValueGenerationType
	SetNonRequiredFields bool
	RecursiveDefinition  RecursiveDefinition
}

GenerationSettings defines how values are generated within a dynamic struct.

func DefaultGenerationSettings

func DefaultGenerationSettings() GenerationSettings

DefaultGenerationSettings returns a default configuration for generation values.

func (*GenerationSettings) WithNonRequiredFields

func (gs *GenerationSettings) WithNonRequiredFields(required bool) GenerationSettings

type Number

type Number interface {
	int | int8 | int16 | int32 | int64 | float32 | float64 |
		uint | uint8 | uint16 | uint32 | uint64 | uintptr
}

Number is a type that represents a number.

type NumberRange

type NumberRange[n Number] struct {
	// contains filtered or unexported fields
}

numRange represents the range of a number.

func (*NumberRange[n]) Max

func (nr *NumberRange[n]) Max() n

func (*NumberRange[n]) Min

func (nr *NumberRange[n]) Min() n

func (*NumberRange[n]) Range

func (nr *NumberRange[n]) Range() (n, n)

func (*NumberRange[n]) RangeRef

func (nr *NumberRange[n]) RangeRef() (*n, *n)

func (*NumberRange[n]) SetMax

func (nr *NumberRange[n]) SetMax(max n)

func (*NumberRange[n]) SetMin

func (nr *NumberRange[n]) SetMin(min n)

func (*NumberRange[n]) SetRange

func (nr *NumberRange[n]) SetRange(min n, max n)

type NumberRangeConfig

type NumberRangeConfig interface {
	// Int returns the configuration for an int number range.
	Int() *NumberRange[int]

	// Int8 returns the configuration for an int8 number range.
	Int8() *NumberRange[int8]

	// Int16 returns the configuration for an int16 number range.
	Int16() *NumberRange[int16]

	// Int32 returns the configuration for an int32 number range.
	Int32() *NumberRange[int32]

	// Int64 returns the configuration for an int64 number range.
	Int64() *NumberRange[int64]

	// Float32 returns the configuration for a float32 number range.
	Float32() *NumberRange[float32]

	// Float64 returns the configuration for a float64 number range.
	Float64() *NumberRange[float64]

	// UInt returns the configuration for a uint number range.
	UInt() *NumberRange[uint]

	// UInt8 returns the configuration for a uint8 number range.
	UInt8() *NumberRange[uint8]

	// UInt16 returns the configuration for a uint16 number range.
	UInt16() *NumberRange[uint16]

	// Uint32 returns the configuration for a uint32 number range.
	UInt32() *NumberRange[uint32]

	// UInt64 returns the configuration for a uint64 number range.
	UInt64() *NumberRange[uint64]

	// UIntPtr returns the configuration for a uintptr number range.
	UIntPtr() *NumberRange[uintptr]

	// Copy returns a copy of the configuration.
	Copy() NumberRangeConfig

	// SetFrom sets the configuration from another configuration.
	SetFrom(cfg NumberRangeConfig)
}

NumberRangeConfig represents the configuration for a number range within a dynamic struct.

type RecursiveDefinition

type RecursiveDefinition struct {
	// Allow defines if recursive definitions are allowed.
	Allow bool
	// Depth defines the depth of the recursive definition if recursion is allowed.
	Depth uint
}

RecursiveDefinition defines the configuration for recursive definitions within a dynamic struct.

type SliceConfig

type SliceConfig interface {

	// SetLengthRange sets the length range for the slice.
	SetLengthRange(min, max int) SliceConfig

	// MinLength returns the minimum length of the slice.
	MinLength() int

	// MaxLength returns the maximum length of the slice.
	MaxLength() int

	// Copy returns a copy of the slice configuration.
	Copy() SliceConfig
}

type ValueGenerationType

type ValueGenerationType uint8
const (
	Generate     ValueGenerationType = iota // will generate all field
	GenerateOnce                            // will generate the fields once
	UseDefaults
)

Jump to

Keyboard shortcuts

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