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:
Émile Ré
2026-05-20 11:46:39 +04:00
parent 34c25c2727
commit f5703d390b
105 changed files with 1180 additions and 940 deletions

View File

@@ -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
}