sure

package module
v0.0.0-...-c5948ed Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2018 License: GPL-2.0 Imports: 0 Imported by: 0

README

sure

-- import "github.com/anikhasibul/sure"

Package sure helps you to use interfaces with more confidence. It returns zero value when the confidence is not so good.

It helps you to code like this:

if sure.Bool(value){
    //..
} 

instead of

if v,ok := value.(bool); ok {

    //...

}

With sure:

var v = sure.Int(anInterface)

Without sure:

var (

    v int
    ok bool

) 
v, ok = anInterface.(int) if !ok {

    // hndle zero value

} 
// use `v` 

Usage

var PanicWhenWrong = false

PanicWhenWrong - when true it panics when the interface doesn't match with the prefered type. Default is false

func Bool
func Bool(value interface{}) bool

Bool returns bool

func Float32
func Float32(value interface{}) float32

Float32 returns float32

func Float64
func Float64(value interface{}) float64

Float64 returns float64

func HasSet
func HasSet(value interface{}) bool

HasSet returns false if the interface is nil

func Int
func Int(value interface{}) int

Int returns int

func Int64
func Int64(value interface{}) int64

Int64 returns int64

func String
func String(value interface{}) string

String returns string

Documentation

Overview

Package sure helps you to use interfaces with more confidence. It returns zero value when the confidence is not so good.

It helps you to code like this:

```

if sure.Bool(value){
	//..
}

```

instead of

```

if v,ok := value.(bool); ok {
	//...
}

```

With `sure`:

``` var v = sure.Int(anInterface) ```

Without `sure`:

``` var (

v int
ok bool

) v, ok = anInterface.(int)

if !ok {
	// hndle zero value
}

// use `v` ```

Index

Constants

This section is empty.

Variables

View Source
var PanicWhenWrong = false

PanicWhenWrong - when true it panics when the interface doesn't match with the prefered type. Default is false

Functions

func Bool

func Bool(value interface{}) bool

Bool returns bool

func Float32

func Float32(value interface{}) float32

Float32 returns float32

func Float64

func Float64(value interface{}) float64

Float64 returns float64

func HasSet

func HasSet(value interface{}) bool

HasSet returns false if the interface is nil

func Int

func Int(value interface{}) int

Int returns int

func Int64

func Int64(value interface{}) int64

Int64 returns int64

func String

func String(value interface{}) string

String returns string

Types

This section is empty.

Jump to

Keyboard shortcuts

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