gitlab.com/evatix-go/core@v1.3.55/coreutils/stringutil/ToInt16Default.go (about)

     1  package stringutil
     2  
     3  import (
     4  	"math"
     5  	"strconv"
     6  
     7  	"gitlab.com/evatix-go/core/constants"
     8  )
     9  
    10  func ToInt16Default(
    11  	s string,
    12  ) int16 {
    13  	toInt, err := strconv.Atoi(s)
    14  
    15  	if err != nil {
    16  		return constants.Zero
    17  	}
    18  
    19  	if toInt >= math.MinInt16 && toInt <= math.MaxInt16 {
    20  		return int16(toInt)
    21  	}
    22  
    23  	return constants.Zero
    24  }