I also have a frontend that send requests for these resourcers. When I don’t find one of this, I want to say “ResourceCustomerLoyalty not found”. But if I do fmt.Errorf("%s not found", resources[i]), where resourcers is an array of Resource, I’ll print “0 not found”.
And refactor the consts to be string is out of the league
@Edjan_Michiles I see, so it’s not the variable name you want but a string representation of the value. In that case, the stringer tool you referenced is exactly what you’re looking for. Just put:
//go:generate stringer -type Resource
above your Resource type definition and then run go generate once to generate a resource_string.go file with a fmt.Stringer implementation for you. You can check the resulting code; there’s no real overhead. Less than a custom implementation mot of the time.