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:
@@ -338,10 +338,12 @@ INSERT INTO connectors (
|
||||
|
||||
if c.Provider == ConnectorProviderSlack {
|
||||
if slackConn, ok := c.Connection.(*connector.SlackConnection); ok {
|
||||
_ = c.SetSettings(&SlackConnectorSettings{
|
||||
Channel: slackConn.Settings.Channel,
|
||||
ChannelID: slackConn.Settings.ChannelID,
|
||||
})
|
||||
_ = c.SetSettings(
|
||||
&SlackConnectorSettings{
|
||||
Channel: slackConn.Settings.Channel,
|
||||
ChannelID: slackConn.Settings.ChannelID,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,10 +556,12 @@ WHERE
|
||||
|
||||
if c.Provider == ConnectorProviderSlack {
|
||||
if slackConn, ok := c.Connection.(*connector.SlackConnection); ok {
|
||||
_ = c.SetSettings(&SlackConnectorSettings{
|
||||
Channel: slackConn.Settings.Channel,
|
||||
ChannelID: slackConn.Settings.ChannelID,
|
||||
})
|
||||
_ = c.SetSettings(
|
||||
&SlackConnectorSettings{
|
||||
Channel: slackConn.Settings.Channel,
|
||||
ChannelID: slackConn.Settings.ChannelID,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.probo.inc/probo/pkg/connector"
|
||||
)
|
||||
|
||||
|
||||
@@ -822,8 +822,7 @@ VALUES (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "controls_framework_ref_unique" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
@@ -892,8 +891,7 @@ WHERE %s
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "controls_framework_ref_unique" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -72,8 +72,7 @@ VALUES (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "controls_policies_pkey" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -458,8 +458,7 @@ INSERT INTO custom_domains (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "custom_domains_domain_key" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -453,8 +453,7 @@ INSERT INTO processing_activity_data_protection_impact_assessments (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "processing_activity_dpias_processing_activity_id_snapshot_id_uniq" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -130,13 +130,16 @@ WHEN NOT MATCHED BY SOURCE
|
||||
|
||||
result := make(DocumentDefaultApprovers, 0, len(approverProfileIDs))
|
||||
for _, profileID := range approverProfileIDs {
|
||||
result = append(result, &DocumentDefaultApprover{
|
||||
DocumentID: documentID,
|
||||
ApproverProfileID: profileID,
|
||||
OrganizationID: organizationID,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
})
|
||||
result = append(
|
||||
result,
|
||||
&DocumentDefaultApprover{
|
||||
DocumentID: documentID,
|
||||
ApproverProfileID: profileID,
|
||||
OrganizationID: organizationID,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
*das = result
|
||||
|
||||
@@ -273,8 +273,7 @@ VALUES (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" {
|
||||
if pgErr.ConstraintName == "document_versions_document_id_major_minor_key" || pgErr.ConstraintName == "document_one_active_version_idx" {
|
||||
return ErrResourceAlreadyExists
|
||||
@@ -589,9 +588,13 @@ LIMIT 1
|
||||
FOR UPDATE OF dv SKIP LOCKED;
|
||||
`
|
||||
|
||||
rows, err := conn.Query(ctx, q, pgx.StrictNamedArgs{
|
||||
"max_pdf_attempts": maxAttempts,
|
||||
})
|
||||
rows, err := conn.Query(
|
||||
ctx,
|
||||
q,
|
||||
pgx.StrictNamedArgs{
|
||||
"max_pdf_attempts": maxAttempts,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query document versions: %w", err)
|
||||
}
|
||||
|
||||
@@ -328,19 +328,22 @@ func (ds DocumentVersionApprovalDecisions) BulkInsert(
|
||||
|
||||
rows := make([][]any, 0, len(ds))
|
||||
for _, d := range ds {
|
||||
rows = append(rows, []any{
|
||||
d.ID,
|
||||
scope.GetTenantID(),
|
||||
d.OrganizationID,
|
||||
d.QuorumID,
|
||||
d.ApproverID,
|
||||
d.State,
|
||||
d.Comment,
|
||||
d.ElectronicSignatureID,
|
||||
d.DecidedAt,
|
||||
d.CreatedAt,
|
||||
d.UpdatedAt,
|
||||
})
|
||||
rows = append(
|
||||
rows,
|
||||
[]any{
|
||||
d.ID,
|
||||
scope.GetTenantID(),
|
||||
d.OrganizationID,
|
||||
d.QuorumID,
|
||||
d.ApproverID,
|
||||
d.State,
|
||||
d.Comment,
|
||||
d.ElectronicSignatureID,
|
||||
d.DecidedAt,
|
||||
d.CreatedAt,
|
||||
d.UpdatedAt,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
_, err := conn.CopyFrom(
|
||||
|
||||
@@ -216,8 +216,7 @@ INSERT INTO document_version_signatures (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "policy_version_signatures_policy_version_id_signed_by_key" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -176,20 +176,23 @@ func (emails Emails) BulkInsert(
|
||||
|
||||
rows := make([][]any, 0, len(emails))
|
||||
for _, e := range emails {
|
||||
rows = append(rows, []any{
|
||||
e.ID,
|
||||
e.RecipientEmail,
|
||||
e.RecipientName,
|
||||
e.SenderName,
|
||||
e.ReplyTo,
|
||||
e.UnsubscribeURL,
|
||||
e.MailingListUpdateID,
|
||||
e.Subject,
|
||||
e.TextBody,
|
||||
e.HtmlBody,
|
||||
e.CreatedAt,
|
||||
e.UpdatedAt,
|
||||
})
|
||||
rows = append(
|
||||
rows,
|
||||
[]any{
|
||||
e.ID,
|
||||
e.RecipientEmail,
|
||||
e.RecipientName,
|
||||
e.SenderName,
|
||||
e.ReplyTo,
|
||||
e.UnsubscribeURL,
|
||||
e.MailingListUpdateID,
|
||||
e.Subject,
|
||||
e.TextBody,
|
||||
e.HtmlBody,
|
||||
e.CreatedAt,
|
||||
e.UpdatedAt,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
_, err := conn.CopyFrom(
|
||||
|
||||
@@ -204,8 +204,7 @@ VALUES (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "evidences_reference_id_key" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -20,26 +20,24 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
EvidenceState uint8
|
||||
EvidenceState string
|
||||
)
|
||||
|
||||
const (
|
||||
EvidenceStateRequested EvidenceState = iota
|
||||
EvidenceStateFulfilled
|
||||
EvidenceStateRequested EvidenceState = "REQUESTED"
|
||||
EvidenceStateFulfilled EvidenceState = "FULFILLED"
|
||||
)
|
||||
|
||||
func (es EvidenceState) MarshalText() ([]byte, error) {
|
||||
return []byte(es.String()), nil
|
||||
return []byte(es), nil
|
||||
}
|
||||
|
||||
func (es *EvidenceState) UnmarshalText(data []byte) error {
|
||||
val := string(data)
|
||||
val := EvidenceState(data)
|
||||
|
||||
switch val {
|
||||
case EvidenceStateRequested.String():
|
||||
*es = EvidenceStateRequested
|
||||
case EvidenceStateFulfilled.String():
|
||||
*es = EvidenceStateFulfilled
|
||||
case EvidenceStateRequested, EvidenceStateFulfilled:
|
||||
*es = val
|
||||
default:
|
||||
return fmt.Errorf("invalid EvidenceState value: %q", val)
|
||||
}
|
||||
@@ -48,16 +46,7 @@ func (es *EvidenceState) UnmarshalText(data []byte) error {
|
||||
}
|
||||
|
||||
func (es EvidenceState) String() string {
|
||||
var val string
|
||||
|
||||
switch es {
|
||||
case EvidenceStateRequested:
|
||||
val = "REQUESTED"
|
||||
case EvidenceStateFulfilled:
|
||||
val = "FULFILLED"
|
||||
}
|
||||
|
||||
return val
|
||||
return string(es)
|
||||
}
|
||||
|
||||
func (es *EvidenceState) Scan(value any) error {
|
||||
@@ -70,5 +59,5 @@ func (es *EvidenceState) Scan(value any) error {
|
||||
}
|
||||
|
||||
func (es EvidenceState) Value() (driver.Value, error) {
|
||||
return es.String(), nil
|
||||
return string(es), nil
|
||||
}
|
||||
|
||||
@@ -20,26 +20,24 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
EvidenceType uint8
|
||||
EvidenceType string
|
||||
)
|
||||
|
||||
const (
|
||||
EvidenceTypeFile EvidenceType = iota
|
||||
EvidenceTypeLink
|
||||
EvidenceTypeFile EvidenceType = "FILE"
|
||||
EvidenceTypeLink EvidenceType = "LINK"
|
||||
)
|
||||
|
||||
func (et EvidenceType) MarshalText() ([]byte, error) {
|
||||
return []byte(et.String()), nil
|
||||
return []byte(et), nil
|
||||
}
|
||||
|
||||
func (et *EvidenceType) UnmarshalText(data []byte) error {
|
||||
val := string(data)
|
||||
val := EvidenceType(data)
|
||||
|
||||
switch val {
|
||||
case EvidenceTypeFile.String():
|
||||
*et = EvidenceTypeFile
|
||||
case EvidenceTypeLink.String():
|
||||
*et = EvidenceTypeLink
|
||||
case EvidenceTypeFile, EvidenceTypeLink:
|
||||
*et = val
|
||||
default:
|
||||
return fmt.Errorf("invalid EvidenceType value: %q", val)
|
||||
}
|
||||
@@ -48,16 +46,7 @@ func (et *EvidenceType) UnmarshalText(data []byte) error {
|
||||
}
|
||||
|
||||
func (et EvidenceType) String() string {
|
||||
var val string
|
||||
|
||||
switch et {
|
||||
case EvidenceTypeFile:
|
||||
val = "FILE"
|
||||
case EvidenceTypeLink:
|
||||
val = "LINK"
|
||||
}
|
||||
|
||||
return val
|
||||
return string(et)
|
||||
}
|
||||
|
||||
func (et *EvidenceType) Scan(value any) error {
|
||||
@@ -70,5 +59,5 @@ func (et *EvidenceType) Scan(value any) error {
|
||||
}
|
||||
|
||||
func (et EvidenceType) Value() (driver.Value, error) {
|
||||
return et.String(), nil
|
||||
return string(et), nil
|
||||
}
|
||||
|
||||
@@ -232,8 +232,7 @@ VALUES (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "files_file_key_key" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -336,8 +336,7 @@ VALUES (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "frameworks_org_ref_unique" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -204,8 +204,7 @@ VALUES (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && strings.Contains(pgErr.ConstraintName, "email_address") {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -23,10 +23,9 @@ import (
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"go.gearno.de/kit/pg"
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
"go.probo.inc/probo/pkg/page"
|
||||
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -630,8 +629,7 @@ VALUES (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "mitigations_org_ref_unique" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -72,8 +72,7 @@ VALUES (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "measures_documents_pkey" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -20,16 +20,16 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
MeasureState uint8
|
||||
MeasureState string
|
||||
)
|
||||
|
||||
const (
|
||||
MeasureStateNotStarted MeasureState = iota
|
||||
MeasureStateInProgress
|
||||
MeasureStateNotApplicable
|
||||
MeasureStateImplemented
|
||||
MeasureStateUnknown
|
||||
MeasureStateNotImplemented
|
||||
MeasureStateNotStarted MeasureState = "NOT_STARTED"
|
||||
MeasureStateInProgress MeasureState = "IN_PROGRESS"
|
||||
MeasureStateNotApplicable MeasureState = "NOT_APPLICABLE"
|
||||
MeasureStateImplemented MeasureState = "IMPLEMENTED"
|
||||
MeasureStateUnknown MeasureState = "UNKNOWN"
|
||||
MeasureStateNotImplemented MeasureState = "NOT_IMPLEMENTED"
|
||||
)
|
||||
|
||||
func MeasureStates() []MeasureState {
|
||||
@@ -44,25 +44,17 @@ func MeasureStates() []MeasureState {
|
||||
}
|
||||
|
||||
func (ms MeasureState) MarshalText() ([]byte, error) {
|
||||
return []byte(ms.String()), nil
|
||||
return []byte(ms), nil
|
||||
}
|
||||
|
||||
func (ms *MeasureState) UnmarshalText(data []byte) error {
|
||||
val := string(data)
|
||||
val := MeasureState(data)
|
||||
|
||||
switch val {
|
||||
case MeasureStateNotStarted.String():
|
||||
*ms = MeasureStateNotStarted
|
||||
case MeasureStateInProgress.String():
|
||||
*ms = MeasureStateInProgress
|
||||
case MeasureStateNotApplicable.String():
|
||||
*ms = MeasureStateNotApplicable
|
||||
case MeasureStateImplemented.String():
|
||||
*ms = MeasureStateImplemented
|
||||
case MeasureStateUnknown.String():
|
||||
*ms = MeasureStateUnknown
|
||||
case MeasureStateNotImplemented.String():
|
||||
*ms = MeasureStateNotImplemented
|
||||
case MeasureStateNotStarted, MeasureStateInProgress,
|
||||
MeasureStateNotApplicable, MeasureStateImplemented,
|
||||
MeasureStateUnknown, MeasureStateNotImplemented:
|
||||
*ms = val
|
||||
default:
|
||||
return fmt.Errorf("invalid MeasureState value: %q", val)
|
||||
}
|
||||
@@ -71,24 +63,7 @@ func (ms *MeasureState) UnmarshalText(data []byte) error {
|
||||
}
|
||||
|
||||
func (ms MeasureState) String() string {
|
||||
var val string
|
||||
|
||||
switch ms {
|
||||
case MeasureStateNotStarted:
|
||||
val = "NOT_STARTED"
|
||||
case MeasureStateInProgress:
|
||||
val = "IN_PROGRESS"
|
||||
case MeasureStateNotApplicable:
|
||||
val = "NOT_APPLICABLE"
|
||||
case MeasureStateImplemented:
|
||||
val = "IMPLEMENTED"
|
||||
case MeasureStateUnknown:
|
||||
val = "UNKNOWN"
|
||||
case MeasureStateNotImplemented:
|
||||
val = "NOT_IMPLEMENTED"
|
||||
}
|
||||
|
||||
return val
|
||||
return string(ms)
|
||||
}
|
||||
|
||||
func (ms *MeasureState) Scan(value any) error {
|
||||
@@ -101,5 +76,5 @@ func (ms *MeasureState) Scan(value any) error {
|
||||
}
|
||||
|
||||
func (ms MeasureState) Value() (driver.Value, error) {
|
||||
return ms.String(), nil
|
||||
return string(ms), nil
|
||||
}
|
||||
|
||||
@@ -51,8 +51,7 @@ VALUES (@id, @organization_id, @used_at, @expires_at)
|
||||
|
||||
_, err := conn.Exec(ctx, query, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) && pgErr.Code == "23505" && pgErr.ConstraintName == "iam_saml_assertions_pkey" {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok && pgErr.Code == "23505" && pgErr.ConstraintName == "iam_saml_assertions_pkey" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
|
||||
@@ -333,8 +333,7 @@ INSERT INTO iam_saml_configurations (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "idx_saml_config_domain_org_unique" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -268,8 +268,7 @@ INSERT INTO iam_scim_configurations (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "iam_scim_configurations_organization_unique" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -23,10 +23,9 @@ import (
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"go.gearno.de/kit/pg"
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
"go.probo.inc/probo/pkg/page"
|
||||
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -252,8 +251,7 @@ RETURNING rank, priority_rank;
|
||||
|
||||
err := conn.QueryRow(ctx, q, args).Scan(&t.Rank, &t.PriorityRank)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "tasks_reference_id_unique" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -94,8 +94,7 @@ INSERT INTO iam_tokens(
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "iam_tokens_hashed_value_unique" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -452,8 +452,7 @@ INSERT INTO processing_activity_transfer_impact_assessments (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "processing_activity_tias_processing_activity_id_snapshot_id_uniq" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -327,8 +327,7 @@ INSERT INTO trust_centers (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "trust_centers_slug_key" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -208,8 +208,7 @@ INSERT INTO trust_center_accesses (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "trust_center_accesses_trust_center_id_email_key" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
@@ -271,8 +271,7 @@ INSERT INTO trust_center_document_accesses (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" {
|
||||
switch pgErr.ConstraintName {
|
||||
case "trust_center_document_accesse_trust_center_access_id_docume_key",
|
||||
|
||||
@@ -171,8 +171,7 @@ RETURNING rank;
|
||||
|
||||
err := conn.QueryRow(ctx, q, args).Scan(&t.Rank)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "trust_center_references_trust_center_id_rank_key" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user