github.com/haraldrudell/parl@v0.4.176/pstrings/defaultvalue.go (about)

     1  /*
     2  © 2021–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package pstrings
     7  
     8  import (
     9  	"time"
    10  
    11  	"github.com/haraldrudell/parl/perrors"
    12  )
    13  
    14  func IsDefaultValue(pt interface{}) (isDefault bool) {
    15  	switch p := pt.(type) {
    16  	case *bool:
    17  		return !*p
    18  	case *time.Duration:
    19  		return *p == 0
    20  	case *float64:
    21  		return *p == 0
    22  	case *int64:
    23  		return *p == 0
    24  	case *int:
    25  		return *p == 0
    26  	case *string:
    27  		return *p == ""
    28  	case *uint64:
    29  		return *p == 0
    30  	case *uint:
    31  		return *p == 0
    32  	case *[]string:
    33  		return len(*p) == 0
    34  	default:
    35  		panic(perrors.Errorf("unknown pointer type: %T", p))
    36  	}
    37  }