當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Object.Set方法代碼示例

本文整理匯總了Golang中github.com/robertkrimen/otto.Object.Set方法的典型用法代碼示例。如果您正苦於以下問題:Golang Object.Set方法的具體用法?Golang Object.Set怎麽用?Golang Object.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/robertkrimen/otto.Object的用法示例。


在下文中一共展示了Object.Set方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例2: ResponseWriterToJso

func ResponseWriterToJso(o *otto.Object, w http.ResponseWriter) {
	o.Set("write", func(c otto.FunctionCall) otto.Value {
		text, _ := c.Argument(0).ToString()
		w.Write([]byte(text))
		return otto.TrueValue()
	})
	o.Set("writeHeader", func(c otto.FunctionCall) otto.Value {
		statusCode, _ := c.Argument(0).ToInteger()
		w.WriteHeader(int(statusCode))
		return otto.TrueValue()
	})
}
開發者ID:BlackEspresso,項目名稱:ServeJS,代碼行數:12,代碼來源:http.go

示例3: embedFinals

func embedFinals(env *otto.Otto, ses *Session, obj *otto.Object) {
	obj.Set("All", allFunc(env, ses, obj))
	obj.Set("GetLimit", limitFunc(env, ses, obj))
	obj.Set("ToArray", toArrayFunc(env, ses, obj, false))
	obj.Set("ToValue", toValueFunc(env, ses, obj, false))
	obj.Set("TagArray", toArrayFunc(env, ses, obj, true))
	obj.Set("TagValue", toValueFunc(env, ses, obj, true))
	obj.Set("Map", mapFunc(env, ses, obj))
	obj.Set("ForEach", mapFunc(env, ses, obj))
}
開發者ID:jacqui,項目名稱:cayley,代碼行數:10,代碼來源:finals.go

示例4: embedFinals

func (wk *worker) embedFinals(env *otto.Otto, obj *otto.Object) {
	obj.Set("All", wk.allFunc(env, obj))
	obj.Set("GetLimit", wk.limitFunc(env, obj))
	obj.Set("ToArray", wk.toArrayFunc(env, obj, false))
	obj.Set("ToValue", wk.toValueFunc(env, obj, false))
	obj.Set("TagArray", wk.toArrayFunc(env, obj, true))
	obj.Set("TagValue", wk.toValueFunc(env, obj, true))
	obj.Set("Map", wk.mapFunc(env, obj))
	obj.Set("ForEach", wk.mapFunc(env, obj))
}
開發者ID:Joeento,項目名稱:cayley,代碼行數:10,代碼來源:finals.go

示例5: embedTraversals

func (wk *worker) embedTraversals(env *otto.Otto, obj *otto.Object) {
	for _, t := range traversals {
		obj.Set(t, wk.gremlinFunc(t, obj, env))
	}
}
開發者ID:kortschak,項目名稱:cayley,代碼行數:5,代碼來源:traversals.go

示例6: embedTraversals

func embedTraversals(env *otto.Otto, ses *GremlinSession, obj *otto.Object) {
	obj.Set("In", gremlinFunc("in", obj, env, ses))
	obj.Set("Out", gremlinFunc("out", obj, env, ses))
	obj.Set("Is", gremlinFunc("is", obj, env, ses))
	obj.Set("Both", gremlinFunc("both", obj, env, ses))
	obj.Set("Follow", gremlinFunc("follow", obj, env, ses))
	obj.Set("FollowR", gremlinFollowR("followr", obj, env, ses))
	obj.Set("And", gremlinFunc("and", obj, env, ses))
	obj.Set("Intersect", gremlinFunc("and", obj, env, ses))
	obj.Set("Union", gremlinFunc("or", obj, env, ses))
	obj.Set("Or", gremlinFunc("or", obj, env, ses))
	obj.Set("Back", gremlinBack("back", obj, env, ses))
	obj.Set("Tag", gremlinFunc("tag", obj, env, ses))
	obj.Set("As", gremlinFunc("tag", obj, env, ses))
	obj.Set("Has", gremlinFunc("has", obj, env, ses))
	obj.Set("Save", gremlinFunc("save", obj, env, ses))
	obj.Set("SaveR", gremlinFunc("saver", obj, env, ses))
}
開發者ID:JIVS,項目名稱:cayley,代碼行數:18,代碼來源:gremlin-traversals.go

示例7: RequestToJso

func RequestToJso(o *otto.Object, r *http.Request) {
	o.Set("url", r.URL.String())
	o.Set("header", r.Header)
	o.Set("cookies", r.Cookies())
	o.Set("method", r.Method)
	o.Set("host", r.Host)
	o.Set("contentLength", r.ContentLength)
	o.Set("proto", r.Proto)
	o.Set("transferEncoding", r.TransferEncoding)
	r.ParseForm()
	o.Set("formValues", r.Form)
}
開發者ID:BlackEspresso,項目名稱:ServeJS,代碼行數:12,代碼來源:http.go

示例8: ResponseToJso

func ResponseToJso(o *otto.Object, w *http.Response) {
	o.Set("status", w.Status)
	o.Set("header", w.Header)
	o.Set("cookies", w.Cookies())
	o.Set("statusCode", w.StatusCode)
	o.Set("proto", w.Proto)
	c, _ := ioutil.ReadAll(w.Body)
	o.Set("body", string(c))
	if w.TLS != nil {
		o.Set("tlsServerName", w.TLS.ServerName)
		o.Set("tlsNegotiatedProtocol", w.TLS.NegotiatedProtocol)
		names := []string{}
		ips := []string{}
		for _, k := range w.TLS.PeerCertificates {
			for _, n := range k.DNSNames {
				names = append(names, n)
			}
			for _, n := range k.IPAddresses {
				ips = append(ips, n.String())
			}
		}
		o.Set("tlsDNSNames", names)
		o.Set("tlsIPs", ips)
	}
}
開發者ID:BlackEspresso,項目名稱:ServeJS,代碼行數:25,代碼來源:http.go

示例9: embedTraversals

func (wk *worker) embedTraversals(env *otto.Otto, obj *otto.Object) {
	obj.Set("In", wk.gremlinFunc("in", obj, env))
	obj.Set("Out", wk.gremlinFunc("out", obj, env))
	obj.Set("Is", wk.gremlinFunc("is", obj, env))
	obj.Set("Both", wk.gremlinFunc("both", obj, env))
	obj.Set("Follow", wk.gremlinFunc("follow", obj, env))
	obj.Set("FollowR", wk.gremlinFollowR("followr", obj, env))
	obj.Set("And", wk.gremlinFunc("and", obj, env))
	obj.Set("Intersect", wk.gremlinFunc("and", obj, env))
	obj.Set("Union", wk.gremlinFunc("or", obj, env))
	obj.Set("Or", wk.gremlinFunc("or", obj, env))
	obj.Set("Back", wk.gremlinBack("back", obj, env))
	obj.Set("Tag", wk.gremlinFunc("tag", obj, env))
	obj.Set("As", wk.gremlinFunc("tag", obj, env))
	obj.Set("Has", wk.gremlinFunc("has", obj, env))
	obj.Set("Save", wk.gremlinFunc("save", obj, env))
	obj.Set("SaveR", wk.gremlinFunc("saver", obj, env))
	obj.Set("Except", wk.gremlinFunc("except", obj, env))
	obj.Set("Difference", wk.gremlinFunc("except", obj, env))
	obj.Set("InPredicates", wk.gremlinFunc("in_predicates", obj, env))
	obj.Set("OutPredicates", wk.gremlinFunc("out_predicates", obj, env))
}
開發者ID:lytics,項目名稱:cayley,代碼行數:22,代碼來源:traversals.go


注:本文中的github.com/robertkrimen/otto.Object.Set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。