From cdc2bdaeb0b23fb1655c5ea4b37a39a79b357c54 Mon Sep 17 00:00:00 2001 From: Phil Date: Wed, 9 Apr 2025 20:39:49 +0200 Subject: [PATCH 1/2] removed views --- views/404.html | 68 ---------------------------------- views/home.html | 98 ------------------------------------------------- 2 files changed, 166 deletions(-) delete mode 100644 views/404.html delete mode 100644 views/home.html diff --git a/views/404.html b/views/404.html deleted file mode 100644 index ea1ba5c..0000000 --- a/views/404.html +++ /dev/null @@ -1,68 +0,0 @@ - - - - - Uff 404 - - - - - - - - - - -
-

:(


-

A 404 error occured, Page not found, check the URL and try again.

-
-

Ein 404 Fehler ist aufgetreten, Seite nicht gefunden, überprüfen Sie die URL und versuchen Sie es erneut.

-
-

404 エラーが発生しました。ページが見つかりません。URLを確認して、再試行してください。

-
-

发生 404 错误,找不到页面,请检查 URL 并重试。

- -

-

Return to home | Go Back -

-
- - - - - - - \ No newline at end of file diff --git a/views/home.html b/views/home.html deleted file mode 100644 index 7a64b09..0000000 --- a/views/home.html +++ /dev/null @@ -1,98 +0,0 @@ - - - - - goshorly - - - - - - - - - - -

-
-
-

goshorly

-

An dead simple & fast URL shortener.
- All shorten URLs will be available for 30days! -

- {{ if and .TotalLinks .TotalViews }} -

This Instance has served over {{ .TotalLinks }} URLs and {{ .TotalViews }} total Views!

- {{ end }} -
-
-
- -
-
- -
-
-
-
- - - {{ if .URL }} -
- -
-
- -
-
- {{ end }} - - - {{ if .ERR }} -
-

{{ .ERR }}

-
- {{ end }} - -
- - - - - - - - - - -- 2.45.3 From fce20e7c61abe71de539410342921fec53a5e7fb Mon Sep 17 00:00:00 2001 From: Phil Date: Wed, 9 Apr 2025 21:06:28 +0200 Subject: [PATCH 2/2] removed renderings to comments --- LICENSE | 2 +- go.mod | 4 +- go.sum | 6 --- main.go | 9 ---- routes/gethome.go | 12 +----- routes/id.go | 5 +-- routes/posthome.go | 102 +++++++++++++++++++++++---------------------- utils/limiter.go | 9 +--- 8 files changed, 58 insertions(+), 91 deletions(-) diff --git a/LICENSE b/LICENSE index 57bbc4c..34c58c2 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SOFTWARE. \ No newline at end of file diff --git a/go.mod b/go.mod index 882a4ec..2212f40 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ toolchain go1.24.2 require ( github.com/go-redis/redis/v8 v8.11.5 github.com/gofiber/fiber/v2 v2.52.6 - github.com/gofiber/template/html/v2 v2.1.3 github.com/joho/godotenv v1.5.1 github.com/matoous/go-nanoid/v2 v2.1.0 ) @@ -16,8 +15,6 @@ require ( github.com/andybalholm/brotli v1.1.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect - github.com/gofiber/template v1.8.3 // indirect - github.com/gofiber/utils v1.1.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.18.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect @@ -25,6 +22,7 @@ require ( github.com/mattn/go-runewidth v0.0.16 // indirect github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect github.com/rivo/uniseg v0.4.7 // indirect + github.com/stretchr/testify v1.10.0 // indirect github.com/tinylib/msgp v1.2.5 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.60.0 // indirect diff --git a/go.sum b/go.sum index f28ea52..e69f83c 100644 --- a/go.sum +++ b/go.sum @@ -12,12 +12,6 @@ github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/gofiber/fiber/v2 v2.52.6 h1:Rfp+ILPiYSvvVuIPvxrBns+HJp8qGLDnLJawAu27XVI= github.com/gofiber/fiber/v2 v2.52.6/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw= -github.com/gofiber/template v1.8.3 h1:hzHdvMwMo/T2kouz2pPCA0zGiLCeMnoGsQZBTSYgZxc= -github.com/gofiber/template v1.8.3/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8= -github.com/gofiber/template/html/v2 v2.1.3 h1:n1LYBtmr9C0V/k/3qBblXyMxV5B0o/gpb6dFLp8ea+o= -github.com/gofiber/template/html/v2 v2.1.3/go.mod h1:U5Fxgc5KpyujU9OqKzy6Kn6Qup6Tm7zdsISR+VpnHRE= -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.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.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 8b6a70b..c03e9f1 100644 --- a/main.go +++ b/main.go @@ -1,21 +1,15 @@ package main import ( - "embed" "log" - "net/http" "git.hackmi.ch/Phil/goshorly/db" "git.hackmi.ch/Phil/goshorly/routes" "git.hackmi.ch/Phil/goshorly/utils" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/limiter" - "github.com/gofiber/template/html/v2" ) -//go:embed views/* -var viewsfs embed.FS - func main() { utils.Print_Starting_Screen() utils.Init_env_file() @@ -24,11 +18,8 @@ func main() { db.Init_redis() - engine := html.NewFileSystem(http.FS(viewsfs), ".html") - app := fiber.New(fiber.Config{ CaseSensitive: true, - Views: engine, }) app.Get("/", routes.Gethome) diff --git a/routes/gethome.go b/routes/gethome.go index ac9a63d..79c2856 100644 --- a/routes/gethome.go +++ b/routes/gethome.go @@ -1,19 +1,9 @@ package routes import ( - "git.hackmi.ch/Phil/goshorly/db" - "git.hackmi.ch/Phil/goshorly/utils" "github.com/gofiber/fiber/v2" ) func Gethome(c *fiber.Ctx) error { - return c.Render("views/home", fiber.Map{ - "CI_COMMIT_SHA": utils.CI_COMMIT_SHA, - "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, - "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, - "CI_TAGGED": utils.CI_TAGGED, - "CI_BUILD": utils.CI_BUILD, - "TotalLinks": db.GetTotalLinks(), - "TotalViews": db.GetTotalViews(), - }) + return c.SendString("Homepage") } diff --git a/routes/id.go b/routes/id.go index e0075eb..54c06a7 100644 --- a/routes/id.go +++ b/routes/id.go @@ -4,7 +4,6 @@ import ( "log" "git.hackmi.ch/Phil/goshorly/db" - "git.hackmi.ch/Phil/goshorly/utils" "github.com/gofiber/fiber/v2" ) @@ -18,9 +17,7 @@ func ID(c *fiber.Ctx) error { "url": "URL not found", }) } else { - return c.Render("views/404", fiber.Map{ - "BASEURL": utils.URL, - }) + return c.SendStatus(404) } } diff --git a/routes/posthome.go b/routes/posthome.go index a568222..495be53 100644 --- a/routes/posthome.go +++ b/routes/posthome.go @@ -27,16 +27,16 @@ func Posthome(c *fiber.Ctx) error { }) } - return c.Status(500).Render("views/home", fiber.Map{ - "ERR": "Parsing Error", - "CI_COMMIT_SHA": utils.CI_COMMIT_SHA, - "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, - "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, - "CI_TAGGED": utils.CI_TAGGED, - "CI_BUILD": utils.CI_BUILD, - "TotalLinks": db.GetTotalLinks(), - "TotalViews": db.GetTotalViews(), - }) + // return c.Status(500).Render("views/home", fiber.Map{ + // "ERR": "Parsing Error", + // "CI_COMMIT_SHA": utils.CI_COMMIT_SHA, + // "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, + // "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, + // "CI_TAGGED": utils.CI_TAGGED, + // "CI_BUILD": utils.CI_BUILD, + // "TotalLinks": db.GetTotalLinks(), + // "TotalViews": db.GetTotalViews(), + // }) } if !regexp.MustCompile(`^(http|https|mailto|ts3server)://`).MatchString(u.URL) { @@ -48,16 +48,16 @@ func Posthome(c *fiber.Ctx) error { }) } - return c.Status(424).Render("views/home", fiber.Map{ - "ERR": "Invalid URL, please check and try again.", - "CI_COMMIT_SHA": utils.CI_COMMIT_SHA, - "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, - "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, - "CI_TAGGED": utils.CI_TAGGED, - "CI_BUILD": utils.CI_BUILD, - "TotalLinks": db.GetTotalLinks(), - "TotalViews": db.GetTotalViews(), - }) + // return c.Status(424).Render("views/home", fiber.Map{ + // "ERR": "Invalid URL, please check and try again.", + // "CI_COMMIT_SHA": utils.CI_COMMIT_SHA, + // "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, + // "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, + // "CI_TAGGED": utils.CI_TAGGED, + // "CI_BUILD": utils.CI_BUILD, + // "TotalLinks": db.GetTotalLinks(), + // "TotalViews": db.GetTotalViews(), + // }) } id, err := gonanoid.New(8) @@ -71,16 +71,16 @@ func Posthome(c *fiber.Ctx) error { }) } - return c.Status(500).Render("views/home", fiber.Map{ - "ERR": err.Error(), - "CI_COMMIT_SHA": utils.CI_COMMIT_SHA, - "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, - "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, - "CI_TAGGED": utils.CI_TAGGED, - "CI_BUILD": utils.CI_BUILD, - "TotalLinks": db.GetTotalLinks(), - "TotalViews": db.GetTotalViews(), - }) + // return c.Status(500).Render("views/home", fiber.Map{ + // "ERR": err.Error(), + // "CI_COMMIT_SHA": utils.CI_COMMIT_SHA, + // "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, + // "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, + // "CI_TAGGED": utils.CI_TAGGED, + // "CI_BUILD": utils.CI_BUILD, + // "TotalLinks": db.GetTotalLinks(), + // "TotalViews": db.GetTotalViews(), + // }) } err = db.Set(id, u.URL, 1296000*time.Second) @@ -93,16 +93,16 @@ func Posthome(c *fiber.Ctx) error { }) } - return c.Status(500).Render("views/home", fiber.Map{ - "ERR": err.Error(), - "CI_COMMIT_SHA": utils.CI_COMMIT_SHA, - "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, - "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, - "CI_TAGGED": utils.CI_TAGGED, - "CI_BUILD": utils.CI_BUILD, - "TotalLinks": db.GetTotalLinks(), - "TotalViews": db.GetTotalViews(), - }) + // return c.Status(500).Render("views/home", fiber.Map{ + // "ERR": err.Error(), + // "CI_COMMIT_SHA": utils.CI_COMMIT_SHA, + // "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, + // "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, + // "CI_TAGGED": utils.CI_TAGGED, + // "CI_BUILD": utils.CI_BUILD, + // "TotalLinks": db.GetTotalLinks(), + // "TotalViews": db.GetTotalViews(), + // }) } fURL := utils.URL + id @@ -121,14 +121,16 @@ func Posthome(c *fiber.Ctx) error { }) } - return c.Status(201).Render("views/home", fiber.Map{ - "URL": fURL, - "CI_COMMIT_SHA": utils.CI_COMMIT_SHA, - "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, - "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, - "CI_TAGGED": utils.CI_TAGGED, - "CI_BUILD": utils.CI_BUILD, - "TotalLinks": db.GetTotalLinks(), - "TotalViews": db.GetTotalViews(), - }) + // return c.Status(201).Render("views/home", fiber.Map{ + // "URL": fURL, + // "CI_COMMIT_SHA": utils.CI_COMMIT_SHA, + // "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, + // "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, + // "CI_TAGGED": utils.CI_TAGGED, + // "CI_BUILD": utils.CI_BUILD, + // "TotalLinks": db.GetTotalLinks(), + // "TotalViews": db.GetTotalViews(), + // }) + + return c.SendStatus(200) } diff --git a/utils/limiter.go b/utils/limiter.go index 69b3122..b876a53 100644 --- a/utils/limiter.go +++ b/utils/limiter.go @@ -12,16 +12,11 @@ var ConfigLimiter limiter.Config = limiter.Config{ Expiration: 60 * time.Second, LimitReached: func(c *fiber.Ctx) error { if c.Get("content-type") == "application/json" { - return c.Status(418).JSON(fiber.Map{ + return c.Status(429).JSON(fiber.Map{ "msg": "Too many requests, slow down I'm a teapot (10 requests per minute)", "success": false, }) } - return c.Render("views/home", fiber.Map{ - "ERR": "You have reached the limit of requests! Please check back later. (1 minute)", - "CI_COMMIT_SHA": CI_COMMIT_SHA, - "CI_COMMIT_BRANCH": CI_COMMIT_BRANCH, - "CI_BUILD": CI_BUILD, - }) + return c.SendStatus(429) }, } -- 2.45.3