Skip to content

Create an ObjectID type for dealing with partition and object name #19

@gilliek

Description

@gilliek

A lot of method are using an id, which references an object on the BIG-IP (e.g. /Common/foobar). Such id is composed of a partition name and the actual object name. iControl REST are using ~Common~foobar to create such a reference and just using a plain string is not necessarily the best.

A structure like ObjectID would make things a lot easier:

type ObjectID string

func NewObjectID(partition, name string) ObjectID {
	if partition == "" {
		partition = "Common"
	}
	return ObjectID("~" + partition + "~" + name)
}

func ParseObjectID(fullname string) ObjectID {
	return ObjectID(strings.Replace(fullname, "/", "~", -1))
}

func (oid ObjectID) Partition() string {
	idx := strings.LastIndex(string(oid), "~")
	if idx == -1 {
		return ""
	}
	return string(oid)[1:idx]
}

func (oid ObjectID) Name() string {
	idx := strings.LastIndex(string(oid), "~")
	if idx == -1 {
		return ""
	}
	return string(oid)[idx+1:]
}

func (oid ObjectID) String() string {
	return strings.Replace(string(oid), "~", "/", -1)
}

(note that this is just a prototype, not the final implementation)

This feature should be implemented in the next release (v1.0.0) in order not to break any existing implementation using the f5-rest-client.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions