utils

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: MIT Imports: 23 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomPin

func GenerateRandomPin() string

func GetFirst added in v0.8.1

func GetFirst[T any](opts []T) *T

func GetRandomName

func GetRandomName() (string, error)

GetRandomName returns mnemonicoded random name

func HasDryRun added in v0.8.1

func HasDryRun(r *http.Request) bool

func HashName

func HashName(b []byte) string

func Must added in v0.8.1

func Must[T any](t T, err error) T

unwraps the first value, panics if err

func ResolveAndStripSemver added in v0.8.0

func ResolveAndStripSemver(v string) ([]string, error)
Example (Major)
vs, err := ResolveAndStripSemver("v1")
fmt.Println(err)
fmt.Println(vs)
Output:

<nil>
[1.0.0 1.0 1]
Example (Minor)
vs, err := ResolveAndStripSemver("v1.2")
fmt.Println(err)
fmt.Println(vs)
Output:

<nil>
[1.2.0 1.2 1]
Example (Patch)
vs, err := ResolveAndStripSemver("v1.2.3")
fmt.Println(err)
fmt.Println(vs)
Output:

<nil>
[1.2.3 1.2 1]
Example (Prerelease)
vs, err := ResolveAndStripSemver("v1.2.3-beta.1")
fmt.Println(err)
fmt.Println(vs)
Output:

<nil>
[1.2.3-beta.1]
Example (Sample)
vs, err := ResolveAndStripSemver("2.0.4")
fmt.Println(err)
fmt.Println(vs)
Output:

<nil>
[2.0.4 2.0 2]

func SelfCheck

func SelfCheck(limits SelfCheckLimit, log logger.AppLogger, unhealhtyStreak int)

SelfCheck will watch the applications metrics, and crash it if it is considered to be unhealthy. This is only for use outside of kubernetes/docker

func SortedMapKeys

func SortedMapKeys[T any](input map[string]T) []string

Types

type Batcher

type Batcher struct {
	Watcher *fsnotify.Watcher

	Events chan []fsnotify.Event // Events are returned on this channel
	// contains filtered or unexported fields
}

Batcher batches file watch events in a given interval.

func NewDirWatcher

func NewDirWatcher(path string) (*Batcher, error)

Watches a directory recursively Caller must call .Close

func (*Batcher) Close

func (b *Batcher) Close()

type BinaryMeta added in v0.8.1

type BinaryMeta struct {
	Hash          string `json:"hash"`
	Size          uint64 `json:"size"`
	SizeHumanized string `json:"size_humanized"`
	IdentiHash    []byte `json:"identi_hash"`
}

BinaryMeta is a humanized version of the raw data of an object

func NewBinaryMeta added in v0.8.1

func NewBinaryMeta(a interface{}) (*BinaryMeta, error)

func NewBinaryMetaFromBytes added in v0.8.1

func NewBinaryMetaFromBytes(b []byte) BinaryMeta

For consistency, input is expectd to be the return-type of json.Marshal(input), but works with any []byte

func (BinaryMeta) Equal added in v0.8.1

func (bm BinaryMeta) Equal(bm2 BinaryMeta) bool

type IdentiHash added in v0.8.1

type IdentiHash struct {
	Img  []byte
	Hash []byte
}

func NewIdentiHash added in v0.8.1

func NewIdentiHash(hash []byte) IdentiHash

type ProjectDiffResponse added in v0.8.1

type ProjectDiffResponse struct {
	Diff diff.Changelog `json:"diff"`
	A    ProjectStats   `json:"a"`
	B    ProjectStats   `json:"b"`
}

func NewProjectDiff added in v0.8.1

func NewProjectDiff(a, b any, input models.DiffSnapshotInput) (*ProjectDiffResponse, error)

type ProjectStats added in v0.8.1

type ProjectStats struct {
	BinaryMeta
	ProjectID string `json:"project_id"`
	Tag       string `json:"tag"`
}

type SelfCheckLimit

type SelfCheckLimit struct {
	MemoryMB   uint64
	GoRoutines int
	Streaks    int
}

type Suggestion added in v0.8.1

type Suggestion struct {
	Index               int
	Value               string
	LevenshteinDistance int
	From                string
}

type Suggestions added in v0.8.1

type Suggestions []Suggestion

func SuggestionsFor added in v0.8.1

func SuggestionsFor(typedName string, stringSlice []string, maxDistance int, maxItems int) Suggestions

func (Suggestions) Len added in v0.8.1

func (s Suggestions) Len() int

func (Suggestions) Less added in v0.8.1

func (s Suggestions) Less(i, j int) bool

func (Suggestions) String added in v0.8.1

func (s Suggestions) String() string

func (Suggestions) Swap added in v0.8.1

func (s Suggestions) Swap(i, j int)

func (Suggestions) ToStringSlice added in v0.8.1

func (s Suggestions) ToStringSlice() []string

Jump to

Keyboard shortcuts

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