-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (38 loc) · 788 Bytes
/
main.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
package main
import (
"fmt"
"log"
"math"
"os"
"strconv"
"strings"
"budget/database"
"budget/api"
"github.com/joho/godotenv"
)
func DollarStringToCents(s string) (int, error) {
s = strings.ReplaceAll(s, "$", "")
s = strings.ReplaceAll(s, ",", "")
amount, err := strconv.ParseFloat(s, 32)
if err != nil {
return 0, err
}
return int(math.Round(amount * 100)), nil
}
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
db, err := database.Create()
if err != nil {
log.Fatal("Error opening database:", err)
}
defer db.Close()
PORT, err := strconv.Atoi(os.Getenv("PORT"))
if err != nil {
log.Fatal("Error parsing PORT env variable:", err)
}
fmt.Println("Running at port", PORT)
log.Fatal(api.Start(PORT, db))
}