diff --git a/cmd/fuego/commands/controller.go b/cmd/fuego/commands/controller.go new file mode 100644 index 00000000..91793ca0 --- /dev/null +++ b/cmd/fuego/commands/controller.go @@ -0,0 +1,57 @@ +package commands + +import ( + "fmt" + "os" + "strings" + + "github.com/go-fuego/fuego/cmd/fuego/templates" + "github.com/urfave/cli/v2" +) + +func ControllerCommand() *cli.Command { + return &cli.Command{ + Name: "controller", + Usage: "add a new template", + Aliases: []string{"c"}, + Action: func(cCtx *cli.Context) error { + controllerName := "newController" + if cCtx.NArg() > 0 { + controllerName = cCtx.Args().First() + } else { + fmt.Println("Note: You can add a controller name as an argument. Example: fuego controller yourControllerName") + } + + err := createController(controllerName) + if err != nil { + return err + } + + fmt.Printf("🔥 Controller %s created successfully\n", controllerName) + return nil + }, + } +} + +func createController(controllerName string) error { + controllerDir := "./controllers/" + if _, err := os.Stat(controllerDir); os.IsNotExist(err) { + err = os.Mkdir(controllerDir, 0755) + if err != nil { + return err + } + } + + templateContent, err := templates.FS.ReadFile("controller.template") + + newContent := strings.ReplaceAll(string(templateContent), "newController", controllerName) + newContent = strings.ReplaceAll(newContent, "NewController", strings.Title(controllerName)) + + controllerPath := fmt.Sprintf("%s%s.go", controllerDir, controllerName) + err = os.WriteFile(controllerPath, []byte(newContent), 0644) + if err != nil { + return err + } + + return nil +} diff --git a/cmd/fuego/go.mod b/cmd/fuego/go.mod new file mode 100644 index 00000000..a2ddeeca --- /dev/null +++ b/cmd/fuego/go.mod @@ -0,0 +1,11 @@ +module github.com/go-fuego/fuego/cmd/fuego + +go 1.21.5 + +require github.com/urfave/cli/v2 v2.27.1 + +require ( + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect +) diff --git a/cmd/fuego/go.sum b/cmd/fuego/go.sum new file mode 100644 index 00000000..31517c04 --- /dev/null +++ b/cmd/fuego/go.sum @@ -0,0 +1,8 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= +github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= diff --git a/cmd/fuego/main.go b/cmd/fuego/main.go new file mode 100644 index 00000000..3ee8dd10 --- /dev/null +++ b/cmd/fuego/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "log" + "os" + + "github.com/go-fuego/fuego/cmd/fuego/commands" + "github.com/urfave/cli/v2" +) + +func main() { + app := &cli.App{ + Name: "fuego", + Usage: "Fire like fuego!", + Action: func(*cli.Context) error { + fmt.Println("The 🔥 CLI!") + return nil + }, + Commands: []*cli.Command{ + commands.ControllerCommand(), + }, + } + + if err := app.Run(os.Args); err != nil { + log.Fatal(err) + } +} diff --git a/cmd/fuego/templates/controller.template b/cmd/fuego/templates/controller.template new file mode 100644 index 00000000..bfe396fa --- /dev/null +++ b/cmd/fuego/templates/controller.template @@ -0,0 +1,45 @@ +package controllers + +import ( + "github.com/go-fuego/fuego" +) + +type NewControllerEntityRepository interface { + // TODO add queries interfaces +} + +type NewControllerService interface { + // TODO add service functions interfaces +} + +type newControllerRessources struct { + // TODO add ressourses + NewControllerRepository NewControllerRepository + NewControllerService NewControllerService +} + +func (rs newControllerRessources) Routes(s *fuego.Server) { + newControllerRoutesGroupe := fuego.Group(s, "/newController") + fuego.Post(newControllerRoutesGroupe, "/", rs.postNewControllerFunction) + fuego.Get(newControllerRoutesGroupe, "/{id}", rs.getNewControllerFunction) + fuego.Patch(newControllerRoutesGroupe, "/{id}", rs.patchNewControllerFunction) + fuego.Put(newControllerRoutesGroupe, "/{id}", rs.putNewControllerFunction) + fuego.Delete(newControllerRoutesGroupe, "/{id}", rs.deleteNewControllerFunction) +} + +// TODO replace the following with your own functions +func (rs newControllerRessources) postNewControllerRessources(c fuego.Ctx[any]) (string, error) { + return "🔥", nil +} +func (rs newControllerRessources) getNewControllerRessources(c fuego.Ctx[any]) (string, error) { + return "🔥", nil +} +func (rs newControllerRessources) patchNewControllerRessources(c fuego.Ctx[any]) (string, error) { + return "🔥", nil +} +func (rs newControllerRessources) putNewControllerRessources(c fuego.Ctx[any]) (string, error) { + return "🔥", nil +} +func (rs newControllerRessources) deleteNewControllerRessources(c fuego.Ctx[any]) (string, error) { + return "🔥", nil +} diff --git a/cmd/fuego/templates/embed.go b/cmd/fuego/templates/embed.go new file mode 100644 index 00000000..c7cbf56e --- /dev/null +++ b/cmd/fuego/templates/embed.go @@ -0,0 +1,8 @@ +package templates + +import ( + "embed" +) + +//go:embed *.template +var FS embed.FS diff --git a/go.mod b/go.mod index a2f39dca..6e765bd1 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,12 @@ require ( github.com/swaggo/http-swagger v1.3.4 ) +require ( + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect +) + require ( github.com/KyleBanks/depth v1.2.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -32,6 +38,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/swaggo/files v1.0.1 // indirect github.com/swaggo/swag v1.16.2 // indirect + github.com/urfave/cli/v2 v2.27.1 golang.org/x/crypto v0.18.0 // indirect golang.org/x/net v0.20.0 // indirect golang.org/x/sys v0.16.0 // indirect diff --git a/go.sum b/go.sum index fd897746..378d4df2 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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= @@ -53,6 +55,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -69,6 +73,10 @@ github.com/swaggo/swag v1.16.2 h1:28Pp+8DkQoV+HLzLx8RGJZXNGKbFqnuvSbAAtoxiY04= github.com/swaggo/swag v1.16.2/go.mod h1:6YzXnDcpr0767iOejs318CwYkCQqyGer6BizOg03f+E= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= +github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= +github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= diff --git a/go.work b/go.work index 3fe45e8c..71f86ee5 100644 --- a/go.work +++ b/go.work @@ -4,4 +4,5 @@ use ( . ./examples/simple-crud ./examples/basic + ./cmd/fuego ) diff --git a/go.work.sum b/go.work.sum index 9749dde5..7ecea231 100644 --- a/go.work.sum +++ b/go.work.sum @@ -22,6 +22,7 @@ github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSY github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/ClickHouse/clickhouse-go v1.4.3/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ=