utils

package
v2.33.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

mapstruct is similar in idea to mitchellh/mapstructure, with a difference that values are assumed to always be created through json serialization.

Eg. If one would try to directly convert some struct to map[string]any via mapstructure, resulting map wouldn't necessary match json representation of said object, especially if custom UnmarshalJSON are present. Object created by EncodeObject avoids such mismatch.

Index

Constants

View Source
const (
	// ApertureAgent is the service name for Agent.
	ApertureAgent = "aperture-agent"
	// ApertureController is the service name for Controller.
	ApertureController = "aperture-controller"

	// ApertureCloudAgentGroup agent group name for Cloud Agents.
	ApertureCloudAgentGroup = "aperture-cloud"

	// InstallationModeKubernetesSidecar for sidecar installation mode.
	InstallationModeKubernetesSidecar = "KUBERNETES_SIDECAR"
	// InstallationModeKubernetesDaemonSet for Kubernetes DaemonSet installation mode.
	InstallationModeKubernetesDaemonSet = "KUBERNETES_DAEMONSET"
	// InstallationModeLinuxBareMetal for bare metal installation mode.
	InstallationModeLinuxBareMetal = "LINUX_BARE_METAL"
	// InstallationModeCloudAgent for Cloud Agents.
	InstallationModeCloudAgent = "CLOUD_AGENT"
)

Variables

This section is empty.

Functions

func Get

func Get(ctx context.Context, url string, headers map[string]string, timeout time.Duration) (string, error)

Get is a helper function to make a GET request to the specified URL and return the response body as a string.

func IsHTTPUrl

func IsHTTPUrl(url string) bool

IsHTTPUrl returns true if the given string is an HTTP(S) URL.

func MarshalGob added in v2.2.0

func MarshalGob(value interface{}) ([]byte, error)

MarshalGob encodes an interface into a byte array.

func Mod

func Mod(a, b int) int

Mod is a normal modulo operation which does not produce negative values.

func RemoveFromSlice

func RemoveFromSlice(a []string, x string) []string

RemoveFromSlice removes x from a and returns the new slice.

func Shutdown

func Shutdown(shutdowner fx.Shutdowner)

Shutdown invokes fx.Shutdowner and logs error if any.

func SliceContains

func SliceContains(a []string, x string) bool

SliceContains tells whether a contains x.

func SliceFind

func SliceFind(a []string, x string) int

SliceFind returns the smallest index i at which x == a[i], or len(a) if there is no such index.

func UnmarshalGob added in v2.2.0

func UnmarshalGob(data []byte, value interface{}) error

UnmarshalGob decodes a byte array into an interface.

Types

type GoLeakDetector

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

GoLeakDetector holds options for the goleak detector.

func NewGoLeakDetector

func NewGoLeakDetector() *GoLeakDetector

NewGoLeakDetector creates a new GoLeakDetector with goleakOptions.

func (*GoLeakDetector) AddIgnoreTopFunctions

func (l *GoLeakDetector) AddIgnoreTopFunctions(fs ...string)

AddIgnoreTopFunctions adds functions to ignore in the leak detector.

func (*GoLeakDetector) FindLeaks

func (l *GoLeakDetector) FindLeaks() error

FindLeaks finds memory leaks in the current process.

type MapStruct

type MapStruct map[string]any

MapStruct is an in-memory representation of JSON object.

func ToMapStruct

func ToMapStruct(obj any) (MapStruct, error)

ToMapStruct encodes any json-serializable struct as Object

json.Unmarshal(obj) and json.Unmarshal(returnedObject) should be equivalent.

type Set added in v2.6.0

type Set[T comparable] map[T]struct{}

Set represents set of values.

func SliceToSet added in v2.6.0

func SliceToSet(a []string) Set[string]

SliceToSet converts a slice of strings to a set.

func (Set[T]) Contains added in v2.6.0

func (s Set[T]) Contains(x T) bool

Contains returns whether the set contains given element.

Jump to

Keyboard shortcuts

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