Skip to content

Commit

Permalink
feat: export CapabilitiesSpec for go-ftw to use
Browse files Browse the repository at this point in the history
  • Loading branch information
theseion committed Jul 14, 2024
1 parent 605596d commit f9d3e3f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 2 additions & 6 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ type reflectionSpec struct {
LogMessage string `json:"logMessage"`
}

type capabilitiesSpec struct {
Endpoints []endpoint `json:"endpoints" yaml:"endpoints"`
}

type endpoint struct {
Path string `json:"path" yaml:"path"`
Methods []string `json:"methods,omitempty" yaml:"methods"`
Expand Down Expand Up @@ -166,14 +162,14 @@ func handleReflect(w http.ResponseWriter, r *http.Request) {
func handleCapabilities(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")

spec := &capabilitiesSpec{}
spec := &CapabilitiesSpec{}
err := yaml.Unmarshal([]byte(capabilitiesDescription), spec)
if err != nil {
log.Fatal("Failed to unmarshal capabilities description")
}

if r.URL.Query().Get("quiet") == "true" {
quietSpec := &capabilitiesSpec{}
quietSpec := &CapabilitiesSpec{}
for _, ep := range spec.Endpoints {
quietSpec.Endpoints = append(quietSpec.Endpoints, endpoint{Path: ep.Path})
}
Expand Down
4 changes: 2 additions & 2 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *serverTestSuite) TestCapabilities() {
body, err := io.ReadAll(response.Body)
s.Require().NoError(err)

spec := &capabilitiesSpec{}
spec := &CapabilitiesSpec{}
err = json.Unmarshal(body, spec)
s.Require().NoError(err)

Expand Down Expand Up @@ -175,7 +175,7 @@ func (s *serverTestSuite) TestCapabilities_Quiet() {
s.NotContains("contentType", string(body))
s.NotContains("description", string(body))

spec := &capabilitiesSpec{}
spec := &CapabilitiesSpec{}
err = json.Unmarshal(body, spec)
s.Require().NoError(err)

Expand Down
5 changes: 5 additions & 0 deletions server/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package server

type CapabilitiesSpec struct {
Endpoints []endpoint `json:"endpoints" yaml:"endpoints"`
}

0 comments on commit f9d3e3f

Please sign in to comment.