util

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertOptionsExist

func AssertOptionsExist(params Params, opts ...string) []string

Assert that the options exists within the params map

func CopyIf

func CopyIf[T comparable](s []T, condition func(t T) bool) []T

General function to copy elements from slice if condition is true.

func CreateArchive

func CreateArchive(files []string, buf io.Writer) error

func Get

func Get[T any](params Params, key string) *T

Sugary generic function to get parameter from util.Params.

func GetOpt

func GetOpt[T any](opts []Option, key string) *T

func GitCommit

func GitCommit() string

Returns the git commit string by executing command. NOTE: This currently requires git to be installed. TODO: Change how this is done to not require executing a command.

func IsDirectory

func IsDirectory(path string) (bool, error)

Wrapper function to simplify checking if a path is a directory.

func MakeRequest

func MakeRequest(url string, httpMethod string, body []byte, headers map[string]string) (*http.Response, []byte, error)

Wrapper function to confine making a HTTP request into a single function instead of multiple.

func PathExists

func PathExists(path string) (bool, error)

Wrapper function to simplify checking if a path exists.

func RemoveDuplicates

func RemoveDuplicates[T cmp.Ordered](s []T) []T

func RemoveIndex

func RemoveIndex[T comparable](s []T, index int) []T

General function to remove element by a given index. NOTE: would it be better to use slices.DeleteFunc instead?

Types

type Option

type Option func(Params)

func WithDefault

func WithDefault[T any](v T) Option

type Params

type Params map[string]any

Params are accessible in generator.Generate().

func ToDict

func ToDict(opts ...Option) Params

Extract all parameters from the options passed as map[string]any.

func (Params) GetVerbose

func (p Params) GetVerbose() bool

func (*Params) OptionExists

func (p *Params) OptionExists(params Params, opt string) bool

Test if an option is present in params

Jump to

Keyboard shortcuts

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