Debian Codegraph @

object_type.go

raw
1 package gitobj
2
3 import "strings"
4
5 // ObjectType is a constant enumeration type for identifying the kind of object
6 // type an implementing instance of the Object interface is.
7 type ObjectType uint8
8
9 const (
10 UnknownObjectType ObjectType = iota
11 BlobObjectType
12 TreeObjectType
13 CommitObjectType
14 TagObjectType
15 )
16
17 // ObjectTypeFromString converts from a given string to an ObjectType
18 // enumeration instance.
19 func ObjectTypeFromString(s string) ObjectType {
20 switch strings.ToLower(s) {
21 case "blob":
22 return BlobObjectType
23 case "tree":
24 return TreeObjectType
25 case "commit":
26 return CommitObjectType
27 case "tag":
28 return TagObjectType
29 default:
30 return UnknownObjectType
31 }
32 }
33
34 // String implements the fmt.Stringer interface and returns a string
35 // representation of the ObjectType enumeration instance.
36 func (t ObjectType) String() string {
37 switch t {
38 case UnknownObjectType:
39 return "unknown"
40 case BlobObjectType:
41 return "blob"
42 case TreeObjectType:
43 return "tree"
44 case CommitObjectType:
45 return "commit"
46 case TagObjectType:
47 return "tag"
48 }
49 return "<unknown>"
50 }