github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/middleware/dispatcher/dispatcher.go (about)

     1  package dispatcher
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/authzed/spicedb/internal/dispatch"
     7  	dispatchermw "github.com/authzed/spicedb/internal/middleware/dispatcher"
     8  )
     9  
    10  // FromContext reads the selected dispatcher out of a context.Context
    11  // and returns nil if it does not exist.
    12  func FromContext(ctx context.Context) dispatch.Dispatcher {
    13  	return dispatchermw.FromContext(ctx)
    14  }
    15  
    16  // MustFromContext reads the selected dispatcher out of a context.Context, computes a zedtoken
    17  // from it, and panics if it has not been set on the context.
    18  func MustFromContext(ctx context.Context) dispatch.Dispatcher {
    19  	dispatcher := dispatchermw.FromContext(ctx)
    20  	if dispatcher == nil {
    21  		panic("dispatcher middleware did not inject dispatcher")
    22  	}
    23  
    24  	return dispatcher
    25  }