From 275053ddb38ec5cc5f44b6f3a061cb188766b294 Mon Sep 17 00:00:00 2001 From: ngn Date: Tue, 19 Mar 2024 23:16:26 +0300 Subject: [PATCH] update: remove fiber's log module --- go.mod | 9 ++++++--- main.go | 13 ++++++++----- routes/download.go | 5 +++-- routes/index.go | 5 +++-- routes/news.go | 12 ++++++------ routes/wiki.go | 9 +++++---- 6 files changed, 31 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index 7dbd5f2..0066ea6 100644 --- a/go.mod +++ b/go.mod @@ -2,11 +2,15 @@ module git.matterlinux.xyz/Matter/website go 1.21.4 +require ( + github.com/gofiber/fiber/v2 v2.51.0 + github.com/gofiber/template/html/v2 v2.0.5 + github.com/russross/blackfriday/v2 v2.1.0 +) + require ( github.com/andybalholm/brotli v1.0.6 // indirect - github.com/gofiber/fiber/v2 v2.51.0 // indirect github.com/gofiber/template v1.8.2 // indirect - github.com/gofiber/template/html/v2 v2.0.5 // indirect github.com/gofiber/utils v1.1.0 // indirect github.com/google/uuid v1.4.0 // indirect github.com/klauspost/compress v1.17.4 // indirect @@ -14,7 +18,6 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/rivo/uniseg v0.4.4 // indirect - github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.51.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect diff --git a/main.go b/main.go index f7536e2..bb96808 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ /* - * website | MatterLinux Official Website - * MatterLinux 2023-2024 (https://matterlinux.xyz) + * website | MatterLinux Official Website + * MatterLinux 2023-2024 (https://matterlinux.xyz) * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,19 +16,22 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ package main import ( + "log" + "git.matterlinux.xyz/Matter/website/lib" "git.matterlinux.xyz/Matter/website/routes" "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/log" "github.com/gofiber/template/html/v2" ) func main(){ + log.SetFlags(log.Lshortfile | log.Ltime) + engine := html.New("./templates", ".html") app := fiber.New(fiber.Config{ DisableStartupMessage: true, @@ -50,7 +53,7 @@ func main(){ return lib.RenderError(c, 404) }) - log.Info("Starting MatterLinux Website on port 9878") + log.Println("Starting MatterLinux Website on port 9878") err := app.Listen(":9878") if err != nil { log.Fatalf("Error starting server: %s", err) diff --git a/routes/download.go b/routes/download.go index 58248b6..b74a097 100644 --- a/routes/download.go +++ b/routes/download.go @@ -1,15 +1,16 @@ package routes import ( + "log" + "git.matterlinux.xyz/Matter/website/lib" "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/log" ) func DownloadRoute(c *fiber.Ctx) error{ con, err := lib.GetContent("", "download") if err != nil { - log.Error("GetContent -> ", err) + log.Printf("GetContent failed: %s", err.Error()) return lib.RenderError(c, 500) } diff --git a/routes/index.go b/routes/index.go index 61e2499..4448057 100644 --- a/routes/index.go +++ b/routes/index.go @@ -1,15 +1,16 @@ package routes import ( + "log" + "git.matterlinux.xyz/Matter/website/lib" "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/log" ) func IndexRoute(c *fiber.Ctx) error{ con, err := lib.GetContent("", "index") if err != nil { - log.Error("GetContent -> ", err) + log.Printf("GetContent failed: %s", err.Error()) return lib.RenderError(c, 500) } diff --git a/routes/news.go b/routes/news.go index 0619e68..1848481 100644 --- a/routes/news.go +++ b/routes/news.go @@ -1,30 +1,30 @@ package routes import ( + "log" "sort" "git.matterlinux.xyz/Matter/website/lib" "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/log" ) func NewsRoute(c *fiber.Ctx) error { contents, err := lib.ListContent("news") if err != nil { - log.Errorf("ListContent -> %s", err.Error()) + log.Printf("ListContent failed: %s", err.Error()) return lib.RenderError(c, 500) } sort.Slice(contents, func(i, j int) bool { time1, err := lib.TimeFromString(contents[i].Date) if err != nil { - log.Errorf("Bad date while sorting: %s", err.Error()) + log.Printf("Bad date while sorting: %s", err.Error()) return false } time2, err := lib.TimeFromString(contents[j].Date) if err != nil { - log.Errorf("Bad date while sorting: %s", err.Error()) + log.Printf("Bad date while sorting: %s", err.Error()) return false } @@ -44,7 +44,7 @@ func PostRoute(c *fiber.Ctx) error { contents, err := lib.ListContent("news") if err != nil { - log.Errorf("ListContent -> %s", err.Error()) + log.Printf("ListContent failed: %s", err.Error()) return lib.RenderError(c, 500) } @@ -55,7 +55,7 @@ func PostRoute(c *fiber.Ctx) error { con, err = lib.GetContent(con.Dir, con.Name) if err != nil { - log.Errorf("GetContent -> %s", err.Error()) + log.Printf("ListContent failed: %s", err.Error()) return lib.RenderError(c, 500) } diff --git a/routes/wiki.go b/routes/wiki.go index d39add2..97b2941 100644 --- a/routes/wiki.go +++ b/routes/wiki.go @@ -1,15 +1,16 @@ package routes import ( + "log" + "git.matterlinux.xyz/Matter/website/lib" "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/log" ) func WikiMainRoute(c *fiber.Ctx) error { con, err := lib.GetContent("wiki", "main") if err != nil { - log.Error("GetContent -> ", err) + log.Printf("GetContent failed: %s", err.Error()) return lib.RenderError(c, 500) } @@ -27,7 +28,7 @@ func WikiRoute(c *fiber.Ctx) error{ contents, err := lib.ListContent("wiki") if err != nil { - log.Errorf("ListContent -> %s", err.Error()) + log.Printf("ListContent failed: %s", err.Error()) return lib.RenderError(c, 500) } @@ -38,7 +39,7 @@ func WikiRoute(c *fiber.Ctx) error{ con, err = lib.GetContent(con.Dir, con.Name) if err != nil { - log.Errorf("GetContent -> %s", err.Error()) + log.Printf("GetContent failed: %s", err.Error()) return lib.RenderError(c, 500) }