Enforce Go style rules across codebase
Apply five style rules: convert iota string enums to typed string constants, replace errors.As with errors.AsType, merge three-group imports into two groups, fix multiline parameter/argument formatting, and replace fmt.Sprintf URL construction with net/url. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -143,11 +143,9 @@ func Conflictf(ctx context.Context, format string, a ...any) *gqlerror.Error {
|
||||
}
|
||||
|
||||
func Invalid(ctx context.Context, err error) *gqlerror.Error {
|
||||
var errValidation *validator.ValidationError
|
||||
|
||||
var details map[string]any
|
||||
|
||||
if errors.As(err, &errValidation) {
|
||||
if errValidation, ok := errors.AsType[*validator.ValidationError](err); ok {
|
||||
details = map[string]any{
|
||||
"cause": errValidation.Code,
|
||||
"field": errValidation.Field,
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/99designs/gqlgen/graphql/handler"
|
||||
"github.com/99designs/gqlgen/graphql/handler/extension"
|
||||
"github.com/99designs/gqlgen/graphql/handler/transport"
|
||||
|
||||
"go.gearno.de/kit/log"
|
||||
)
|
||||
|
||||
|
||||
@@ -31,8 +31,7 @@ func RecoverFunc(ctx context.Context, err any) error {
|
||||
return gqlErr
|
||||
}
|
||||
|
||||
var errValidations validator.ValidationErrors
|
||||
if errors.As(asError(err), &errValidations) {
|
||||
if errValidations, ok := errors.AsType[validator.ValidationErrors](asError(err)); ok {
|
||||
gqlErrors := gqlerror.List{}
|
||||
|
||||
for _, err := range errValidations {
|
||||
@@ -48,9 +47,10 @@ func RecoverFunc(ctx context.Context, err any) error {
|
||||
return gqlErrors
|
||||
}
|
||||
|
||||
var permissionDeniedErr *iam.ErrInsufficientPermissions
|
||||
if errTyped, ok := err.(error); ok && errors.As(errTyped, &permissionDeniedErr) {
|
||||
return Forbidden(ctx, permissionDeniedErr)
|
||||
if errTyped, ok := err.(error); ok {
|
||||
if permissionDeniedErr, ok := errors.AsType[*iam.ErrInsufficientPermissions](errTyped); ok {
|
||||
return Forbidden(ctx, permissionDeniedErr)
|
||||
}
|
||||
}
|
||||
|
||||
logger := httpserver.LoggerFromContext(ctx)
|
||||
|
||||
Reference in New Issue
Block a user