From c64d8eedd3eeb97e3b9ff38e540662bff91d06b4 Mon Sep 17 00:00:00 2001 From: Tom Andrade Date: Sun, 14 Apr 2019 22:37:01 +0200 Subject: [PATCH] Add some html templates --- main.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 9d8f9aa..74a40cb 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,59 @@ const ( appVersion = "0.0.1" ) +const indexPage = ` + + + + Short: the simple url shortener + + + +
+ +
+ + +
+ + +` + +const returnPage = ` + + + + Short: the simple url shortner + + + +
+ URL Shortened to %s +
+ + +` + var domain string var redisServer string var listenAddr string @@ -34,6 +87,7 @@ var path string var src = rand.NewSource(time.Now().UnixNano()) var pool = newPool() +func index() string { return indexPage } func newPool() *redis.Pool { return &redis.Pool{ // Maximum number of idle connections in the pool. @@ -131,7 +185,9 @@ func shortner(ctx *web.Context) { if err != nil { ctx.Abort(500, "Internal Error") } else { - ctx.WriteString("URL shortened at: " + proto + "://" + domain + port + path + suffix + "\n") + shortend := proto + "://" + domain + port + path + suffix + output := fmt.Sprintf(returnPage, shortend, shortend) + ctx.WriteString(output) } } } @@ -171,6 +227,7 @@ func main() { path = path + "/" } + web.Get("/", index) web.Post("/", shortner) web.Get("/(.*)", redirect) log.Printf("Domain: %s, Redis: %s\n", domain, redisServer)