// find the node from the based ont the hash passed in
// the hash needs to at least have a {name: }property
find the node from the based ont the hash passed in
the hash needs to at least have a {name: }property
// find the node from the based ont the hash passed in // the hash needs to at least have a { name : } property
func (js *JavascriptBuilder) findNode(token string, in otto.Value) (n Node, err error) {
	var (
		givenOptions map[string]interface{}
		ok           bool
		name         string
	)
	e, err := in.Export()
	if err != nil {
		return n, err
	}
	 if the arg is a string, then use that string as the name
	 and pull the config node
	switch arg := e.(type) {
	case map[string]interface{}:
		givenOptions = arg
		if name, ok = givenOptions["name"].(string); ok {
			 merge the two maps
			tmpMap := make(map[string]interface{})
			for k, v := range js.config.Nodes[name] {
				tmpMap[k] = v
			}
			for k, v := range givenOptions {
				tmpMap[k] = v
			}
			givenOptions = tmpMap
		} else {  we don't have a name, so lets generate one.
			u, err := uuid.NewV4()
			if err != nil {
				return n, fmt.Errorf("%s error. unable to create uuid (%s)", token, err.Error())
			}
			name = u.String()
			givenOptions["name"] = name
		}
	case string:
		name = arg
		givenOptions, ok = js.config.Nodes[name]
		if !ok {
			return n, fmt.Errorf("%s error. unable to find node '%s'", token, name)
		}
	}
	if token == "transform" {
		 this is a little bit of magic so that transformers (which are added by the transform fn get the right kind)
		givenOptions["type"] = "transformer"
	}
	kind, ok := givenOptions["type"].(string)
	if !ok {
		return n, fmt.Errorf("%s: hash requires a type field, but no type given", token)
	}
	return NewNode(name, kind, givenOptions)
}
func ( js * JavascriptBuilder ) findNode ( token string , in otto . Value ) ( n Node , err error ) { var ( givenOptions map [ string ] interface { } ok bool name string ) e , err := in . Export ( ) if err != nil { return n , err } switch arg := e . ( type ) { case map [ string ] interface { } : givenOptions = arg if name , ok = givenOptions [ " " ] . ( string ) ; ok { tmpMap := make ( map [ string ] interface { } ) for k , v := range js . config . Nodes [ name ] { tmpMap [ k ] = v } for k , v := range givenOptions { tmpMap [ k ] = v } givenOptions = tmpMap } else { u , err := uuid . NewV4 ( ) if err != nil { return n , fmt . Errorf ( " " , token , err . Error ( ) ) } name = u . String ( ) givenOptions [ " " ] = name } case string : name = arg givenOptions , ok = js . config . Nodes [ name ] if ! ok { return n , fmt . Errorf ( " " , token , name ) } } if token == " " { givenOptions [ " " ] = " " } kind , ok := givenOptions [ " " ] . ( string ) if ! ok { return n , fmt . Errorf ( " " , token ) } return NewNode ( name , kind , givenOptions ) }
find the node from the based ont the hash passed in
the hash needs to at least have a {name: }property
find the node from the based ont the hash passed in the hash needs to at least have a { name : } property
// accept both a json hash and a string as an argument. // if the arg is a hash, then we should extract the name, // and pull the node from the yaml, and then merge the given options // over top of the options presented in the config node. // // if the arg is a string, then use that string as the name // and pull the config node // merge the two maps // we don't have a name, so lets generate one. // this is a little bit of magic so that transformers (which are added by the transform fn get the right kind)