Skip to content

Commit

Permalink
Merge pull request #93 from Kong/flights/add-hostname-header
Browse files Browse the repository at this point in the history
flight-data/flights Adds Hostname header to responses
  • Loading branch information
rspurgeon authored Aug 29, 2023
2 parents 07ce149 + e3aba2d commit b06fee0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
32 changes: 31 additions & 1 deletion flight-data/flights/api/flights.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (

"github.com/Kong/KongAir/flight-data/flights/api/models"
"github.com/labstack/echo/v4"
"net/http"
"net/http"
"os"
)

func stringPtr(str string) *string {
Expand Down Expand Up @@ -151,26 +152,55 @@ func NewFlightService() *FlightService {
}

func (s *FlightService) GetHealth(ctx echo.Context) error {

hostname, err := os.Hostname()
if err != nil {
return err
}
ctx.Response().Header().Set("Hostname", hostname)

return ctx.JSON(http.StatusOK, map[string]string{"status": "OK"})
}

func (s *FlightService) GetFlights(ctx echo.Context, params models.GetFlightsParams) error {

hostname, err := os.Hostname()
if err != nil {
return err
}
ctx.Response().Header().Set("Hostname", hostname)

return ctx.JSON(http.StatusOK, s.Flights)
}
func (s *FlightService) GetFlightByNumber(ctx echo.Context, flightNumber string) error {

for _, flight := range s.Flights {
if flight.Number == flightNumber {
hostname, err := os.Hostname()
if err != nil {
return err
}
ctx.Response().Header().Set("Hostname", hostname)
return ctx.JSON(http.StatusOK, flight)
}
}

// Include the hostname header in the response
return ctx.JSON(http.StatusNotFound, map[string]string{"message": "Flight not found"})
}

func (s *FlightService) GetFlightDetails(ctx echo.Context, flightNumber string) error {

for _, flight := range s.FlightDetails {
if flight.FlightNumber == flightNumber {
hostname, err := os.Hostname()
if err != nil {
return err
}
ctx.Response().Header().Set("Hostname", hostname)
return ctx.JSON(http.StatusOK, flight)
}
}

return ctx.JSON(http.StatusNotFound, map[string]string{"message": "Flight not found"})
}
20 changes: 20 additions & 0 deletions flight-data/flights/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ paths:
status:
type: string
example: "OK"
headers:
hostname:
description: "The hostname of the machine fulfilling the request."
schema:
type: string
'500':
description: Service is unhealthy
content:
Expand Down Expand Up @@ -57,6 +62,11 @@ paths:
responses:
'200':
description: Successful respone with scheduled flights
headers:
hostname:
description: "The hostname of the machine fulfilling the request."
schema:
type: string
content:
application/json:
schema:
Expand Down Expand Up @@ -100,6 +110,11 @@ paths:
responses:
'200':
description: Successful response with the requested flight
headers:
hostname:
description: "The hostname of the machine fulfilling the request."
schema:
type: string
content:
application/json:
schema:
Expand Down Expand Up @@ -141,6 +156,11 @@ paths:
responses:
'200':
description: Successful response with the requested flight details
headers:
hostname:
description: "The hostname of the machine fulfilling the request."
schema:
type: string
content:
application/json:
schema:
Expand Down

0 comments on commit b06fee0

Please sign in to comment.