util

package
v0.0.0-...-bc6eac3 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: MIT Imports: 10 Imported by: 0

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 Get

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

Syntactic sugar generic function to get parameter from util.Params.

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 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 GetParams

func GetParams(opts ...Option) Params

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

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