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

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