-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add handler for index page
- Loading branch information
1 parent
70afe99
commit 9370f7b
Showing
3 changed files
with
23 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.