index and stub /api handle

master
bel 2023-06-17 09:31:13 -06:00
parent fe4e9c4214
commit f0289d774e
2 changed files with 16 additions and 5 deletions

View File

@ -114,8 +114,10 @@ func _handle(w http.ResponseWriter, r *http.Request) error {
switch first { switch first {
case "login": case "login":
return handleLogin(w, r) return handleLogin(w, r)
case "api":
return handleAPI(w, r)
default: default:
return handleLoggedIn(w, r) return handleUI(w, r)
} }
} }
@ -142,13 +144,11 @@ func handleLogin(w http.ResponseWriter, r *http.Request) error {
} }
} }
func handleLoggedIn(w http.ResponseWriter, r *http.Request) error { func handleUI(w http.ResponseWriter, r *http.Request) error {
cookie, err := ParseCookie(r) if _, err := ParseCookie(r); err != nil {
if err != nil {
http.Redirect(w, r, "/login", http.StatusTemporaryRedirect) http.Redirect(w, r, "/login", http.StatusTemporaryRedirect)
return err return err
} }
_ = cookie
switch r.URL.Path { switch r.URL.Path {
case "/": case "/":
@ -212,3 +212,11 @@ func (cookie Cookie) Serialize(w http.ResponseWriter) {
} }
http.SetCookie(w, c) http.SetCookie(w, c)
} }
func handleAPI(w http.ResponseWriter, r *http.Request) error {
if _, err := ParseCookie(r); err != nil {
http.Redirect(w, r, "/login", http.StatusTemporaryRedirect)
return err
}
return errors.New("not impl")
}

View File

@ -3,6 +3,9 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
</header> </header>
<body> <body>
<ul>
<li><a href="/chatbot">Chat bot</a></li>
</ul>
</body> </body>
<footer> <footer>
</footer> </footer>