本文整理匯總了Golang中github.com/codedellemc/libstorage/api/types.Context.Error方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Error方法的具體用法?Golang Context.Error怎麽用?Golang Context.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/codedellemc/libstorage/api/types.Context
的用法示例。
在下文中一共展示了Context.Error方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: makeHTTPHandler
func (s *server) makeHTTPHandler(
ctx types.Context,
route types.Route) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
w.Header().Set(types.ServerNameHeader, s.name)
ctx := context.WithRequestRoute(ctx, req, route)
if req.TLS != nil {
if len(req.TLS.PeerCertificates) > 0 {
userName := req.TLS.PeerCertificates[0].Subject.CommonName
ctx = ctx.WithValue(context.UserKey, userName)
}
}
ctx.Info("http request")
vars := mux.Vars(req)
if vars == nil {
vars = map[string]string{}
}
store := utils.NewStoreWithVars(vars)
handlerFunc := s.handleWithMiddleware(ctx, route)
if err := handlerFunc(ctx, w, req, store); err != nil {
ctx.Error(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}
示例2: TrapSignals
// TrapSignals tells the process to trap incoming process signals.
func TrapSignals(ctx apitypes.Context) {
context.RegisterCustomKey(signalContextKey, context.CustomLoggerKey)
sigc := make(chan os.Signal, 1)
signal.Notify(sigc)
go func() {
for s := range sigc {
ctx := ctx.WithValue(signalContextKey, s.String())
if ok, graceful := IsExitSignal(s); ok && !graceful {
ctx.Error("received signal; aborting")
os.Exit(1)
}
func() {
sigHandlersRWL.RLock()
defer sigHandlersRWL.RUnlock()
// execute the signal handlers in reverse order. the first
// one registered should be executed last as it was registered
// the earliest
for i := len(sigHandlers) - 1; i >= 0; i-- {
sigHandlers[i](ctx, s)
}
}()
if ok, graceful := IsExitSignal(s); ok && graceful {
ctx.Error("received signal; shutting down")
os.Exit(0)
}
}
}()
}
示例3: Handle
// Handle is the type's Handler function.
func (h *errorHandler) Handle(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
err := h.handler(ctx, w, req, store)
if err == nil {
return nil
}
ctx.Error(err)
httpErr := goof.NewHTTPError(err, getStatus(err))
httputils.WriteJSON(w, httpErr.Status(), httpErr)
return nil
}