zero

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2021 License: MIT Imports: 1 Imported by: 4

README

vincentinttsh/zero

Build Status codecov Go Report Card GoDoc

Check if golang struct is empty

package main

import (
        "fmt"

        "github.com/vincentinttsh/zero"
)

type Structure struct {
        ID int
}

func ExampleStructure() {
        zeroStructure := Structure{}
        zeroStructurePointer := &zeroStructure
        nonZero := Structure{ID: 1}
        nonZeroPointer := &nonZero
        fmt.Println(zero.IsZero(zeroStructure))        // true
        fmt.Println(zero.IsZero(zeroStructurePointer)) // true
        fmt.Println(zero.IsZero(nonZero))              // false
        fmt.Println(zero.IsZero(nonZeroPointer))       // false
        // Output:
        // true
        // true
        // false
        // false
}

func main() {
        ExampleStructure()
}

Documentation

Overview

Package zero provides a zero check for arbitrary values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsZero

func IsZero(v interface{}) bool

IsZero reports whether v is zero struct Does not support cycle pointers for performance, so as json

Types

This section is empty.

Jump to

Keyboard shortcuts

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