當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Error.SetResponseGoError方法代碼示例

本文整理匯總了Golang中github.com/cockroachdb/cockroach/proto.Error.SetResponseGoError方法的典型用法代碼示例。如果您正苦於以下問題:Golang Error.SetResponseGoError方法的具體用法?Golang Error.SetResponseGoError怎麽用?Golang Error.SetResponseGoError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cockroachdb/cockroach/proto.Error的用法示例。


在下文中一共展示了Error.SetResponseGoError方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: makeResultFromError

// If we hit an error and there is a pending transaction, rollback
// the transaction before returning. The client does not have to
// deal with cleaning up transaction state.
func makeResultFromError(planMaker *planner, err error) driver.Result {
	if planMaker.txn != nil {
		if err != errTransactionAborted {
			planMaker.txn.Cleanup(err)
		}
		// This transaction will normally get marked aborted as part of
		// Cleanup above, but we do it explicitly here because edge cases
		// exist:
		// (1)
		// BEGIN
		// <some operation which is implemented using CPut, which fails>
		// (2)
		// BEGIN
		// <syntax error>
		// Both cases will not write any intents, and so client.Txn will
		// not actually send an EndTransaction, and rightly so.
		// Unfortunately, we depend on txn.Proto.Status being equivalent to
		// our SQL transaction's status, and in these cases, our SQL
		// transaction is aborted.
		planMaker.txn.Proto.Status = proto.ABORTED
	}
	var errProto proto.Error
	errProto.SetResponseGoError(err)
	return driver.Result{Error: &errProto}
}
開發者ID:kangxinrong,項目名稱:cockroach,代碼行數:28,代碼來源:server.go

示例2: ServeHTTP

// ServeHTTP serves the SQL API by treating the request URL path
// as the method, the request body as the arguments, and sets the
// response body as the method reply. The request body is unmarshalled
// into arguments based on the Content-Type request header. Protobuf
// and JSON-encoded requests are supported. The response body is
// encoded according to the request's Accept header, or if not
// present, in the same format as the request's incoming Content-Type
// header.
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()
	method := r.URL.Path
	if !strings.HasPrefix(method, driver.Endpoint) {
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}

	// Check TLS settings.
	authenticationHook, err := security.AuthenticationHook(s.context.Insecure, r.TLS)
	if err != nil {
		http.Error(w, err.Error(), http.StatusUnauthorized)
		return
	}

	method = strings.TrimPrefix(method, driver.Endpoint)
	if method != driver.Execute.String() {
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}

	// Unmarshal the request.
	reqBody, err := ioutil.ReadAll(r.Body)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	var args driver.Request
	if err := util.UnmarshalRequest(r, reqBody, &args, allowedEncodings); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	// Check request user against client certificate user.
	if err := authenticationHook(&args); err != nil {
		http.Error(w, err.Error(), http.StatusUnauthorized)
		return
	}

	// Send the Request for SQL execution and set the application-level error
	// on the reply.
	reply, err := s.exec(args)
	if err != nil {
		errProto := proto.Error{}
		errProto.SetResponseGoError(err)
		reply.Error = &errProto
	}

	// Marshal the response.
	body, contentType, err := util.MarshalResponse(r, &reply, allowedEncodings)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.Header().Set(util.ContentTypeHeader, contentType)
	w.Write(body)
}
開發者ID:arypurnomoz,項目名稱:cockroach,代碼行數:66,代碼來源:server.go

示例3: makeResultFromError

// If we hit an error and there is a pending transaction, rollback
// the transaction before returning. The client does not have to
// deal with cleaning up transaction state.
func makeResultFromError(planMaker *planner, err error) driver.Result {
	if planMaker.txn != nil {
		if err != errTransactionAborted {
			planMaker.txn.Cleanup(err)
		}
	}
	var errProto proto.Error
	errProto.SetResponseGoError(err)
	return driver.Result{Error: &errProto}
}
開發者ID:earlredwolf,項目名稱:cockroach,代碼行數:13,代碼來源:executor.go

示例4: rollbackTxnAndReturnResultWithError

// If we hit an error and there is a pending transaction, rollback
// the transaction before returning. The client does not have to
// deal with cleaning up transaction state.
func rollbackTxnAndReturnResultWithError(planMaker *planner, err error) driver.Result {
	if planMaker.txn != nil {
		// What do we do with a rollback error? This is an internally
		// initiated rollback that the client is unaware of. Reporting it
		// will only cause confusion. Not reporting it could leave a transaction
		// pending, but that will get GCed eventually.
		_ = planMaker.txn.Rollback()
	}
	var errProto proto.Error
	errProto.SetResponseGoError(err)
	return driver.Result{Error: &errProto}
}
開發者ID:slavau,項目名稱:cockroach,代碼行數:15,代碼來源:server.go


注:本文中的github.com/cockroachdb/cockroach/proto.Error.SetResponseGoError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。