Skip to content

Commit

Permalink
fix: implement api details method for local (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
davemooreuws authored Dec 9, 2024
1 parent 2baf292 commit fff2739
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
17 changes: 14 additions & 3 deletions pkg/cloud/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package apis

import (
"context"
"fmt"
"slices"
"strings"
Expand All @@ -36,6 +37,8 @@ type (
State = map[ApiName]map[ServiceName][]*apispb.RegistrationRequest
)

type GetApiAddress = func(apiName string) string

type ApiRequestState struct {
Api string
ReqCtx *fasthttp.RequestCtx
Expand All @@ -44,8 +47,9 @@ type ApiRequestState struct {
type LocalApiGatewayService struct {
*apis.RouteWorkerManager

apiRegLock sync.RWMutex
state State
apiRegLock sync.RWMutex
state State
getApiAddress GetApiAddress

bus EventBus.Bus
}
Expand Down Expand Up @@ -166,10 +170,17 @@ func (l *LocalApiGatewayService) Serve(stream apispb.Api_ServeServer) error {
return l.RouteWorkerManager.Serve(peekableStream)
}

func NewLocalApiGatewayService() *LocalApiGatewayService {
func (a *LocalApiGatewayService) ApiDetails(ctx context.Context, req *apispb.ApiDetailsRequest) (*apispb.ApiDetailsResponse, error) {
return &apispb.ApiDetailsResponse{
Url: a.getApiAddress(req.ApiName),
}, nil
}

func NewLocalApiGatewayService(getApiAddress GetApiAddress) *LocalApiGatewayService {
return &LocalApiGatewayService{
RouteWorkerManager: apis.New(),
state: State{},
bus: EventBus.New(),
getApiAddress: getApiAddress,
}
}
3 changes: 2 additions & 1 deletion pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ func New(projectName string, opts LocalCloudOptions) (*LocalCloud, error) {
}

localResources := resources.NewLocalResourcesService()
localApis := apis.NewLocalApiGatewayService()
localBatch := batch.NewLocalBatchService()
localSchedules := schedules.NewLocalSchedulesService(localResources.LogServiceError)
localHttpProxy := http.NewLocalHttpProxyService()
Expand All @@ -271,6 +270,8 @@ func New(projectName string, opts LocalCloudOptions) (*LocalCloud, error) {
return nil, err
}

localApis := apis.NewLocalApiGatewayService(localGateway.GetApiAddress)

localSecrets, err := secrets.NewSecretService()
if err != nil {
return nil, err
Expand Down
13 changes: 13 additions & 0 deletions pkg/cloud/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ func (s *LocalGatewayService) GetApiAddresses() map[string]string {
return addresses
}

func (s *LocalGatewayService) GetApiAddress(apiName string) string {
s.lock.RLock()
defer s.lock.RUnlock()

addresses := s.GetApiAddresses()

if address, ok := addresses[apiName]; ok {
return address
}

return ""
}

func (s *LocalGatewayService) GetHttpWorkerAddresses() map[string]string {
s.lock.RLock()
defer s.lock.RUnlock()
Expand Down

0 comments on commit fff2739

Please sign in to comment.