Add annotations to routes and apps (#866)

Adds 'annotations' attribute to Routes and Apps
This commit is contained in:
Owen Cliffe
2018-03-20 18:02:49 +00:00
committed by GitHub
parent 845f40ee86
commit d25b5af59d
31 changed files with 1838 additions and 669 deletions

View File

@@ -8,10 +8,11 @@ import (
)
type App struct {
Name string `json:"name" db:"name"`
Config Config `json:"config,omitempty" db:"config"`
CreatedAt strfmt.DateTime `json:"created_at,omitempty" db:"created_at"`
UpdatedAt strfmt.DateTime `json:"updated_at,omitempty" db:"updated_at"`
Name string `json:"name" db:"name"`
Config Config `json:"config,omitempty" db:"config"`
Annotations Annotations `json:"annotations,omitempty" db:"annotations"`
CreatedAt strfmt.DateTime `json:"created_at,omitempty" db:"created_at"`
UpdatedAt strfmt.DateTime `json:"updated_at,omitempty" db:"updated_at"`
}
func (a *App) SetDefaults() {
@@ -39,6 +40,10 @@ func (a *App) Validate() error {
return ErrAppsInvalidName
}
}
err := a.Annotations.Validate()
if err != nil {
return err
}
return nil
}
@@ -53,6 +58,7 @@ func (a *App) Clone() *App {
clone.Config[k] = v
}
}
return clone
}
@@ -63,6 +69,7 @@ func (a1 *App) Equals(a2 *App) bool {
eq := true
eq = eq && a1.Name == a2.Name
eq = eq && a1.Config.Equals(a2.Config)
eq = eq && a1.Annotations.Equals(a2.Annotations)
// NOTE: datastore tests are not very fun to write with timestamp checks,
// and these are not values the user may set so we kind of don't care.
//eq = eq && time.Time(a1.CreatedAt).Equal(time.Time(a2.CreatedAt))
@@ -70,15 +77,15 @@ func (a1 *App) Equals(a2 *App) bool {
return eq
}
// Update adds entries from patch to a.Config, and removes entries with empty values.
func (a *App) Update(src *App) {
// Update adds entries from patch to a.Config and a.Annotations, and removes entries with empty values.
func (a *App) Update(patch *App) {
original := a.Clone()
if src.Config != nil {
if patch.Config != nil {
if a.Config == nil {
a.Config = make(Config)
}
for k, v := range src.Config {
for k, v := range patch.Config {
if v == "" {
delete(a.Config, k)
} else {
@@ -87,6 +94,8 @@ func (a *App) Update(src *App) {
}
}
a.Annotations = a.Annotations.MergeChange(patch.Annotations)
if !a.Equals(original) {
a.UpdatedAt = strfmt.DateTime(time.Now())
}