Documentation ¶
Overview ¶
A JavaScript Unmarshaler for Go
See the tests for ideas on how to translate variables between Go and JavaScript.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrArrayExpected is returned when the JS variable is not an array (i.e. for a go slice) ErrArrayExpected = errors.New("array expected") // ErrObjectExpected is returned when the JS variable is not an object (i.e. for a go map or struct) ErrObjectExpected = errors.New("object expected") )
Functions ¶
func Unmarshal ¶
Unmarshal transfers the contents of d into result.
Example ¶
package main import ( "fmt" "github.com/martint17r/encodingjs" "github.com/robertkrimen/otto" ) func main() { vm := otto.New() jsresult, err := vm.Run(`a={Foo: "bar", Fubar:"bob"}; a`) if err != nil { panic(err) } result := struct { Foo string Fubar string }{} err = encodingjs.Unmarshal(jsresult, &result) if err != nil { panic(err) } fmt.Printf("%+v\n", result) }
Output: {Foo:bar Fubar:bob}
Types ¶
type InvalidValueError ¶
InvalidValueError is returned when the js variable does not match the requirements from go
func (*InvalidValueError) Error ¶
func (ive *InvalidValueError) Error() string
type Unmarshaler ¶
Unmarshaler is the interface implemented by objects that can unmarshal a JS representation of themselves.
type UnsupportedTypeError ¶
type UnsupportedTypeError struct {
// contains filtered or unexported fields
}
UnsupportedTypeError is returned when channels and functions are given as targets
func (*UnsupportedTypeError) Error ¶
func (ute *UnsupportedTypeError) Error() string
Click to show internal directories.
Click to hide internal directories.