KiteFromString returns a new Kite string from the given string representation in the form of "/username/environment/...". It's the inverse of k.String()
(s string)
| 93 | // representation in the form of "/username/environment/...". It's the inverse |
| 94 | // of k.String() |
| 95 | func KiteFromString(s string) (*Kite, error) { |
| 96 | if s == "" || s[0] != '/' { |
| 97 | return nil, errors.New("invalid kite string") |
| 98 | } |
| 99 | |
| 100 | fields := make([]string, 7) |
| 101 | copy(fields, strings.SplitN(s[1:], "/", 7)) |
| 102 | |
| 103 | return &Kite{ |
| 104 | Username: fields[0], |
| 105 | Environment: fields[1], |
| 106 | Name: fields[2], |
| 107 | Version: fields[3], |
| 108 | Region: fields[4], |
| 109 | Hostname: fields[5], |
| 110 | ID: fields[6], |
| 111 | }, nil |
| 112 | } |
| 113 | |
| 114 | // RegisterArgs is used as the function argument to the Kontrol's register |
| 115 | // method. |
no outgoing calls