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 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 ( require (
github.com/andybalholm/brotli v1.0.6 // indirect 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 v1.8.2 // indirect
github.com/gofiber/template/html/v2 v2.0.5 // indirect
github.com/gofiber/utils v1.1.0 // indirect github.com/gofiber/utils v1.1.0 // indirect
github.com/google/uuid v1.4.0 // indirect github.com/google/uuid v1.4.0 // indirect
github.com/klauspost/compress v1.17.4 // 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-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // 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/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect

13
main.go
View File

@ -1,7 +1,7 @@
/* /*
* website | MatterLinux Official Website * website | MatterLinux Official Website
* MatterLinux 2023-2024 (https://matterlinux.xyz) * MatterLinux 2023-2024 (https://matterlinux.xyz)
* This program is free software: you can redistribute it and/or modify * 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 * 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package main package main
import ( import (
"log"
"git.matterlinux.xyz/Matter/website/lib" "git.matterlinux.xyz/Matter/website/lib"
"git.matterlinux.xyz/Matter/website/routes" "git.matterlinux.xyz/Matter/website/routes"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
"github.com/gofiber/template/html/v2" "github.com/gofiber/template/html/v2"
) )
func main(){ func main(){
log.SetFlags(log.Lshortfile | log.Ltime)
engine := html.New("./templates", ".html") engine := html.New("./templates", ".html")
app := fiber.New(fiber.Config{ app := fiber.New(fiber.Config{
DisableStartupMessage: true, DisableStartupMessage: true,
@ -50,7 +53,7 @@ func main(){
return lib.RenderError(c, 404) 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") err := app.Listen(":9878")
if err != nil { if err != nil {
log.Fatalf("Error starting server: %s", err) log.Fatalf("Error starting server: %s", err)

View File

@ -1,15 +1,16 @@
package routes package routes
import ( import (
"log"
"git.matterlinux.xyz/Matter/website/lib" "git.matterlinux.xyz/Matter/website/lib"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
) )
func DownloadRoute(c *fiber.Ctx) error{ func DownloadRoute(c *fiber.Ctx) error{
con, err := lib.GetContent("", "download") con, err := lib.GetContent("", "download")
if err != nil { if err != nil {
log.Error("GetContent -> ", err) log.Printf("GetContent failed: %s", err.Error())
return lib.RenderError(c, 500) return lib.RenderError(c, 500)
} }

View File

@ -1,15 +1,16 @@
package routes package routes
import ( import (
"log"
"git.matterlinux.xyz/Matter/website/lib" "git.matterlinux.xyz/Matter/website/lib"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
) )
func IndexRoute(c *fiber.Ctx) error{ func IndexRoute(c *fiber.Ctx) error{
con, err := lib.GetContent("", "index") con, err := lib.GetContent("", "index")
if err != nil { if err != nil {
log.Error("GetContent -> ", err) log.Printf("GetContent failed: %s", err.Error())
return lib.RenderError(c, 500) return lib.RenderError(c, 500)
} }

View File

@ -1,30 +1,30 @@
package routes package routes
import ( import (
"log"
"sort" "sort"
"git.matterlinux.xyz/Matter/website/lib" "git.matterlinux.xyz/Matter/website/lib"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
) )
func NewsRoute(c *fiber.Ctx) error { func NewsRoute(c *fiber.Ctx) error {
contents, err := lib.ListContent("news") contents, err := lib.ListContent("news")
if err != nil { if err != nil {
log.Errorf("ListContent -> %s", err.Error()) log.Printf("ListContent failed: %s", err.Error())
return lib.RenderError(c, 500) return lib.RenderError(c, 500)
} }
sort.Slice(contents, func(i, j int) bool { sort.Slice(contents, func(i, j int) bool {
time1, err := lib.TimeFromString(contents[i].Date) time1, err := lib.TimeFromString(contents[i].Date)
if err != nil { if err != nil {
log.Errorf("Bad date while sorting: %s", err.Error()) log.Printf("Bad date while sorting: %s", err.Error())
return false return false
} }
time2, err := lib.TimeFromString(contents[j].Date) time2, err := lib.TimeFromString(contents[j].Date)
if err != nil { if err != nil {
log.Errorf("Bad date while sorting: %s", err.Error()) log.Printf("Bad date while sorting: %s", err.Error())
return false return false
} }
@ -44,7 +44,7 @@ func PostRoute(c *fiber.Ctx) error {
contents, err := lib.ListContent("news") contents, err := lib.ListContent("news")
if err != nil { if err != nil {
log.Errorf("ListContent -> %s", err.Error()) log.Printf("ListContent failed: %s", err.Error())
return lib.RenderError(c, 500) return lib.RenderError(c, 500)
} }
@ -55,7 +55,7 @@ func PostRoute(c *fiber.Ctx) error {
con, err = lib.GetContent(con.Dir, con.Name) con, err = lib.GetContent(con.Dir, con.Name)
if err != nil { if err != nil {
log.Errorf("GetContent -> %s", err.Error()) log.Printf("ListContent failed: %s", err.Error())
return lib.RenderError(c, 500) return lib.RenderError(c, 500)
} }

View File

@ -1,15 +1,16 @@
package routes package routes
import ( import (
"log"
"git.matterlinux.xyz/Matter/website/lib" "git.matterlinux.xyz/Matter/website/lib"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
) )
func WikiMainRoute(c *fiber.Ctx) error { func WikiMainRoute(c *fiber.Ctx) error {
con, err := lib.GetContent("wiki", "main") con, err := lib.GetContent("wiki", "main")
if err != nil { if err != nil {
log.Error("GetContent -> ", err) log.Printf("GetContent failed: %s", err.Error())
return lib.RenderError(c, 500) return lib.RenderError(c, 500)
} }
@ -27,7 +28,7 @@ func WikiRoute(c *fiber.Ctx) error{
contents, err := lib.ListContent("wiki") contents, err := lib.ListContent("wiki")
if err != nil { if err != nil {
log.Errorf("ListContent -> %s", err.Error()) log.Printf("ListContent failed: %s", err.Error())
return lib.RenderError(c, 500) return lib.RenderError(c, 500)
} }
@ -38,7 +39,7 @@ func WikiRoute(c *fiber.Ctx) error{
con, err = lib.GetContent(con.Dir, con.Name) con, err = lib.GetContent(con.Dir, con.Name)
if err != nil { if err != nil {
log.Errorf("GetContent -> %s", err.Error()) log.Printf("GetContent failed: %s", err.Error())
return lib.RenderError(c, 500) return lib.RenderError(c, 500)
} }