Skip to content
forked from ernado/zero

Check if golang struct is empty

License

Notifications You must be signed in to change notification settings

vincentinttsh/zero

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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()
}

About

Check if golang struct is empty

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%