Documentation
¶
Overview ¶
Package sips provides structures for implementing an IPFS pinning service.
The primary purpose of this package is to allow a user to create an IPFS pinning service with minimal effort. The package is based around the PinHandler interface. An implementation of this interface can be passed to the Handler function in order to create an HTTP handler that serves a valid pinning service.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(h PinHandler) http.Handler
Handler returns a new HTTP handler that uses h to handle pinning service requests. It will handle requests to the "/pins" path and related subpaths, so the user does not need to strip the prefix in order to use it.
Types ¶
type Pin ¶
type Pin struct { CID string `json:"cid"` Name string `json:"name"` Origins []string `json:"origins"` Meta interface{} `json:"meta,omitempty"` }
Pin describes a single pinned item.
type PinHandler ¶
type PinHandler interface { // Pins returns a list of pinning request statuses based on the // given query. Pins(ctx context.Context, query PinQuery) ([]PinStatus, error) // AddPin adds a new pin to the service's backend. AddPin(ctx context.Context, pin Pin) (PinStatus, error) // GetPin gets the status of a specific pinning request. GetPin(ctx context.Context, requestID string) (PinStatus, error) // UpdatePin replaces a pinning request's pin with new info. UpdatePin(ctx context.Context, requestID string, pin Pin) (PinStatus, error) // DeletePin removes a pinning request. DeletePin(ctx context.Context, requestID string) error }
PinHandler is an interface satisfied by types that can be used to handle pinning service requests.
Every method is called after the authentication token is pulled from HTTP headers, so it can be assumed that a token is included in the provided context. It should not, however, be assumed that the token is valid.
Errors returned by a PinHandler's methods are returned to the client verbatim, so implementations should be careful not to include data that shouldn't be shown to clients in them. If an error implements StatusError, the HTTP status code returned will be whatever the error's Status method returns.
type PinQuery ¶
type PinQuery struct { // CID is a list CIDs that are being searched for. CID []string // Name is the name of the desired pinning request. Name string // Match is the strategy to use for finding the name. Match TextMatchingStrategy // Status is a list of statuses used to filter the returned // requests. Status []RequestStatus // Before and After indicate creation time filters. Before, After time.Time // Limit is the maximum number of results that should be returned. // If the handler returns more than this, the list will be truncated // to match the value of this field. Limit int // Meta is used to filter against the Meta field of the returned // requests. Note that this is simply the result of unmarshalling // json using the encoding/json package, so it will likely be a // map[string]interface{}, but it might not be, either. It is up to // the handler to deal with this as it sees fit. Meta interface{} }
PinQuery provides query info for finding pinning requests. Any fields which are zero values, or have length zero in the case of slices, should be considered as though they are not present.
type PinStatus ¶
type PinStatus struct { RequestID string `json:"requestid"` Status RequestStatus `json:"status"` Created time.Time `json:"created"` Delegates []string `json:"delegates"` Info interface{} `json:"info,omitempty"` Pin Pin `json:"pin"` }
PinStatus indicates the status of a pinning request and provides associated info.
type RequestStatus ¶
type RequestStatus string
RequestStatus is the status of a given pinning request.
const ( Queued RequestStatus = "queued" Pinning RequestStatus = "pinning" Pinned RequestStatus = "pinned" Failed RequestStatus = "failed" )
type StatusError ¶ added in v0.1.2
type StatusError interface {
Status() int
}
StatusError is implemented by errors returned by PinHandler implementations that want to send custom status codes to the client.
Several status codes have special handling. These include
- 400 Bad Request
- 401 Unauthorized
- 404 Not Found
- 409 Conflict
These status codes will produce special error messages for the client. All other status codes will produce the same error message as a 500 Internal Server Error code does.
type TextMatchingStrategy ¶
type TextMatchingStrategy string
TextMatchingStrategy indicates a strategy to use for matching one string against another.
const ( Exact TextMatchingStrategy = "exact" IExact TextMatchingStrategy = "iexact" Partial TextMatchingStrategy = "partial" IPartial TextMatchingStrategy = "ipartial" )
func (TextMatchingStrategy) Match ¶
func (tms TextMatchingStrategy) Match(haystack, needle string) bool
Match performs a match using the specified strategy. It will panic if the strategy provided is invalid.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
sips
sips is the primary implementation of a simple pinning service daemon.
|
sips is the primary implementation of a simple pinning service daemon. |
sipsctl
sipsctl is a simple utility for administrating the database used by SIPS.
|
sipsctl is a simple utility for administrating the database used by SIPS. |
internal
|
|