本文整理匯總了Golang中github.com/google/cayley/query.HttpSession.InputParses方法的典型用法代碼示例。如果您正苦於以下問題:Golang HttpSession.InputParses方法的具體用法?Golang HttpSession.InputParses怎麽用?Golang HttpSession.InputParses使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/google/cayley/query.HttpSession
的用法示例。
在下文中一共展示了HttpSession.InputParses方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ServeV1Shape
func (api *Api) ServeV1Shape(w http.ResponseWriter, r *http.Request, params httprouter.Params) int {
var ses query.HttpSession
switch params.ByName("query_lang") {
case "gremlin":
ses = gremlin.NewSession(api.ts, api.config.GremlinTimeout, false)
case "mql":
ses = mql.NewSession(api.ts)
default:
return FormatJson400(w, "Need a query language.")
}
bodyBytes, err := ioutil.ReadAll(r.Body)
if err != nil {
return FormatJson400(w, 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 FormatJson400(w, err)
}
fmt.Fprint(w, string(output))
return 200
case query.ParseFail:
return FormatJson400(w, err)
default:
return FormatJsonError(w, 500, "Incomplete data?")
}
http.Error(w, "", http.StatusNotFound)
return http.StatusNotFound
}
示例2: ServeV1Query
// TODO(barakmich): Turn this into proper middleware.
func (api *Api) ServeV1Query(w http.ResponseWriter, r *http.Request, params httprouter.Params) int {
var ses query.HttpSession
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 FormatJson400(w, "Need a query language.")
}
bodyBytes, err := ioutil.ReadAll(r.Body)
if err != nil {
return FormatJson400(w, err)
}
code := string(bodyBytes)
result, err := ses.InputParses(code)
switch result {
case query.Parsed:
var output interface{}
var bytes []byte
var err error
output, err = RunJsonQuery(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 FormatJson400(w, err)
}
fmt.Fprint(w, string(bytes))
ses = nil
return 200
case query.ParseFail:
ses = nil
return FormatJson400(w, err)
default:
ses = nil
return FormatJsonError(w, 500, "Incomplete data?")
}
}