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 {
case "login":
return handleLogin(w, r)
case "api":
return handleAPI(w, r)
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 {
cookie, err := ParseCookie(r)
if err != nil {
func handleUI(w http.ResponseWriter, r *http.Request) error {
if _, err := ParseCookie(r); err != nil {
http.Redirect(w, r, "/login", http.StatusTemporaryRedirect)
return err
}
_ = cookie
switch r.URL.Path {
case "/":
@ -212,3 +212,11 @@ func (cookie Cookie) Serialize(w http.ResponseWriter) {
}
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">
</header>
<body>
<ul>
<li><a href="/chatbot">Chat bot</a></li>
</ul>
</body>
<footer>
</footer>