Reorganized directories and packages.
This commit is contained in:
parent
1018d82d13
commit
72ce41c828
61 changed files with 83 additions and 83 deletions
71
cmd/web/main.go
Normal file
71
cmd/web/main.go
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/mikestefanello/pagoda/pkg/routes"
|
||||
"github.com/mikestefanello/pagoda/pkg/services"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Start a new container
|
||||
c := services.NewContainer()
|
||||
defer func() {
|
||||
if err := c.Shutdown(); err != nil {
|
||||
c.Web.Logger.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Build the router
|
||||
routes.BuildRouter(c)
|
||||
|
||||
// Start the server
|
||||
go func() {
|
||||
srv := http.Server{
|
||||
Addr: fmt.Sprintf("%s:%d", c.Config.HTTP.Hostname, c.Config.HTTP.Port),
|
||||
Handler: c.Web,
|
||||
ReadTimeout: c.Config.HTTP.ReadTimeout,
|
||||
WriteTimeout: c.Config.HTTP.WriteTimeout,
|
||||
IdleTimeout: c.Config.HTTP.IdleTimeout,
|
||||
}
|
||||
|
||||
if c.Config.HTTP.TLS.Enabled {
|
||||
certs, err := tls.LoadX509KeyPair(c.Config.HTTP.TLS.Certificate, c.Config.HTTP.TLS.Key)
|
||||
if err != nil {
|
||||
c.Web.Logger.Fatalf("cannot load TLS certificate: %v", err)
|
||||
}
|
||||
|
||||
srv.TLSConfig = &tls.Config{
|
||||
Certificates: []tls.Certificate{certs},
|
||||
}
|
||||
}
|
||||
|
||||
if err := c.Web.StartServer(&srv); err != http.ErrServerClosed {
|
||||
c.Web.Logger.Fatalf("shutting down the server: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Start the scheduler service to queue periodic tasks
|
||||
go func() {
|
||||
if err := c.Tasks.StartScheduler(); err != nil {
|
||||
c.Web.Logger.Fatalf("scheduler shutdown: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for interrupt signal to gracefully shutdown the server with a timeout of 10 seconds.
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, os.Interrupt)
|
||||
signal.Notify(quit, os.Kill)
|
||||
<-quit
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if err := c.Web.Shutdown(ctx); err != nil {
|
||||
c.Web.Logger.Fatal(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue