Refactor to JSON API with Chi router and interface-based design

- Add pkg/greet/api_v1.go with ApiV1Greet interface and handler
- Implement Greeter interface for dependency injection
- Return JSON responses with proper Content-Type headers
- Move greet service instantiation to server package
- Separate v1 route registration into registerApiV1Routes function
- Health endpoint at /api level, greet endpoints at /api/v1/greet
- Simplify server entrypoint by removing external dependencies
This commit is contained in:
Gabriel Radureau
2026-04-03 13:04:33 +02:00
parent 04d34bead1
commit 6365f92359
8 changed files with 134 additions and 4 deletions

View File

@@ -2,7 +2,8 @@ package greet
import "testing"
func TestGreet(t *testing.T) {
func TestService_Greet(t *testing.T) {
service := NewService()
tests := []struct {
name string
expected string
@@ -15,7 +16,7 @@ func TestGreet(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := Greet(tt.name)
result := service.Greet(tt.name)
if result != tt.expected {
t.Errorf("Greet(%q) = %q, want %q", tt.name, result, tt.expected)
}