metadata

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2026 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNotFound is returned when the metadata is not found
	ErrNotFound = fmt.Errorf("metadata not found")
)

Functions

func CID

func CID(v any) (types.HexBytes, error)

CID calculates the IPFS Cid hash (v1) from a bytes buffer, using parameters:

  • Codec: DagProtobuf
  • MhType: SHA2_256

func CIDStringToHexBytes

func CIDStringToHexBytes(s string) types.HexBytes

CIDStringToHexBytes converts a string to a types.HexBytes cid

func CIDToHexBytes

func CIDToHexBytes(c cid.Cid) types.HexBytes

CIDToHexBytes converts a cid.Cid to a types.HexBytes

func HexBytesToCID

func HexBytesToCID(b types.HexBytes) (cid.Cid, error)

HexBytesToCID converts a types.HexBytes to a cid.Cid

Types

type LocalMetadata

type LocalMetadata struct {
	// contains filtered or unexported fields
}

LocalMetadata is a local implementation of the MetadataStorage interface that stores the metadata in an local database. It also provides a cache for the artifacts.

func NewLocalMetadata

func NewLocalMetadata(db db.Database) *LocalMetadata

NewLocalMetadata creates a new LocalMetadata instance with the given database instance. It also creates a cache for the artifacts if possible and returns it.

func (*LocalMetadata) Metadata

func (lm *LocalMetadata) Metadata(_ context.Context, key types.HexBytes) (*types.Metadata, error)

Metadata returns the metadata stored in the local database for the given key. It returns an error if the request fails.

func (*LocalMetadata) SetMetadata

func (lm *LocalMetadata) SetMetadata(_ context.Context, key types.HexBytes, metadata *types.Metadata) error

SetMetadata stores the given metadata in the local database and returns an error if the request fails.

type MetadataKeyProvider

type MetadataKeyProvider func(data any) (types.HexBytes, error)

MetadataKeyProvider is a function that returns the key for a given metadata

type MetadataProvider

type MetadataProvider interface {
	SetMetadata(ctx context.Context, key types.HexBytes, metadata *types.Metadata) error
	Metadata(ctx context.Context, key types.HexBytes) (*types.Metadata, error)
}

MetadataProvider is an interface for storing and retrieving metadata

type MetadataStorage

type MetadataStorage struct {
	// contains filtered or unexported fields
}

MetadataStorage is a struct that stores and retrieves metadata for a given key. It wraps multiple metadata providers storing the metadata in all of them but retrieving it from the first one that has it.

func New

func New(keyProvider MetadataKeyProvider, providers ...MetadataProvider) *MetadataStorage

New returns a new MetadataStorage for the given MetadataKeyProvider and MetadataProviders.

func (*MetadataStorage) Get

Get returns the metadata for the given key from the first provider that has it or an error if none of the providers has it.

func (*MetadataStorage) Set

func (ms *MetadataStorage) Set(ctx context.Context, metadata *types.Metadata) (types.HexBytes, error)

Set stores the metadata for the given key in all of the providers. It returns the key and an error if any of the providers fails.

type PinataMetadataProvider

type PinataMetadataProvider struct {
	PinataMetadataProviderConfig
	// contains filtered or unexported fields
}

PinataMetadataProvider is a provider for metadata stored in Pinata.

func NewPinataMetadataProvider

func NewPinataMetadataProvider(config PinataMetadataProviderConfig) *PinataMetadataProvider

NewPinataMetadataProvider creates a new PinataMetadataProvider instance with the given configuration.

func (*PinataMetadataProvider) Metadata

Metadata returns the metadata stored in Pinata for the given key. It returns an error if the request fails.

func (*PinataMetadataProvider) SetMetadata

func (p *PinataMetadataProvider) SetMetadata(ctx context.Context, key types.HexBytes, metadata *types.Metadata) error

SetMetadata stores the given metadata in Pinata. It returns an error if the request fails. It ensures that the resulting CID matches with the key provided.

type PinataMetadataProviderConfig

type PinataMetadataProviderConfig struct {
	HostnameURL  string
	HostnameJWT  string
	GatewayURL   string
	GatewayToken string
}

PinataMetadataProviderConfig is the configuration for the PinataMetadataProvider. It includes the hostname URL, JWT and gateway URL and token.

func (*PinataMetadataProviderConfig) Valid

Valid checks if the PinataMetadataProviderConfig is valid. It returns true if the hostname URL, JWT and gateway URL and token are not empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL