-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (36 loc) · 1.37 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
package main
import (
"flag"
"fmt"
"os"
"github.com/Suhaibinator/SuhaibMessageQueue/config"
"github.com/Suhaibinator/SuhaibMessageQueue/server"
)
func init() {
// Custom usage function to display help information
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), "Options:\n")
flag.PrintDefaults()
fmt.Fprintf(flag.CommandLine.Output(), "\nAll flags are optional. Environment variables or default values are used if flags are not provided.\n")
fmt.Fprintf(flag.CommandLine.Output(), "Environment Variables:\n")
fmt.Fprintf(flag.CommandLine.Output(), " %s: Path to the SQLite database file (default \"%s\")\n", config.ENV_DB_PATH, config.DBPath)
fmt.Fprintf(flag.CommandLine.Output(), " %s: Port to listen on (default \"%s\")\n", config.ENV_PORT, config.Port)
}
// Check environment variables
if dbPath, exists := os.LookupEnv(config.ENV_DB_PATH); exists {
config.DBPath = dbPath
}
if port, exists := os.LookupEnv(config.ENV_PORT); exists {
config.Port = port
}
// Check program arguments
flag.StringVar(&config.DBPath, "dbpath", config.DBPath, "path to the SQLite database file")
flag.StringVar(&config.Port, "port", config.Port, "port to listen on")
flag.Parse()
}
func main() {
// Start the server
server := server.NewServer(config.Port, config.DBPath)
server.Start()
}