package cmd import ( "fmt" "github.com/gorilla/mux" "github.com/patrickmn/go-cache" "github.com/urfave/cli/v2" "go-opds-pse/app/routes" "net/http" "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() }