f5-rest-client icon indicating copy to clipboard operation
f5-rest-client copied to clipboard

Create an ObjectID type for dealing with partition and object name

Open gilliek opened this issue 4 years ago • 0 comments

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.

gilliek avatar Dec 26 '19 16:12 gilliek