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

     1  package namespace
     2  
     3  // Mapper provides an interface for creating synthetic namespace names from
     4  // user provided namespace names.
     5  type Mapper interface {
     6  	// Encode translates a given namespace name to an encoded namespace identifier.
     7  	Encode(name string) (string, error)
     8  
     9  	// Reverse translates a given namespace identifier to the user supplied namespace name.
    10  	Reverse(id string) (string, error)
    11  }
    12  
    13  type passthrough struct{}
    14  
    15  // Encode implements Mapper
    16  func (p passthrough) Encode(name string) (string, error) {
    17  	return name, nil
    18  }
    19  
    20  // Reverse implements Mapper
    21  func (p passthrough) Reverse(id string) (string, error) {
    22  	return id, nil
    23  }
    24  
    25  // PassthroughMapper is a mapper implementation which passes through the original namespace
    26  // names unmodified.
    27  var PassthroughMapper Mapper = passthrough{}