Documentation ¶
Index ¶
- Constants
- Variables
- func CreatePin(w http.ResponseWriter, r *http.Request, p server.Parameters)
- func FindPins(w http.ResponseWriter, r *http.Request, p server.Parameters)
- func GetPin(w http.ResponseWriter, r *http.Request, p server.Parameters)
- func PatchPin(w http.ResponseWriter, r *http.Request, p server.Parameters)
- func RemovePin(w http.ResponseWriter, r *http.Request, p server.Parameters)
- func UpdatePin(w http.ResponseWriter, r *http.Request, p server.Parameters)
- type Config
- type Controller
- type Route
Constants ¶
View Source
const ( MaxPinLimit = 1000 MaxNameLimit = 255 )
Variables ¶
View Source
var Ctrl = func() Controller { controllerOnce.Do(func() { var cfg Config if err := config.Load(&cfg); err != nil { panic(err) } if len(cfg.AuthenticationGrants) > 0 { err := auth.SetAuthGrants(cfg.AuthenticationGrants) if err != nil { panic(fmt.Errorf( "Controller: failed to set custom authentication grants with error: %s", err, )) } } ctx := context.Background() db, err := pinsdb.New(ctx, cfg.DatabaseAddr, cfg.DropDatabaseOnStart) if err != nil { panic(fmt.Errorf( "Controller: failed to connect to database at address ('%s') with error: %s", cfg.DatabaseAddr, err, )) } apiAddr, err := ma.NewMultiaddr(cfg.IpfsClusterApiAddr) if err != nil { panic(fmt.Errorf( "Controller: failed to parse IPFS cluster API address ('%s')", cfg.IpfsClusterApiAddr, )) } ipfsClient, err := cluster.NewDefaultClient(&cluster.Config{ SSL: cfg.IpfsClusterSsl, NoVerifyCert: cfg.IpfsClusterNoVerifyCert, APIAddr: apiAddr, ProtectorKey: cfg.IpfsClusterProtectorKey, Timeout: time.Duration(cfg.IpfsClusterTimeout) * time.Second, }) if err != nil { panic(fmt.Errorf( "Controller: failed to create client for IPFS cluster ('%s') with error %s", cfg.IpfsClusterApiAddr, err, )) } middleware.SetKeyFunc(auth.KeyFunc(cfg.AuthenticatorAddr)) middleware.SetErrFunc(auth.ErrFunc()) control = New(ctx, ipfsClient, db) }) return control }
View Source
var ( // Pins controller errors ErrorPinNotFound = errors.New("pin not found") )
View Source
var Routes = []Route{ Route{ auth.Authorize(GetPin), http.MethodGet, "/pins/:id", []server.ResponseSetting{}, }, Route{ auth.Authorize(FindPins), http.MethodGet, "/pins", []server.ResponseSetting{}, }, Route{ auth.Authorize(CreatePin), http.MethodPost, "/pins", []server.ResponseSetting{}, }, Route{ auth.Authorize(UpdatePin), http.MethodPut, "/pins/:id", []server.ResponseSetting{}, }, Route{ auth.Authorize(UpdatePin), http.MethodPost, "/pins/:id", []server.ResponseSetting{}, }, Route{ auth.Authorize(PatchPin), http.MethodPatch, "/pins/:id", []server.ResponseSetting{}, }, Route{ auth.Authorize(RemovePin), http.MethodDelete, "/pins/:id", []server.ResponseSetting{}, }, }
Routes is the list of routes of the Pins HTTP API
Functions ¶
func CreatePin ¶
func CreatePin(w http.ResponseWriter, r *http.Request, p server.Parameters)
func FindPins ¶
func FindPins(w http.ResponseWriter, r *http.Request, p server.Parameters)
func GetPin ¶
func GetPin(w http.ResponseWriter, r *http.Request, p server.Parameters)
func PatchPin ¶
func PatchPin(w http.ResponseWriter, r *http.Request, p server.Parameters)
func RemovePin ¶
func RemovePin(w http.ResponseWriter, r *http.Request, p server.Parameters)
func UpdatePin ¶
func UpdatePin(w http.ResponseWriter, r *http.Request, p server.Parameters)
Types ¶
type Config ¶
type Config struct { DatabaseAddr string `toml:"database_addr"` AuthenticatorAddr string `toml:"authenticator_addr"` AuthenticationGrants []string `toml:"authentication_grants"` DropDatabaseOnStart bool `toml:"drop_database_on_start"` // IPFS configuration IpfsClusterSsl bool `toml:"ipfs_cluster_ssl"` IpfsClusterNoVerifyCert bool `toml:"ipfs_cluster_no_verify_cert"` IpfsClusterApiAddr string `toml:"ipfs_cluster_api_addr"` IpfsClusterProtectorKey []byte `toml:"ipfs_cluster_protector_key"` IpfsClusterTimeout int `toml:"ipfs_cluster_timeout"` // in seconds }
type Controller ¶
type Controller interface { // FindPins returns all pins that match the given parameters FindPins( uid string, cids []string, name, before, after string, match models.TextMatch, statuses []models.Status, limit int, offset int, sortBy string, meta models.Info, ) (models.Pins, error) // GetPin returns the Pin for the given ID GetPin(uid, id string) (models.PinStatus, error) // CreatePin creates a new Pin based on the given Pin object CreatePin(uid string, pin models.Pin) (models.PinStatus, error) // UpdatePin updates the Pin at the given ID via the given data UpdatePin(uid, id string, data models.Pin) (models.PinStatus, error) // PatchPin modifies the Pin at the given ID via the set fields of data PatchPin(uid, id string, data models.Pin) (models.PinStatus, error) // RemovePin deletes the Pin at the given ID RemovePin(uid, id string) error }
Controller represents an interface to the Pins manager
Click to show internal directories.
Click to hide internal directories.