本文整理汇总了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
}