add dummy routes and handlers and update makefile
This commit is contained in:
parent
7c3ec901cd
commit
14e5752d35
12
Makefile
12
Makefile
@ -19,7 +19,17 @@ migrateup:
|
||||
.PHONY: run
|
||||
# Run all services
|
||||
run:
|
||||
go run ./service_a/server/main.go & go run ./service_b/server/main.go
|
||||
cd $(SERVICE_A) && go run ./server/main.go & cd $(SERVICE_B) && go run ./server/main.go
|
||||
|
||||
.PHONY: run-a
|
||||
# Run service_a only
|
||||
run-a:
|
||||
cd $(SERVICE_A) && go run ./server/main.go
|
||||
|
||||
.PHONY: run-b
|
||||
# Run service_b only
|
||||
run-b:
|
||||
cd $(SERVICE_B) && go run ./server/main.go
|
||||
|
||||
.PHONY: test
|
||||
# Run all tests with coverage
|
||||
|
||||
20
service_a/internal/domains/meteo/handlers.go
Normal file
20
service_a/internal/domains/meteo/handlers.go
Normal file
@ -0,0 +1,20 @@
|
||||
package meteo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Handler struct{}
|
||||
|
||||
func NewHandler() *Handler {
|
||||
return &Handler{}
|
||||
}
|
||||
|
||||
func (h *Handler) IngestCSV(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "hello from csv")
|
||||
}
|
||||
|
||||
func (h *Handler) IngestExcel(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "hello from excel")
|
||||
}
|
||||
8
service_a/internal/domains/meteo/router.go
Normal file
8
service_a/internal/domains/meteo/router.go
Normal file
@ -0,0 +1,8 @@
|
||||
package meteo
|
||||
|
||||
import "net/http"
|
||||
|
||||
func RegisterRoutes(mux *http.ServeMux, handler *Handler) {
|
||||
mux.HandleFunc("POST /ingest/csv", handler.IngestCSV)
|
||||
mux.HandleFunc("POST /ingest/excel", handler.IngestExcel)
|
||||
}
|
||||
16
service_a/internal/router/router.go
Normal file
16
service_a/internal/router/router.go
Normal file
@ -0,0 +1,16 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SetupRoutes() *http.ServeMux {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "hello world")
|
||||
})
|
||||
|
||||
return mux
|
||||
}
|
||||
@ -1,18 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"servicea/internal/domains/meteo"
|
||||
"servicea/internal/router"
|
||||
)
|
||||
|
||||
func main() {
|
||||
mux := http.NewServeMux()
|
||||
mux := router.SetupRoutes()
|
||||
|
||||
mux.HandleFunc("GET /hello", func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("Received request on /hello endpoint")
|
||||
fmt.Fprintf(w, "Hello world from service A")
|
||||
})
|
||||
meteoHandler := meteo.NewHandler()
|
||||
meteo.RegisterRoutes(mux, meteoHandler)
|
||||
|
||||
slog.Info("server starting on :8080")
|
||||
http.ListenAndServe(":8080", mux)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user