pm/meta.go

43 lines
874 B
Go
Raw Normal View History

2018-03-02 23:22:57 -08:00
package pm
2018-03-02 23:23:11 -08:00
import (
"errors"
2018-03-03 22:32:30 -08:00
"fmt"
2018-03-02 23:23:11 -08:00
"net/url"
)
2018-03-02 23:22:57 -08:00
2018-03-02 23:23:08 -08:00
// Meta tracks metadata for a package
2018-03-02 23:22:57 -08:00
type Meta struct {
Name Name `json:"name"`
Version Version `json:"version"`
Description string `json:"description"`
2018-03-02 23:23:11 -08:00
Remote url.URL `json:"remote"`
2018-03-02 23:22:57 -08:00
}
2018-03-02 23:23:08 -08:00
// Valid validates the contents of a Meta for requires fields.
2018-03-03 22:32:12 -08:00
func (m Meta) Valid() (bool, error) {
2018-03-02 23:22:57 -08:00
if m.Name == "" {
return false, errors.New("name cannot be empty")
}
if m.Version == "" {
return false, errors.New("version cannot be empty")
}
if m.Description == "" {
return false, errors.New("description cannot be empty")
}
return true, nil
}
2018-03-03 22:32:30 -08:00
// URL returns the http location of this package.
func (m Meta) URL() string {
return fmt.Sprintf("%s/%s-%s.pkg", m.Remote.String(), m.Name, m.Version)
}
func (m Meta) String() string {
return m.URL()
}
// Metas is a slice of Meta
type Metas []Meta