ssr

package module
v0.0.0-...-7a73a85 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2021 License: MIT Imports: 14 Imported by: 0

README

ssr

GitHub Workflow Status Codecov GitHub repo size MIT license

Golang server side render (SSR) with Vue.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	ID          string `json:"id"`
	Path        string `json:"path"`
	QueryString string `json:"query_string"`
}

func NewContext

func NewContext(r *http.Request) *Context

func (*Context) ToMap

func (ctx *Context) ToMap() (map[string]interface{}, error)

type JSEngine

type JSEngine struct {
	*eventloop.EventLoop

	// Maximum render time
	Timeout time.Duration
	// contains filtered or unexported fields
}

func NewJSEngine

func NewJSEngine(bundle *ScriptBundle, timeout time.Duration) (*JSEngine, error)

func (*JSEngine) Handle

func (je *JSEngine) Handle(ctx *Context) <-chan *Result

type Pool

type Pool interface {
	// Get a js-engine from pool
	Get() *JSEngine

	// Put back js-engine to pool for re-use
	Put(je *JSEngine)

	// Drop js-engine if render failed
	Drop(je *JSEngine)
}

type PoolPrefork

type PoolPrefork struct {
	// contains filtered or unexported fields
}

func NewPoolPrefork

func NewPoolPrefork(bundle *ScriptBundle, timeout time.Duration, size uint) *PoolPrefork

func (*PoolPrefork) Drop

func (p *PoolPrefork) Drop(je *JSEngine)

func (*PoolPrefork) Get

func (p *PoolPrefork) Get() *JSEngine

func (*PoolPrefork) Put

func (p *PoolPrefork) Put(je *JSEngine)

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer implement http.Handler

func NewRenderer

func NewRenderer(bundle *ScriptBundle, tmpl *template.Template) *Renderer

func (*Renderer) ServeHTTP

func (r *Renderer) ServeHTTP(w http.ResponseWriter, req *http.Request)

type Result

type Result struct {
	ContextID  string        `json:"id"`
	Title      string        `json:"title,omitempty"`
	Meta       string        `json:"meta,omitempty"`
	Body       string        `json:"body"`
	RenderTime time.Duration `json:"-"`
}

func NewResultFromMap

func NewResultFromMap(obj map[string]interface{}) (*Result, error)

type ScriptBundle

type ScriptBundle struct {
	// js script content
	Content []byte

	// js bundle script entry function name
	FuncName string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL