Commit all code. Should be mostly functional.

This commit is contained in:
2024-12-31 03:38:40 -07:00
commit b4e9727e8c
15 changed files with 622 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
package cmd
import (
"fmt"
"github.com/gorilla/mux"
"github.com/patrickmn/go-cache"
"github.com/urfave/cli/v2"
"net/http"
"opds-pse-server/app/routes"
"time"
)
var Serve = cli.Command{
Name: "serve",
Usage: "start the http server",
Flags: []cli.Flag{
IntFlag("port, p", 3000, "web server port"),
},
Action: runServe,
}
func runServe(ctx *cli.Context) error {
r := mux.NewRouter()
fs := http.FileServer(http.Dir("manga/"))
r.PathPrefix("/manga/").Handler(http.StripPrefix("/manga", fs))
c := cache.New(5*time.Minute, 10*time.Minute)
routes.Init(ctx, r, c)
srv := &http.Server{
Handler: r,
Addr: fmt.Sprintf(":%d", ctx.Int("port")),
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
return srv.ListenAndServe()
}