extratypes

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

Extra Types

The current package contains types that I require in projects where the type never changes, and used globally.

Current Type Support

  • Duration - Ability to store time.Duration over JSON and database.
  • Numeric values - Ability to store and load int and uint family even when they are string for example.
  • Bool - Ability to take boolean value as int, string and boolean and convert to bool type, with nil support.

TODO

  • Add Tests for nil duration
  • Add more test covers for nil duration
  • Add More int and uint type support

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDestUnsupported = errors.New("Unsupported dest type")
)

Functions

This section is empty.

Types

type Bool added in v0.0.6

type Bool struct {
	sql.NullBool
	Val bool `json:"val" toml:"val"`
	Nil bool `json:"nil" toml:"nil"`
}

Bool contain a boolean data that can be null, and also string on JSON and SQL, but value will be converted into bool type

func (Bool) MarshalJSON added in v0.0.6

func (b Bool) MarshalJSON() ([]byte, error)

MarshalJSON implement the Marshaler interface

func (Bool) MarshalText added in v0.0.6

func (b Bool) MarshalText() ([]byte, error)

MarshalText implement Text Marshaller interface

func (*Bool) Scan added in v0.0.6

func (b *Bool) Scan(value interface{}) error

Scan implements the Scanner interface.

func (Bool) String added in v0.0.6

func (b Bool) String() string

func (*Bool) UnmarshalJSON added in v0.0.6

func (b *Bool) UnmarshalJSON(buf []byte) error

UnmarshalJSON implement the un-Marshaler interface

func (*Bool) UnmarshalText added in v0.0.6

func (b *Bool) UnmarshalText(buf []byte) error

UnmarshalText implement the text un-Marshaller interface

func (Bool) Value added in v0.0.6

func (b Bool) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Duration

type Duration struct {
	time.Duration
	Nil bool
}

Duration is wrapper for time.Duration with additional methods

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON takes a duration and marshal it as a string

func (*Duration) MarshalText added in v0.0.3

func (d *Duration) MarshalText() ([]byte, error)

MarshalText takes duration and marshal it as a string

func (*Duration) Scan

func (d *Duration) Scan(v interface{}) error

Scan the result from a query and assign it to the struct

func (Duration) String

func (d Duration) String() string

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON takes a slice of bytes and convert it to Duration

func (*Duration) UnmarshalText added in v0.0.3

func (d *Duration) UnmarshalText(b []byte) error

UnmarshalText unmar

func (Duration) Value

func (d Duration) Value() (driver.Value, error)

Value that the database usage will see

type Int added in v0.0.6

type Int struct {
	Val int
	Nil bool
}

Int struct contains int data type that can be null, and also string on JSON and SQL, but value will be converted to int type

func (Int) MarshalJSON added in v0.0.6

func (i Int) MarshalJSON() ([]byte, error)

MarshalJSON takes a Int and marshal it as a string

func (Int) MarshalText added in v0.0.6

func (i Int) MarshalText() ([]byte, error)

MarshalText takes a Int and marshal it as a string

func (*Int) Scan added in v0.0.6

func (i *Int) Scan(v interface{}) error

Scan implement the Scan function from db interface

func (Int) String added in v0.0.6

func (i Int) String() string

func (*Int) UnmarshalJSON added in v0.0.6

func (i *Int) UnmarshalJSON(b []byte) error

UnmarshalJSON takes a slice of bytes and convert it to Int

func (*Int) UnmarshalText added in v0.0.6

func (i *Int) UnmarshalText(b []byte) error

UnmarshalText takes a slice of bytes and convert it to Int

func (Int) Value added in v0.0.6

func (i Int) Value() (driver.Value, error)

Value interface for db

type SlicedString added in v0.0.7

type SlicedString []string

SlicedString parses and translate either a string or a slice of strings based on serialization JSON/Text/DB.

func (*SlicedString) Scan added in v0.0.7

func (s *SlicedString) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*SlicedString) UnmarshalJSON added in v0.0.7

func (s *SlicedString) UnmarshalJSON(data []byte) error

UnmarshalJSON for contacts

Jump to

Keyboard shortcuts

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