Ejemplo n.º 1
0
// ContextWithLoggable returns a derived context which contains the provided
// Loggable. Any Events logged with the derived context will include the
// provided Loggable.
func ContextWithLoggable(ctx context.Context, l Loggable) context.Context {
	existing, err := MetadataFromContext(ctx)
	if err != nil {
		// context does not contain meta. just set the new metadata
		child := context.WithValue(ctx, metadataKey, Metadata(l.Loggable()))
		return child
	}

	merged := DeepMerge(existing, l.Loggable())
	child := context.WithValue(ctx, metadataKey, merged)
	return child
}
Ejemplo n.º 2
0
				res.SetError(fmt.Errorf("error parsing lifetime option: %s", err), cmds.ErrNormal)
				return
			}

			popts.pubValidTime = d
		}

		ctx := req.Context()
		if ttl, found, _ := req.Option("ttl").String(); found {
			d, err := time.ParseDuration(ttl)
			if err != nil {
				res.SetError(err, cmds.ErrNormal)
				return
			}

			ctx = context.WithValue(ctx, "ipns-publish-ttl", d)
		}

		output, err := publish(ctx, n, n.PrivateKey, path.Path(pstr), popts)
		if err != nil {
			res.SetError(err, cmds.ErrNormal)
			return
		}
		res.SetOutput(output)
	},
	Marshalers: cmds.MarshalerMap{
		cmds.Text: func(res cmds.Response) (io.Reader, error) {
			v := res.Output().(*IpnsEntry)
			s := fmt.Sprintf("Published to %s: %s\n", v.Name, v.Value)
			return strings.NewReader(s), nil
		},
Ejemplo n.º 3
0
func RegisterForQueryEvents(ctx context.Context, ch chan<- *QueryEvent) context.Context {
	return context.WithValue(ctx, RoutingQueryKey, ch)
}
Ejemplo n.º 4
0
// ContextWithErrorLog returns a copy of parent and an error channel that can
// be used to receive errors sent with the LogError method.
func ContextWithErrorLog(parent context.Context) (context.Context, <-chan error) {
	errs := make(privateChanType)
	ctx := context.WithValue(parent, errLogKey, errs)
	return ctx, errs
}