Skip to content

Commit c40ebe9

Browse files
committed
Empty the URL arrays every time
1 parent ef76d52 commit c40ebe9

7 files changed

Lines changed: 72 additions & 63 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.24.1 as builder
1+
FROM golang:1.23.6 as builder
22

33
COPY . /go/src/github.com/DistroByte/molocule
44

docker-compose.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/DistroByte/molecule
22

3-
go 1.24.1
3+
go 1.23.6
44

55
require (
66
github.com/getkin/kin-openapi v0.131.0

internal/api/v1/health_service.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package v1
2+
3+
import (
4+
"context"
5+
"net/http"
6+
7+
openapi "github.com/DistroByte/molecule/internal/generated/go"
8+
)
9+
10+
func (s *MoleculeAPIService) Healthcheck(ctx context.Context) (openapi.ImplResponse, error) {
11+
return openapi.Response(http.StatusOK, "OK"), nil
12+
}

internal/api/v1/nomad_service.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func (s *NomadService) ExtractAll(print bool) (map[string]string, error) {
4949
return nil, err
5050
}
5151

52+
serviceUrls = make(map[string]string)
53+
hostReservedPorts = make(map[string]string)
54+
servicePorts = make(map[string]string)
55+
5256
for _, allocation := range allocations {
5357
s.processAllocation(allocation)
5458
}
@@ -84,6 +88,8 @@ func (s *NomadService) ExtractURLs() (map[string]string, error) {
8488
return nil, err
8589
}
8690

91+
serviceUrls = make(map[string]string)
92+
8793
for _, allocation := range allocations {
8894
s.processAllocation(allocation)
8995
}
@@ -105,6 +111,8 @@ func (s *NomadService) ExtractHostPorts() (map[string]string, error) {
105111
return nil, err
106112
}
107113

114+
hostReservedPorts = make(map[string]string)
115+
108116
for _, allocation := range allocations {
109117
s.processAllocation(allocation)
110118
}
@@ -122,6 +130,8 @@ func (s *NomadService) ExtractServicePorts() (map[string]string, error) {
122130
return nil, err
123131
}
124132

133+
servicePorts = make(map[string]string)
134+
125135
for _, allocation := range allocations {
126136
s.processAllocation(allocation)
127137
}

internal/api/v1/service.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,9 @@
11
package v1
22

3-
import (
4-
"context"
5-
"net/http"
6-
7-
openapi "github.com/DistroByte/molecule/internal/generated/go"
8-
)
9-
103
type MoleculeAPIService struct {
114
nomadService NomadServiceInterface
125
}
136

147
func NewMoleculeAPIService(nomadService NomadServiceInterface) *MoleculeAPIService {
158
return &MoleculeAPIService{nomadService: nomadService}
169
}
17-
18-
func (s *MoleculeAPIService) GetURLs(ctx context.Context, print bool) (openapi.ImplResponse, error) {
19-
urls, err := s.nomadService.ExtractAll(print)
20-
if err != nil {
21-
return openapi.Response(http.StatusInternalServerError, err.Error()), nil
22-
}
23-
24-
// Return the response
25-
return openapi.Response(http.StatusOK, urls), nil
26-
}
27-
28-
func (s *MoleculeAPIService) GetHostURLs(ctx context.Context) (openapi.ImplResponse, error) {
29-
urls, err := s.nomadService.ExtractHostPorts()
30-
if err != nil {
31-
return openapi.Response(http.StatusInternalServerError, err.Error()), nil
32-
}
33-
34-
// Return the response
35-
return openapi.Response(http.StatusOK, urls), nil
36-
}
37-
38-
func (s *MoleculeAPIService) GetServiceURLs(ctx context.Context) (openapi.ImplResponse, error) {
39-
urls, err := s.nomadService.ExtractServicePorts()
40-
if err != nil {
41-
return openapi.Response(http.StatusInternalServerError, err.Error()), nil
42-
}
43-
44-
// Return the response
45-
return openapi.Response(http.StatusOK, urls), nil
46-
}
47-
48-
func (s *MoleculeAPIService) GetTraefikURLs(ctx context.Context) (openapi.ImplResponse, error) {
49-
urls, err := s.nomadService.ExtractURLs()
50-
if err != nil {
51-
return openapi.Response(http.StatusInternalServerError, err.Error()), nil
52-
}
53-
54-
// Return the response
55-
return openapi.Response(http.StatusOK, urls), nil
56-
}
57-
58-
func (s *MoleculeAPIService) Healthcheck(ctx context.Context) (openapi.ImplResponse, error) {
59-
return openapi.Response(http.StatusOK, "OK"), nil
60-
}

internal/api/v1/url_service.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package v1
2+
3+
import (
4+
"context"
5+
"net/http"
6+
7+
openapi "github.com/DistroByte/molecule/internal/generated/go"
8+
)
9+
10+
func (s *MoleculeAPIService) GetURLs(ctx context.Context, print bool) (openapi.ImplResponse, error) {
11+
urls, err := s.nomadService.ExtractAll(print)
12+
if err != nil {
13+
return openapi.Response(http.StatusInternalServerError, err.Error()), nil
14+
}
15+
16+
// Return the response
17+
return openapi.Response(http.StatusOK, urls), nil
18+
}
19+
20+
func (s *MoleculeAPIService) GetHostURLs(ctx context.Context) (openapi.ImplResponse, error) {
21+
urls, err := s.nomadService.ExtractHostPorts()
22+
if err != nil {
23+
return openapi.Response(http.StatusInternalServerError, err.Error()), nil
24+
}
25+
26+
// Return the response
27+
return openapi.Response(http.StatusOK, urls), nil
28+
}
29+
30+
func (s *MoleculeAPIService) GetServiceURLs(ctx context.Context) (openapi.ImplResponse, error) {
31+
urls, err := s.nomadService.ExtractServicePorts()
32+
if err != nil {
33+
return openapi.Response(http.StatusInternalServerError, err.Error()), nil
34+
}
35+
36+
// Return the response
37+
return openapi.Response(http.StatusOK, urls), nil
38+
}
39+
40+
func (s *MoleculeAPIService) GetTraefikURLs(ctx context.Context) (openapi.ImplResponse, error) {
41+
urls, err := s.nomadService.ExtractURLs()
42+
if err != nil {
43+
return openapi.Response(http.StatusInternalServerError, err.Error()), nil
44+
}
45+
46+
// Return the response
47+
return openapi.Response(http.StatusOK, urls), nil
48+
}

0 commit comments

Comments
 (0)