aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/main.go
diff options
context:
space:
mode:
authorMax Resnick <max@ofmax.li>2020-05-23 07:56:12 -0700
committerMax Resnick <max@ofmax.li>2020-06-22 22:37:17 -0700
commit85e7eaa3a1c9024c02cc9a63744cdfb144cc3737 (patch)
treea44855abcf5424126c54ee636463dc866e558561 /cmd/web/main.go
parent4e77ad5762539d8f9edf40d2668a998c38e834d3 (diff)
downloadiserv-85e7eaa3a1c9024c02cc9a63744cdfb144cc3737.tar.gz
adds tmpl, css, and fileserver
Diffstat (limited to 'cmd/web/main.go')
-rw-r--r--cmd/web/main.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/cmd/web/main.go b/cmd/web/main.go
index 3f16dec..f215d1e 100644
--- a/cmd/web/main.go
+++ b/cmd/web/main.go
@@ -4,29 +4,43 @@ import (
"log"
"net/http"
"os"
+ "path"
"github.com/go-chi/chi"
"git.ofmax.li/iserv/internal/db/redis"
+ "git.ofmax.li/iserv/internal/fs"
"git.ofmax.li/iserv/internal/image"
+ "go.ofmax.li/tmpl"
)
func main() {
connPool := redis.CreatePool("localhost:6379")
db := redis.NewRedisImageRepo(connPool)
+ renderer, err := tmpl.NewHTMLTmpl("templates")
+ if err != nil {
+ log.Fatal(err)
+ }
+
storagePath, err := os.Getwd()
if err != nil {
log.Fatal("couldn't find directory to write images to")
}
- imageService := image.NewService(db, storagePath)
+ // Image
+ imageService := image.NewService(db, storagePath, renderer)
imageHandler := image.NewHandler(imageService)
+ imageFile := fs.NewHandler(storagePath)
+ // Static Files
+ staticFiles := fs.NewHandler(path.Join(storagePath, "static"))
r := chi.NewRouter()
- r.Get("/i", imageHandler.GetImage)
- r.Post("/i", imageHandler.PostImage)
+ r.Get("/i/{fileName}", imageHandler.GetImage)
+ r.Post("/u", imageHandler.PostImage)
+ r.Get("/f/*", imageFile)
+ r.Get("/static/*", staticFiles)
log.Print("starting imageserv")
log.Fatal(http.ListenAndServe(":8080", r))
}