58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
/*
|
|
Petit site web pour montrer une hiérarchie de fichiers.
|
|
Copyright (C) 2021 rick <rick@gnous.eu>
|
|
|
|
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 the Free Software
|
|
Foundation, either version 3 of the License, or (at your option) any later
|
|
version.
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
//"fmt"
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/template/html"
|
|
)
|
|
|
|
func index(c *fiber.Ctx) error {
|
|
var f []string
|
|
path := c.Params("*")
|
|
|
|
if len(path) == 0 {
|
|
path = "/"
|
|
} else {
|
|
path = "/" + path
|
|
}
|
|
|
|
files, _ := ioutil.ReadDir("public/" + path)
|
|
|
|
f = append(f, "..")
|
|
for _, file := range files {
|
|
if file.IsDir() {
|
|
f = append(f, file.Name() + "/")
|
|
} else if filepath.Ext(file.Name()) == ".html" {
|
|
f = append(f, file.Name())
|
|
}
|
|
}
|
|
|
|
return c.Render("index", fiber.Map{"path": path,"lists": f,})
|
|
}
|
|
|
|
func main() {
|
|
app := fiber.New(fiber.Config{Views: html.New("./views", ".html"),})
|
|
app.Static("/", "./public")
|
|
app.Get("/*", index)
|
|
app.Listen(":8080")
|
|
}
|