Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetMetadataHandler ¶
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
Types ¶
type Config ¶ added in v0.3.0
type Config struct {
HTTP HTTPConfig
}
type HTTPConfig ¶ added in v0.3.0
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.