-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
111 additions
and
59 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cluster | ||
|
||
import ( | ||
"context" | ||
"github.com/icinga/icinga-go-library/types" | ||
) | ||
|
||
// Private type to prevent collisions with other context keys | ||
type contextKey string | ||
|
||
// clusterUuidContextKey is the key for Cluster values in contexts. | ||
var clusterUuidContextKey = contextKey("cluster_uuid") | ||
|
||
// NewClusterUuidContext creates a new context that carries the provided cluster UUID. | ||
// The new context is derived from the given parent context and associates the cluster UUID | ||
// with a predefined key (clusterContextKey). | ||
func NewClusterUuidContext(parent context.Context, clusterUuid types.UUID) context.Context { | ||
return context.WithValue(parent, clusterUuidContextKey, clusterUuid) | ||
} | ||
|
||
// ClusterUuidFromContext returns the uuid value of the cluster stored in ctx, if any: | ||
// | ||
// clusterUuid, ok := ClusterUuidFromContext(ctx) | ||
// if !ok { | ||
// // Error handling. | ||
// } | ||
func ClusterUuidFromContext(ctx context.Context) types.UUID { | ||
clusterUuid, ok := ctx.Value(clusterUuidContextKey).(types.UUID) | ||
if !ok { | ||
panic("cluster not found in context") | ||
} | ||
|
||
return clusterUuid | ||
} |
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,10 @@ | ||
package v1 | ||
|
||
import ( | ||
"github.com/icinga/icinga-go-library/types" | ||
) | ||
|
||
type Cluster struct { | ||
Uuid types.UUID | ||
Name string | ||
} |
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
Oops, something went wrong.