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

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