util

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetType

func GetType(r interface{}) (attr.Type, error)

func GetValue

func GetValue(r interface{}) (attr.Value, error)

func Int64

func Int64(in int64) basetypes.Int64Value

func Int64Set

func Int64Set(in []attr.Value) basetypes.SetValue

Int64Set accepts a `[]attr.Value` and returns a `basetypes.SetValue`. The return type automatically handles `SetNull` for empty results and coercing all element values to a string if there are any elements.

nolint: contextcheck

func IsoFromCloudInit

func IsoFromCloudInit(ctx context.Context, ci CloudInit) (string, error)

func IsoFromFiles

func IsoFromFiles(ctx context.Context, isoName string, files map[string]string) (string, error)

func MarshalURL

func MarshalURL(r any) (url.Values, error)

func String

func String(in string) basetypes.StringValue

String accepts a `string` and returns a `basetypes.StringValue`. The return type automatically handles `StringNull` should the string be empty.

Removes the need for the following code when saving to state.

if response.MyField == "" {
    state.MyField = types.StringValue(response.MyField)
} else {
    state.MyField = types.StringNull()
}

Not recommended if you care about returning an empty string for the state.

nolint: contextcheck

func StringSet

func StringSet(in []attr.Value) basetypes.SetValue

StringSet accepts a `[]attr.Value` and returns a `basetypes.SetValue`. The return type automatically handles `SetNull` for empty results and coercing all element values to a string if there are any elements.

nolint: contextcheck

Types

type CloudInit

type CloudInit struct {
	MetaData      string `yaml:"meta_data"`
	UserData      string `yaml:"user_data"`
	NetworkConfig string `yaml:"network_config"`
}

type ParseOption

type ParseOption int

Configuration options for creating a parser. Most options specify which fields should be included, while others enable features. If a field is not included the parser will assume a default value. These options do not change the order fields are parse in.

const (
	Second      ParseOption = 1 << iota // Seconds field, default 0
	Minute                              // Minutes field, default 0
	Hour                                // Hours field, default 0
	Dom                                 // Day of month field, default *
	Month                               // Month field, default *
	Dow                                 // Day of week field, default *
	DowOptional                         // Optional day of week field, default *
	Descriptor                          // Allow descriptors such as @monthly, @weekly, etc.
)

type Parser

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

A custom Parser that can be configured.

func NewParser

func NewParser(options ParseOption) Parser

Creates a custom Parser with custom options.

// Standard parser without descriptors
specParser := NewParser(Minute | Hour | Dom | Month | Dow)
sched, err := specParser.Parse("0 0 15 */3 *")

// Same as above, just excludes time fields
subsParser := NewParser(Dom | Month | Dow)
sched, err := specParser.Parse("15 */3 *")

// Same as above, just makes Dow optional
subsParser := NewParser(Dom | Month | DowOptional)
sched, err := specParser.Parse("15 */3")

func (Parser) Parse

func (p Parser) Parse(spec string) (*Schedule, error)

Parse returns a new crontab schedule representing the given spec. It returns a descriptive error if the spec is not valid. It accepts crontab specs and features configured by NewParser.

type Schedule

type Schedule struct {
	Second, Minute, Hour, Dom, Month, Dow, RepeatHour, RepeatMin, RepeatDate int64

	// Override location for this schedule.
	Location *time.Location
}

SpecSchedule specifies a duty cycle (to the second granularity), based on a traditional crontab specification. It is computed initially and stored as bit sets.

func Parse

func Parse(spec string) (*Schedule, error)

Parse returns a new crontab schedule representing the given spec. It returns a descriptive error if the spec is not valid.

It accepts

  • Full crontab specs, e.g. "* * * * * ?"
  • Descriptors, e.g. "@midnight", "@every 1h30m"

func ParseStandard

func ParseStandard(standardSpec string) (*Schedule, error)

ParseStandard returns a new crontab schedule representing the given standardSpec (https://en.wikipedia.org/wiki/Cron). It differs from Parse requiring to always pass 5 entries representing: minute, hour, day of month, month and day of week, in that order. It returns a descriptive error if the spec is not valid.

It accepts

  • Standard crontab specs, e.g. "* * * * ?"
  • Descriptors, e.g. "@midnight", "@every 1h30m"

Jump to

Keyboard shortcuts

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