forked from sandia-minimega/minimega
-
Notifications
You must be signed in to change notification settings - Fork 1
/
alias.go
37 lines (29 loc) · 799 Bytes
/
alias.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (2015) Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
package vlans
import "strings"
// AliasSep separates namespace from VLAN alias
const AliasSep = "//"
type Alias struct {
Namespace string
Value string
}
func (a Alias) String() string {
return a.Namespace + AliasSep + a.Value
}
func ParseAlias(namespace, alias string) Alias {
// If the alias includes the alias separator, assume the user wants to
// override the namespace.
if !strings.Contains(alias, AliasSep) {
return Alias{
Namespace: namespace,
Value: alias,
}
}
i := strings.Index(alias, AliasSep)
return Alias{
Namespace: alias[:i],
Value: alias[i+len(AliasSep):],
}
}