SAVEPOINT

This commit is contained in:
2017-11-10 22:43:33 +00:00
parent 59301c7622
commit 57af3d95d0
3 changed files with 25 additions and 20 deletions
Generated
+1 -1
View File
@@ -286,6 +286,6 @@
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "7fe7043406866580df73f74659708b2fdf217782ba07d20308ad056e03b93600" inputs-digest = "51eae27f28863a252458b48550cafcecabcd948c8112922acf1a2a001a477226"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1
-1
View File
@@ -13,7 +13,6 @@ func Test_Route_Creation(t *testing.T) {
router := tuu.NewRouter() router := tuu.NewRouter()
router.GET("/testing", func(ctx tuu.Context) error { return nil }) router.GET("/testing", func(ctx tuu.Context) error { return nil })
routes := router.GetRoutes() routes := router.GetRoutes()
r.Len(routes, 1) r.Len(routes, 1)
route := routes[0] route := routes[0]
+24 -18
View File
@@ -1,12 +1,21 @@
package tuu package tuu
import ( import (
"context"
"fmt"
"log" "log"
"net/http" "net/http"
"os"
"os/signal"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
type Config struct {
IPAddr string
Port string
}
func New(r Router) *App { func New(r Router) *App {
return &App{router: r} return &App{router: r}
} }
@@ -15,7 +24,7 @@ type App struct {
router Router router Router
} }
func (a *App) Serve() error { func (a *App) Serve(cfg Config) error {
r := mux.NewRouter() r := mux.NewRouter()
for _, route := range a.router.GetRoutes() { for _, route := range a.router.GetRoutes() {
@@ -27,29 +36,26 @@ func (a *App) Serve() error {
} }
server := http.Server{ server := http.Server{
Addr: "", Addr: fmt.Sprintf("%s:%s", cfg.IPAddr, cfg.Port),
Handler: r, Handler: r,
} }
/*ctx, cancel := sigtx.WithCancel(a.Context, syscall.SIGTERM, os.Interrupt) // Check for a closing signal
defer cancel()
go func() { go func() {
// gracefully shut down the application when the context is cancelled // Graceful shutdown
<-ctx.Done() sigquit := make(chan os.Signal, 1)
fmt.Println("Shutting down application") signal.Notify(sigquit, os.Interrupt, os.Kill)
err := a.Stop(ctx.Err()) sig := <-sigquit
if err != nil { log.Printf("caught sig: %+v", sig)
fmt.Println(err) log.Printf("Gracefully shutting down server...")
if err := server.Shutdown(context.Background()); err != nil {
log.Printf("Unable to shut down server: %v", err)
} else {
log.Println("Server stopped")
} }
}()
err = server.Shutdown(ctx)
if err != nil {
fmt.Println(err)
}
}()*/
// start the web server // start the web server
return server.ListenAndServe() return server.ListenAndServe()