Adding a 'Typename' strongtype for representing all compute resource types.

This commit is contained in:
Vishnu Kannan
2015-01-17 00:34:47 +00:00
parent 4c413e794e
commit c32295a180
8 changed files with 146 additions and 0 deletions

View File

@@ -20,10 +20,12 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"path"
"reflect"
"regexp"
"runtime"
"strconv"
"strings"
"time"
"github.com/golang/glog"
@@ -183,3 +185,20 @@ func AllPtrFieldsNil(obj interface{}) bool {
}
return true
}
// Splits a fully qualified name and returns its namespace and name.
// Assumes that the input 'str' has been validated.
func SplitQualifiedName(str string) (string, string) {
parts := strings.Split(str, "/")
if len(parts) < 2 {
return "", str
}
return parts[0], parts[1]
}
// Joins 'namespace' and 'name' and returns a fully qualified name
// Assumes that the input is valid.
func JoinQualifiedName(namespace, name string) string {
return path.Join(namespace, name)
}