-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enables to pre-fill PubSub Message Attributes independent of CloudEvent spec. Thus this allows for setting arbitrary Message Attributes (given that they are not later overwritten by CloudEvent Attributes). Signed-off-by: Andreas Bergmeier <andreas.bergmeier@otto.de>
- Loading branch information
1 parent
0836a52
commit ed7be6b
Showing
5 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Copyright 2021 The CloudEvents Authors | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package pubsub | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cloudevents/sdk-go/v2/binding" | ||
) | ||
|
||
type withCustomAttributes struct{} | ||
|
||
func AttributesFrom(ctx context.Context) map[string]string { | ||
return binding.GetOrDefaultFromCtx(ctx, withCustomAttributes{}, make(map[string]string)).(map[string]string) | ||
} | ||
|
||
// WithCustomAttributes sets Message Attributes without any CloudEvent logic. | ||
// Note that this function is not intended for CloudEvent Extensions or any `ce-`-prefixed Attributes. | ||
// For these please see `Event` and `Event.SetExtension`. | ||
func WithCustomAttributes(ctx context.Context, attrs map[string]string) context.Context { | ||
return context.WithValue(ctx, withCustomAttributes{}, attrs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters