Commit all code. Should be mostly functional.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package cmd
|
||||
|
||||
import "github.com/urfave/cli/v2"
|
||||
|
||||
func IntFlag(name string, value int, usage string) *cli.IntFlag {
|
||||
return &cli.IntFlag{
|
||||
Name: name,
|
||||
Usage: usage,
|
||||
Value: value,
|
||||
}
|
||||
}
|
||||
|
||||
func StringFlag(name string, value string, usage string) *cli.StringFlag {
|
||||
return &cli.StringFlag{
|
||||
Name: name,
|
||||
Usage: usage,
|
||||
Value: value,
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user