本文整理汇总了Golang中github.com/robertkrimen/otto.NullValue函数的典型用法代码示例。如果您正苦于以下问题:Golang NullValue函数的具体用法?Golang NullValue怎么用?Golang NullValue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NullValue函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: addDiscoveryService
func (ctrl *JsController) addDiscoveryService(o *otto.Otto) {
o.Set("discover", func(call otto.FunctionCall) otto.Value {
if len(call.ArgumentList) == 0 {
glog.Errorf("DISCOVER: Missing arguments")
return otto.NullValue()
}
url, _ := call.Argument(0).ToString()
upstreams, err := ctrl.DiscoveryService.Get(url)
if err != nil {
glog.Errorf("Failed to discover upstreams: %v", err)
return otto.NullValue()
}
glog.Infof("Discovered upstreams: %v", upstreams)
result, err := o.ToValue(upstreams)
if err != nil {
glog.Errorf("Failed to convert: %v", err)
return otto.NullValue()
}
return result
})
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:25,代码来源:js.go
示例2: toValue
func (p *pathObject) toValue(call otto.FunctionCall, withTags bool) otto.Value {
it := p.buildIteratorTree()
it.Tagger().Add(TopResultTag)
const limit = 1
var (
val otto.Value
err error
)
if !withTags {
array := p.wk.runIteratorToArrayNoTags(it, limit)
if len(array) < 1 {
return otto.NullValue()
}
val, err = call.Otto.ToValue(array[0])
} else {
array := p.wk.runIteratorToArray(it, limit)
if len(array) < 1 {
return otto.NullValue()
}
val, err = call.Otto.ToValue(array[0])
}
if err != nil {
glog.Error(err)
return otto.NullValue()
}
return val
}
开发者ID:dennwc,项目名称:cayley,代码行数:27,代码来源:finals.go
示例3: setFunc
// pipelines in javascript are chainable, you take in a pipeline, and you return a pipeline
// we just generalize some of that logic here
func (js *JavascriptBuilder) setFunc(obj *otto.Object, token string, fn func(string, Node, otto.FunctionCall) (Node, error)) error {
return obj.Set(token, func(call otto.FunctionCall) otto.Value {
this, _ := call.This.Export()
node, err := CreateNode(this)
if err != nil {
js.err = err
return otto.NullValue()
}
node, err = fn(token, node, call)
if err != nil {
js.err = err
return otto.NullValue()
}
o, err := node.Object()
if err != nil {
js.err = err
return otto.NullValue()
}
js.setFunc(o, "transform", js.transform)
js.setFunc(o, "save", js.save)
return o.Value()
})
}
开发者ID:Garyguo110,项目名称:transporter,代码行数:30,代码来源:javascript_builder.go
示例4: toValueFunc
func (wk *worker) toValueFunc(env *otto.Otto, obj *otto.Object, withTags bool) func(otto.FunctionCall) otto.Value {
return func(call otto.FunctionCall) otto.Value {
it := buildIteratorTree(obj, wk.qs)
it.Tagger().Add(TopResultTag)
limit := 1
var val otto.Value
var err error
if !withTags {
array := wk.runIteratorToArrayNoTags(it, limit)
if len(array) < 1 {
return otto.NullValue()
}
val, err = call.Otto.ToValue(array[0])
} else {
array := wk.runIteratorToArray(it, limit)
if len(array) < 1 {
return otto.NullValue()
}
val, err = call.Otto.ToValue(array[0])
}
if err != nil {
clog.Errorf("%v", err)
return otto.NullValue()
}
return val
}
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:27,代码来源:finals.go
示例5: has
func (p *pathObject) has(call otto.FunctionCall, rev bool) otto.Value {
args := exportArgs(call.ArgumentList)
if len(args) == 0 {
return otto.NullValue()
}
via := args[0]
if vp, ok := via.(*pathObject); ok {
via = vp.path
} else {
via, ok = toQuadValue(via)
if !ok {
return otto.NullValue()
}
}
qv, err := toQuadValues(args[1:])
if err != nil {
//TODO(dennwc): pass error to caller
return otto.NullValue()
}
np := p.clonePath()
if rev {
np = np.HasReverse(via, qv...)
} else {
np = np.Has(via, qv...)
}
return outObj(call, p.new(np))
}
开发者ID:rlugojr,项目名称:cayley,代码行数:27,代码来源:traversals.go
示例6: save
func (p *pathObject) save(call otto.FunctionCall, rev bool) otto.Value {
args := exportArgs(call.ArgumentList)
if len(args) > 2 || len(args) == 0 {
return otto.NullValue()
}
vtag := args[0]
if len(args) == 2 {
vtag = args[1]
}
tag, ok := vtag.(string)
if !ok {
return otto.NullValue()
}
via := args[0]
if vp, ok := via.(*pathObject); ok {
via = vp.path
} else {
via, ok = toQuadValue(via)
if !ok {
return otto.NullValue()
}
}
np := p.clonePath()
if rev {
np = np.SaveReverse(via, tag)
} else {
np = np.Save(via, tag)
}
return outObj(call, p.new(np))
}
开发者ID:rlugojr,项目名称:cayley,代码行数:30,代码来源:traversals.go
示例7: convertNilsToNulls
func convertNilsToNulls(object interface{}) {
switch object := object.(type) {
case map[string]interface{}:
for key, obj := range object {
switch obj := obj.(type) {
case map[string]interface{}:
convertNilsToNulls(obj)
case []interface{}:
convertNilsToNulls(obj)
case nil:
object[key] = otto.NullValue()
}
}
case []interface{}:
for key, obj := range object {
switch obj := obj.(type) {
case map[string]interface{}:
convertNilsToNulls(obj)
case []interface{}:
convertNilsToNulls(obj)
case nil:
object[key] = otto.NullValue()
}
}
}
}
开发者ID:cloudwan,项目名称:gohan,代码行数:26,代码来源:otto.go
示例8: toArray
func (p *pathObject) toArray(call otto.FunctionCall, withTags bool) otto.Value {
args := exportArgs(call.ArgumentList)
if len(args) != 1 {
return otto.NullValue()
}
limit := -1
if len(args) > 0 {
limit = toInt(args[0])
}
it := p.buildIteratorTree()
it.Tagger().Add(TopResultTag)
var (
val otto.Value
err error
)
if !withTags {
array := p.wk.runIteratorToArrayNoTags(it, limit)
val, err = call.Otto.ToValue(array)
} else {
array := p.wk.runIteratorToArray(it, limit)
val, err = call.Otto.ToValue(array)
}
if err != nil {
glog.Error(err)
return otto.NullValue()
}
return val
}
开发者ID:dennwc,项目名称:cayley,代码行数:28,代码来源:finals.go
示例9: toValueFunc
func toValueFunc(env *otto.Otto, ses *Session, obj *otto.Object, withTags bool) func(otto.FunctionCall) otto.Value {
return func(call otto.FunctionCall) otto.Value {
it := buildIteratorTree(obj, ses.ts)
it.Tagger().Add(TopResultTag)
limit := 1
var val otto.Value
var err error
if !withTags {
array := runIteratorToArrayNoTags(it, ses, limit)
if len(array) < 1 {
return otto.NullValue()
}
val, err = call.Otto.ToValue(array[0])
} else {
array := runIteratorToArray(it, ses, limit)
if len(array) < 1 {
return otto.NullValue()
}
val, err = call.Otto.ToValue(array[0])
}
if err != nil {
glog.Error(err)
return otto.NullValue()
} else {
return val
}
}
}
开发者ID:jacqui,项目名称:cayley,代码行数:29,代码来源:finals.go
示例10: cmpOpType
func cmpOpType(op iterator.Operator) func(call otto.FunctionCall) otto.Value {
return func(call otto.FunctionCall) otto.Value {
args := exportArgs(call.ArgumentList)
if len(args) != 1 {
return otto.NullValue()
}
qv, ok := toQuadValue(args[0])
if !ok {
return otto.NullValue()
}
return outObj(call, cmpOperator{op: op, val: qv})
}
}
开发者ID:dennwc,项目名称:cayley,代码行数:13,代码来源:environ.go
示例11: runCompScript
func (j *job) runCompScript(irs [][]*gnr.InteractionResult) {
vm := otto.New()
injectRuntime(vm)
if err := vm.Set("interactions", irs); err != nil {
panic(err)
}
vm.Set("width", Width)
vm.Set("height", Height)
compositions := make([]composition, 0, 5)
vm.Set("composition", func(call otto.FunctionCall) otto.Value {
name, err := call.Argument(0).ToString()
if err != nil {
panic("First argument to composition() must be a string")
}
cb := call.Argument(1)
if !cb.IsFunction() {
panic("Second argument to composition() must be a function(x,y)")
}
compositions = append(compositions, composition{name, cb})
return otto.NullValue()
})
if _, err := vm.Run(j.Composite); err != nil {
panic(err)
}
for _, comp := range compositions {
img := image.NewRGBA(image.Rect(0, 0, Width, Height))
for y := 0; y < Height; y++ {
for x := 0; x < Width; x++ {
v, err := comp.Func.Call(otto.NullValue(), x, y)
if err != nil {
panic(err)
}
c, err := v.Export()
if err != nil {
panic(err)
}
img.Set(x, y, mapToColor(c.(map[string]interface{})))
}
}
buf := &bytes.Buffer{}
if err := png.Encode(buf, img); err != nil {
panic(err)
}
j.Compositions[comp.Name] = buf.Bytes()
}
}
开发者ID:surma-dump,项目名称:gophernamedray,代码行数:51,代码来源:compparser.go
示例12: reverseGremlinChainTo
func reverseGremlinChainTo(env *otto.Otto, prevObj *otto.Object, tag string) (*otto.Object, *otto.Object) {
env.Run("var _base_object = {}")
base, err := env.Object("_base_object")
if err != nil {
glog.Error(err)
return otto.NullValue().Object(), otto.NullValue().Object()
}
if isVertexChain(prevObj) {
base.Set("_gremlin_type", "vertex")
} else {
base.Set("_gremlin_type", "morphism")
}
return reverseGremlinChainHelper(env, prevObj, base, tag)
}
开发者ID:JIVS,项目名称:cayley,代码行数:14,代码来源:gremlin-traversals.go
示例13: ForEach
func (p *pathObject) ForEach(call otto.FunctionCall) otto.Value {
it := p.buildIteratorTree()
it.Tagger().Add(TopResultTag)
limit := -1
if len(call.ArgumentList) == 0 {
return otto.NullValue()
}
callback := call.Argument(len(call.ArgumentList) - 1)
args := exportArgs(call.ArgumentList[:len(call.ArgumentList)-1])
if len(args) > 1 {
limit = toInt(args[0])
}
p.wk.runIteratorWithCallback(it, callback, call, limit)
return otto.NullValue()
}
开发者ID:dennwc,项目名称:cayley,代码行数:15,代码来源:finals.go
示例14: Filter
func (p *pathObject) Filter(call otto.FunctionCall) otto.Value {
args := exportArgs(call.ArgumentList)
if len(args) == 0 {
return otto.NullValue()
}
np := p.clonePath()
for _, arg := range args {
op, ok := arg.(cmpOperator)
if !ok {
return otto.NullValue()
}
np = np.Filter(op.op, op.val)
}
return outObj(call, p.new(np))
}
开发者ID:rlugojr,项目名称:cayley,代码行数:15,代码来源:traversals.go
示例15: DirectCallFunction
// Invokes the JS function. Not thread-safe! This is exposed for use by unit tests.
func (server *JSServer) DirectCallFunction(inputs []string) (interface{}, error) {
if server.Before != nil {
server.Before()
}
var result otto.Value
var err error
if server.fn.IsUndefined() {
result = otto.UndefinedValue()
} else {
inputJS := make([]interface{}, len(inputs))
for i, inputStr := range inputs {
if inputStr == "" {
inputJS[i] = otto.NullValue()
} else {
var err error
inputJS[i], err = server.js.Object("x = " + inputStr)
if err != nil {
return nil, fmt.Errorf("Unparseable input %q: %s", inputStr, err)
}
}
}
result, err = server.fn.Call(server.fn, inputJS...)
}
if server.After != nil {
return server.After(result, err)
}
return nil, err
}
开发者ID:steveyen,项目名称:walrus,代码行数:30,代码来源:js_server.go
示例16: Worker
func Worker(lines, out chan *string, script, preload string, wg *sync.WaitGroup) {
defer wg.Done()
vm := otto.New()
if preload != "" {
_, err := vm.Run(preload)
if err != nil {
log.Fatal(err)
}
}
compiled, err := vm.Compile("", script)
if err != nil {
log.Fatal(err)
}
for line := range lines {
vm.Set("input", *line)
_, err := vm.Run(compiled)
if err != nil {
log.Fatal(err)
}
result, err := vm.Get("output")
if result == otto.NullValue() {
continue
}
if err != nil {
log.Fatal(err)
}
r := result.String()
out <- &r
}
}
开发者ID:ubleipzig,项目名称:ottily,代码行数:33,代码来源:main.go
示例17: SpawnPrefab
// SpawnPrefab is an otto function that takes three arguments, a string and two integer. This spawns an object.
// The string is the name of the prefab, while the int arguments are X and Y coords, respectively.
func (api *EngineInterface) SpawnPrefab(call otto.FunctionCall) otto.Value {
prefabName, err := call.Argument(0).ToString()
if err != nil {
gLogger.Fatalln(err)
}
x, err := call.Argument(1).ToInteger()
if err != nil {
gLogger.Fatalln(err)
}
y, err := call.Argument(2).ToInteger()
if err != nil {
gLogger.Fatalln(err)
}
prefab := api.base.Prefabs().Prefab(prefabName)
if prefab == nil {
gLogger.Fatalln("Prefab", prefabName, "doesn't exit")
}
// api is a bit dirty don't you think?
cords := prefab.Component(new(TransformComponent)).(*TransformComponent)
cords.X = int32(x)
cords.Y = int32(y)
return otto.NullValue()
}
开发者ID:j6n,项目名称:Not3D,代码行数:29,代码来源:interface.go
示例18: End
func (rc *RunContext) End(call otto.FunctionCall) otto.Value {
log.Println("END OTTO")
go func() {
rc.EndChan <- true
}()
return otto.NullValue()
}
开发者ID:ciasia,项目名称:go_gsd,代码行数:7,代码来源:RunContext.go
示例19: Execute
func (t *fetchTask) Execute(vm *otto.Otto, l *loop.Loop) error {
var arguments []interface{}
if t.err != nil {
e, err := vm.Call(`new Error`, nil, t.err.Error())
if err != nil {
return err
}
arguments = append(arguments, e)
}
t.jsRes.Set("status", t.status)
t.jsRes.Set("statusText", t.statusText)
h := mustValue(t.jsRes.Get("headers")).Object()
for k, vs := range t.headers {
for _, v := range vs {
if _, err := h.Call("append", k, v); err != nil {
return err
}
}
}
t.jsRes.Set("_body", string(t.body))
if _, err := t.cb.Call(otto.NullValue(), arguments...); err != nil {
return err
}
return nil
}
开发者ID:deoxxa,项目名称:ottoext,代码行数:30,代码来源:fetch.go
示例20: SendMail
func (rc *RunContext) SendMail(call otto.FunctionCall) otto.Value {
if len(call.ArgumentList) < 3 {
return rc.Err("sendMail called with too few parameters")
}
to, err := call.ArgumentList[0].ToString()
if err != nil {
return rc.Err(err.Error())
}
subject, err := call.ArgumentList[1].ToString()
if err != nil {
return rc.Err(err.Error())
}
body, err := call.ArgumentList[2].ToString()
if err != nil {
return rc.Err(err.Error())
}
rc.runner.Mailer.SendMailSimple(to, subject, body)
return otto.NullValue()
}
开发者ID:ciasia,项目名称:go_gsd,代码行数:26,代码来源:RunContext.go
注:本文中的github.com/robertkrimen/otto.NullValue函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论