forked from wisepythagoras/pos-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.go
59 lines (43 loc) · 947 Bytes
/
helpers.go
1
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
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"errors"
"log"
"net"
"strconv"
"github.com/gin-gonic/gin"
)
func DivMod(numerator, denominator int64) (quotient, remainder int64) {
quotient = numerator / denominator
remainder = numerator % denominator
return
}
func IntToColumnString(col int64) string {
str := ""
for col > 0 {
n, remainder := DivMod(col-1, 26)
str = string(65+remainder) + str
col = n
}
return str
}
func GetOutboundIP() net.IP {
conn, err := net.Dial("udp", "1.1.1.1:53")
if err != nil {
log.Fatal(err)
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP
}
// getIntFromParams parses an id from the param string.
func getIntFromParams(name string, c *gin.Context) (int, error) {
itemIdStr := c.Param(name)
if len(itemIdStr) == 0 {
return 0, errors.New("invalid numeric id")
}
itemId, err := strconv.Atoi(itemIdStr)
if err != nil {
return 0, err
}
return itemId, nil
}