nill

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: MIT Imports: 3 Imported by: 0

README

nill

Github Actions GoDoc Go Report Card

Features

  • Support for echo (web framework) https://echo.labstack.com/
  • The zero-value is 0, and is safe to use without initialization
  • Addition, subtraction, multiplication, division, modulo and etc.
  • JSON serialization/deserialization
  • Support for Custom JSON Encoder/Decoder

Install

Run go get github.com/RekeningkuDev/nill

Requirements

nill library requires Go version >=1.18

Usage

package main

import (
	"encoding/json"
	"fmt"
	"github.com/RekeningkuDev/nill"
	goJson "github.com/goccy/go-json"
)

func init() {
	// Custom JSON unmarshal or Unmarshal
	nill.JSONMarshal = goJson.Marshal
	nill.JSONUnmarshal = goJson.Unmarshal
}

func main() {
	price := nill.NewFloat64(50.99)
	// Add 
	subtotal := price.Mul(nill.NewFloat64(8))
	fmt.Println("Subtotal:", subtotal)    // Subtotal: 407.92
	
	// Custom type
	type product struct {
		Name nill.String `json:"name"`
		Price nill.Float64 `json:"price"`
    }
	
	type information struct {
		Product nill.Type[product] `json:"product"`
		Qty nill.Int `json:"qty"`
    }
	
	// JSON serialization/deserialization
	p := information{
		Product: nill.Type[product]{
			Valid: true,
			Value: product{
				Name: nill.NewString("Product A"),
				Price: nill.NewFloat64(50.99),
			},
		},
		Qty: nill.NewInt(8),
	}
	
	// Marshal
	b, err := json.Marshal(p)
	if err != nil {
        fmt.Println(err)
	}
	
	fmt.Println(string(b)) // {"product":{"name":"Product A","price":50.99},"qty":8}
}

Documentation

http://godoc.org/github.com/RekeningkuDev/nill

License

The MIT License (MIT)

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	JSONMarshal   = json.Marshal
	JSONUnmarshal = json.Unmarshal
)

Functions

This section is empty.

Types

type Float32 added in v0.2.0

type Float32 Type[float32]

Float32 is a wrapper for float32 type.

func NewFloat32 added in v0.2.0

func NewFloat32(value float32) Float32

NewFloat32 creates a new Float32.

func (*Float32) Add added in v0.2.0

func (v *Float32) Add(value float32)

Add adds value to Float32.

func (*Float32) Dec added in v0.2.0

func (v *Float32) Dec()

Dec decrements Float32 by 1.

func (*Float32) Div added in v0.2.0

func (v *Float32) Div(value float32)

Div divides Float32 by value.

func (*Float32) Inc added in v0.2.0

func (v *Float32) Inc()

Inc calculates the remainder of Float32 divided by value.

func (*Float32) Mul added in v0.2.0

func (v *Float32) Mul(value float32)

Mul multiplies Float32 by value.

func (*Float32) Negative added in v0.2.0

func (v *Float32) Negative() bool

Negative returns true if Float32 is negative.

func (*Float32) Positive added in v0.2.0

func (v *Float32) Positive() bool

Positive returns true if Float32 is positive.

func (*Float32) Sub added in v0.2.0

func (v *Float32) Sub(value float32)

Sub subtracts value from Float32.

func (*Float32) Zero added in v0.2.0

func (v *Float32) Zero() bool

Zero returns true if Float32 is zero.

type Float64 added in v0.2.0

type Float64 Type[float64]

func NewFloat64 added in v0.2.0

func NewFloat64(value float64) Float64

func (*Float64) Add added in v0.2.0

func (v *Float64) Add(value float64)

Add adds value to Float32.

func (*Float64) Dec added in v0.2.0

func (v *Float64) Dec()

Dec decrements Float32 by 1.

func (*Float64) Div added in v0.2.0

func (v *Float64) Div(value float64)

Div divides Float32 by value.

func (*Float64) Inc added in v0.2.0

func (v *Float64) Inc()

Inc calculates the remainder of Float32 divided by value.

func (*Float64) Mul added in v0.2.0

func (v *Float64) Mul(value float64)

Mul multiplies Float32 by value.

func (*Float64) Negative added in v0.2.0

func (v *Float64) Negative() bool

Negative returns true if Float32 is negative.

func (*Float64) Positive added in v0.2.0

func (v *Float64) Positive() bool

Positive returns true if Float32 is positive.

func (*Float64) Sub added in v0.2.0

func (v *Float64) Sub(value float64)

Sub subtracts value from Float32.

func (*Float64) Zero added in v0.2.0

func (v *Float64) Zero() bool

Zero returns true if Float32 is zero.

type Int added in v0.2.0

type Int Type[int]

Int is a wrapper for int type.

func NewInt added in v0.2.0

func NewInt(value int) Int

NewInt creates a new Int.

func (*Int) Add added in v0.2.0

func (v *Int) Add(value int)

Add adds value to Int.

func (*Int) Dec added in v0.2.0

func (v *Int) Dec()

Dec decrements Int by 1.

func (*Int) Div added in v0.2.0

func (v *Int) Div(value int)

Div divides Int by value.

func (*Int) DivisibleBy added in v0.2.0

func (v *Int) DivisibleBy(value int) bool

DivisibleBy returns true if Int is divisible by value.

func (*Int) Equal added in v0.2.0

func (v *Int) Equal(value int) bool

Equal returns true if Int is equal to value.

func (*Int) Even added in v0.2.0

func (v *Int) Even() bool

Even returns true if Int is even.

func (*Int) GreaterThan added in v0.2.0

func (v *Int) GreaterThan(value int) bool

GreaterThan returns true if Int is greater than value.

func (*Int) GreaterThanOrEqual added in v0.2.0

func (v *Int) GreaterThanOrEqual(value int) bool

GreaterThanOrEqual returns true if Int is greater than or equal to value.

func (*Int) Inc added in v0.2.0

func (v *Int) Inc()

Inc increments Int by 1.

func (*Int) LessThan added in v0.2.0

func (v *Int) LessThan(value int) bool

LessThan returns true if Int is less than value.

func (*Int) LessThanOrEqual added in v0.2.0

func (v *Int) LessThanOrEqual(value int) bool

LessThanOrEqual returns true if Int is less than or equal to value.

func (*Int) Mod added in v0.2.0

func (v *Int) Mod(value int)

Mod calculates the remainder of Int divided by value.

func (*Int) Mul added in v0.2.0

func (v *Int) Mul(value int)

Mul multiplies Int by value.

func (*Int) Negative added in v0.2.0

func (v *Int) Negative() bool

Negative returns true if Int is negative.

func (*Int) NotEqual added in v0.2.0

func (v *Int) NotEqual(value int) bool

NotEqual returns true if Int is not equal to value.

func (*Int) Odd added in v0.2.0

func (v *Int) Odd() bool

Odd returns true if Int is odd.

func (*Int) Positive added in v0.2.0

func (v *Int) Positive() bool

Positive returns true if Int is positive.

func (*Int) Prime added in v0.2.0

func (v *Int) Prime() bool

Prime returns true if Int is a prime number.

func (*Int) Sub added in v0.2.0

func (v *Int) Sub(value int)

Sub subtracts value from Int.

func (*Int) Zero added in v0.2.0

func (v *Int) Zero() bool

Zero returns true if Int is zero.

type Int16 added in v0.2.0

type Int16 Type[int16]

Int16 is a wrapper for int type.

func NewInt16 added in v0.2.0

func NewInt16(value int16) Int16

NewInt16 creates a new Int16.

func (*Int16) Add added in v0.2.0

func (v *Int16) Add(value int16)

Add adds value to Int16.

func (*Int16) Dec added in v0.2.0

func (v *Int16) Dec()

Dec decrements Int16 by 1.

func (*Int16) Div added in v0.2.0

func (v *Int16) Div(value int16)

Div divides Int16 by value.

func (*Int16) DivisibleBy added in v0.2.0

func (v *Int16) DivisibleBy(value int16) bool

DivisibleBy returns true if Int16 is divisible by value.

func (*Int16) Equal added in v0.2.0

func (v *Int16) Equal(value int16) bool

Equal returns true if Int16 is equal to value.

func (*Int16) Even added in v0.2.0

func (v *Int16) Even() bool

Even returns true if Int16 is even.

func (*Int16) GreaterThan added in v0.2.0

func (v *Int16) GreaterThan(value int16) bool

GreaterThan returns true if Int16 is greater than value.

func (*Int16) GreaterThanOrEqual added in v0.2.0

func (v *Int16) GreaterThanOrEqual(value int16) bool

GreaterThanOrEqual returns true if Int16 is greater than or equal to value.

func (*Int16) Inc added in v0.2.0

func (v *Int16) Inc()

Inc increments Int16 by 1.

func (*Int16) LessThan added in v0.2.0

func (v *Int16) LessThan(value int16) bool

LessThan returns true if Int16 is less than value.

func (*Int16) LessThanOrEqual added in v0.2.0

func (v *Int16) LessThanOrEqual(value int16) bool

LessThanOrEqual returns true if Int16 is less than or equal to value.

func (*Int16) Mod added in v0.2.0

func (v *Int16) Mod(value int16)

Mod calculates the remainder of Int16 divided by value.

func (*Int16) Mul added in v0.2.0

func (v *Int16) Mul(value int16)

Mul multiplies Int16 by value.

func (*Int16) Negative added in v0.2.0

func (v *Int16) Negative() bool

Negative returns true if Int16 is negative.

func (*Int16) NotEqual added in v0.2.0

func (v *Int16) NotEqual(value int16) bool

NotEqual returns true if Int16 is not equal to value.

func (*Int16) Odd added in v0.2.0

func (v *Int16) Odd() bool

Odd returns true if Int16 is odd.

func (*Int16) Positive added in v0.2.0

func (v *Int16) Positive() bool

Positive returns true if Int16 is positive.

func (*Int16) Prime added in v0.2.0

func (v *Int16) Prime() bool

Prime returns true if Int16 is a prime number.

func (*Int16) Sub added in v0.2.0

func (v *Int16) Sub(value int16)

Sub subtracts value from Int16.

func (*Int16) Zero added in v0.2.0

func (v *Int16) Zero() bool

Zero returns true if Int16 is zero.

type Int32 added in v0.2.0

type Int32 Type[int32]

Int32 is a wrapper for int type.

func NewInt32 added in v0.2.0

func NewInt32(value int32) Int32

NewInt32 creates a new Int32.

func (*Int32) Add added in v0.2.0

func (v *Int32) Add(value int32)

Add adds value to Int32.

func (*Int32) Dec added in v0.2.0

func (v *Int32) Dec()

Dec decrements Int32 by 1.

func (*Int32) Div added in v0.2.0

func (v *Int32) Div(value int32)

Div divides Int32 by value.

func (*Int32) DivisibleBy added in v0.2.0

func (v *Int32) DivisibleBy(value int32) bool

DivisibleBy returns true if Int32 is divisible by value.

func (*Int32) Equal added in v0.2.0

func (v *Int32) Equal(value int32) bool

Equal returns true if Int32 is equal to value.

func (*Int32) Even added in v0.2.0

func (v *Int32) Even() bool

Even returns true if Int32 is even.

func (*Int32) GreaterThan added in v0.2.0

func (v *Int32) GreaterThan(value int32) bool

GreaterThan returns true if Int32 is greater than value.

func (*Int32) GreaterThanOrEqual added in v0.2.0

func (v *Int32) GreaterThanOrEqual(value int32) bool

GreaterThanOrEqual returns true if Int32 is greater than or equal to value.

func (*Int32) Inc added in v0.2.0

func (v *Int32) Inc()

Inc increments Int32 by 1.

func (*Int32) LessThan added in v0.2.0

func (v *Int32) LessThan(value int32) bool

LessThan returns true if Int32 is less than value.

func (*Int32) LessThanOrEqual added in v0.2.0

func (v *Int32) LessThanOrEqual(value int32) bool

LessThanOrEqual returns true if Int32 is less than or equal to value.

func (*Int32) Mod added in v0.2.0

func (v *Int32) Mod(value int32)

Mod calculates the remainder of Int32 divided by value.

func (*Int32) Mul added in v0.2.0

func (v *Int32) Mul(value int32)

Mul multiplies Int32 by value.

func (*Int32) Negative added in v0.2.0

func (v *Int32) Negative() bool

Negative returns true if Int32 is negative.

func (*Int32) NotEqual added in v0.2.0

func (v *Int32) NotEqual(value int32) bool

NotEqual returns true if Int32 is not equal to value.

func (*Int32) Odd added in v0.2.0

func (v *Int32) Odd() bool

Odd returns true if Int32 is odd.

func (*Int32) Positive added in v0.2.0

func (v *Int32) Positive() bool

Positive returns true if Int32 is positive.

func (*Int32) Prime added in v0.2.0

func (v *Int32) Prime() bool

Prime returns true if Int32 is a prime number.

func (*Int32) Sub added in v0.2.0

func (v *Int32) Sub(value int32)

Sub subtracts value from Int32.

func (*Int32) Zero added in v0.2.0

func (v *Int32) Zero() bool

Zero returns true if Int32 is zero.

type Int64 added in v0.2.0

type Int64 Type[int64]

Int64 is a wrapper for int type.

func NewInt64 added in v0.2.0

func NewInt64(value int64) Int64

NewInt64 creates a new Int64.

func (*Int64) Add added in v0.2.0

func (v *Int64) Add(value int64)

Add adds value to Int64.

func (*Int64) Dec added in v0.2.0

func (v *Int64) Dec()

Dec decrements Int64 by 1.

func (*Int64) Div added in v0.2.0

func (v *Int64) Div(value int64)

Div divides Int64 by value.

func (*Int64) DivisibleBy added in v0.2.0

func (v *Int64) DivisibleBy(value int64) bool

DivisibleBy returns true if Int64 is divisible by value.

func (*Int64) Equal added in v0.2.0

func (v *Int64) Equal(value int64) bool

Equal returns true if Int64 is equal to value.

func (*Int64) Even added in v0.2.0

func (v *Int64) Even() bool

Even returns true if Int64 is even.

func (*Int64) GreaterThan added in v0.2.0

func (v *Int64) GreaterThan(value int64) bool

GreaterThan returns true if Int64 is greater than value.

func (*Int64) GreaterThanOrEqual added in v0.2.0

func (v *Int64) GreaterThanOrEqual(value int64) bool

GreaterThanOrEqual returns true if Int64 is greater than or equal to value.

func (*Int64) Inc added in v0.2.0

func (v *Int64) Inc()

Inc increments Int64 by 1.

func (*Int64) LessThan added in v0.2.0

func (v *Int64) LessThan(value int64) bool

LessThan returns true if Int64 is less than value.

func (*Int64) LessThanOrEqual added in v0.2.0

func (v *Int64) LessThanOrEqual(value int64) bool

LessThanOrEqual returns true if Int64 is less than or equal to value.

func (*Int64) Mod added in v0.2.0

func (v *Int64) Mod(value int64)

Mod calculates the remainder of Int64 divided by value.

func (*Int64) Mul added in v0.2.0

func (v *Int64) Mul(value int64)

Mul multiplies Int64 by value.

func (*Int64) Negative added in v0.2.0

func (v *Int64) Negative() bool

Negative returns true if Int64 is negative.

func (*Int64) NotEqual added in v0.2.0

func (v *Int64) NotEqual(value int64) bool

NotEqual returns true if Int64 is not equal to value.

func (*Int64) Odd added in v0.2.0

func (v *Int64) Odd() bool

Odd returns true if Int64 is odd.

func (*Int64) Positive added in v0.2.0

func (v *Int64) Positive() bool

Positive returns true if Int64 is positive.

func (*Int64) Prime added in v0.2.0

func (v *Int64) Prime() bool

Prime returns true if Int64 is a prime number.

func (*Int64) Sub added in v0.2.0

func (v *Int64) Sub(value int64)

Sub subtracts value from Int64.

func (*Int64) Zero added in v0.2.0

func (v *Int64) Zero() bool

Zero returns true if Int64 is zero.

type Int8 added in v0.2.0

type Int8 Type[int8]

Int8 is a wrapper for int type.

func NewInt8 added in v0.2.0

func NewInt8(value int8) Int8

NewInt8 creates a new Int8.

func (*Int8) Add added in v0.2.0

func (v *Int8) Add(value int8)

Add adds value to Int8.

func (*Int8) Dec added in v0.2.0

func (v *Int8) Dec()

Dec decrements Int8 by 1.

func (*Int8) Div added in v0.2.0

func (v *Int8) Div(value int8)

Div divides Int8 by value.

func (*Int8) DivisibleBy added in v0.2.0

func (v *Int8) DivisibleBy(value int8) bool

DivisibleBy returns true if Int8 is divisible by value.

func (*Int8) Equal added in v0.2.0

func (v *Int8) Equal(value int8) bool

Equal returns true if Int8 is equal to value.

func (*Int8) Even added in v0.2.0

func (v *Int8) Even() bool

Even returns true if Int8 is even.

func (*Int8) GreaterThan added in v0.2.0

func (v *Int8) GreaterThan(value int8) bool

GreaterThan returns true if Int8 is greater than value.

func (*Int8) GreaterThanOrEqual added in v0.2.0

func (v *Int8) GreaterThanOrEqual(value int8) bool

GreaterThanOrEqual returns true if Int8 is greater than or equal to value.

func (*Int8) Inc added in v0.2.0

func (v *Int8) Inc()

Inc increments Int8 by 1.

func (*Int8) LessThan added in v0.2.0

func (v *Int8) LessThan(value int8) bool

LessThan returns true if Int8 is less than value.

func (*Int8) LessThanOrEqual added in v0.2.0

func (v *Int8) LessThanOrEqual(value int8) bool

LessThanOrEqual returns true if Int8 is less than or equal to value.

func (*Int8) Mod added in v0.2.0

func (v *Int8) Mod(value int8)

Mod calculates the remainder of Int8 divided by value.

func (*Int8) Mul added in v0.2.0

func (v *Int8) Mul(value int8)

Mul multiplies Int8 by value.

func (*Int8) Negative added in v0.2.0

func (v *Int8) Negative() bool

Negative returns true if Int8 is negative.

func (*Int8) NotEqual added in v0.2.0

func (v *Int8) NotEqual(value int8) bool

NotEqual returns true if Int8 is not equal to value.

func (*Int8) Odd added in v0.2.0

func (v *Int8) Odd() bool

Odd returns true if Int8 is odd.

func (*Int8) Positive added in v0.2.0

func (v *Int8) Positive() bool

Positive returns true if Int8 is positive.

func (*Int8) Prime added in v0.2.0

func (v *Int8) Prime() bool

Prime returns true if Int8 is a prime number.

func (*Int8) Sub added in v0.2.0

func (v *Int8) Sub(value int8)

Sub subtracts value from Int8.

func (*Int8) Zero added in v0.2.0

func (v *Int8) Zero() bool

Zero returns true if Int8 is zero.

type String added in v0.2.0

type String Type[string]

func NewString added in v0.2.0

func NewString(value string) String

type Type

type Type[T any] sql.Null[T]
Example
package main

import (
	"encoding/json"
	"fmt"
	"log"

	"github.com/RekeningkuDev/nill"
)

func main() {
	type BarTest struct {
		Text nill.Type[string] `json:"text"`
	}

	type FooTest struct {
		Bar nill.Type[BarTest] `json:"bar"`
	}

	foo := FooTest{
		Bar: nill.Type[BarTest]{
			Valid: true,
			V: BarTest{
				Text: nill.Type[string]{
					Valid: true,
					V:     "test",
				},
			},
		},
	}

	jsonStr, err := json.Marshal(foo)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(string(jsonStr))
}
Output:

{"bar":{"text":"test"}}

func New

func New[T any](v T) Type[T]

func (Type[T]) MarshalJSON

func (n Type[T]) MarshalJSON() ([]byte, error)

func (*Type[T]) Scan added in v1.1.0

func (t *Type[T]) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (*Type[T]) UnmarshalJSON

func (n *Type[T]) UnmarshalJSON(data []byte) error

func (Type[T]) Value

func (t Type[T]) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

Jump to

Keyboard shortcuts

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