first

package module
v0.0.0-...-4f70a30 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2018 License: MIT Imports: 1 Imported by: 0

README

first

Hi. I like to add fallback logic to my programs, but sometimes it's awkward.

I wrote this little library so we can write:

use(first.String(os.Getenv("CONFIG_FIELD_NAME"), "some sort of default"))

as opposed to:

configValue := os.Getenv("CONFIG_FIELD_NAME")
if configValue == "" {
    configValue = "some sort of default"
}
use(configValue)

First also supports:

  • frist.String("arbitrary", "numbers", "of", "arguments")
  • s := "pointers"; first.String(&s)
  • first.String(func() { return "functions returning strings" })
  • Interfaces with a String() string method
  • first.Error(err1, err2)

Don't panic().

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(errors ...error) error

Error returns the first non-nil argument or nil.

func String

func String(stringables ...interface{}) string

String returns the first non-nil, non-empty argument. It supports strings, string pointers, functions returning strings, and stringers.

Types

This section is empty.

Jump to

Keyboard shortcuts

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