Exemple #1
0
// Push - Pushes values from `push` context map to context.
func Push(ctx action.Map) (action.Map, error) {
	p := ctx.Pop("push")

	// If it is a string push current context under `push` name to a new one
	if push, ok := p.String(); ok {
		clean := make(action.Map)
		clean.Push(push, ctx)
		return clean, nil
	}

	// If it is a map iterate through `push` map and pull values by `key` from context and push under `value`
	if push, ok := p.Map(); ok {
		for key := range push {
			if value := ctx.Pop(key); !value.IsNil() {
				name, _ := push.Get(key).String()
				ctx.Push(name, value.Value)
				glog.V(3).Infof("Pushing %#v value %#v under name %#v", key, value, name)
			}
		}
		return ctx, nil
	}

	return nil, ErrPushUnexpected
}