Skip to content

Library to execution of JavaScript templates in Go using V8 engine

Notifications You must be signed in to change notification settings

sergei-svistunov/v8tpl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

v8tpl

Description

Using the library you can execute JavaScript templates in Go by V8 engine.

How to install

Download source:

go get -d github.com/sergei-svistunov/v8tpl/

Go to source directory:

cd $GOPATH/src/github.com/sergei-svistunov/v8tpl

Install depot_tools if you haven't it (https://www.chromium.org/developers/how-tos/install-depot-tools):

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=`pwd`/depot_tools:"$PATH"

Build and install the library:

make -j4 install

How to use

package main

import (
	"github.com/sergei-svistunov/v8tpl"
)

// The JS template's source must contain function `template(data)` that will be called to process data
const TEMPLATE = `
	var template = function(data) {
		return "Hello " + data.name;
	}
`

func main() {
	// Create template object
	tpl, err := v8tpl.NewTemplate(TEMPLATE)
	if err != nil {
		panic(err)
	}

	// Prepare data
	data := map[string]string{
		"name": "world",
	}

	// Process it
	res, err := tpl.Eval(data)
	if err != nil {
		panic(err)
	}

	println(res)
}

About

Library to execution of JavaScript templates in Go using V8 engine

Resources

Stars

Watchers

Forks

Packages

No packages published