Skip to content

Commit

Permalink
feat: Adding add/remove tag on the backend side
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Dec 31, 2022
1 parent bf90367 commit 1c0a612
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/provider/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ func ReplaceDescription(description string) MetadataAction {
}
}

func AddTag(tag string) MetadataAction {
return func(instance Metadata) Metadata {
instance.Tags = append(instance.Tags, tag)

return instance
}
}

func RemoveTag(tag string) MetadataAction {
return func(instance Metadata) Metadata {
if index := findIndex(instance.Tags, tag); index != -1 {
instance.Tags = append(instance.Tags[:index], instance.Tags[index+1:]...)
}

return instance
}
}

type MetadataManager interface {
ListDir(ctx context.Context, item absto.Item) ([]absto.Item, error)

Expand Down
10 changes: 10 additions & 0 deletions pkg/provider/utils.go → pkg/provider/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,13 @@ func EtagMatch(w http.ResponseWriter, r *http.Request, hash string) (etag string

return
}

func findIndex(arr []string, value string) int {
for index, item := range arr {
if item == value {
return index
}
}

return -1
}
File renamed without changes.

0 comments on commit 1c0a612

Please sign in to comment.