|
1 | 1 | package v1 |
2 | 2 |
|
3 | | -import ( |
4 | | - "context" |
5 | | - "net/http" |
6 | | - |
7 | | - openapi "github.com/DistroByte/molecule/internal/generated/go" |
8 | | -) |
9 | | - |
10 | 3 | type MoleculeAPIService struct { |
11 | 4 | nomadService NomadServiceInterface |
12 | 5 | } |
13 | 6 |
|
14 | 7 | func NewMoleculeAPIService(nomadService NomadServiceInterface) *MoleculeAPIService { |
15 | 8 | return &MoleculeAPIService{nomadService: nomadService} |
16 | 9 | } |
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 | | -} |
0 commit comments