📝 docs: add ADR for staged-only Git hooks formatting

- Add ADR-0012 documenting the decision to format only staged Go files
- Update ADR README.md with new entry
- Document rationale, alternatives, and verification results
- Include future considerations for monitoring and CI/CD integration

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-04-04 21:36:57 +02:00
parent 371dee01d5
commit 9336178d73
18 changed files with 483 additions and 47 deletions

View File

@@ -48,14 +48,14 @@ func (sc *StepContext) iRequestTheHealthEndpoint() error {
func (sc *StepContext) theResponseShouldBe(arg1, arg2 string) error {
// The regex captures the full JSON from the feature file, including quotes
// We need to extract just the key and value without the surrounding quotes and backslashes
// Remove the surrounding quotes and backslashes
cleanArg1 := strings.Trim(arg1, `"\`)
cleanArg2 := strings.Trim(arg2, `"\`)
// Build the expected JSON string
expected := fmt.Sprintf(`{"%s":"%s"}`, cleanArg1, cleanArg2)
return sc.client.ExpectResponseBody(expected)
}
@@ -70,7 +70,7 @@ func (sc *StepContext) theServerIsRunningWithV2Enabled() error {
if err := sc.client.Request("GET", "/api/ready", nil); err != nil {
return err
}
// Check if v2 endpoint is available (should return 405 Method Not Allowed for GET, which means endpoint exists)
// If v2 is disabled, this will return 404
resp, err := sc.client.CustomRequest("GET", "/api/v2/greet", nil)
@@ -78,13 +78,13 @@ func (sc *StepContext) theServerIsRunningWithV2Enabled() error {
return err
}
defer resp.Body.Close()
// If we get 405, v2 is enabled (endpoint exists but doesn't allow GET)
// If we get 404, v2 is disabled
if resp.StatusCode == 404 {
return fmt.Errorf("v2 endpoint not available - v2 feature flag not enabled")
}
return nil
}

View File

@@ -23,7 +23,7 @@ func NewClient(server *Server) *Client {
func (c *Client) Request(method, path string, body interface{}) error {
url := c.server.GetBaseURL() + path
var reqBody io.Reader
if body != nil {
// Handle different body types
@@ -42,12 +42,12 @@ func (c *Client) Request(method, path string, body interface{}) error {
return fmt.Errorf("unsupported body type: %T", body)
}
}
req, err := http.NewRequest(method, url, reqBody)
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
}
// Set content type for JSON bodies
if body != nil && reqBody != nil {
req.Header.Set("Content-Type", "application/json")
@@ -70,7 +70,7 @@ func (c *Client) Request(method, path string, body interface{}) error {
func (c *Client) CustomRequest(method, path string, body interface{}) (*http.Response, error) {
url := c.server.GetBaseURL() + path
var reqBody io.Reader
if body != nil {
// Handle different body types
@@ -89,12 +89,12 @@ func (c *Client) CustomRequest(method, path string, body interface{}) (*http.Res
return nil, fmt.Errorf("unsupported body type: %T", body)
}
}
req, err := http.NewRequest(method, url, reqBody)
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}
// Set content type for JSON bodies
if body != nil && reqBody != nil {
req.Header.Set("Content-Type", "application/json")
@@ -104,7 +104,7 @@ func (c *Client) CustomRequest(method, path string, body interface{}) (*http.Res
if err != nil {
return nil, fmt.Errorf("request failed: %w", err)
}
// Don't close the body here - let the caller handle it
c.lastResp = resp
c.lastBody, err = io.ReadAll(resp.Body)
@@ -123,7 +123,7 @@ func (c *Client) ExpectResponseBody(expected string) error {
actual := string(c.lastBody)
// Trim trailing newline if present (common in JSON responses)
actual = strings.TrimSuffix(actual, "\n")
if actual != expected {
return fmt.Errorf("expected response body %q, got %q", expected, actual)
}

View File

@@ -12,7 +12,7 @@ import (
)
type Server struct {
httpServer *http.Server
httpServer *http.Server
port int
baseURL string
}
@@ -94,8 +94,8 @@ func createTestConfig(port int) *config.Config {
Timeout: 5 * time.Second,
},
Logging: config.LoggingConfig{
JSON: false,
Level: "trace",
JSON: false,
Level: "trace",
},
Telemetry: config.TelemetryConfig{
Enabled: false,

View File

@@ -33,9 +33,9 @@ type ShutdownConfig struct {
// LoggingConfig holds logging-related configuration
type LoggingConfig struct {
JSON bool `mapstructure:"json"`
Level string `mapstructure:"level"`
Output string `mapstructure:"output"`
JSON bool `mapstructure:"json"`
Level string `mapstructure:"level"`
Output string `mapstructure:"output"`
}
// TelemetryConfig holds OpenTelemetry-related configuration
@@ -63,7 +63,7 @@ type SamplerConfig struct {
// To specify a custom config file path, set DLC_CONFIG_FILE environment variable
func LoadConfig() (*Config, error) {
v := viper.New()
// Set up initial console logging for config loading messages
consoleWriter := zerolog.ConsoleWriter{Out: os.Stderr}
log.Logger = log.Output(consoleWriter)
@@ -221,7 +221,7 @@ func (c *Config) SetupLogging() {
// Setup log output
c.setupLogOutput()
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
}
@@ -255,14 +255,14 @@ func (c *Config) setupLogOutput() {
// Use stderr by default
return
}
// Open the log file
file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Error().Err(err).Str("output", output).Msg("Failed to open log file, using stderr")
return
}
// Set the log output
log.Logger = log.Output(file)
log.Trace().Str("output", output).Msg("Logging to file")

View File

@@ -4,9 +4,9 @@ import (
"context"
"encoding/json"
"errors"
"strconv"
"io"
"net/http"
"strconv"
"DanceLessonsCoach/pkg/validation"
"github.com/go-chi/chi/v5"
@@ -22,7 +22,7 @@ type ApiV2Greet interface {
}
type apiV2GreetHandler struct {
greeter GreeterV2
greeter GreeterV2
validator *validation.Validator
}
@@ -108,4 +108,4 @@ func (h *apiV2GreetHandler) handleValidationError(w http.ResponseWriter, err err
func (h *apiV2GreetHandler) writeJSONResponse(w http.ResponseWriter, message string) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(greetResponse{Message: message})
}
}

View File

@@ -21,4 +21,4 @@ func (s *Service) Greet(ctx context.Context, name string) string {
return "Hello world!"
}
return "Hello " + name + "!"
}
}

View File

@@ -21,4 +21,4 @@ func (s *ServiceV2) GreetV2(ctx context.Context, name string) string {
return "Hello my friend!"
}
return "Hello my friend " + name + "!"
}
}

View File

@@ -25,4 +25,4 @@ func TestServiceV2_GreetV2(t *testing.T) {
}
})
}
}
}

View File

@@ -10,8 +10,8 @@ import (
"DanceLessonsCoach/pkg/config"
"DanceLessonsCoach/pkg/greet"
"DanceLessonsCoach/pkg/validation"
"DanceLessonsCoach/pkg/telemetry"
"DanceLessonsCoach/pkg/validation"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
sdktrace "go.opentelemetry.io/otel/sdk/trace"

View File

@@ -8,9 +8,9 @@ import (
"strings"
"github.com/go-playground/locales/en"
en_translations "github.com/go-playground/validator/v10/translations/en"
"github.com/go-playground/validator/v10"
ut "github.com/go-playground/universal-translator"
"github.com/go-playground/validator/v10"
en_translations "github.com/go-playground/validator/v10/translations/en"
)
// Validator wraps the go-playground/validator with custom error handling
@@ -82,7 +82,7 @@ func (v *Validator) formatValidationErrors(errors validator.ValidationErrors) er
// Get custom error message
message := fmt.Errorf("%s failed validation for '%s'", field, tag).Error()
// Add parameter if available
if param != "" {
message += fmt.Sprintf(" (parameter: %s)", param)
@@ -120,4 +120,4 @@ func GetValidatorFromConfig(cfg *config.Config) (*Validator, error) {
// For now, config doesn't affect validator creation
// But this allows future configuration (e.g., language, strict mode)
return NewValidator()
}
}