Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typo error message AccountDB to UserDB #42

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
326 changes: 163 additions & 163 deletions README.MD

Large diffs are not rendered by default.

33 changes: 27 additions & 6 deletions cmd/api/server/server.go
@@ -1,10 +1,12 @@
package server

import (
"context"
"net/http"
"os"
"os/signal"
"time"

"github.com/facebookgo/grace/gracehttp"
"github.com/go-playground/validator"
"github.com/labstack/echo/middleware"
"github.com/ribice/gorsk/cmd/api/config"
Expand All @@ -30,11 +32,30 @@ func healthCheck(c echo.Context) error {
return c.JSON(http.StatusOK, "OK")
}

// Start starts echo server
// Start starts echo server handling graceful shutdown, needs go1.8+.
func Start(e *echo.Echo, cfg *config.Server) {
e.Server.Addr = cfg.Port
e.Server.ReadTimeout = time.Duration(cfg.ReadTimeout) * time.Minute
e.Server.WriteTimeout = time.Duration(cfg.WriteTimeout) * time.Minute
s := &http.Server{
Addr: cfg.Port,
ReadTimeout: time.Duration(cfg.ReadTimeout) * time.Minute,
WriteTimeout: time.Duration(cfg.WriteTimeout) * time.Minute,
}
e.Debug = cfg.Debug
e.Logger.Fatal(gracehttp.Serve(e.Server))

// Start server
go func() {
if err := e.StartServer(s); err != nil {
e.Logger.Info("Shutting down the server")
}
}()

// Wait for interrupt signal to gracefully shutdown the server with
// a timeout of 10 seconds.
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := e.Shutdown(ctx); err != nil {
e.Logger.Fatal(err)
}
}