github.com/RevenueMonster/sqlike@v1.0.6/types/boolean.go (about)

     1  package types
     2  
     3  import (
     4  	"strconv"
     5  	"strings"
     6  )
     7  
     8  // Boolean :
     9  type Boolean bool
    10  
    11  // Scan :
    12  func (x *Boolean) Scan(src interface{}) error {
    13  	*x = false
    14  	switch vi := src.(type) {
    15  	case []byte:
    16  		{
    17  			val := strings.ToLower(string(vi))
    18  			switch val {
    19  			case "yes", "y":
    20  				*x = true
    21  			case "no", "n":
    22  				*x = false
    23  			default:
    24  				b, _ := strconv.ParseBool(val)
    25  				*x = Boolean(b)
    26  			}
    27  		}
    28  
    29  	case string:
    30  		{
    31  			vi = strings.ToLower(vi)
    32  			switch vi {
    33  			case "yes", "y":
    34  				*x = true
    35  			case "no", "n":
    36  				*x = false
    37  			default:
    38  				b, _ := strconv.ParseBool(vi)
    39  				*x = Boolean(b)
    40  			}
    41  		}
    42  
    43  	case int64:
    44  		{
    45  			if vi == 0 {
    46  				*x = Boolean(false)
    47  			} else if vi == 1 {
    48  				*x = Boolean(true)
    49  			}
    50  		}
    51  	}
    52  	return nil
    53  }