You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.2 KiB

package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"time"
"github.com/aws/aws-sdk-go/aws"
"www.andrewcsellers.com/andrew/shiptdemo/api"
"www.andrewcsellers.com/andrew/shiptdemo/config"
"www.andrewcsellers.com/andrew/shiptdemo/db"
)
var (
prod = flag.Bool("prod", false, "Use Production Mode")
)
func init() {
config.SetMode("prod")
if s := os.Getenv("AWSACCESS"); s != "" {
config.AccessKey = s
}
if s := os.Getenv("AWSSECRET"); s != "" {
config.SecretKey = s
}
if s := os.Getenv("AWSREGION"); s != "" {
config.Region = s
}
if s := os.Getenv("TOKENHOST"); s != "" {
config.TokenHost = s
}
if s := os.Getenv("TOKEN_HOST"); s != "" {
config.TokenHost = s
}
if s := os.Getenv("LISTENHOST"); s != "" {
config.ListenAddr = s
}
sess, err := config.AWSSession()
if err != nil {
log.Fatal("Cannot start AWS Session: ", err)
}
err = db.Init(sess, &aws.Config{Region: aws.String(config.Region)})
if err != nil {
log.Fatal("Database Init: ", err)
}
api.Init()
}
func main() {
go api.Serve()
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := api.Shutdown(ctx); err != nil {
log.Fatal(err)
}
}