Skip to content

Commit

Permalink
feat: add MustGetMountedStreamContext
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <[email protected]>
  • Loading branch information
paralin committed Jul 13, 2024
1 parent 9dceb1e commit 93da1d7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion link/mounted-stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package link

import (
"context"
"errors"

"github.com/aperturerobotics/bifrost/peer"
"github.com/aperturerobotics/bifrost/protocol"
Expand Down Expand Up @@ -53,8 +54,20 @@ func WithMountedStreamContext(ctx context.Context, msc MountedStreamContext) con
func GetMountedStreamContext(ctx context.Context) MountedStreamContext {
val := ctx.Value(mountedStreamContextKey{})
msc, ok := val.(MountedStreamContext)
if !ok {
if !ok || msc == nil {
return nil
}
return msc
}

// ErrNoMountedStreamContext is returned if there was no MountedStreamContext.
var ErrNoMountedStreamContext = errors.New("no mounted stream context")

// MustGetMountedStreamContext returns the MountedStreamContext from the Context or an error if unset.
func MustGetMountedStreamContext(ctx context.Context) (MountedStreamContext, error) {
msc := GetMountedStreamContext(ctx)
if msc == nil {
return nil, ErrNoMountedStreamContext
}
return msc, nil
}

0 comments on commit 93da1d7

Please sign in to comment.