setter

package
v4.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: Apache-2.0 Imports: 1 Imported by: 9

Documentation

Overview

Copyright 2017 Mailgun Technologies Inc

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNil

func IsNil(i interface{}) bool

Returns true if the interface value is nil or the pointed to value is nil, for instance a map, array, channel or slice

func IsZero

func IsZero(value interface{}) bool

Returns true if 'value' is zero (the default golang value)

var thingy string
holster.IsZero(thingy) == true

func IsZeroValue

func IsZeroValue(value reflect.Value) bool

Returns true if 'value' is zero (the default golang value)

var count int64
holster.IsZeroValue(reflect.ValueOf(count)) == true

func SetDefault

func SetDefault(dest interface{}, defaultValue ...interface{})

If 'dest' is empty or of zero value, assign the default value. This panics if the value is not a pointer or if value and default value are not of the same type.

 var config struct {
		Verbose *bool
		Foo string
		Bar int
	}
	holster.SetDefault(&config.Foo, "default")
	holster.SetDefault(&config.Bar, 200)

Supply additional default values and SetDefault will choose the first default that is not of zero value

holster.SetDefault(&config.Foo, os.Getenv("FOO"), "default")

func SetOverride

func SetOverride(dest interface{}, values ...interface{})

Assign the first value that is not empty or of zero value. This panics if the value is not a pointer or if value and default value are not of the same type.

 var config struct {
		Verbose *bool
		Foo string
		Bar int
	}

 loadFromFile(&config)
 argFoo = flag.String("foo", "", "foo via cli arg")

 // Override the config file if 'foo' is provided via
 // the cli or defined in the environment.
	holster.SetOverride(&config.Foo, *argFoo, os.Env("FOO"))

Supply additional values and SetOverride() will choose the first value that is not of zero value. If all values are empty or zero the 'dest' will remain unchanged.

Types

This section is empty.

Jump to

Keyboard shortcuts

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