本文整理汇总了Golang中github.com/juju/juju/apiserver/common/apihttp.NewHandlerArgs类的典型用法代码示例。如果您正苦于以下问题:Golang NewHandlerArgs类的具体用法?Golang NewHandlerArgs怎么用?Golang NewHandlerArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NewHandlerArgs类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newHandlerArgs
func (srv *Server) newHandlerArgs(spec apihttp.HandlerConstraints) apihttp.NewHandlerArgs {
ctxt := httpContext{
srv: srv,
strictValidation: spec.StrictValidation,
controllerModelOnly: spec.ControllerModelOnly,
}
var args apihttp.NewHandlerArgs
switch spec.AuthKind {
case names.UserTagKind:
args.Connect = ctxt.stateForRequestAuthenticatedUser
case names.UnitTagKind:
args.Connect = ctxt.stateForRequestAuthenticatedAgent
case "":
logger.Tracef(`no access level specified; proceeding with "unauthenticated"`)
args.Connect = func(req *http.Request) (*state.State, state.Entity, error) {
st, err := ctxt.stateForRequestUnauthenticated(req)
return st, nil, err
}
default:
logger.Warningf(`unrecognized access level %q; proceeding with "unauthenticated"`, spec.AuthKind)
args.Connect = func(req *http.Request) (*state.State, state.Entity, error) {
st, err := ctxt.stateForRequestUnauthenticated(req)
return st, nil, err
}
}
return args
}
示例2: NewUploadHandler
// NewUploadHandler returns a new HTTP handler for the given args.
func NewUploadHandler(args apihttp.NewHandlerArgs) http.Handler {
return server.NewLegacyHTTPHandler(
func(req *http.Request) (server.DataStore, names.Tag, error) {
st, entity, err := args.Connect(req)
if err != nil {
return nil, nil, errors.Trace(err)
}
resources, err := st.Resources()
if err != nil {
return nil, nil, errors.Trace(err)
}
return resources, entity.Tag(), nil
},
)
}