Blame view

int_util.go 641 Bytes
18fcd6d6b   Marko Tikvić   merged with util ...
1
  package webutility
cacf57bd4   Marko Tikvić   merging with /uti...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  
  import (
  	"fmt"
  	"strconv"
  )
  
  // ClampInt64 ...
  func ClampInt64(v, min, max int64) int64 {
  	if v < min {
  		return min
  	} else if v > max {
  		return max
  	}
  
  	return v
  }
  
  // InRangeInt64 ...
  func InRangeInt64(v, min, max int64) bool {
  	return (v >= min && v <= max)
  }
  
  // StringToInt64 ...
  func StringToInt64(s string) int64 {
  	i, _ := strconv.ParseInt(s, 10, 64)
  	return i
  }
  
  // Int64ToString ...
  func Int64ToString(i int64) string {
  	return fmt.Sprintf("%d", i)
  }
  
  // BoolToInt64 ...
  func BoolToInt64(b bool) int64 {
  	if b {
  		return 1
  	}
  	return 0
  }
  
  // Int64ToBool ...
  func Int64ToBool(i int64) bool {
  	return i != 0
  }