Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Commands = []cli.Command{ Web, }
Commands - List of renderer commands.
View Source
var DefaultWebOptions = []renderer.Option{ renderer.WithAlwaysHTML(true), }
DefaultWebOptions - Default renderer options. You can append options here like renderer.WithMiddleware.
View Source
var Web = cli.Command{ Name: "server", Usage: "renderer server", Flags: []cli.Flag{ cli.StringSliceFlag{ Name: "routes", Usage: "file containing routes in yaml format", }, cli.StringFlag{ Name: "components", Usage: "directory containing components", }, cli.BoolFlag{ Name: "watch", Usage: "watch for changes in components", }, cli.BoolFlag{ Name: "compress", Usage: "removes repeated whitespaces", }, cli.DurationFlag{ Name: "cache-expiration", Usage: "cache expiration time", Value: 15 * time.Minute, }, cli.DurationFlag{ Name: "cache-cleanup", Usage: "cache cleanup interval", Value: 5 * time.Minute, }, cli.StringFlag{ Name: "listen-addr", Usage: "renderer interface listening address", Value: "127.0.0.1:6660", }, cli.DurationFlag{ Name: "render-timeout", Usage: "component render timeout", Value: 5 * time.Second, }, cli.DurationFlag{ Name: "renderer-read-timeout", EnvVar: "RENDERER_READ_TIMEOUT", Usage: "renderer server read timeout", Value: time.Minute, }, cli.DurationFlag{ Name: "renderer-write-timeout", EnvVar: "RENDERER_WRITE_TIMEOUT", Usage: "renderer server write timeout", Value: time.Minute, }, cli.StringFlag{ Name: "debug-addr", EnvVar: "DEBUG_ADDR", Usage: "debug listening address", }, cli.BoolFlag{ Name: "tracing", EnvVar: "TRACING", Usage: "enable tracing (use with --debug-addr)", }, }, Action: func(c *cli.Context) (err error) { if c.String("components") == "" { return errors.New("--components flag cannot be empty") } storage, err := storage.New( storage.WithDir(c.String("components")), storage.WithCacheExpiration(c.Duration("cache-expiration")), storage.WithCacheCleanupInterval(c.Duration("cache-cleanup")), storage.WithWhitespaceRemoval(c.Bool("compress")), ) if err != nil { return fmt.Errorf("[storage] %v", err) } defer storage.Close() comp := compiler.New(storage) ctx := compiler.NewContext(context.Background(), comp) if c.Bool("tracing") { DefaultWebOptions = append(DefaultWebOptions, renderer.WithTracing()) } api, err := constructHandler(c.StringSlice("routes"), DefaultWebOptions) if err != nil { return fmt.Errorf("[routes] %v", err) } handler := &atomicHandler{ Context: ctx, Current: xhandler.New(ctx, api), Options: DefaultWebOptions, Watching: c.Bool("watch"), Routes: c.StringSlice("routes"), Mutex: new(sync.RWMutex), } if c.Bool("watch") { // Start watching for changes in components directory var w *watcher.Watcher w, err = watcher.Start(c.String("components"), storage) if err != nil { return } defer w.Stop() for _, filename := range c.StringSlice("routes") { var watch *watcher.Watcher watch, err = watcher.Start(filename, handler) if err != nil { return } defer watch.Stop() } } if addr := c.String("pprof-addr"); addr != "" { go func() { if err = debugServer(addr); err != nil { glog.Fatal(err) } }() } server := &http.Server{ Addr: c.String("listen-addr"), Handler: handler, ReadTimeout: c.Duration("http-read-timeout"), WriteTimeout: c.Duration("http-write-timeout"), MaxHeaderBytes: 64 * 1024, } glog.Infof("[renderer] starting server on %s", c.String("listen-addr")) return server.ListenAndServe() }, }
Web - Web command.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.