Documentation ¶
Overview ¶
Package image provides the database.Model implementation for the Image entity.
Index ¶
- Variables
- func DownloadJobInit(db *sqlx.DB, q queue.Queue, log *log.Logger, store fs.Store) queue.InitFunc
- func InitEvent(dis event.Dispatcher) queue.InitFunc
- func LoadRelations(loaders *database.Loaders, ii ...*Image) error
- func Model(ii []*Image) func(int) database.Model
- func NewDownloadJob(db *sqlx.DB, i *Image, url DownloadURL) (queue.Job, error)
- type Download
- type DownloadJob
- type DownloadStore
- type DownloadURL
- func (u *DownloadURL) GobDecode(p []byte) error
- func (u *DownloadURL) GobEncode() ([]byte, error)
- func (u *DownloadURL) Scan(v interface{}) error
- func (u *DownloadURL) String() string
- func (u *DownloadURL) UnmarshalText(b []byte) error
- func (u *DownloadURL) Validate() error
- func (u DownloadURL) Value() (driver.Value, error)
- type Event
- type Form
- type Image
- func (i *Image) Bind(mm ...database.Model)
- func (i *Image) Downloaded() bool
- func (i *Image) Endpoint(uri ...string) string
- func (i *Image) IsZero() bool
- func (i *Image) JSON(addr string) map[string]interface{}
- func (i *Image) Primary() (string, int64)
- func (i *Image) SetPrimary(id int64)
- func (i *Image) Values() map[string]interface{}
- type Store
- func (s *Store) All(opts ...query.Option) ([]*Image, error)
- func (s *Store) Bind(mm ...database.Model)
- func (s *Store) Chown(from, to int64) error
- func (s *Store) Create(authorId int64, hash, name string, t driver.Type, r io.Reader) (*Image, error)
- func (s *Store) Delete(id int64, t driver.Type, hash string) error
- func (s *Store) Get(opts ...query.Option) (*Image, error)
- func (s *Store) Index(vals url.Values, opts ...query.Option) ([]*Image, database.Paginator, error)
- func (s *Store) Load(key string, vals []interface{}, fn database.LoaderFunc) error
- func (s *Store) New() *Image
- func (s *Store) Paginate(page int64, opts ...query.Option) (database.Paginator, error)
- func (s *Store) SetBlockStore(store fs.Store)
Constants ¶
This section is empty.
Variables ¶
var ( MimeTypeQEMU = "application/x-qemu-disk" ErrInvalidScheme = errors.New("invalid url scheme") )
Functions ¶
func DownloadJobInit ¶ added in v1.1.0
DownloadJobInit returns a callback for initializing a download job with the given database connection and file store.
func LoadRelations ¶
LoadRelations loads all of the available relations for the given Image models using the given loaders available.
func Model ¶
Model is called along with database.ModelSlice to convert the given slice of Image models to a slice of database.Model interfaces.
func NewDownloadJob ¶ added in v1.1.0
NewDownloadJob creates the underlying Download for the given Image and returns it as a queue.Job for background processing.
Types ¶
type Download ¶ added in v1.1.0
type Download struct { ID int64 `db:"id"` ImageID int64 `db:"image_id"` Source DownloadURL `db:"source"` Error sql.NullString `db:"error"` CreatedAt time.Time `db:"created_at"` StartedAt sql.NullTime `db:"started_at"` FinishedAt sql.NullTime `db:"finished_at"` User *user.User `db:"-"` Image *Image `db:"-"` }
type DownloadJob ¶ added in v1.1.0
type DownloadJob struct { ID int64 ImageID int64 Source DownloadURL // contains filtered or unexported fields }
func (*DownloadJob) Name ¶ added in v1.1.0
func (d *DownloadJob) Name() string
Name implements the queue.Job interface.
func (*DownloadJob) Perform ¶ added in v1.1.0
func (d *DownloadJob) Perform() error
Perform implements the queue.Job interface. This will attempt to download the image from the remote URL. This will fail if the URL does not have a valid scheme such as, http, https, or sftp.
type DownloadStore ¶ added in v1.1.0
func NewDownloadStore ¶ added in v1.1.0
func NewDownloadStore(db *sqlx.DB, mm ...database.Model) *DownloadStore
func (*DownloadStore) All ¶ added in v1.1.0
func (s *DownloadStore) All(opts ...query.Option) ([]*Download, error)
func (*DownloadStore) Bind ¶ added in v1.1.0
func (s *DownloadStore) Bind(mm ...database.Model)
type DownloadURL ¶ added in v1.1.0
func (*DownloadURL) GobDecode ¶ added in v1.1.0
func (u *DownloadURL) GobDecode(p []byte) error
func (*DownloadURL) GobEncode ¶ added in v1.1.0
func (u *DownloadURL) GobEncode() ([]byte, error)
func (*DownloadURL) Scan ¶ added in v1.1.0
func (u *DownloadURL) Scan(v interface{}) error
func (*DownloadURL) String ¶ added in v1.1.0
func (u *DownloadURL) String() string
func (*DownloadURL) UnmarshalText ¶ added in v1.1.0
func (u *DownloadURL) UnmarshalText(b []byte) error
func (*DownloadURL) Validate ¶ added in v1.1.0
func (u *DownloadURL) Validate() error
type Form ¶
type Form struct { namespace.Resource *webutil.File Images *Store `schema:"-"` Name string `schema:"name" json:"name"` DownloadURL DownloadURL `schema:"download_url" json:"download_url"` }
Form is the type that represents input data for uploading a new driver image.
func (*Form) Fields ¶
Fields returns a map containing the namespace, and name fields from the original Form.
func (*Form) Validate ¶
Validate checks to see if there is a name for the image, and if that name is valid. This will also check the contents of the uploaded file to make sure it is a valid QCOW2 image file. It does this by checking the first four bytes of the file match the ASCII magic number for QCOW2.
type Image ¶
type Image struct { ID int64 `db:"id"` UserID int64 `db:"user_id"` AuthorID int64 `db:"author_id"` NamespaceID sql.NullInt64 `db:"namespace_id"` Driver driver.Type `db:"driver"` Hash string `db:"hash"` Name string `db:"name"` CreatedAt time.Time `db:"created_at"` Author *user.User `db:"-" gob:"-"` User *user.User `db:"-" gob:"-"` Download *Download `db:"-" gob:"-"` Namespace *namespace.Namespace `db:"-" gob:"-"` }
Image is the type that represents an image that has been uploaded by a user.
func FromContext ¶
FromContext returns the Image model from the given context, if any.
func (*Image) Bind ¶
Bind implements the database.Binder interface. This will only bind the model if they are pointers to either user.User or namespace.Namespace.
func (*Image) Downloaded ¶ added in v1.1.0
Downloaded returns whether the image was downloaded successfully. If the image has no associated download, then this returns true.
func (*Image) Endpoint ¶
Endpoint implements the database.Model interface. This will return the endpoint to the current Image model.
func (*Image) JSON ¶
JSON implements the database.Model interface. This will return a map with the current Image values under each key. If any of the User, or Namespace bound models exist on the Image, then the JSON representation of these models will be in the returned map, under the user, and namespace keys respectively.
func (*Image) SetPrimary ¶
SetPrimary implements the database.Model interface.
type Store ¶
type Store struct { database.Store // User is the bound user.User model. If not nil this will bind the // user.User model to any Image models that are created. If not nil this // will append a WHERE clause on the user_id column for all SELECT queries // performed. User *user.User // Namespace is the bound namespace.Namespace model. If not nil this will // bind the namespace.Namespace model to any Image models that are created. // If not nil this will append a WHERE clause on the namespace_id column for // all SELECT queries performed. Namespace *namespace.Namespace // contains filtered or unexported fields }
Store is the type for creating and modifying Image models in the database. The Store type can have an underlying fs.Store implementation that is used for storing the contents of an image.
func NewStore ¶
NewStore returns a new Store for querying the images table. Each model passed to this function will be bound to the returned Store.
func NewStoreWithBlockStore ¶
NewStoreWithBlockStore is functionally the same as NewStore, however it sets the fs.Store to use on the returned Store. This will allow for an image file to be stored.
func (*Store) Bind ¶
Bind implements the database.Binder interface. This will only bind the model if they are pointers to either user.User or namespace.Namespace.
func (*Store) Create ¶
func (s *Store) Create(authorId int64, hash, name string, t driver.Type, r io.Reader) (*Image, error)
Create creates a new image with the given name for the given driver.Type. The given io.Reader is used to copy the contents of the image to the underlying fs.Store. It is expected for the Store to have a fs.Store set on it, otherwise it will error.
func (*Store) Delete ¶
Delete deletes the given Image from the database, and removes the underlying image file. It is expected for the Store to have a fs.Store set on it, otherwise it will error.
func (*Store) Index ¶
Index returns the paginated results from the images table depending on the values that are present in url.Values. Detailed below are the values that are used from the given url.Values,
search - This applies the database.Search query.Option using the value of name
func (*Store) Load ¶
func (s *Store) Load(key string, vals []interface{}, fn database.LoaderFunc) error
Load loads in a slice of Image models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback. This method calls Store.All under the hood, so any bound models will impact the models being loaded.
func (*Store) New ¶
New returns a new Image binding any non-nil models to it from the current Store.
func (*Store) Paginate ¶
Paginate returns the database.Paginator for the images table for the given page.