Skip to content

Commit 37d1cde

Browse files
committed
Add a dummy mux
1 parent d82a1b5 commit 37d1cde

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

.DS_Store

0 Bytes
Binary file not shown.

api/services/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/ardanlabs/conf/v3"
1616

1717
"github.com/energy-service/api/services/debug"
18+
"github.com/energy-service/api/services/route"
1819
"github.com/energy-service/platform/logger"
1920
)
2021

@@ -126,7 +127,7 @@ func run(ctx context.Context, log *logger.Logger) error {
126127

127128
srv := http.Server{
128129
Addr: cfg.Web.APIHost,
129-
Handler: nil,
130+
Handler: route.WebAPI(),
130131
ReadTimeout: cfg.Web.ReadTimeout,
131132
WriteTimeout: cfg.Web.WriteTimeout,
132133
IdleTimeout: cfg.Web.IdleTimeout,

api/services/route/route.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package route
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
"os"
8+
)
9+
10+
// WebAPI defines a dummy multiplexer.
11+
func WebAPI() *http.ServeMux {
12+
mux := http.NewServeMux()
13+
14+
h := func(w http.ResponseWriter, req *http.Request) {
15+
status := struct {
16+
Status string
17+
}{
18+
Status: "OK",
19+
}
20+
21+
err := json.NewEncoder(w).Encode(status)
22+
if err != nil {
23+
fmt.Printf("error in encode: %w", err)
24+
os.Exit(1)
25+
}
26+
}
27+
28+
h2 := func(w http.ResponseWriter, req *http.Request) {
29+
err := json.NewEncoder(w).Encode("THIS is a message")
30+
if err != nil {
31+
fmt.Printf("error in encode: %w", err)
32+
os.Exit(1)
33+
}
34+
}
35+
36+
mux.HandleFunc("/", h2)
37+
mux.HandleFunc("/test", h)
38+
39+
return mux
40+
}

makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ dev-logs:
6363
dev-restart:
6464
kubectl rollout restart deployment $(APP) --namespace=$(NAMESPACE)
6565

66-
dev-update: all dev-load dev-apply run
66+
dev-update: all dev-load dev-apply run
67+
68+
curl-test:
69+
curl -il -X GET http://localhost:3011/debug/pprof
70+
curl -il -X GET http://localhost:3000
71+
curl -il -X GET http://localhost:3000/test

0 commit comments

Comments
 (0)