mira

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: MIT Imports: 1 Imported by: 2

README

Mira Go Report Card

This package wraps the reflect package and adds some useful methods for introspecting Go values.

Installation

$ go get github.com/stevenferrer/mira

Usage


import (
    "fmt"

    "github.com/stevenferrer/mira"
)

func main() {
    v := int64(1)
    typeInfo := mira.NewTypeInfo(v)

    // check if value is numeric
    if typeInfo.IsNumeric() {
        fmt.Println("value is a numeric type")
    }

    // check if value is nillable
    if typeInfo.IsNillable() {
        fmt.Println("value is nillable")
    }

    // print type's name
    fmt.Println(typeInfo.Name())
    // print type's pkg path
    fmt.Println(typeInfo.PkgPath())
    // print the interface value
    fmt.Printf("%v\n", typeInfo.V())
    // print the reflect.Type's string representation
    fmt.Printf("%v", typeInfo.T().String())
    ...
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr

func BoolPtr(b bool) *bool

BoolPtr bool to *bool

func Complex128Ptr

func Complex128Ptr(c complex128) *complex128

Complex128Ptr complex128 to *complex128

func Complex64Ptr

func Complex64Ptr(c complex64) *complex64

Complex64Ptr complex64 to *complex64

func Float32Ptr

func Float32Ptr(f float32) *float32

Float32Ptr float32 to *float32

func Float64Ptr

func Float64Ptr(f float64) *float64

Float64Ptr float64 to *float64

func Int16Ptr

func Int16Ptr(i int16) *int16

Int16Ptr int16 to *int16

func Int32Ptr

func Int32Ptr(i int32) *int32

Int32Ptr int32 to *int32

func Int64Ptr

func Int64Ptr(i int64) *int64

Int64Ptr int64 to *int64

func Int8Ptr

func Int8Ptr(i int8) *int8

Int8Ptr int8 to *int8

func IntPtr

func IntPtr(i int) *int

IntPtr int to *int

func StrPtr

func StrPtr(s string) *string

StrPtr string to *string

func Uint16Ptr

func Uint16Ptr(u uint16) *uint16

Uint16Ptr uint16 to *uint16

func Uint32Ptr

func Uint32Ptr(u uint32) *uint32

Uint32Ptr uint32 to *uint32

func Uint64Ptr

func Uint64Ptr(u uint64) *uint64

Uint64Ptr uint64 to *uint64

func Uint8Ptr

func Uint8Ptr(u uint8) *uint8

Uint8Ptr uint8 to *uint8

func UintPtr

func UintPtr(u uint) *uint

UintPtr uint to *uint

Types

type TypeInfo

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

TypeInfo is a type info

func NewTypeInfo

func NewTypeInfo(v interface{}) TypeInfo

NewTypeInfo instrospects v and returns a TypeInfo

func (TypeInfo) IsNillable

func (ti TypeInfo) IsNillable() bool

IsNillable returns true if the type is nillable (i.e. slices, maps and pointers)

func (TypeInfo) IsNumeric

func (ti TypeInfo) IsNumeric() bool

IsNumeric returns true if the type is numeric i.e. int, uint or float.

func (TypeInfo) Name

func (ti TypeInfo) Name() string

Name returns the name of the type within its package for a defined type.

This also works with arrays, slices and pointers.

func (TypeInfo) PkgPath

func (ti TypeInfo) PkgPath() string

PkgPath returns a defined type's package path.

This also works with arrays, slices, maps and pointers.

func (TypeInfo) T

func (ti TypeInfo) T() reflect.Type

T returns the reflect.Type

func (TypeInfo) V

func (ti TypeInfo) V() interface{}

V returns the interface value

Jump to

Keyboard shortcuts

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