-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
166 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
NewControllerEntityRepository NewControllerEntityRepository | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package templates | ||
|
||
import ( | ||
"embed" | ||
) | ||
|
||
//go:embed *.template | ||
var FS embed.FS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ go 1.22.0 | |
|
||
use ( | ||
. | ||
./cmd/fuego | ||
./examples/basic | ||
./examples/full-app-gourmet | ||
./examples/hello-world | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters