github.com/ronaksoft/rony@v0.16.26-0.20230807065236-1743dbfe6959/tools/getter.go (about)

     1  package tools
     2  
     3  /*
     4     Creation Time: 2021 - Jul - 04
     5     Created by:  (ehsan)
     6     Maintainers:
     7        1.  Ehsan N. Moosa (E2)
     8     Auditor: Ehsan N. Moosa (E2)
     9     Copyright Ronak Software Group 2020
    10  */
    11  
    12  func GetString(v interface{}, defaultValue string) string {
    13  	s, ok := v.(string)
    14  	if !ok {
    15  		return defaultValue
    16  	}
    17  
    18  	return s
    19  }
    20  
    21  func GetInt64(v interface{}, defaultValue int64) int64 {
    22  	s, ok := v.(int64)
    23  	if !ok {
    24  		return defaultValue
    25  	}
    26  
    27  	return s
    28  }
    29  
    30  func GetUint64(v interface{}, defaultValue uint64) uint64 {
    31  	s, ok := v.(uint64)
    32  	if !ok {
    33  		return defaultValue
    34  	}
    35  
    36  	return s
    37  }
    38  
    39  func GetInt32(v interface{}, defaultValue int32) int32 {
    40  	s, ok := v.(int32)
    41  	if !ok {
    42  		return defaultValue
    43  	}
    44  
    45  	return s
    46  }
    47  
    48  func GetUint32(v interface{}, defaultValue uint32) uint32 {
    49  	s, ok := v.(uint32)
    50  	if !ok {
    51  		return defaultValue
    52  	}
    53  
    54  	return s
    55  }
    56  
    57  func GetBytes(v interface{}, defaultValue []byte) []byte {
    58  	s, ok := v.([]byte)
    59  	if !ok {
    60  		return defaultValue
    61  	}
    62  
    63  	return s
    64  }