-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainFunctions.go
More file actions
106 lines (74 loc) · 1.88 KB
/
mainFunctions.go
File metadata and controls
106 lines (74 loc) · 1.88 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"strconv"
"strings"
"time"
)
func generateApiKey(s string) string {
var timeNow string = time.Now().Format("010206")
result := strings.Split(s, "")
result1 := result[0:26]
result1WithDate := append(result1, timeNow)
userApiKey := strings.Join(result1WithDate, "")
return userApiKey
}
func retrieveUserApiKey(un string) string {
var apiKey string
rows, err := db.Query(`SELECT apiKey FROM usersDB where un =?`, un)
check(err)
defer rows.Close()
for rows.Next() {
err = rows.Scan(&apiKey)
check(err)
}
return apiKey
}
func showSessions() {
fmt.Println("********")
fmt.Println("")
}
func checkPostalCodeInputValidity(s []string) bool {
for _, v := range s {
if len(v) != 9 {
return false
}
}
for _, v := range s {
OperatingHours := strings.Split(v, "")
startingTimeSlice := OperatingHours[:4] //gives me the first 4 digits representing the operating hours
endingTimeASlice := OperatingHours[6:] //gives me the last 4 digits representing the closing hours
startingTimeString := strings.Join(startingTimeSlice, "")
endingTimeString := strings.Join(endingTimeASlice, "")
startingTimeInt, err := strconv.Atoi(startingTimeString)
if err != nil {
fmt.Println("error occured when converting starting time's string to int")
return false
}
endingTimeInt, err2 := strconv.Atoi(endingTimeString)
if err2 != nil {
fmt.Println("error occured when converting starting time's string to int")
return false
}
if startingTimeInt < endingTimeInt {
return false
}
}
return true
}
func toTitle(s string) string {
slice := strings.Split(s, "")
var pos []int
for i := 0; i < len(slice); i++ {
if slice[i] == " " {
pos = append(pos, i+1)
i++
}
}
pos = append(pos, 0)
for i := 0; i < len(pos); i++ {
slice[pos[i]] = strings.ToUpper(slice[pos[i]])
}
result := strings.Join(slice, "")
return result
}