Added route handler, views, utils, static assets, env engine
This commit is contained in:
parent
cdbd3ab3f0
commit
c410dd5480
11 changed files with 156 additions and 31 deletions
12
assets/css/bootstrap.min.css
vendored
Normal file
12
assets/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
14
assets/css/style.css
Normal file
14
assets/css/style.css
Normal file
|
@ -0,0 +1,14 @@
|
|||
footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
#footer-text {
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
7
assets/js/bootstrap.min.js
vendored
Normal file
7
assets/js/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
6
assets/js/popper.min.js
vendored
Normal file
6
assets/js/popper.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
25
main.go
25
main.go
|
@ -1,24 +1,41 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"gitea.hackmi.ch/Phil/gobin/routes"
|
||||
"gitea.hackmi.ch/Phil/gobin/utils"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/template/html"
|
||||
)
|
||||
|
||||
//go:embed views/*
|
||||
var viewsfs embed.FS
|
||||
|
||||
//go:embed assets/*
|
||||
var publicfs embed.FS
|
||||
|
||||
func main() {
|
||||
|
||||
engine := html.New("./views", ".html")
|
||||
utils.Init_ENV()
|
||||
|
||||
engine := html.NewFileSystem(http.FS(viewsfs), ".html")
|
||||
|
||||
app := fiber.New(fiber.Config{
|
||||
Views: engine,
|
||||
ServerHeader: "gobin",
|
||||
})
|
||||
|
||||
app.Get("/", func(c *fiber.Ctx) error {
|
||||
return c.Render("home", fiber.Map{})
|
||||
})
|
||||
utils.ActivateAssets(app, &publicfs)
|
||||
utils.ActivateLogger(app)
|
||||
|
||||
app.Get("/", routes.GetHome)
|
||||
|
||||
app.Get("/tos", routes.GetTos)
|
||||
app.Get("/privacy", routes.GetPrivacy)
|
||||
app.Get("/imprint", routes.GetImprint)
|
||||
|
||||
log.Fatal(app.Listen(":3000"))
|
||||
}
|
||||
|
|
7
routes/home.go
Normal file
7
routes/home.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package routes
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func GetHome(c *fiber.Ctx) error {
|
||||
return c.Render("views/home", fiber.Map{})
|
||||
}
|
15
routes/legal.go
Normal file
15
routes/legal.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package routes
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func GetTos(c *fiber.Ctx) error {
|
||||
return c.SendString("TOS")
|
||||
}
|
||||
|
||||
func GetPrivacy(c *fiber.Ctx) error {
|
||||
return c.SendString("privacy")
|
||||
}
|
||||
|
||||
func GetImprint(c *fiber.Ctx) error {
|
||||
return c.SendString("imprint")
|
||||
}
|
17
utils/assets.go
Normal file
17
utils/assets.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"net/http"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||
)
|
||||
|
||||
func ActivateAssets(app *fiber.App, publicfs *embed.FS) {
|
||||
app.Use("/assets", filesystem.New(filesystem.Config{
|
||||
Root: http.FS(publicfs),
|
||||
PathPrefix: "assets",
|
||||
Browse: false,
|
||||
}))
|
||||
}
|
36
utils/env.go
Normal file
36
utils/env.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
LOGGING string // Default true
|
||||
HOST string // Default ::1
|
||||
PORT string // Default 3000
|
||||
)
|
||||
|
||||
func Init_ENV() {
|
||||
var check bool
|
||||
// LOGGING
|
||||
uLOGGING, _ := os.LookupEnv("LOGGING")
|
||||
if uLOGGING == "false" {
|
||||
LOGGING = "false"
|
||||
} else {
|
||||
LOGGING = "true"
|
||||
}
|
||||
// HOST
|
||||
uHOST, check := os.LookupEnv("HOST")
|
||||
if !check {
|
||||
HOST = "0.0.0.0"
|
||||
} else {
|
||||
HOST = uHOST
|
||||
}
|
||||
// PORT
|
||||
uPORT, check := os.LookupEnv("HOST")
|
||||
if !check {
|
||||
PORT = "3000"
|
||||
} else {
|
||||
PORT = uPORT
|
||||
}
|
||||
}
|
12
utils/logs.go
Normal file
12
utils/logs.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||
)
|
||||
|
||||
func ActivateLogger(app *fiber.App) {
|
||||
if LOGGING == "true" {
|
||||
app.Use(logger.New())
|
||||
}
|
||||
}
|
|
@ -5,27 +5,11 @@
|
|||
<title>gobin</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<link href="https://bootswatch.com/5/sandstone/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/style.css">
|
||||
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
|
||||
|
||||
</head>
|
||||
|
||||
<style>
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
footer>div>center>p {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
</style>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
||||
|
@ -70,26 +54,24 @@
|
|||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-sm">
|
||||
<center><a class="text" href="/imprint">Imprint / Impressum</a></center>
|
||||
<center><a id="footer-text" class="text" href="/imprint">Imprint / Impressum</a></center>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<center><a class="text" href="/privacy">Privacy Policy</a></center>
|
||||
<center><a id="footer-text" class="text" href="/privacy">Privacy Policy</a></center>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<center><a class="text" href="/tos">Terms of Use</a></center>
|
||||
<center><a id="footer-text" class="text" href="/tos">Terms of Use</a></center>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<!-- Bootstrap JavaScript Libraries -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"
|
||||
integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous">
|
||||
</script>
|
||||
<script src="assets/js/popper.min.js">
|
||||
</script>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.min.js"
|
||||
integrity="sha384-7VPbUDkoPSGFnVtYi0QogXtr74QeVeeIs99Qfg5YCF+TidwNdjvaKZX19NZ/e6oz" crossorigin="anonymous">
|
||||
</script>
|
||||
<script src="assets/js/bootstrap.min.js">
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in a new issue