Skip to content

Commit

Permalink
roles: deprecate type Role
Browse files Browse the repository at this point in the history
  • Loading branch information
James DeFelice committed Nov 9, 2017
1 parent cea0362 commit 2e0ed09
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions api/v1/lib/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/mesos/mesos-go/api/v1/lib/roles"
)

const DefaultRole = "*"

type (
Resources []Resource
resourceErrorType int
Expand Down
3 changes: 1 addition & 2 deletions api/v1/lib/resources/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package resources

import (
"github.com/mesos/mesos-go/api/v1/lib"
"github.com/mesos/mesos-go/api/v1/lib/roles"
)

func (n Name) Sum(resources ...mesos.Resource) (*mesos.Resource, bool) {
Expand Down Expand Up @@ -135,7 +134,7 @@ func Flatten(resources []mesos.Resource, opts ...FlattenOpt) []mesos.Resource {
f(fc)
}
if fc.role == "" {
fc.role = string(roles.Default)
fc.role = mesos.DefaultRole
}
// we intentionally manipulate a copy 'r' of the item in resources
for _, r := range resources {
Expand Down
13 changes: 7 additions & 6 deletions api/v1/lib/roles/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"unicode"
)

// Role is a deprecated type.
type Role string

const Default = Role("*")
const defaultRole = Role("*")

func (r Role) IsDefault() bool {
return r == Default
return r == defaultRole
}

func (r Role) Assign() func(interface{}) {
Expand Down Expand Up @@ -41,9 +42,9 @@ var illegalComponents = map[string]struct{}{
"*": struct{}{},
}

func Parse(s string) (Role, error) {
if s == string(Default) {
return Default, nil
func Parse(s string) (string, error) {
if s == string(defaultRole) {
return s, nil
}
if strings.HasPrefix(s, "/") {
return "", fmt.Errorf("role %q cannot start with a slash", s)
Expand All @@ -67,7 +68,7 @@ func Parse(s string) (Role, error) {
return "", fmt.Errorf("role component %q is invalid because it contains backspace or whitespace", part)
}
}
return Role(s), nil
return s, nil
}

func Validate(roles ...string) error {
Expand Down

0 comments on commit 2e0ed09

Please sign in to comment.