本文整理匯總了Golang中github.com/juju/juju/apiserver/common/apihttp.NewHandlerArgs.Connect方法的典型用法代碼示例。如果您正苦於以下問題:Golang NewHandlerArgs.Connect方法的具體用法?Golang NewHandlerArgs.Connect怎麽用?Golang NewHandlerArgs.Connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/apiserver/common/apihttp.NewHandlerArgs
的用法示例。
在下文中一共展示了NewHandlerArgs.Connect方法的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
},
)
}