Last active
September 22, 2015 12:14
-
-
Save iamralch/b5194dfb109626579e77 to your computer and use it in GitHub Desktop.
Example of using https://godoc.org/golang.org/x/tools/cmd/stringer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
//go:generate stringer -type=MessageStatus | |
type MessageStatus int | |
const ( | |
Sent MessageStatus = iota | |
Received | |
Rejected | |
) | |
func main() { | |
status := Sent | |
fmt.Printf("Message is %s", status) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// generated by stringer -type=MessageStatus; DO NOT EDIT | |
package main | |
import "fmt" | |
const _MessageStatus_name = "SentReceivedRejected" | |
var _MessageStatus_index = [...]uint8{0, 4, 12, 20} | |
func (i MessageStatus) String() string { | |
if i < 0 || i >= MessageStatus(len(_MessageStatus_index)-1) { | |
return fmt.Sprintf("MessageStatus(%d)", i) | |
} | |
return _MessageStatus_name[_MessageStatus_index[i]:_MessageStatus_index[i+1]] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment