Skip to content

Commit

Permalink
refactor getFuncInfo to no longer require -gcflags -N
Browse files Browse the repository at this point in the history
  • Loading branch information
e-nikolov committed Jan 7, 2022
1 parent 7551308 commit 9095ef0
Show file tree
Hide file tree
Showing 14 changed files with 708 additions and 115 deletions.
31 changes: 28 additions & 3 deletions examples/chi/celler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"errors"
"fmt"
"net/http"
"strconv"

"github.com/ghodss/yaml"

chai "github.com/go-chai/chai/chi"
"github.com/go-chai/chai/examples/shared/controller"
"github.com/go-chai/chai/examples/shared/model"

_ "github.com/go-chai/chai/examples/docs/celler" // This is required to be able to serve the stored swagger spec in prod
"github.com/go-chai/chai/examples/shared/httputil"
Expand All @@ -34,7 +36,30 @@ func main() {
})

r.Route("/bottles", func(r chi.Router) {
chai.Get(r, "/{id}", c.ShowBottle)
// ShowBottle godoc
// @Summary Show a bottle
// @Description get string by ID
// @ID get-string-by-int
// @Tags bottles
// @Accept json
// @Produce json
// @Param id path int true "Bottle ID"
// @Success 200 {object} model.Bottle
// @Failure 400 {object} httputil.Error
// @Failure 404 {object} httputil.Error
// @Failure 500 {object} httputil.Error
chai.Get(r, "/{id}", func(w http.ResponseWriter, r *http.Request) (*model.Bottle, int, error) {
id := chi.URLParam(r, "id")
bid, err := strconv.Atoi(id)
if err != nil {
return nil, http.StatusBadRequest, err
}
bottle, err := model.BottleOne(bid)
if err != nil {
return nil, http.StatusNotFound, err
}
return bottle, http.StatusOK, nil
})
chai.Get(r, "/", c.ListBottles)
})

Expand Down Expand Up @@ -69,7 +94,7 @@ func main() {

addCustomDocs(docs)

LogYAML(docs)
// LogYAML(docs)

// This must be used only during development to store the swagger spec
err = openapi2.WriteDocs(docs, &openapi2.GenConfig{
Expand All @@ -81,7 +106,7 @@ func main() {

fmt.Println("The swagger spec is available at http://localhost:8080/swagger/")

http.ListenAndServe(":8080", r)
// http.ListenAndServe(":8080", r)
}

func addCustomDocs(docs *spec.Swagger) {
Expand Down
36 changes: 18 additions & 18 deletions examples/docs/basic/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,10 @@ var doc = `{
"summary": "attribute example",
"parameters": [
{
"enum": [
"A",
"B",
"C"
],
"type": "string",
"description": "string enums",
"name": "enumstring",
"default": "A",
"description": "string default",
"name": "default",
"in": "query"
},
{
Expand All @@ -77,11 +73,14 @@ var doc = `{
"in": "query"
},
{
"maxLength": 10,
"minLength": 5,
"enum": [
"A",
"B",
"C"
],
"type": "string",
"description": "string valid",
"name": "string",
"description": "string enums",
"name": "enumstring",
"in": "query"
},
{
Expand All @@ -93,10 +92,11 @@ var doc = `{
"in": "query"
},
{
"maxLength": 10,
"minLength": 5,
"type": "string",
"default": "A",
"description": "string default",
"name": "default",
"description": "string valid",
"name": "string",
"in": "query"
}
],
Expand Down Expand Up @@ -178,15 +178,15 @@ var doc = `{
"parameters": [
{
"type": "integer",
"description": "Group ID",
"name": "group_id",
"description": "Account ID",
"name": "account_id",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Account ID",
"name": "account_id",
"description": "Group ID",
"name": "group_id",
"in": "path",
"required": true
}
Expand Down
36 changes: 18 additions & 18 deletions examples/docs/basic/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@
"summary": "attribute example",
"parameters": [
{
"enum": [
"A",
"B",
"C"
],
"type": "string",
"description": "string enums",
"name": "enumstring",
"default": "A",
"description": "string default",
"name": "default",
"in": "query"
},
{
Expand All @@ -62,11 +58,14 @@
"in": "query"
},
{
"maxLength": 10,
"minLength": 5,
"enum": [
"A",
"B",
"C"
],
"type": "string",
"description": "string valid",
"name": "string",
"description": "string enums",
"name": "enumstring",
"in": "query"
},
{
Expand All @@ -78,10 +77,11 @@
"in": "query"
},
{
"maxLength": 10,
"minLength": 5,
"type": "string",
"default": "A",
"description": "string default",
"name": "default",
"description": "string valid",
"name": "string",
"in": "query"
}
],
Expand Down Expand Up @@ -163,15 +163,15 @@
"parameters": [
{
"type": "integer",
"description": "Group ID",
"name": "group_id",
"description": "Account ID",
"name": "account_id",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Account ID",
"name": "account_id",
"description": "Group ID",
"name": "group_id",
"in": "path",
"required": true
}
Expand Down
34 changes: 17 additions & 17 deletions examples/docs/basic/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@ paths:
get:
description: attribute
parameters:
- description: string enums
enum:
- A
- B
- C
- default: A
description: string default
in: query
name: enumstring
name: default
type: string
- description: int enums
enum:
Expand All @@ -69,22 +66,25 @@ paths:
in: query
name: enumnumber
type: number
- description: string valid
- description: string enums
enum:
- A
- B
- C
in: query
maxLength: 10
minLength: 5
name: string
name: enumstring
type: string
- description: int valid
in: query
maximum: 10
minimum: 1
name: int
type: integer
- default: A
description: string default
- description: string valid
in: query
name: default
maxLength: 10
minLength: 5
name: string
type: string
produces:
- application/json
Expand Down Expand Up @@ -136,14 +136,14 @@ paths:
get:
description: path params
parameters:
- description: Group ID
- description: Account ID
in: path
name: group_id
name: account_id
required: true
type: integer
- description: Account ID
- description: Group ID
in: path
name: account_id
name: group_id
required: true
type: integer
produces:
Expand Down
2 changes: 1 addition & 1 deletion examples/gorilla/celler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {

addCustomDocs(docs)

LogYAML(docs)
// LogYAML(docs)

// This must be used only during development to store the swagger spec
err = openapi2.WriteDocs(docs, &openapi2.GenConfig{
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ module github.com/go-chai/chai
go 1.18

require (
github.com/davecgh/go-spew v1.1.1
github.com/getkin/kin-openapi v0.88.0
github.com/ghodss/yaml v1.0.0
github.com/go-chai/swag v1.7.8-fork2
github.com/go-chi/chi/v5 v5.0.7
github.com/go-chi/docgen v1.2.0
github.com/go-chi/render v1.0.1
github.com/go-openapi/spec v0.20.4
github.com/gofrs/uuid v4.2.0+incompatible
Expand All @@ -21,7 +23,6 @@ require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-chai/swag v1.7.8-fork2 h1:ijgxBjnbrjRK1XAqLor+FvMLpdST7MEk2MGw3V+Zz0I=
github.com/go-chai/swag v1.7.8-fork2/go.mod h1:7osfZ2yWVpvxjKkjueEGIi5GIltebBc7YsfN8JtRURc=
github.com/go-chi/chi/v5 v5.0.1/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/docgen v1.2.0 h1:da0Nq2PKU9W9pSOTUfVrKI1vIgTGpauo9cfh4Iwivek=
github.com/go-chi/docgen v1.2.0/go.mod h1:G9W0G551cs2BFMSn/cnGwX+JBHEloAgo17MBhyrnhPI=
github.com/go-chi/render v1.0.1 h1:4/5tis2cKaNdnv9zFLfXzcquC9HbeZgCnxGnKrltBS8=
github.com/go-chi/render v1.0.1/go.mod h1:pq4Rr7HbnsdaeHagklXub+p6Wd16Af5l9koip1OvJns=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
Expand Down
Loading

0 comments on commit 9095ef0

Please sign in to comment.