当前位置: 首页>>代码示例>>Golang>>正文


Golang errors.MethodNotAllowedf函数代码示例

本文整理汇总了Golang中github.com/juju/errors.MethodNotAllowedf函数的典型用法代码示例。如果您正苦于以下问题:Golang MethodNotAllowedf函数的具体用法?Golang MethodNotAllowedf怎么用?Golang MethodNotAllowedf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MethodNotAllowedf函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ServeHTTP

func (h *toolsDownloadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	st, err := h.ctxt.stateForRequestUnauthenticated(r)
	if err != nil {
		if err := sendError(w, err); err != nil {
			logger.Errorf("%v", err)
		}
		return
	}

	switch r.Method {
	case "GET":
		tarball, err := h.processGet(r, st)
		if err != nil {
			logger.Errorf("GET(%s) failed: %v", r.URL, err)
			if err := sendError(w, errors.NewBadRequest(err, "")); err != nil {
				logger.Errorf("%v", err)
			}
			return
		}
		if err := h.sendTools(w, http.StatusOK, tarball); err != nil {
			logger.Errorf("%v", err)
		}
	default:
		if err := sendError(w, errors.MethodNotAllowedf("unsupported method: %q", r.Method)); err != nil {
			logger.Errorf("%v", err)
		}
	}
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:tools.go

示例2: ServeHTTP

// ServeHTTP implements http.Handler.
func (h *LegacyHTTPHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
	st, tag, err := h.Connect(req)
	if err != nil {
		api.SendHTTPError(resp, err)
		return
	}

	var username string
	switch tag := tag.(type) {
	case *names.UserTag:
		username = tag.Name()
	default:
		// TODO(ericsnow) Fail?
		username = tag.Id()
	}

	// We do this *after* authorization, etc. (in h.Connect) in order
	// to prioritize errors that may originate there.
	switch req.Method {
	case "PUT":
		logger.Infof("handling resource upload request")
		response, err := h.HandleUpload(username, st, req)
		if err != nil {
			api.SendHTTPError(resp, err)
			return
		}
		api.SendHTTPStatusAndJSON(resp, http.StatusOK, &response)
		logger.Infof("resource upload request successful")
	default:
		api.SendHTTPError(resp, errors.MethodNotAllowedf("unsupported method: %q", req.Method))
	}
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:33,代码来源:handler.go

示例3: _http_TestService_List

func (h *testServiceHandler) _http_TestService_List(ctx golang_org_x_net_context.Context, rw net_http.ResponseWriter, req *net_http.Request) error {
	if req.Method != "GET" {
		return github_com_juju_errors.MethodNotAllowedf("expected GET request")
	}

	var (
		input ListOptions
	)

	ctx = github_com_limbo_services_core_runtime_limbo.AnnotateContext(ctx, req)

	// populate after=after
	{
		var msg0 = &input
		val := req.URL.Query().Get("after")
		intVal, _ := strconv.ParseInt(val, 10, 64)
		msg0.After = int64(intVal)
	}

	{ // call
		ss, err := github_com_limbo_services_core_runtime_limbo.NewPagedServerStream(ctx, rw, 0)
		if err != nil {
			return github_com_juju_errors.Trace(err)
		}
		defer ss.Close()
		stream := &testServiceListServer{ss}
		err = h.ss.List(&input, stream)
	}

	return nil
}
开发者ID:limbo-services,项目名称:core,代码行数:31,代码来源:example.pb.go

示例4: ServeHTTP

func (h *backupHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
	// Validate before authenticate because the authentication is dependent
	// on the state connection that is determined during the validation.
	st, _, err := h.ctxt.stateForRequestAuthenticatedUser(req)
	if err != nil {
		h.sendError(resp, err)
		return
	}

	backups, closer := newBackups(st)
	defer closer.Close()

	switch req.Method {
	case "GET":
		logger.Infof("handling backups download request")
		id, err := h.download(backups, resp, req)
		if err != nil {
			h.sendError(resp, err)
			return
		}
		logger.Infof("backups download request successful for %q", id)
	case "PUT":
		logger.Infof("handling backups upload request")
		id, err := h.upload(backups, resp, req)
		if err != nil {
			h.sendError(resp, err)
			return
		}
		logger.Infof("backups upload request successful for %q", id)
	default:
		h.sendError(resp, errors.MethodNotAllowedf("unsupported method: %q", req.Method))
	}
}
开发者ID:bac,项目名称:juju,代码行数:33,代码来源:backup.go

示例5: _http_TestService_FetchPerson

func (h *testServiceHandler) _http_TestService_FetchPerson(ctx golang_org_x_net_context.Context, rw net_http.ResponseWriter, req *net_http.Request) error {
	if req.Method != "GET" {
		return github_com_juju_errors.MethodNotAllowedf("expected GET request")
	}

	var (
		input  FetchOptions
		params = github_com_limbo_services_core_runtime_router.P(ctx)
	)

	ctx = github_com_limbo_services_core_runtime_limbo.AnnotateContext(ctx, req)

	// populate id
	{
		var msg0 = &input
		val := params.Get("id")
		intVal, _ := strconv.ParseInt(val, 10, 64)
		msg0.Id = int64(intVal)
	}

	{ // call
		output, err := h.ss.FetchPerson(ctx, &input)
		if err != nil {
			return github_com_juju_errors.Trace(err)
		}
		github_com_limbo_services_core_runtime_limbo.RenderMessageJSON(rw, 200, output)
		return nil
	}

	return nil
}
开发者ID:limbo-services,项目名称:core,代码行数:31,代码来源:example.pb.go

示例6: _http_TestService_Greet

func (h *testServiceHandler) _http_TestService_Greet(ctx golang_org_x_net_context.Context, rw net_http.ResponseWriter, req *net_http.Request) error {
	if req.Method != "POST" {
		return github_com_juju_errors.MethodNotAllowedf("expected POST request")
	}

	var (
		input Person
	)

	ctx = github_com_limbo_services_core_runtime_limbo.AnnotateContext(ctx, req)

	{ // from body
		err := encoding_json.NewDecoder(req.Body).Decode(&input)
		if err != nil {
			return github_com_juju_errors.Trace(err)
		}
	}

	{ // call
		output, err := h.ss.Greet(ctx, &input)
		if err != nil {
			return github_com_juju_errors.Trace(err)
		}
		github_com_limbo_services_core_runtime_limbo.RenderMessageJSON(rw, 200, output)
		return nil
	}

	return nil
}
开发者ID:limbo-services,项目名称:core,代码行数:29,代码来源:example.pb.go

示例7: ServeHTTP

// ServeHTTP implements the http.Handler interface.
func (h *registerUserHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	if req.Method != "POST" {
		sendError(w, errors.MethodNotAllowedf("unsupported method: %q", req.Method))
		return
	}
	st, err := h.ctxt.stateForRequestUnauthenticated(req)
	if err != nil {
		sendError(w, err)
		return
	}
	userTag, response, err := h.processPost(req, st)
	if err != nil {
		sendError(w, err)
		return
	}

	// Set a short-lived macaroon as a cookie on the response,
	// which the client can use to obtain a discharge macaroon.
	m, err := h.ctxt.srv.authCtxt.CreateLocalLoginMacaroon(userTag)
	if err != nil {
		sendError(w, err)
		return
	}
	cookie, err := httpbakery.NewCookie(macaroon.Slice{m})
	if err != nil {
		sendError(w, err)
		return
	}
	http.SetCookie(w, cookie)

	sendStatusAndJSON(w, http.StatusOK, response)
}
开发者ID:kat-co,项目名称:juju,代码行数:33,代码来源:registration.go

示例8: ServeHTTP

// ServeHTTP implements http.Handler.
func (h *guiVersionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	if req.Method != "PUT" {
		sendError(w, errors.MethodNotAllowedf("unsupported method: %q", req.Method))
		return
	}
	if err := h.handlePut(w, req); err != nil {
		sendError(w, errors.Trace(err))
	}
}
开发者ID:kat-co,项目名称:juju,代码行数:10,代码来源:gui.go

示例9: ServeHTTP

func (h *charmsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	var err error
	switch r.Method {
	case "POST":
		err = h.servePost(w, r)
	case "GET":
		err = h.serveGet(w, r)
	default:
		err = errors.MethodNotAllowedf("unsupported method: %q", r.Method)
	}
	if err != nil {
		h.sendError(w, r, err)
	}
}
开发者ID:pmatulis,项目名称:juju,代码行数:14,代码来源:charms.go

示例10: ServeHTTP

// ServeHTTP implements the http.Handler interface.
func (h *registerUserHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	if req.Method != "POST" {
		sendError(w, errors.MethodNotAllowedf("unsupported method: %q", req.Method))
		return
	}
	st, err := h.ctxt.stateForRequestUnauthenticated(req)
	if err != nil {
		sendError(w, err)
		return
	}
	response, err := h.processPost(req, st)
	if err != nil {
		sendError(w, err)
		return
	}
	sendStatusAndJSON(w, http.StatusOK, response)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:18,代码来源:registration.go

示例11: ServeHTTP

func (h *imagesDownloadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	st, err := h.ctxt.stateForRequestUnauthenticated(r)
	if err != nil {
		sendError(w, err)
		return
	}
	switch r.Method {
	case "GET":
		err := h.processGet(r, w, st)
		if err != nil {
			logger.Errorf("GET(%s) failed: %v", r.URL, err)
			sendError(w, err)
			return
		}
	default:
		sendError(w, errors.MethodNotAllowedf("unsupported method: %q", r.Method))
	}
}
开发者ID:imoapps,项目名称:juju,代码行数:18,代码来源:images.go

示例12: ServeHTTP

// ServeHTTP implements http.Handler.
func (h *LegacyHTTPHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
	opener, err := h.NewResourceOpener(req)
	if err != nil {
		h.SendHTTPError(resp, err)
		return
	}

	// We do this *after* authorization, etc. (in h.Extract...) in order
	// to prioritize errors that may originate there.
	switch req.Method {
	case "GET":
		logger.Infof("handling resource download request")

		opened, err := h.HandleDownload(opener, req)
		if err != nil {
			logger.Errorf("cannot fetch resource reader: %v", err)
			h.SendHTTPError(resp, err)
			return
		}
		defer opened.Close()

		h.UpdateDownloadResponse(resp, opened.Resource)

		resp.WriteHeader(http.StatusOK)
		if err := h.Copy(resp, opened); err != nil {
			// We cannot use api.SendHTTPError here, so we log the error
			// and move on.
			logger.Errorf("unable to complete stream for resource: %v", err)
			return
		}

		logger.Infof("resource download request successful")
	default:
		h.SendHTTPError(resp, errors.MethodNotAllowedf("unsupported method: %q", req.Method))
	}
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:37,代码来源:handler.go

示例13:

	err:        common.OperationBlockedError("test"),
	code:       params.CodeOperationBlocked,
	status:     http.StatusBadRequest,
	helperFunc: params.IsCodeOperationBlocked,
}, {
	err:        errors.NotSupportedf("needed feature"),
	code:       params.CodeNotSupported,
	status:     http.StatusInternalServerError,
	helperFunc: params.IsCodeNotSupported,
}, {
	err:        errors.BadRequestf("something"),
	code:       params.CodeBadRequest,
	status:     http.StatusBadRequest,
	helperFunc: params.IsBadRequest,
}, {
	err:        errors.MethodNotAllowedf("something"),
	code:       params.CodeMethodNotAllowed,
	status:     http.StatusMethodNotAllowed,
	helperFunc: params.IsMethodNotAllowed,
}, {
	err:    stderrors.New("an error"),
	status: http.StatusInternalServerError,
	code:   "",
}, {
	err: &common.DischargeRequiredError{
		Cause:    errors.New("something"),
		Macaroon: sampleMacaroon,
	},
	status: http.StatusUnauthorized,
	code:   params.CodeDischargeRequired,
	helperFunc: func(err error) bool {
开发者ID:bac,项目名称:juju,代码行数:31,代码来源:errors_test.go

示例14: emitUnsupportedMethodErr

func emitUnsupportedMethodErr(method string) error {
	return errors.MethodNotAllowedf("unsupported method: %q", method)
}
开发者ID:bac,项目名称:juju,代码行数:3,代码来源:charms.go


注:本文中的github.com/juju/errors.MethodNotAllowedf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。