sl

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0 Imports: 6 Imported by: 45

Documentation

Overview

Package sl has convenience functions for returning pointers to values

Index

Constants

This section is empty.

Variables

View Source
var DefaultLimit = 50
View Source
var Version = VersionInfo{
	Major: 1,
	Minor: 1,
	Patch: 3,
	Pre:   "",
}

Functions

func Bool

func Bool(v bool) *bool

Bool returns a pointer to the bool value provided

func Float

func Float(v float64) *datatypes.Float64

Float converts the float value provided to a datatypes.Float64 value, and returns a pointer to it

func Get

func Get(p interface{}, d ...interface{}) interface{}

Get returns the value of p, either p itself, or, if p is a pointer, the value that p points to. d is an optional default value to be returned in the event that p is nil. If d is not specified, and p is nil, a type-appropriate zero-value is returned instead.

func GetOk

func GetOk(p interface{}) (interface{}, bool)

GetOk returns the value of p, either p itself, or, if p is a pointer, the value that p points to. If p is nil, a type-appropriate zero-value is returned instead. If p is a value or non-nil pointer, the second return value will be true. Otherwise, it will be false.

func Grab

func Grab(s interface{}, path string, d ...interface{}) interface{}

Grab returns the value specified by the path given, starting from the struct s. If at any point in the path the lookup falls short (i.e. a field is not found), or if the last field in the path is nil itself, a type-appropriate zero-value is returned. This behavior can be overidden by providing a default value.

This is useful for getting values our of deeply nested structures Example: val := sl.Grab(virtualGuest, "Datacenter.Name")

func GrabOk

func GrabOk(s interface{}, path string) (interface{}, bool)

GrabOk returns the value specified by the path given, starting from the struct s. If at any point in the path the lookup falls short (i.e. a field is not found), or if the last field in the path is nil itself, a type-appropriate zero-value is returned. It returns a second value, a boolean, which will be false if it failed to lookup the value, including if the last field in the path was nil.

This is useful for getting values our of deeply nested structures Example: val, ok := sl.GrabOk(virtualGuest, "Datacenter.Name")

func Int

func Int(v int) *int

Int returns a pointer to the int value provided

func String

func String(v string) *string

String returns a pointer to the string value provided

func Time

func Time(v time.Time) *datatypes.Time

Time converts the time.Time value provided to a datatypes.Time value, and returns a pointer to it

func Uint

func Uint(v uint) *uint

Uint returns a pointer to the uint value provided

Types

type Error

type Error struct {
	StatusCode int
	Exception  string `json:"code"`
	Message    string `json:"error"`
	Wrapped    error
}

Error contains detailed information about an API error, which can be useful for debugging, or when finer error handling is required than just the mere presence or absence of an error.

Error implements the error interface

func (Error) Error

func (r Error) Error() string

type Options

type Options struct {
	Id         *int
	Mask       string
	Filter     string
	Limit      *int
	Offset     *int
	TotalItems int
}

Options contains the individual query parameters that can be applied to a request.

func (*Options) GetRemainingAPICalls added in v1.1.4

func (opt *Options) GetRemainingAPICalls() int

returns Math.Ciel((TotalItems - Limit) / Limit)

func (*Options) SetLimit added in v1.1.4

func (opt *Options) SetLimit(limit int)

func (*Options) SetOffset added in v1.1.4

func (opt *Options) SetOffset(offset int)

func (*Options) SetTotalItems added in v1.1.4

func (opt *Options) SetTotalItems(total int)

func (*Options) ValidateLimit added in v1.1.4

func (opt *Options) ValidateLimit() int

Makes sure the limit is set to something, not 0 or 1. Will set to default if no other limit is set.

type VersionInfo

type VersionInfo struct {
	Major int
	Minor int
	Patch int
	Pre   string
}

func (VersionInfo) String

func (v VersionInfo) String() string

Jump to

Keyboard shortcuts

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