github.com/orangenpresse/up@v0.6.0/cmd/up-proxy/main.go (about) 1 package main 2 3 import ( 4 "os" 5 "time" 6 7 "github.com/apex/go-apex" 8 "github.com/apex/log" 9 "github.com/apex/log/handlers/json" 10 11 "github.com/apex/up" 12 "github.com/apex/up/handler" 13 "github.com/apex/up/internal/logs" 14 "github.com/apex/up/internal/proxy" 15 "github.com/apex/up/internal/util" 16 "github.com/apex/up/platform/aws/runtime" 17 ) 18 19 func main() { 20 start := time.Now() 21 stage := os.Getenv("UP_STAGE") 22 23 // setup logging 24 log.SetHandler(json.Default) 25 if s := os.Getenv("LOG_LEVEL"); s != "" { 26 log.SetLevelFromString(s) 27 } 28 29 log.Log = log.WithFields(logs.Fields()) 30 log.Info("initializing") 31 32 // read config 33 c, err := up.ReadConfig("up.json") 34 if err != nil { 35 log.Fatalf("error reading config: %s", err) 36 } 37 38 ctx := log.WithFields(log.Fields{ 39 "name": c.Name, 40 "type": c.Type, 41 }) 42 43 // init project 44 p := runtime.New(c) 45 46 // init runtime 47 if err := p.Init(stage); err != nil { 48 ctx.Fatalf("error initializing: %s", err) 49 } 50 51 // overrides 52 if err := c.Override(stage); err != nil { 53 ctx.Fatalf("error overriding: %s", err) 54 } 55 56 // create handler 57 h, err := handler.FromConfig(c) 58 if err != nil { 59 ctx.Fatalf("error creating handler: %s", err) 60 } 61 62 // init handler 63 h, err = handler.New(c, h) 64 if err != nil { 65 ctx.Fatalf("error initializing handler: %s", err) 66 } 67 68 // serve 69 log.WithField("duration", util.MillisecondsSince(start)).Info("initialized") 70 apex.Handle(proxy.NewHandler(h)) 71 }