ok we got basicauth and / serves index

This commit is contained in:
Bel LaPointe
2024-02-20 08:07:59 -07:00
parent 9be5d8235e
commit ec8d451df8

View File

@@ -2,14 +2,17 @@ package main
import ( import (
"context" "context"
"embed"
"encoding/base64" "encoding/base64"
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"io/fs"
"log" "log"
"net/http" "net/http"
"os" "os"
"os/signal" "os/signal"
"strings"
"syscall" "syscall"
"golang.org/x/time/rate" "golang.org/x/time/rate"
@@ -120,6 +123,20 @@ func (h Handler) auth(r *http.Request) (Session, error) {
return session, nil return session, nil
} }
//go:embed internal/public
var _public embed.FS
var public = func() http.FileSystem {
d, err := fs.Sub(_public, "internal/public")
if err != nil {
panic(err)
}
return http.FS(d)
}()
func (h Handler) handle(session Session, w http.ResponseWriter, r *http.Request) error { func (h Handler) handle(session Session, w http.ResponseWriter, r *http.Request) error {
if !strings.HasPrefix(r.URL.Path, "/api") {
http.FileServer(public).ServeHTTP(w, r)
return nil
}
return errors.New("not impl") return errors.New("not impl")
} }