Skip to content

Commit

Permalink
feat: add ability to set header parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
pers0na2dev authored and EwenQuim committed Feb 21, 2024
1 parent 97ca254 commit 6dda095
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ func main() {
return MyResponse{}, err
}

// read the request header test
if c.Request().Header.Get("test") != "test" {
return MyResponse{}, errors.New("test header not found")
}

c.Response().Header().Set("X-Hello", "World")

return MyResponse{
Message: "Hello, " + data.Name,
BestFramework: "Fuego!",
}, nil
})
}).WithDescription("Say hello to the world").AddHeader("test")

// Standard net/http handler with automatic OpenAPI route declaration
fuego.GetStd(s, "/std", func(w http.ResponseWriter, r *http.Request) {
Expand Down
8 changes: 8 additions & 0 deletions mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ func (r Route[ResponseBody, RequestBody]) SetTags(tags ...string) Route[Response
return r
}

func (r Route[ResponseBody, RequestBody]) AddHeader(header string) Route[ResponseBody, RequestBody] {
r.operation.Parameters = append(r.operation.Parameters, &openapi3.ParameterRef{
Value: openapi3.NewHeaderParameter(header),
})

return r
}

func (r Route[ResponseBody, RequestBody]) AddTags(tags ...string) Route[ResponseBody, RequestBody] {
r.operation.Tags = append(r.operation.Tags, tags...)
return r
Expand Down

0 comments on commit 6dda095

Please sign in to comment.