Skip to content

Commit

Permalink
merge request changes integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignaciojeria committed Dec 26, 2024
1 parent 713d34d commit 05aec47
Show file tree
Hide file tree
Showing 102 changed files with 11,557 additions and 6,877 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
branches: ["main"]

env:
GO_VERSION: "1.22"
GO_VERSION: "1.23"

jobs:
tests:
Expand Down Expand Up @@ -57,4 +57,3 @@ jobs:
go-version: ${{ env.GO_VERSION }}

- run: make dependencies-analyze

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ coverage.out
recipe.db
bin
go.work.sum
fuego
/cmd/fuego/fuego
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ lint:
golangci-lint run ${FIX} ./...

lint-markdown:
markdownlint --ignore documentation/node_modules --dot .
markdownlint ${FIX} --ignore documentation/node_modules --dot .

# Update golden files
golden-update:
(cd examples/petstore/lib && go test -update)

# Check OpenAPI spec generated for the Petstore example. Uses https://github.com/daveshanley/vacuum
openapi-check:
vacuum lint -d examples/petstore/testdata/doc/openapi.json
vacuum lint -d examples/petstore/lib/testdata/doc/openapi.json

# Examples
example:
Expand Down
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

> The framework for busy Go developers
**Build your API or web application in minutes!**
🚀 **Explore and contribute to our [2025 Roadmap](https://github.com/go-fuego/fuego/discussions/263)!** 🚀

Go framework generating OpenAPI documentation from code.
Production-ready Go API framework generating OpenAPI documentation from code.
Inspired by Nest, built for Go developers.

Also empowers `html/template`, `a-h/templ` and `maragudk/gomponents`:
see [the example](./examples/full-app-gourmet) - actually running [in prod](https://gourmet.quimerch.com)!
Also empowers templating with `html/template`, `a-h/templ` and `maragudk/gomponents`:
see [the example](./examples/full-app-gourmet) [running live](https://gourmet.quimerch.com).

## Sponsors

Expand Down Expand Up @@ -105,19 +105,22 @@ func main() {
s := fuego.NewServer()

// Automatically generates OpenAPI documentation for this route
fuego.Post(s, "/", func(c *fuego.ContextWithBody[MyInput]) (MyOutput, error) {
body, err := c.Body()
if err != nil {
return MyOutput{}, err
}

return MyOutput{
Message: "Hello, " + body.Name,
}, nil
})
fuego.Post(s, "/user/{user}", myController)

s.Run()
}

func myController(c fuego.ContextWithBody[MyInput]) (MyOutput, error) {
body, err := c.Body()
if err != nil {
return MyOutput{}, err
}

return MyOutput{
Message: "Hello, " + body.Name,
}, nil
}

```

### With transformation & custom validation
Expand Down Expand Up @@ -254,7 +257,7 @@ func main() {
fuego.Use(s, chiMiddleware.Compress(5, "text/html", "text/css"))

// Fuego 🔥 handler with automatic OpenAPI generation, validation, (de)serialization and error handling
fuego.Post(s, "/", func(c *fuego.ContextWithBody[Received]) (MyResponse, error) {
fuego.Post(s, "/", func(c fuego.ContextWithBody[Received]) (MyResponse, error) {
data, err := c.Body()
if err != nil {
return MyResponse{}, err
Expand Down
25 changes: 25 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Security Policy

## Supported Versions

The following table outlines which versions of Fuego are actively supported with security updates. Please ensure that you are using a supported version to benefit from the latest patches and improvements.

| Version | Supported |
| ----------------------------------------------- | ---------------------- |
| 0.x.y (x being the latest version released) | :white_check_mark: Yes |
| 0.x.y (x being NOT the latest version released) | :x: No |

## Reporting a Vulnerability

Fuego relies on its community to ensure its security. Here is how to report a vulnerability:

1. **Send a Pull Request (PR):** If possible, immediately send a PR addressing the vulnerability and tag the maintainers for a quick review.
2. **Dependency Issues:** For supply chain or dependency-related vulnerabilities, update the all modules with `make check-all-modules` and submit a PR.
3. **Direct Contact:** If you cannot send a PR or the issue requires further discussion, please contact the maintainers directly by email.

### Important Notes

- Please do not publicly disclose the vulnerability until it has been addressed and patched.
- We are committed to transparency and will publicly acknowledge reporters in the release notes unless requested otherwise.

Your cooperation helps ensure Fuego remains a secure and reliable framework for everyone.
43 changes: 31 additions & 12 deletions cmd/fuego/commands/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,65 @@ func Controller() *cli.Command {
Usage: "creates a new controller file",
Aliases: []string{"c"},
Action: func(cCtx *cli.Context) error {
controllerName := cCtx.Args().First()
entityName := cCtx.Args().First()

if controllerName == "" {
controllerName = "newController"
if entityName == "" {
entityName = "newEntity"
fmt.Println("Note: You can add a controller name as an argument. Example: `fuego controller books`")
}

_, err := createController(controllerName)
_, err := createNewEntityDomainFile(entityName, "entity.go", entityName+".go")
if err != nil {
return err
}

fmt.Printf("🔥 Controller %s created successfully\n", controllerName)
_, err = createNewEntityDomainFile(entityName, "controller.go", entityName+"Controller.go")
if err != nil {
return err
}

fmt.Printf("🔥 Controller %s created successfully\n", entityName)
return nil
},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "with-service",
Usage: "enable service file generation",
Value: false,
Action: func(cCtx *cli.Context, shouldGenerateServiceFile bool) error {
if !shouldGenerateServiceFile {
return nil
}

return serviceCommandAction(cCtx)
},
},
},
}
}

// createController creates a new controller file
func createController(controllerName string) (string, error) {
controllerDir := "./controller/"
func createNewEntityDomainFile(entityName, controllerTemplateFileName, outputFileName string) (string, error) {
controllerDir := "./domains/" + entityName + "/"
if _, err := os.Stat(controllerDir); os.IsNotExist(err) {
err = os.Mkdir(controllerDir, 0o755)
err = os.MkdirAll(controllerDir, 0o755)
if err != nil {
return "", err
}
}

templateContent, err := templates.FS.ReadFile("controller/controller.go")
templateContent, err := templates.FS.ReadFile("newEntity/" + controllerTemplateFileName)
if err != nil {
return "", err
}

t := language.English
titler := cases.Title(t)

newContent := strings.ReplaceAll(string(templateContent), "newController", controllerName)
newContent = strings.ReplaceAll(newContent, "NewController", titler.String(controllerName))
newContent := strings.ReplaceAll(string(templateContent), "newEntity", entityName)
newContent = strings.ReplaceAll(newContent, "NewEntity", titler.String(entityName))

controllerPath := fmt.Sprintf("%s%s.go", controllerDir, controllerName)
controllerPath := fmt.Sprintf("%s%s", controllerDir, outputFileName)

err = os.WriteFile(controllerPath, []byte(newContent), 0o644)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions cmd/fuego/commands/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
)

func TestCreateController(t *testing.T) {
res, err := createController("books")
res, err := createNewEntityDomainFile("books", "controller.go", "booksController.go")
require.NoError(t, err)
require.Contains(t, res, "package controller")
require.Contains(t, res, "package books")
require.Contains(t, res, `fuego.Get(booksGroup, "/{id}", rs.getBooks)`)
require.Contains(t, res, `func (rs BooksResources) postBooks(c *fuego.ContextWithBody[BooksCreate]) (Books, error)`)
require.FileExists(t, "./controller/books.go")
os.Remove("./controller/books.go")
require.Contains(t, res, `func (rs BooksResources) postBooks(c fuego.ContextWithBody[BooksCreate]) (Books, error)`)
require.FileExists(t, "./domains/books/booksController.go")
os.Remove("./domains/books/booksController.go")
}
38 changes: 38 additions & 0 deletions cmd/fuego/commands/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package commands

import (
"fmt"

"github.com/urfave/cli/v2"
)

func Service() *cli.Command {
return &cli.Command{
Name: "service",
Usage: "creates a new service file",
Aliases: []string{"s"},
Action: serviceCommandAction,
}
}

func serviceCommandAction(cCtx *cli.Context) error {
entityName := cCtx.Args().First()

if entityName == "" {
entityName = "newController"
fmt.Println("Note: You can add an entity name as an argument. Example: `fuego service books`")
}

_, err := createNewEntityDomainFile(entityName, "entity.go", entityName+".go")
if err != nil {
return err
}

_, err = createNewEntityDomainFile(entityName, "service.go", entityName+"Service.go")
if err != nil {
return err
}

fmt.Printf("🔥 Service %s created successfully\n", entityName)
return nil
}
18 changes: 8 additions & 10 deletions cmd/fuego/go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
module github.com/go-fuego/fuego/cmd/fuego

go 1.22.2

toolchain go1.22.5
go 1.23.3

require (
github.com/go-fuego/fuego v0.15.0
github.com/go-fuego/fuego v0.16.2
github.com/stretchr/testify v1.10.0
github.com/urfave/cli/v2 v2.27.5
golang.org/x/text v0.20.0
golang.org/x/text v0.21.0
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.7 // indirect
github.com/getkin/kin-openapi v0.128.0 // indirect
Expand All @@ -26,14 +24,14 @@ require (
github.com/invopop/yaml v0.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
28 changes: 14 additions & 14 deletions cmd/fuego/go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.7 h1:SKFKl7kD0RiPdbht0s7hFtjl489WcQ1VyPW8ZzUMYCA=
github.com/gabriel-vasile/mimetype v1.4.7/go.mod h1:GDlAgAyIRT27BhFl53XNAFtfjzOkLaF35JdEG0P7LtU=
github.com/getkin/kin-openapi v0.128.0 h1:jqq3D9vC9pPq1dGcOCv7yOp1DaEe7c/T1vzcLbITSp4=
github.com/getkin/kin-openapi v0.128.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM=
github.com/go-fuego/fuego v0.15.0 h1:T3DcbOSM9TDUn6ksXk2YH+bs4xDIyP1ObANokhGHLaw=
github.com/go-fuego/fuego v0.15.0/go.mod h1:oZ5g39TgfqG4S1mc2wlRZxl72aRCO26OnJemUIUJGHE=
github.com/go-fuego/fuego v0.16.2 h1:xEMJBbGEo/8324NTHbT4peLiM1g2dpYAiG08z/d0+dU=
github.com/go-fuego/fuego v0.16.2/go.mod h1:V4DCdygAVcKYKUyeizhb1J83azstmaCJWDSJNMzeTDE=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
Expand Down Expand Up @@ -36,8 +36,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
Expand All @@ -58,14 +58,14 @@ github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
1 change: 1 addition & 0 deletions cmd/fuego/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func main() {
},
Commands: []*cli.Command{
commands.Controller(),
commands.Service(),
},
}

Expand Down
Loading

0 comments on commit 05aec47

Please sign in to comment.