update: remove fiber's log module

This commit is contained in:
ngn 2024-03-19 23:16:26 +03:00
parent ce2a577f97
commit 275053ddb3
6 changed files with 31 additions and 22 deletions

9
go.mod
View File

@ -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

13
main.go
View File

@ -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 <https://www.gnu.org/licenses/>.
*/
*/
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)

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}