-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
|
||
"github.com/mpoegel/rsvp.pizza/pkg/pizza" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func main() { | ||
configFile := flag.String("config", "configs/pizza.yaml", "config file") | ||
flag.Parse() | ||
config, err := pizza.LoadConfig(*configFile) | ||
if err != nil { | ||
pizza.Log.Fatal("could not load config", zap.Error(err)) | ||
args := os.Args | ||
if len(args) < 2 { | ||
fmt.Println("command required: [run, edit]") | ||
os.Exit(1) | ||
} | ||
metricsReg := pizza.NewPrometheusRegistry() | ||
server, err := pizza.NewServer(config, metricsReg) | ||
if err != nil { | ||
pizza.Log.Fatal("could not create server", zap.Error(err)) | ||
switch args[1] { | ||
case "run": | ||
pizza.Run(os.Args[2:]) | ||
case "edit": | ||
// TODO | ||
default: | ||
fmt.Println("command must be one of [run, edit]") | ||
os.Exit(1) | ||
} | ||
|
||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, os.Interrupt) | ||
go func() { | ||
<-c | ||
pizza.Log.Info("shutting down") | ||
server.Stop() | ||
}() | ||
|
||
if config.MetricsPort != 0 { | ||
go metricsReg.Serve(config.MetricsPort) | ||
} | ||
|
||
server.Start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package pizza | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
"os/signal" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
func Run(args []string) { | ||
fs := flag.NewFlagSet("run", flag.ExitOnError) | ||
configFile := fs.String("config", "configs/pizza.yaml", "config file") | ||
fs.Parse(args) | ||
|
||
config, err := LoadConfig(*configFile) | ||
if err != nil { | ||
Log.Fatal("could not load config", zap.Error(err)) | ||
} | ||
metricsReg := NewPrometheusRegistry() | ||
server, err := NewServer(config, metricsReg) | ||
if err != nil { | ||
Log.Fatal("could not create server", zap.Error(err)) | ||
} | ||
|
||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, os.Interrupt) | ||
go func() { | ||
<-c | ||
Log.Info("shutting down") | ||
server.Stop() | ||
}() | ||
|
||
if config.MetricsPort != 0 { | ||
go metricsReg.Serve(config.MetricsPort) | ||
} | ||
|
||
server.Start() | ||
} |