From 10f08282bb7053a12e866d917e3901f4f7bf5595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabi=C3=A1n=20Monsalve?= Date: Wed, 13 Dec 2023 16:30:25 -0500 Subject: [PATCH] feat: add initial app to drop files --- go.mod | 3 +++ go.sum | 6 ++++++ main.go | 18 +++++++++++++++--- network/network.go | 2 ++ views/assets/style.css | 24 ++++++++++++++++++++++++ views/index.html | 18 ++++++++++++++++++ 6 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 views/assets/style.css create mode 100644 views/index.html diff --git a/go.mod b/go.mod index 62a6b35..29ca0d1 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,9 @@ go 1.21.5 require ( github.com/andybalholm/brotli v1.0.5 // 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/joho/godotenv v1.5.1 // indirect github.com/klauspost/compress v1.16.7 // indirect diff --git a/go.sum b/go.sum index 04f6f65..3ab7279 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,12 @@ github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/ github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/gofiber/fiber/v2 v2.51.0 h1:JNACcZy5e2tGApWB2QrRpenTWn0fq0hkFm6k0C86gKQ= github.com/gofiber/fiber/v2 v2.51.0/go.mod h1:xaQRZQJGqnKOQnbQw+ltvku3/h8QxvNi8o6JiJ7Ll0U= +github.com/gofiber/template v1.8.2 h1:PIv9s/7Uq6m+Fm2MDNd20pAFFKt5wWs7ZBd8iV9pWwk= +github.com/gofiber/template v1.8.2/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8= +github.com/gofiber/template/html/v2 v2.0.5 h1:BKLJ6Qr940NjntbGmpO3zVa4nFNGDCi/IfUiDB9OC20= +github.com/gofiber/template/html/v2 v2.0.5/go.mod h1:RCF14eLeQDCSUPp0IGc2wbSSDv6yt+V54XB/+Unz+LM= +github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= +github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= diff --git a/main.go b/main.go index a9c314d..a61b3d8 100644 --- a/main.go +++ b/main.go @@ -1,21 +1,33 @@ package main import ( + "log" + "github.com/buildtheui/DropMyFile/network" "github.com/gofiber/fiber/v2" + "github.com/gofiber/template/html/v2" "github.com/joho/godotenv" ) func main() { godotenv.Load(".env") - app := fiber.New() + // Load templates + engine := html.New("./views", ".html") + + + app := fiber.New(fiber.Config{ + Views: engine, + }) + + // Load extra needed files for the views like css or js + app.Static("/assets", "./views/assets") app.Get("/", func(c *fiber.Ctx) error { - return c.SendString("Hello, World!") + return c.Render("index", fiber.Map{}) }) network.PrintLanServerIpQr() - app.Listen(":" + network.GetServerPort()) + log.Fatal(app.Listen(":" + network.GetServerPort())) } \ No newline at end of file diff --git a/network/network.go b/network/network.go index 16a17b8..0992f96 100644 --- a/network/network.go +++ b/network/network.go @@ -1,6 +1,7 @@ package network import ( + "fmt" "log" "net" "os" @@ -12,6 +13,7 @@ func PrintLanServerIpQr() { myIp, _ := getLocalIp() serverAddr := "http://" + myIp + ":" + GetServerPort() qrterminal.Generate(serverAddr, qrterminal.L, os.Stdout) + fmt.Println("Or go to: " + serverAddr) } func getLocalIp() (string, error) { diff --git a/views/assets/style.css b/views/assets/style.css new file mode 100644 index 0000000..2f23225 --- /dev/null +++ b/views/assets/style.css @@ -0,0 +1,24 @@ +/* style.css */ +body { + font-size: "62.5%"; + font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; + line-height: 1.5; + font-weight: 400; + + background-color: #f4f4f4; + margin: 0; + padding: 0; +} + +h1 { + color: #333; + font-family: 1.6rem; +} + +form { + margin-top: 20px; + padding: 20px; + background-color: #fff; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} diff --git a/views/index.html b/views/index.html new file mode 100644 index 0000000..2d5fcbe --- /dev/null +++ b/views/index.html @@ -0,0 +1,18 @@ + + + + + + + Drop my file + + +

Select your files to transfer

+
+ + +
+ +
+ +