Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (23 sloc) 606 Bytes
package gologin
import (
"context"
"fmt"
)
// unexported key type prevents collisions
type key int
const (
errorKey key = iota
)
// WithError returns a copy of ctx that stores the given error value.
func WithError(ctx context.Context, err error) context.Context {
return context.WithValue(ctx, errorKey, err)
}
// ErrorFromContext returns the error value from the ctx or an error that the
// context was missing an error value.
func ErrorFromContext(ctx context.Context) error {
err, ok := ctx.Value(errorKey).(error)
if !ok {
return fmt.Errorf("Context missing error value")
}
return err
}
You can’t perform that action at this time.