Skip to content
/ nil Public

Golang immutable nilable structures to avoid pointers for nil values.

License

Notifications You must be signed in to change notification settings

vvelikodny/nil

Repository files navigation

Build Status

nil

Golang immutable nilable structures to avoid pointers for nil values.

status

development in progress

Usage

package main

import (
	"bytes"
	"encoding/json"
	"fmt"

	"github.com/vvelikodny/nil"
)

type Json struct {
	Field nil.String `json:"field"`
}

func main() {
    str1 := nil.NewNilString()
    str2 := nil.NewString("value")
    
    var b bytes.Buffer
    json.NewEncoder(&b).Encode(Json{
        Field: null.NewNilString(),
    })
    // `{"field":null}`
    fmt.Println(b.String())
    
    var b *bool
    value := nil.FromBoolPtr(b)
    // `nil? true`
    fmt.Println("nil? ", value.Nil())
    
    b = true
    value := nil.FromBoolPtr(&b)
    // `nil? false`
    fmt.Println("nil?", value.Nil())
}

About

Golang immutable nilable structures to avoid pointers for nil values.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages