本文整理汇总了Golang中github.com/google/cayley/query.HTTP类的典型用法代码示例。如果您正苦于以下问题:Golang HTTP类的具体用法?Golang HTTP怎么用?Golang HTTP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTTP类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: runQuery
func runQuery(queryLang, code string) (interface{}, error) {
qs := &QuadStore{}
var ses query.HTTP
switch queryLang {
case "gremlin":
ses = gremlin.NewSession(qs, 100*time.Second, false)
case "mql":
ses = mql.NewSession(qs)
default:
}
result, err := ses.Parse(code)
switch result {
case query.Parsed:
output, err := Run(code, ses)
if err != nil {
return nil, err
}
return output, nil
case query.ParseFail:
ses = nil
return nil, err
default:
ses = nil
return nil, fmt.Errorf("Incomplete data?")
}
}
开发者ID:nunb,项目名称:degdb,代码行数:26,代码来源:gremlin.go
示例2: ServeV1Shape
func (api *API) ServeV1Shape(w http.ResponseWriter, r *http.Request, params httprouter.Params) int {
var ses query.HTTP
switch params.ByName("query_lang") {
case "gremlin":
ses = gremlin.NewSession(api.handle.QuadStore, api.config.Timeout, false)
case "mql":
ses = mql.NewSession(api.handle.QuadStore)
default:
return jsonResponse(w, 400, "Need a query language.")
}
bodyBytes, err := ioutil.ReadAll(r.Body)
if err != nil {
return jsonResponse(w, 400, err)
}
code := string(bodyBytes)
result, err := ses.InputParses(code)
switch result {
case query.Parsed:
var output []byte
var err error
output, err = GetQueryShape(code, ses)
if err != nil {
return jsonResponse(w, 400, err)
}
fmt.Fprint(w, string(output))
return 200
case query.ParseFail:
return jsonResponse(w, 400, err)
default:
return jsonResponse(w, 500, "Incomplete data?")
}
}
开发者ID:ericcapricorn,项目名称:cayley,代码行数:32,代码来源:query.go
示例3: GetQueryShape
func GetQueryShape(q string, ses query.HTTP) ([]byte, error) {
s, err := ses.ShapeOf(q)
if err != nil {
return nil, err
}
return json.Marshal(s)
}
开发者ID:e4x,项目名称:cayley,代码行数:7,代码来源:query.go
示例4: GetQueryShape
func GetQueryShape(q string, ses query.HTTP) ([]byte, error) {
c := make(chan map[string]interface{}, 5)
go ses.GetQuery(q, c)
var data map[string]interface{}
for res := range c {
data = res
}
return json.Marshal(data)
}
开发者ID:ericcapricorn,项目名称:cayley,代码行数:9,代码来源:query.go
示例5: ServeV1Query
// TODO(barakmich): Turn this into proper middleware.
func (api *API) ServeV1Query(w http.ResponseWriter, r *http.Request, params httprouter.Params) int {
h, err := api.GetHandleForRequest(r)
var ses query.HTTP
switch params.ByName("query_lang") {
case "gremlin":
ses = gremlin.NewSession(h.QuadStore, api.config.Timeout, false)
case "mql":
ses = mql.NewSession(h.QuadStore)
default:
return jsonResponse(w, 400, "Need a query language.")
}
bodyBytes, err := ioutil.ReadAll(r.Body)
if err != nil {
return jsonResponse(w, 400, err)
}
code := string(bodyBytes)
result, err := ses.Parse(code)
switch result {
case query.Parsed:
var output interface{}
var bytes []byte
var err error
output, err = Run(code, ses)
if err != nil {
bytes, err = WrapErrResult(err)
http.Error(w, string(bytes), 400)
ses = nil
return 400
}
bytes, err = WrapResult(output)
if err != nil {
ses = nil
return jsonResponse(w, 400, err)
}
fmt.Fprint(w, string(bytes))
ses = nil
return 200
case query.ParseFail:
ses = nil
return jsonResponse(w, 400, err)
default:
ses = nil
return jsonResponse(w, 500, "Incomplete data?")
}
}
开发者ID:e4x,项目名称:cayley,代码行数:46,代码来源:query.go
示例6: Run
func Run(q string, ses query.HTTP) (interface{}, error) {
c := make(chan interface{}, 5)
go ses.ExecInput(q, c, 100)
for res := range c {
ses.BuildJSON(res)
}
return ses.GetJSON()
}
开发者ID:ericcapricorn,项目名称:cayley,代码行数:8,代码来源:query.go
示例7: Run
func Run(q string, ses query.HTTP) (interface{}, error) {
c := make(chan interface{}, 5)
go ses.Execute(q, c, 100)
for res := range c {
ses.Collate(res)
}
return ses.Results()
}
开发者ID:e4x,项目名称:cayley,代码行数:8,代码来源:query.go
示例8: runGremlinQuery
func runGremlinQuery(q string, session cayleyQuery.HTTP) (interface{}, error) {
c := make(chan interface{}, 5)
go session.Execute(q, c, 100)
for result := range c {
session.Collate(result)
}
return session.Results()
}
开发者ID:rentpath,项目名称:ogma-prime,代码行数:9,代码来源:ogma-prime.go
注:本文中的github.com/google/cayley/query.HTTP类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论