contentprovider

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: Apache-2.0, MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMetadataHandler

func GetMetadataHandler(c echo.Context, db *gorm.DB) error

GetMetadataHandler is a function that handles HTTP requests to get the metadata of a piece. It takes an Echo context and a Gorm DBNoContext connection as arguments.

The function first parses the piece CID from the URL parameters. If the CID is invalid, it returns a 400 Bad Request response.

Then, it queries the database for the car associated with the CID. If no car is found, it returns a 404 Not Found response.

Next, it retrieves the metadata of the piece. If there's an error, it returns a 500 Internal Server Error response.

Finally, it removes any sensitive information from the metadata and returns it in the response. The format of the response depends on the "Accept" header of the request: if it's "application/cbor", the metadata is encoded as CBOR; otherwise, it's encoded as JSON.

Parameters:

  • c: The Echo context for the HTTP request.
  • dbNoContext: The Gorm DBNoContext connection to use for database queries.

Returns:

  • An error if there was a problem handling the request.

func SetCommonHeaders added in v0.5.1

func SetCommonHeaders(c echo.Context, pieceCid string)

Types

type Config added in v0.3.0

type Config struct {
	HTTP HTTPConfig
}

type HTTPConfig added in v0.3.0

type HTTPConfig struct {
	EnablePiece         bool
	EnablePieceMetadata bool
	EnableIPFS          bool
	IPFSSpan            store.SpanConfig
	Bind                string
}

type HTTPServer added in v0.3.0

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

func (*HTTPServer) Name added in v0.3.0

func (*HTTPServer) Name() string

func (*HTTPServer) Start added in v0.3.0

func (s *HTTPServer) Start(ctx context.Context, exitErr chan<- error) error

Start is a method on the HTTPServer struct that starts the HTTP server.

It sets up the Echo framework with various middleware for gzip compression, request logging, and panic recovery. It also sets up routes for getting piece metadata and the piece itself.

The server runs in its own goroutine until the provided context is cancelled. When the context is cancelled, the server is shut down gracefully.

The method returns two channels: a Done channel that is closed when the server has stopped, and a Fail channel that receives an error if the server fails to start or stop.

Parameters:

  • ctx: The context for the server. This can be used to cancel the server or set a deadline.

Returns:

  • A Done channel slice that are closed when the server has stopped.
  • A Fail channel that receives an error if the server fails to start or stop.
  • An error if the server fails to start.

type PieceMetadata

type PieceMetadata struct {
	Car       model.Car        `cbor:"1,keyasint,omitempty" json:"car"`
	Storage   model.Storage    `cbor:"2,keyasint,omitempty" json:"storage"`
	CarBlocks []model.CarBlock `cbor:"3,keyasint,omitempty" json:"carBlocks"`
	Files     []model.File     `cbor:"4,keyasint,omitempty" json:"files"`
}

type Service added in v0.3.0

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

func NewService added in v0.3.0

func NewService(db *gorm.DB, config Config) (*Service, error)

func (*Service) Start added in v0.3.0

func (s *Service) Start(ctx context.Context) error

Jump to

Keyboard shortcuts

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