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:
@@ -55,13 +55,11 @@ func NewRecoverFunc(logger *log.Logger) mcpgenmcp.RecoverFunc {
|
||||
// those. Unknown errors are logged and replaced with a generic internal error
|
||||
// to avoid leaking implementation details to the client.
|
||||
func sanitizeError(ctx context.Context, logger *log.Logger, err error) error {
|
||||
var permissionDeniedErr *iam.ErrInsufficientPermissions
|
||||
if errors.As(err, &permissionDeniedErr) {
|
||||
if _, ok := errors.AsType[*iam.ErrInsufficientPermissions](err); ok {
|
||||
return fmt.Errorf("permission denied")
|
||||
}
|
||||
|
||||
var assumptionRequiredErr *iam.ErrAssumptionRequired
|
||||
if errors.As(err, &assumptionRequiredErr) {
|
||||
if _, ok := errors.AsType[*iam.ErrAssumptionRequired](err); ok {
|
||||
return fmt.Errorf("assumption required")
|
||||
}
|
||||
|
||||
@@ -77,13 +75,11 @@ func sanitizeError(ctx context.Context, logger *log.Logger, err error) error {
|
||||
return fmt.Errorf("resource is in use")
|
||||
}
|
||||
|
||||
var validationErrors validator.ValidationErrors
|
||||
if errors.As(err, &validationErrors) {
|
||||
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
||||
return validationErrors
|
||||
}
|
||||
|
||||
var validationError *validator.ValidationError
|
||||
if errors.As(err, &validationError) {
|
||||
if validationError, ok := errors.AsType[*validator.ValidationError](err); ok {
|
||||
return validationError
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
package mcp_v1
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"go.gearno.de/kit/httpserver"
|
||||
"go.gearno.de/kit/log"
|
||||
|
||||
@@ -2435,8 +2435,7 @@ func (r *Resolver) ListUsersTool(ctx context.Context, req *mcp.CallToolRequest,
|
||||
func (r *Resolver) GetUserTool(ctx context.Context, req *mcp.CallToolRequest, input *types.GetUserInput) (*mcp.CallToolResult, types.GetUserOutput, error) {
|
||||
profile, err := r.iamSvc.OrganizationService.GetProfile(ctx, input.ID)
|
||||
if err != nil {
|
||||
var errNotFound *iam.ErrProfileNotFound
|
||||
if errors.As(err, &errNotFound) {
|
||||
if _, ok := errors.AsType[*iam.ErrProfileNotFound](err); ok {
|
||||
return nil, types.GetUserOutput{}, fmt.Errorf("user not found: %w", err)
|
||||
}
|
||||
|
||||
@@ -2472,8 +2471,7 @@ func (r *Resolver) CreateUserTool(ctx context.Context, req *mcp.CallToolRequest,
|
||||
ContractEndDate: contractEnd,
|
||||
})
|
||||
if err != nil {
|
||||
var errAlreadyExists *iam.ErrUserAlreadyExists
|
||||
if errors.As(err, &errAlreadyExists) {
|
||||
if _, ok := errors.AsType[*iam.ErrUserAlreadyExists](err); ok {
|
||||
return nil, types.CreateUserOutput{}, fmt.Errorf("user with email already exists: %w", err)
|
||||
}
|
||||
|
||||
@@ -2491,16 +2489,11 @@ func (r *Resolver) InviteUserTool(ctx context.Context, req *mcp.CallToolRequest,
|
||||
ProfileID: input.ProfileID,
|
||||
})
|
||||
if err != nil {
|
||||
var (
|
||||
errOrgNotFound *iam.ErrOrganizationNotFound
|
||||
errUserExists *iam.ErrUserAlreadyExists
|
||||
)
|
||||
|
||||
if errors.As(err, &errOrgNotFound) {
|
||||
if _, ok := errors.AsType[*iam.ErrOrganizationNotFound](err); ok {
|
||||
return nil, types.InviteUserOutput{}, fmt.Errorf("organization not found: %w", err)
|
||||
}
|
||||
|
||||
if errors.As(err, &errUserExists) {
|
||||
if _, ok := errors.AsType[*iam.ErrUserAlreadyExists](err); ok {
|
||||
return nil, types.InviteUserOutput{}, fmt.Errorf("user already in organization: %w", err)
|
||||
}
|
||||
|
||||
@@ -2574,16 +2567,11 @@ func (r *Resolver) RemoveUserTool(ctx context.Context, req *mcp.CallToolRequest,
|
||||
|
||||
err := r.iamSvc.OrganizationService.RemoveUser(ctx, input.OrganizationID, input.ProfileID)
|
||||
if err != nil {
|
||||
var (
|
||||
errManagedBySCIM *iam.ErrUserManagedBySCIM
|
||||
errLastOwner *iam.ErrLastActiveOwner
|
||||
)
|
||||
|
||||
if errors.As(err, &errManagedBySCIM) {
|
||||
if _, ok := errors.AsType[*iam.ErrUserManagedBySCIM](err); ok {
|
||||
return nil, types.RemoveUserOutput{}, fmt.Errorf("user is managed by SCIM and cannot be removed: %w", err)
|
||||
}
|
||||
|
||||
if errors.As(err, &errLastOwner) {
|
||||
if _, ok := errors.AsType[*iam.ErrLastActiveOwner](err); ok {
|
||||
return nil, types.RemoveUserOutput{}, fmt.Errorf("cannot remove last active owner: %w", err)
|
||||
}
|
||||
|
||||
@@ -5189,8 +5177,7 @@ func (r *Resolver) GetSCIMConfigurationTool(ctx context.Context, req *mcp.CallTo
|
||||
|
||||
config, err := r.iamSvc.OrganizationService.GetSCIMConfiguration(ctx, input.OrganizationID)
|
||||
if err != nil {
|
||||
var errNotFound *iam.ErrNoSCIMConfigurationFound
|
||||
if errors.As(err, &errNotFound) {
|
||||
if _, ok := errors.AsType[*iam.ErrNoSCIMConfigurationFound](err); ok {
|
||||
return nil, types.GetSCIMConfigurationOutput{}, fmt.Errorf("SCIM configuration not found")
|
||||
}
|
||||
|
||||
@@ -5255,8 +5242,7 @@ func (r *Resolver) GetSCIMBridgeTool(ctx context.Context, req *mcp.CallToolReque
|
||||
|
||||
bridge, err := r.iamSvc.OrganizationService.GetSCIMBridgeByID(ctx, input.ID)
|
||||
if err != nil {
|
||||
var errNotFound *iam.ErrSCIMBridgeNotFound
|
||||
if errors.As(err, &errNotFound) {
|
||||
if _, ok := errors.AsType[*iam.ErrSCIMBridgeNotFound](err); ok {
|
||||
return nil, types.GetSCIMBridgeOutput{}, fmt.Errorf("SCIM bridge %s not found", input.ID)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user