From 9370f7b3a8e42fbf5d0e9139e940a8270625e747 Mon Sep 17 00:00:00 2001 From: Kailash Choudhary Date: Sat, 6 Jul 2024 15:23:22 +0530 Subject: [PATCH] refactor: add handler for index page --- handlers/index.go | 18 ++++++++++++++++++ main.go | 15 ++++----------- templates/homePage_templ.go | 2 +- 3 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 handlers/index.go diff --git a/handlers/index.go b/handlers/index.go new file mode 100644 index 0000000..5525eb8 --- /dev/null +++ b/handlers/index.go @@ -0,0 +1,18 @@ +package handlers + +import ( + "context" + "fmt" + "net/http" + "os" + + "github.com/kailashchoudhary11/repo-guard/templates" +) + +func Index(w http.ResponseWriter, r *http.Request) { + appName := os.Getenv("APP_NAME") + authorizationUrl := fmt.Sprintf("https://github.com/apps/%v/installations/new", appName) + + template := templates.HomePage(authorizationUrl) + template.Render(context.Background(), w) +} diff --git a/main.go b/main.go index bd2b272..a05d524 100644 --- a/main.go +++ b/main.go @@ -1,30 +1,23 @@ package main import ( - "context" "fmt" "net/http" - "os" "github.com/kailashchoudhary11/repo-guard/handlers" "github.com/kailashchoudhary11/repo-guard/initializers" - "github.com/kailashchoudhary11/repo-guard/templates" ) func main() { initializers.LoadDotEnv() initializers.LoadGithubClient() + router := http.NewServeMux() router.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) - router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - appName := os.Getenv("APP_NAME") - authorizationUrl := fmt.Sprintf("https://github.com/apps/%v/installations/new", appName) - - template := templates.HomePage(authorizationUrl) - template.Render(context.Background(), w) - }) - + router.HandleFunc("/", handlers.Index) router.HandleFunc("/webhook", handlers.Webhook) + fmt.Println("Service is up and running at port 8000") + http.ListenAndServe(":8000", router) } diff --git a/templates/homePage_templ.go b/templates/homePage_templ.go index 85821d1..862d96c 100644 --- a/templates/homePage_templ.go +++ b/templates/homePage_templ.go @@ -47,7 +47,7 @@ func HomePage(authorizationURL string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" class=\"inline-flex items-center justify-center gap-3 bg-[#90D3DF] hover:bg-[#7BBAC5] text-black font-rubik px-6 py-4 rounded-lg font-bold text-lg group transition-all duration-300 transform hover:scale-105 hover:shadow-lg\">\"GitHub Authorize Repo Guard \"Right Learn More

Features:

\"Duplicate

Duplicate Detection

AI-powered algorithm understands context, not just keywords.

\"Instant

Instant Action

Duplicates are handled in real-time, keeping your workflow smooth.

\"GitHub

GitHub Integration

Seamlessly integrates with your existing GitHub workflow.

How Repo Guard Works:

\"Step
A new issue appears in your repository.
\"Step
Repo Guard quickly checks for duplicates.
\"Step
If it's a duplicate, Repo Guard closes it and links to the original.
\"Step
Your repository stays tidy and contributors stay informed.

Make your
Github
Repositories
Smarter Today!

Features:

\"Duplicate

Duplicate Detection

AI-powered algorithm understands context, not just keywords.

\"Instant

Instant Action

Duplicates are handled in real-time, keeping your workflow smooth.

\"GitHub

GitHub Integration

Seamlessly integrates with your existing GitHub workflow.

How Repo Guard Works:

\"Step
A new issue appears in your repository.
\"Step
Repo Guard quickly checks for duplicates.
\"Step
If it's a duplicate, Repo Guard closes it and links to the original.
\"Step
Your repository stays tidy and contributors stay informed.

Make your
Github
Repositories
Smarter Today!

\"Repo