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

2
Gopkg.lock generated
View File

@@ -286,6 +286,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "7fe7043406866580df73f74659708b2fdf217782ba07d20308ad056e03b93600"
inputs-digest = "51eae27f28863a252458b48550cafcecabcd948c8112922acf1a2a001a477226"
solver-name = "gps-cdcl"
solver-version = 1

View File

@@ -13,7 +13,6 @@ func Test_Route_Creation(t *testing.T) {
router := tuu.NewRouter()
router.GET("/testing", func(ctx tuu.Context) error { return nil })
routes := router.GetRoutes()
r.Len(routes, 1)
route := routes[0]

42
tuu.go
View File

@@ -1,12 +1,21 @@
package tuu
import (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"github.com/gorilla/mux"
)
type Config struct {
IPAddr string
Port string
}
func New(r Router) *App {
return &App{router: r}
}
@@ -15,7 +24,7 @@ type App struct {
router Router
}
func (a *App) Serve() error {
func (a *App) Serve(cfg Config) error {
r := mux.NewRouter()
for _, route := range a.router.GetRoutes() {
@@ -27,29 +36,26 @@ func (a *App) Serve() error {
}
server := http.Server{
Addr: "",
Addr: fmt.Sprintf("%s:%s", cfg.IPAddr, cfg.Port),
Handler: r,
}
/*ctx, cancel := sigtx.WithCancel(a.Context, syscall.SIGTERM, os.Interrupt)
defer cancel()
// Check for a closing signal
go func() {
// gracefully shut down the application when the context is cancelled
<-ctx.Done()
fmt.Println("Shutting down application")
// Graceful shutdown
sigquit := make(chan os.Signal, 1)
signal.Notify(sigquit, os.Interrupt, os.Kill)
err := a.Stop(ctx.Err())
if err != nil {
fmt.Println(err)
sig := <-sigquit
log.Printf("caught sig: %+v", sig)
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
return server.ListenAndServe()