-
Notifications
You must be signed in to change notification settings - Fork 10
/
object_type.go
50 lines (45 loc) · 1.06 KB
/
object_type.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
38
39
40
41
42
43
44
45
46
47
48
49
50
package gitobj
import "strings"
// ObjectType is a constant enumeration type for identifying the kind of object
// type an implementing instance of the Object interface is.
type ObjectType uint8
const (
UnknownObjectType ObjectType = iota
BlobObjectType
TreeObjectType
CommitObjectType
TagObjectType
)
// ObjectTypeFromString converts from a given string to an ObjectType
// enumeration instance.
func ObjectTypeFromString(s string) ObjectType {
switch strings.ToLower(s) {
case "blob":
return BlobObjectType
case "tree":
return TreeObjectType
case "commit":
return CommitObjectType
case "tag":
return TagObjectType
default:
return UnknownObjectType
}
}
// String implements the fmt.Stringer interface and returns a string
// representation of the ObjectType enumeration instance.
func (t ObjectType) String() string {
switch t {
case UnknownObjectType:
return "unknown"
case BlobObjectType:
return "blob"
case TreeObjectType:
return "tree"
case CommitObjectType:
return "commit"
case TagObjectType:
return "tag"
}
return "<unknown>"
}