本文整理匯總了Golang中github.com/MG-RAST/golib/stretchr/goweb/context.Context.QueryValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.QueryValue方法的具體用法?Golang Context.QueryValue怎麽用?Golang Context.QueryValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/MG-RAST/golib/stretchr/goweb/context.Context
的用法示例。
在下文中一共展示了Context.QueryValue方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WriteResponseObject
// WriteResponseObject writes the status code and response object to the HttpResponseWriter in
// the specified context, in the format best suited based on the request.
//
// Goweb uses the WebCodecService to decide which codec to use when responding
// see http://godoc.org/github.com/stretchr/codecs/services#WebCodecService for more information.
//
// This method should be used when the Goweb Standard Response Object does not satisfy the needs of
// the API, but other Respond* methods are recommended.
func (a *GowebAPIResponder) WriteResponseObject(ctx context.Context, status int, responseObject interface{}) error {
service := a.GetCodecService()
acceptHeader := ctx.HttpRequest().Header.Get("Accept")
extension := ctx.FileExtension()
hasCallback := len(ctx.QueryValue(CallbackParameter)) > 0
codec, codecError := service.GetCodecForResponding(acceptHeader, extension, hasCallback)
if codecError != nil {
return codecError
}
options := ctx.CodecOptions()
// do we need to add some options?
if _, exists := options[constants.OptionKeyClientCallback]; hasCallback && !exists {
options[constants.OptionKeyClientCallback] = ctx.QueryValue(CallbackParameter)
}
output, marshalErr := service.MarshalWithCodec(codec, responseObject, options)
if marshalErr != nil {
return marshalErr
}
// use the HTTP responder to respond
ctx.HttpResponseWriter().Header().Set("Content-Type", codec.ContentType()) // TODO: test me
a.httpResponder.With(ctx, status, output)
return nil
}
示例2: Respond
// Responds to the Context with the specified status, data and errors.
func (a *GowebAPIResponder) Respond(ctx context.Context, status int, data interface{}, errors []string) error {
if data != nil {
var dataErr error
data, dataErr = codecs.PublicData(data, nil)
if dataErr != nil {
return dataErr
}
}
// make the standard response object
if (a.AlwaysEnvelopResponse && ctx.QueryValue("envelop") != "false") || ctx.QueryValue("envelop") == "true" {
sro := map[string]interface{}{
a.StandardFieldStatusKey: status,
}
if data != nil {
sro[a.StandardFieldDataKey] = data
}
if len(errors) > 0 {
sro[a.StandardFieldErrorsKey] = errors
}
data = sro
}
// transform the object
var transformErr error
data, transformErr = a.TransformStandardResponseObject(ctx, data)
if transformErr != nil {
return transformErr
}
return a.WriteResponseObject(ctx, status, data)
}