Made use of my own httpr router in main.
This commit is contained in:
parent
b18338e4e1
commit
38e6813d11
@ -4,6 +4,7 @@ import (
|
|||||||
"dwelling-upload/internal/http"
|
"dwelling-upload/internal/http"
|
||||||
"dwelling-upload/pkg/utils"
|
"dwelling-upload/pkg/utils"
|
||||||
"dwelling-upload/pkg/watcher"
|
"dwelling-upload/pkg/watcher"
|
||||||
|
"dwelling-upload/web"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@ -14,6 +15,8 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"git.arav.su/Arav/httpr"
|
||||||
)
|
)
|
||||||
|
|
||||||
var listenAddress *string = flag.String("listen", "/var/run/dwelling-upload/sock", "listen address (ip:port|unix_path)")
|
var listenAddress *string = flag.String("listen", "/var/run/dwelling-upload/sock", "listen address (ip:port|unix_path)")
|
||||||
@ -88,21 +91,24 @@ func main() {
|
|||||||
|
|
||||||
hand := http.NewUploadHandlers(logFile, *uploadDir, &uploadDirSize, string(hashSalt),
|
hand := http.NewUploadHandlers(logFile, *uploadDir, &uploadDirSize, string(hashSalt),
|
||||||
*keepFileForHours, *limitStorage, *limitFileSize)
|
*keepFileForHours, *limitStorage, *limitFileSize)
|
||||||
srv := http.NewHttpServer()
|
|
||||||
|
|
||||||
srv.SetNotFoundHandler(func(w nethttp.ResponseWriter, r *nethttp.Request) {
|
r := httpr.New()
|
||||||
|
|
||||||
|
r.NotFoundHandler = func(w nethttp.ResponseWriter, r *nethttp.Request) {
|
||||||
http.Error(w, r, nethttp.StatusNotFound, "")
|
http.Error(w, r, nethttp.StatusNotFound, "")
|
||||||
})
|
}
|
||||||
|
|
||||||
srv.ServeStatic("/assets/*filepath", http.AssetsFS())
|
r.Handler(nethttp.MethodGet, "/", hand.Index)
|
||||||
srv.GET("/robots.txt", http.RobotsTxt)
|
r.Handler(nethttp.MethodPost, "/", hand.Upload)
|
||||||
srv.GET("/favicon.svg", http.Favicon)
|
r.Handler(nethttp.MethodGet, "/:hash/:name", hand.Download)
|
||||||
|
r.Handler(nethttp.MethodPost, "/delete", hand.Delete)
|
||||||
|
r.Handler(nethttp.MethodDelete, "/:hash", hand.Delete)
|
||||||
|
|
||||||
srv.GET("/", hand.Index)
|
r.ServeStatic("/assets/*filepath", web.Assets())
|
||||||
srv.POST("/", hand.Upload)
|
r.Handler(nethttp.MethodGet, "/robots.txt", http.RobotsTxt)
|
||||||
srv.POST("/delete", hand.Delete)
|
r.Handler(nethttp.MethodGet, "/favicon.svg", http.Favicon)
|
||||||
srv.GET("/f/:hash/:name", hand.Download)
|
|
||||||
srv.DELETE("/:hash", hand.Delete)
|
srv := http.NewHttpServer(r)
|
||||||
|
|
||||||
if err := srv.Start(network, *listenAddress); err != nil {
|
if err := srv.Start(network, *listenAddress); err != nil {
|
||||||
log.Fatalln("failed to start a server:", err)
|
log.Fatalln("failed to start a server:", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user