github.com/openfga/openfga@v1.5.4-rc1/pkg/storage/sqlcommon/encoding.go (about)

     1  package sqlcommon
     2  
     3  import (
     4  	openfgav1 "github.com/openfga/api/proto/openfga/v1"
     5  	"google.golang.org/protobuf/proto"
     6  )
     7  
     8  func marshalRelationshipCondition(
     9  	rel *openfgav1.RelationshipCondition,
    10  ) (name string, context []byte, err error) {
    11  	if rel != nil {
    12  		// Normalize empty context to nil.
    13  		if rel.GetContext() != nil && len(rel.GetContext().GetFields()) > 0 {
    14  			context, err = proto.Marshal(rel.GetContext())
    15  			if err != nil {
    16  				return name, context, err
    17  			}
    18  		}
    19  
    20  		return rel.GetName(), context, err
    21  	}
    22  
    23  	return name, context, err
    24  }