Skip to content

Commit

Permalink
refactor: add handler for index page
Browse files Browse the repository at this point in the history
  • Loading branch information
kailashchoudhary11 committed Jul 6, 2024
1 parent 70afe99 commit 9370f7b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
18 changes: 18 additions & 0 deletions handlers/index.go
Original file line number Diff line number Diff line change
@@ -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)
}
15 changes: 4 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion templates/homePage_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9370f7b

Please sign in to comment.