gitlab.com/evatix-go/core@v1.3.55/converters/StringToIntegerWithDefault.go (about)

     1  package converters
     2  
     3  import (
     4  	"strconv"
     5  
     6  	"gitlab.com/evatix-go/core/constants"
     7  )
     8  
     9  func StringToIntegerWithDefault(
    10  	input string,
    11  	defaultInt int,
    12  ) (value int, isSuccess bool) {
    13  	if input == constants.EmptyString {
    14  		return defaultInt, false
    15  	}
    16  
    17  	convertedVal, err := strconv.Atoi(input)
    18  
    19  	if err != nil {
    20  		return defaultInt, false
    21  	}
    22  
    23  	return convertedVal, true
    24  }