Browse Source

retcode.Error() from go generate

pull/1780/head
Ethan Buchman 9 years ago
parent
commit
4d0eb1d95a
2 changed files with 40 additions and 5 deletions
  1. +24
    -5
      types/retcode.go
  2. +16
    -0
      types/retcode_string.go

+ 24
- 5
types/retcode.go View File

@ -1,12 +1,31 @@
package types package types
import (
"errors"
)
type RetCode int type RetCode int
// Reserved return codes // Reserved return codes
const ( const (
RetCodeOK = RetCode(0)
RetCodeInternalError = RetCode(1)
RetCodeUnauthorized = RetCode(2)
RetCodeInsufficientFees = RetCode(3)
RetCodeUnknownRequest = RetCode(4)
RetCodeOK RetCode = 0
RetCodeInternalError RetCode = 1
RetCodeUnauthorized RetCode = 2
RetCodeInsufficientFees RetCode = 3
RetCodeUnknownRequest RetCode = 4
) )
func (r RetCode) Error() error {
switch r {
case RetCodeOK:
return nil
default:
return errors.New(r.String())
}
}
//go:generate stringer -type=RetCode
// NOTE: The previous comment generates r.String().
// To run it, `go get golang.org/x/tools/cmd/stringer`
// and `go generate` in tmsp/types

+ 16
- 0
types/retcode_string.go View File

@ -0,0 +1,16 @@
// generated by stringer -type=RetCode; DO NOT EDIT
package types
import "fmt"
const _RetCode_name = "RetCodeOKRetCodeInternalErrorRetCodeUnauthorizedRetCodeInsufficientFeesRetCodeUnknownRequest"
var _RetCode_index = [...]uint8{0, 9, 29, 48, 71, 92}
func (i RetCode) String() string {
if i < 0 || i+1 >= RetCode(len(_RetCode_index)) {
return fmt.Sprintf("RetCode(%d)", i)
}
return _RetCode_name[_RetCode_index[i]:_RetCode_index[i+1]]
}

Loading…
Cancel
Save