-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
89 lines (74 loc) · 1.79 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"context"
"embed"
"flag"
"io"
"log"
"log/slog"
"net/http"
"github.com/a-h/templ"
"github.com/facebookgo/flagenv"
_ "github.com/joho/godotenv/autoload"
"within.website/x/tigris"
"within.website/x/web/ollama"
"within.website/x/xess"
// image formats
_ "image/gif"
_ "image/jpeg"
_ "image/png"
// more image formats
_ "github.com/gen2brain/avif"
_ "github.com/gen2brain/heic"
_ "github.com/gen2brain/jpegxl"
_ "github.com/gen2brain/webp"
_ "golang.org/x/image/bmp"
_ "golang.org/x/image/tiff"
_ "golang.org/x/image/vp8"
_ "golang.org/x/image/vp8l"
)
//go:generate go run github.com/a-h/templ/cmd/templ@latest generate
var (
bind = flag.String("bind", ":8080", "address to bind to")
bucketName = flag.String("bucket", "how2make-uploads", "s3 bucket name")
ollamaHost = flag.String("ollama-host", "http://gpu-holy-sunset-3896.flycast", "ollama host")
ollamaModel = flag.String("ollama-model", "llava", "ollama model")
//go:embed static
static embed.FS
)
func main() {
flagenv.Parse()
flag.Parse()
cli := ollama.NewClient(*ollamaHost)
_ = cli
mux := http.NewServeMux()
xess.Mount(mux)
s3, err := tigris.Client(context.Background())
if err != nil {
log.Fatal(err)
}
s := &Server{
cli: cli,
s3: s3,
}
mux.Handle("GET /{$}", templ.Handler(
xess.Base(
"How do I make this sandwich?",
headArea(),
nil,
index(),
footer(),
),
))
mux.HandleFunc("/", s.NotFound)
mux.HandleFunc("POST /upload", s.POSTUpload)
mux.Handle("GET /static/", http.FileServerFS(static))
slog.Info("server", "listening", *bind)
log.Fatal(http.ListenAndServe(*bind, mux))
}
func Unsafe(html string) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) {
_, err = io.WriteString(w, html)
return
})
}