瀏覽代碼

Refactor code changes

Florian Hoss 2 年之前
父節點
當前提交
ecc8b98c45
共有 2 個文件被更改,包括 15 次插入11 次删除
  1. 11 8
      main.go
  2. 4 3
      routes.go

+ 11 - 8
main.go

@@ -1,20 +1,23 @@
 package main
 package main
 
 
 import (
 import (
-	"context"
-	"fmt"
-	"github.com/caarlos0/env/v6"
-	"github.com/labstack/echo/v4"
-	"go.uber.org/zap"
 	"godash/bookmarks"
 	"godash/bookmarks"
 	"godash/hub"
 	"godash/hub"
 	"godash/system"
 	"godash/system"
 	"godash/weather"
 	"godash/weather"
+
+	"context"
+	"fmt"
 	"html/template"
 	"html/template"
 	"net/http"
 	"net/http"
 	"os"
 	"os"
 	"os/signal"
 	"os/signal"
+	"syscall"
 	"time"
 	"time"
+
+	"github.com/caarlos0/env/v6"
+	"github.com/labstack/echo/v4"
+	"go.uber.org/zap"
 )
 )
 
 
 type goDash struct {
 type goDash struct {
@@ -56,7 +59,7 @@ func (g *goDash) startServer() {
 
 
 func (g *goDash) setupTemplateRender() {
 func (g *goDash) setupTemplateRender() {
 	g.router.Renderer = &TemplateRenderer{
 	g.router.Renderer = &TemplateRenderer{
-		templates: template.Must(template.ParseGlob("templates/*.gohtml")),
+		templates: template.Must(template.ParseGlob("templates/*.html")),
 	}
 	}
 }
 }
 
 
@@ -79,9 +82,9 @@ func main() {
 	go g.startServer()
 	go g.startServer()
 	g.logger.Infof("running on %s:%d", "http://localhost", g.config.Port)
 	g.logger.Infof("running on %s:%d", "http://localhost", g.config.Port)
 
 
-	// handle graceful shutdown
 	quit := make(chan os.Signal, 1)
 	quit := make(chan os.Signal, 1)
-	signal.Notify(quit, os.Interrupt)
+	// https://docs.docker.com/engine/reference/commandline/stop/
+	signal.Notify(quit, syscall.SIGTERM)
 	<-quit
 	<-quit
 	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
 	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
 	defer cancel()
 	defer cancel()

+ 4 - 3
routes.go

@@ -1,10 +1,11 @@
 package main
 package main
 
 
 import (
 import (
-	"github.com/gorilla/websocket"
-	"github.com/labstack/echo/v4"
 	"godash/hub"
 	"godash/hub"
 	"net/http"
 	"net/http"
+
+	"github.com/gorilla/websocket"
+	"github.com/labstack/echo/v4"
 )
 )
 
 
 var (
 var (
@@ -12,7 +13,7 @@ var (
 )
 )
 
 
 func (g *goDash) index(c echo.Context) error {
 func (g *goDash) index(c echo.Context) error {
-	return c.Render(http.StatusOK, "index.gohtml", map[string]interface{}{
+	return c.Render(http.StatusOK, "index.html", map[string]interface{}{
 		"Title":   g.config.Title,
 		"Title":   g.config.Title,
 		"Weather": g.info.weather.CurrentWeather,
 		"Weather": g.info.weather.CurrentWeather,
 		"Parsed":  g.info.bookmarks.Parsed,
 		"Parsed":  g.info.bookmarks.Parsed,