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

     1  package datastore
     2  
     3  import (
     4  	"context"
     5  
     6  	datastoremw "github.com/authzed/spicedb/internal/middleware/datastore"
     7  	"github.com/authzed/spicedb/pkg/datastore"
     8  )
     9  
    10  // FromContext reads the selected datastore out of a context.Context
    11  // and returns nil if it does not exist.
    12  func FromContext(ctx context.Context) datastore.Datastore {
    13  	return datastoremw.FromContext(ctx)
    14  }
    15  
    16  // MustFromContext reads the selected datastore 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) datastore.Datastore {
    19  	datastore := FromContext(ctx)
    20  	if datastore == nil {
    21  		panic("datastore middleware did not inject datastore")
    22  	}
    23  
    24  	return datastore
    25  }