コード例 #1
0
func askOnRuntime(va ...interface{}) (int64, int64, int64, int64) {
	var v [4]int64
	var typeof = ""
	for i := 0; i < 4; i++ {
		if i < len(va) {
			typeof = as.String(reflect.TypeOf(va[i]))
		} else {
			typeof = "nil"
		}

		if typeof == "int" || typeof == "int8" || typeof == "int16" || typeof == "int32" || typeof == "int64" {
			v[i] = as.Int(va[i])
		} else {
			switch i {
			case 0:
				v[i] = as.Int(askFor("first value"))
			case 1:
				v[i] = as.Int(askFor("second value"))
			case 2:
				v[i] = as.Int(askFor("third value"))
			case 3:
				v[i] = as.Int(askFor("fourth value"))
			}
		}
	}
	return v[0], v[1], v[2], v[3]
}
コード例 #2
0
func defaultValue(va ...interface{}) (int64, int64, int64, int64) {
	var v [4]int64
	var typeof = ""
	for i := 0; i < 4; i++ {
		if i < len(va) {
			typeof = as.String(reflect.TypeOf(va[i]))
		} else {
			typeof = "nil"
		}

		if typeof == "int" || typeof == "int8" || typeof == "int16" || typeof == "int32" || typeof == "int64" {
			v[i] = as.Int(va[i])
		} else {
			switch i {
			case 0:
				v[i] = 2
			case 1:
				v[i] = 4
			case 2:
				v[i] = 8
			case 3:
				v[i] = 16
			}
		}
	}
	return v[0], v[1], v[2], v[3]
}
コード例 #3
0
ファイル: all.go プロジェクト: stvvan/golibs
func main() {
	floats := []float64{1.4, 3.14, 9.81, 13.2, 23.42, 33.7, 44.11, 51}
	array := stack.Lifo()
	array.Push(fmt.Sprintf("Lorem %v", ansi.Color("Ipsum", ansi.Blue)))
	array.Push(fmt.Sprintf("Dolor %v", ansi.Bold("sit Amet")))
	array.Push(fmt.Sprintf("5th Prime: %v", xmath.Prime(5)))
	array.Push(fmt.Sprintf("\n\tMin: %v\n\tMax: %v\n\tMedian: %v\n\tArithmetic: %v\n\tHarmonic: %v\n\tGeometric: %v", xmath.Min(floats), xmath.Max(floats), xmath.Median(floats), xmath.Arithmetic(floats), xmath.Harmonic(floats), xmath.Geometric(floats)))
	array.Push(fmt.Sprintf("Date: %v", as.Time("11.01.2015")))
	for array.Len() > 0 {
		log.Println(array.Pop())
	}

	array.Push(string(as.Bytes(regex.ReplaceAllString("foobar", "o+", "u"))))
	array.Push(as.Int(23.0000))
	array.Push(as.Float(13.37))
	array.Push(as.String(23.0))
	array.Push(as.Bool(111111))
	array.Push(as.Bytes(12.34))
	array.Push(as.String(strconv.ParseInt("42", 10, 0)))
	array.Push(as.FloatFromXString("2,3"))
	array.Push(as.FloatFromXString(".23"))
	array.Push(as.String("\r\n\t\n"))
	for array.Len() > 0 {
		log.Println(array.Pop())
	}
}
コード例 #4
0
func optionalValue(v ...interface{}) (int64, error) {
	countArguments := len(v)
	if countArguments < 4 && countArguments > 0 { //we check for the right amount of arguments
		switch countArguments {
		case 1:
			return as.Int(v[0]), nil
		case 2:
			return as.Int(v[0]) * as.Int(v[1]), nil
		case 3:
			return as.Int(v[0]) * as.Int(v[1]) * as.Int(v[2]), nil
		}
	}
	return int64(len(v)), errors.New(fmt.Sprintf("wrong number of arguments, expected between 1 and 3, discovered %v", countArguments))
}