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:
@@ -8,10 +8,11 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
service := greet.NewService()
|
||||
name := ""
|
||||
if len(os.Args) > 1 {
|
||||
name = os.Args[1]
|
||||
}
|
||||
|
||||
fmt.Println(greet.Greet(name))
|
||||
fmt.Println(service.Greet(name))
|
||||
}
|
||||
15
cmd/server/main.go
Normal file
15
cmd/server/main.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"DanceLessonsCoach/pkg/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
server := server.NewServer()
|
||||
|
||||
fmt.Println("Server running on :8080")
|
||||
http.ListenAndServe(":8080", server.Router())
|
||||
}
|
||||
Reference in New Issue
Block a user