selfjs

package module
v0.0.0-...-72ce342 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2015 License: MPL-2.0 Imports: 9 Imported by: 1 module, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Self.js GoDoc

Wrapper around v8worker and net/http. Run Universal React applications faster than Node.js.

Setup

First you need to install v8worker. Then:

go get -u github.com/nmerouze/selfjs

Usage

import (
  "io/ioutil"
  "net/http"
  "runtime"

  "github.com/nmerouze/selfjs"
)

func main() {
  runtime.GOMAXPROCS(runtime.NumCPU())

  js, _ := ioutil.ReadFile("path/to/file.js")
  http.Handle("/", selfjs.New(runtime.NumCPU(), `
    selfjs.handleRequest = function(req, res) {
      res.write('Hello World!');
    }
  `))
  http.ListenAndServe(":8080", nil)
}

Example

cd example
npm install
npm run build
go run server.go
open http://localhost:8080

The application is rendered on the server. Both the client and the server share the same file (universal.js) with a few conditions to select the right rendering function. The code also runs on Node.js, just run node server.js. Self.js is 50% than Node.js while Node.js consumes 50% memory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(poolSize int, script string, data interface{}) echo.HandlerFunc

func PageAsString

func PageAsString(poolSize int, script string, data string, w http.ResponseWriter, r *http.Request) string

Types

type Worker

type Worker struct {
	*v8worker.Worker
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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