-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (35 loc) · 1.17 KB
/
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
package main
import (
"handySports/api/database"
"handySports/api/routes"
"log"
)
func init() {
// Load environment variables from .env file
loadEnv()
// get the variable for the database connection
connectString := GetEnv("DB_CONNECT_STRING", "ws://localhost:8000/rpc")
// username := GetEnv("DB_USERNAME", "root")
// password := GetEnv("DB_PASSWORD", "root")
namespace := GetEnv("DB_NAMESPACE", "default")
collection := GetEnv("DB_COLLECTION", "default")
// Connect to the database
// database.Connect(connectString, username, password, namespace, collection)
database.Connect(connectString, namespace, collection)
}
func main() {
// Load environment variables
fullUrl := GetEnv("API_URL", "http://localhost:8080/api/v1")
port := GetEnv("API_PORT", "8080")
basePath := GetEnv("API_BASE_PATH", "/api")
apiVersion := GetEnv("API_VERSION", "v1")
router := routes.SetupRoutes(database.DB, basePath, apiVersion)
// router.Use(middleware.CORSMiddleware())
//
// Start the server
log.Printf("API version %s", apiVersion)
log.Printf("Starting server on port %s", port)
log.Printf("API URL : %s", fullUrl)
log.Fatal(router.Run(":" + port))
defer database.DB.Close()
}