Clean up main a little
This commit is contained in:
parent
4423678786
commit
013a69fa63
1 changed files with 11 additions and 3 deletions
14
main.go
14
main.go
|
@ -19,19 +19,23 @@ var data = flag.String("data", os.TempDir(), "Directory to store persistant data
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
// Print the version if requested
|
||||||
if *ver {
|
if *ver {
|
||||||
fmt.Println(version.Version)
|
fmt.Println(version.Version)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Initialising version %s...\n", version.Version)
|
||||||
|
|
||||||
// Set the persistence path
|
// Set the persistence path
|
||||||
persistence.SetPath(*data)
|
persistence.SetPath(*data)
|
||||||
|
|
||||||
|
// Create the server data
|
||||||
s := server.NewServer(
|
s := server.NewServer(
|
||||||
server.OptionPort(*port),
|
server.OptionPort(*port),
|
||||||
server.OptionPersistentData())
|
server.OptionPersistentData())
|
||||||
|
|
||||||
fmt.Printf("Initialising version %s...\n", version.Version)
|
// Initialise the server
|
||||||
if err := s.Initialise(); err != nil {
|
if err := s.Initialise(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -42,14 +46,18 @@ func main() {
|
||||||
go func() {
|
go func() {
|
||||||
<-c
|
<-c
|
||||||
fmt.Println("SIGTERM recieved, exiting...")
|
fmt.Println("SIGTERM recieved, exiting...")
|
||||||
s.Close()
|
if err := s.Close(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
fmt.Println("Initialised")
|
fmt.Println("Running...")
|
||||||
|
|
||||||
|
// Run the server
|
||||||
s.Run()
|
s.Run()
|
||||||
|
|
||||||
|
// Close the server
|
||||||
if err := s.Close(); err != nil {
|
if err := s.Close(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue