exposed configuration
This commit is contained in:
parent
6eaff883d4
commit
9f85a8901e
31
cmd/serve.go
31
cmd/serve.go
@ -16,10 +16,17 @@ limitations under the License.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/dalu/chromedom/server"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/dalu/chromedom/server"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
binary string
|
||||||
|
duration time.Duration
|
||||||
|
maxmem int
|
||||||
)
|
)
|
||||||
|
|
||||||
// serveCmd represents the serve command
|
// serveCmd represents the serve command
|
||||||
@ -28,18 +35,17 @@ var serveCmd = &cobra.Command{
|
|||||||
Short: "",
|
Short: "",
|
||||||
Long: ``,
|
Long: ``,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
binary := cmd.Flag("binary").Value.String()
|
|
||||||
s := http.DefaultServeMux
|
s := http.DefaultServeMux
|
||||||
h := server.NewHandler(binary, 30*time.Minute)
|
h := server.NewHandler(binary, duration, maxmem)
|
||||||
s.Handle("/", h)
|
s.Handle("/", h)
|
||||||
return http.ListenAndServe(":9292", s)
|
return http.ListenAndServe(":9292", s)
|
||||||
// return RunUnix("/tmp/chromedom.sock", s)
|
// return runUnix("/tmp/chromedom.sock", s)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
func RunUnix(file string, engine *http.ServeMux) (err error) {
|
func runUnix(file string, engine *http.ServeMux) (err error) {
|
||||||
fmt.Printf("Listening and serving HTTP on unix:/%s", file)
|
fmt.Printf("Listening and serving HTTP on unix:/%s", file)
|
||||||
os.Remove(file)
|
os.Remove(file)
|
||||||
listener, err := net.Listen("unix", file)
|
listener, err := net.Listen("unix", file)
|
||||||
@ -56,14 +62,7 @@ func RunUnix(file string, engine *http.ServeMux) (err error) {
|
|||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(serveCmd)
|
rootCmd.AddCommand(serveCmd)
|
||||||
|
|
||||||
// Here you will define your flags and configuration settings.
|
serveCmd.Flags().StringVarP(&binary, "binary", "b", "/usr/bin/google-chrome", "chrome, chromium or headless binary path")
|
||||||
|
serveCmd.Flags().DurationVarP(&duration, "duration", "d", 60*time.Minute, "how long the values live in the cache")
|
||||||
// Cobra supports Persistent Flags which will work for this command
|
serveCmd.Flags().IntVarP(&maxmem, "maxmem", "m", 500*1024*1024, "maximum memory the cache may use in bytes")
|
||||||
// and all subcommands, e.g.:
|
|
||||||
// serveCmd.PersistentFlags().String("foo", "", "A help for foo")
|
|
||||||
|
|
||||||
// Cobra supports local flags which will only run when this command
|
|
||||||
// is called directly, e.g.:
|
|
||||||
// serveCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
|
||||||
serveCmd.Flags().String("binary", "/bin/chromium", "chrome, chromium or headless binary path")
|
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ type Handler struct {
|
|||||||
cache *bigcache.BigCache
|
cache *bigcache.BigCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandler(binary string, eviction time.Duration) *Handler {
|
func NewHandler(binary string, eviction time.Duration, maxmem int) *Handler {
|
||||||
h := new(Handler)
|
h := new(Handler)
|
||||||
h.binary = binary
|
h.binary = binary
|
||||||
h.uid = syscall.Getuid()
|
h.uid = syscall.Getuid()
|
||||||
@ -64,7 +64,7 @@ func NewHandler(binary string, eviction time.Duration) *Handler {
|
|||||||
}
|
}
|
||||||
h.logger = logrus.StandardLogger()
|
h.logger = logrus.StandardLogger()
|
||||||
cacheConf := bigcache.DefaultConfig(eviction)
|
cacheConf := bigcache.DefaultConfig(eviction)
|
||||||
cacheConf.HardMaxCacheSize = 500 * 1024 * 1024 // 500MB
|
cacheConf.HardMaxCacheSize = maxmem
|
||||||
cache, e := bigcache.NewBigCache(cacheConf)
|
cache, e := bigcache.NewBigCache(cacheConf)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
h.logger.Fatal(e.Error())
|
h.logger.Fatal(e.Error())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user