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:
@@ -1,8 +1,15 @@
|
||||
package greet
|
||||
|
||||
type Service struct{}
|
||||
|
||||
func NewService() *Service {
|
||||
return &Service{}
|
||||
}
|
||||
|
||||
// Greet returns a greeting message for the given name.
|
||||
// If name is empty, it defaults to "world".
|
||||
func Greet(name string) string {
|
||||
// Implements the Greeter interface.
|
||||
func (s *Service) Greet(name string) string {
|
||||
if name == "" {
|
||||
return "Hello world!"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user