mirror of
https://github.com/ent/ent.git
synced 2026-03-05 19:35:23 +03:00
ent: use stringer tool to generate Op.String() (#439)
Signed-off-by: Alex Snast <alexsn@fb.com>
This commit is contained in:
18
ent.go
18
ent.go
@@ -7,7 +7,6 @@ package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebookincubator/ent/schema/edge"
|
||||
"github.com/facebookincubator/ent/schema/field"
|
||||
@@ -319,19 +318,6 @@ const (
|
||||
)
|
||||
|
||||
// Is reports whether o is match the given operation.
|
||||
func (op Op) Is(o Op) bool { return op&o != 0 }
|
||||
func (i Op) Is(o Op) bool { return i&o != 0 }
|
||||
|
||||
func (op Op) String() string {
|
||||
if op > 0 || op < Op(len(ops)) {
|
||||
return ops[op]
|
||||
}
|
||||
return fmt.Sprintf("op(%d)", op)
|
||||
}
|
||||
|
||||
var ops = [...]string{
|
||||
OpCreate: "Create",
|
||||
OpUpdate: "Update",
|
||||
OpUpdateOne: "UpdateOne",
|
||||
OpDelete: "Delete",
|
||||
OpDeleteOne: "DeleteOne",
|
||||
}
|
||||
//go:generate go run golang.org/x/tools/cmd/stringer -type Op
|
||||
|
||||
43
op_string.go
Normal file
43
op_string.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// Code generated by "stringer -type Op"; DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[OpCreate-1]
|
||||
_ = x[OpUpdate-2]
|
||||
_ = x[OpUpdateOne-4]
|
||||
_ = x[OpDelete-8]
|
||||
_ = x[OpDeleteOne-16]
|
||||
}
|
||||
|
||||
const (
|
||||
_Op_name_0 = "OpCreateOpUpdate"
|
||||
_Op_name_1 = "OpUpdateOne"
|
||||
_Op_name_2 = "OpDelete"
|
||||
_Op_name_3 = "OpDeleteOne"
|
||||
)
|
||||
|
||||
var (
|
||||
_Op_index_0 = [...]uint8{0, 8, 16}
|
||||
)
|
||||
|
||||
func (i Op) String() string {
|
||||
switch {
|
||||
case 1 <= i && i <= 2:
|
||||
i -= 1
|
||||
return _Op_name_0[_Op_index_0[i]:_Op_index_0[i+1]]
|
||||
case i == 4:
|
||||
return _Op_name_1
|
||||
case i == 8:
|
||||
return _Op_name_2
|
||||
case i == 16:
|
||||
return _Op_name_3
|
||||
default:
|
||||
return "Op(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user