First let's set up a golang module
module github.com/gen/project
go 1.24using priorities to config type which has different configuration
packages {
["github.com/gen/project"] {
priorities {
[0] {
types { "Status" }
line_comment = true
}
}
types { "Pill" }
}
}source code
// file: enum.go
package enum
type Pill int
const (
Placebo Pill = iota
Aspirin
Ibuprofen
Paracetamol
Acetaminophen = Paracetamol
)
type Status int
const (
StatusInactive Status = iota // inactive
StatusActive // active
)expected generated code
// golden-file: gen_stringer.go
// Code generated by go-stringer-gen - dev. DO NOT EDIT.
package enum
import "strconv"
// Unnamed variable used to ensure `import "strconv"` is generated, as it is required below.
var _ = strconv.FormatInt(0, 10)
// --- Code generated by go run golang.org/x/tools/cmd/stringer@latest -type Status -linecomment -output /dev/stdout
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[StatusInactive-0]
_ = x[StatusActive-1]
}
const _Status_name = "inactiveactive"
var _Status_index = [...]uint8{0, 8, 14}
func (i Status) String() string {
idx := int(i) - 0
if i < 0 || idx >= len(_Status_index)-1 {
return "Status(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _Status_name[_Status_index[idx]:_Status_index[idx+1]]
}
// --- End code generated by go run golang.org/x/tools/cmd/stringer@latest -type Status -linecomment -output /dev/stdout
// --- Code generated by go run golang.org/x/tools/cmd/stringer@latest -type Pill -output /dev/stdout
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[Placebo-0]
_ = x[Aspirin-1]
_ = x[Ibuprofen-2]
_ = x[Paracetamol-3]
}
const _Pill_name = "PlaceboAspirinIbuprofenParacetamol"
var _Pill_index = [...]uint8{0, 7, 14, 23, 34}
func (i Pill) String() string {
idx := int(i) - 0
if i < 0 || idx >= len(_Pill_index)-1 {
return "Pill(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _Pill_name[_Pill_index[idx]:_Pill_index[idx+1]]
}
// --- End code generated by go run golang.org/x/tools/cmd/stringer@latest -type Pill -output /dev/stdout