Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subfolders in actions folder #1868

Open
Maidomax opened this issue Dec 16, 2019 · 3 comments
Open

subfolders in actions folder #1868

Maidomax opened this issue Dec 16, 2019 · 3 comments

Comments

@Maidomax
Copy link

@Maidomax Maidomax commented Dec 16, 2019

Description

I am new in golang, so I apologize if this is just basic ignorance, but my problem is this:
I am trying to organize my actions in sub-folders, but I can't do it either manually, or using the commands.

I am not sure if this is supported, or am I not allowed to create subfolders in the given folder structure.

Steps to Reproduce the Problem

I use the command to generate an action in a subfolder with:

buffalo g action superfly/foobars get

The command runs without a problems, files get generated where I expect them to be.

Expected Behavior

I expect the new route to lead to my new action

Actual Behavior

But I get an error when I try to start the dev server:

➜  myapp git:(master) ✗ buffalo dev                          
buffalo: 2019/12/16 02:05:08 === Rebuild on: :start: ===
buffalo: 2019/12/16 02:05:08 === Running: go build -v -tags development -o tmp/myapp-build  (PID: 26259) ===
yarn run v1.19.2
$ webpack --watch
myapp/actions
# myapp/actions
actions/app.go:64:36: undefined: SuperflyFoobarsGet
buffalo: 2019/12/16 02:05:08 === Error! ===
buffalo: 2019/12/16 02:05:08 === exit status 2
myapp/actions
# myapp/actions
actions/app.go:64:36: undefined: SuperflyFoobarsGet

Info

Please run buffalo info and paste the information below where it says "PASTE_HERE".

➜  myapp git:(master) ✗ buffalo info
-> Go: Checking installation
✓ The `go` executable was found on your system at: /home/mladen/.gvm/gos/go1.13/bin/go

-> Go: Checking minimum version requirements
✓ Your version of Go, 1.13.4, meets the minimum requirements.

-> Go: Checking GOPATH
✓ You are using Go Modules, so no need to worry about the GOPATH.

-> Go: Checking Package Management
✓ You are using Go Modules (`go`) for package management.

-> Go: Checking PATH
✓ Your PATH contains /home/mladen/.gvm/pkgsets/go1.13/global/bin.

-> Node: Checking installation
✓ The `node` executable was found on your system at: /home/mladen/.nvm/versions/node/v12.8.1/bin/node

-> Node: Checking minimum version requirements
✓ Your version of Node, v12.8.1, meets the minimum requirements.

-> NPM: Checking installation
✓ The `npm` executable was found on your system at: /home/mladen/.nvm/versions/node/v12.8.1/bin/npm

-> NPM: Checking minimum version requirements
✓ Your version of NPM, 6.10.3, meets the minimum requirements.

-> Yarn: Checking installation
✓ The `yarnpkg` executable was found on your system at: /home/mladen/.yarn/bin/yarnpkg

-> Yarn: Checking minimum version requirements
✓ Your version of Yarn, 1.19.2, meets the minimum requirements.

-> PostgreSQL: Checking installation
✘ The `postgres` executable could not be found on your system.
For help setting up your Postgres environment please follow the instructions for you platform at:

https://www.postgresql.org/download/

-> MySQL: Checking installation
✓ The `mysql` executable was found on your system at: /usr/bin/mysql

-> MySQL: Checking minimum version requirements
✓ Your version of MySQL, 14.14, meets the minimum requirements.

-> SQLite3: Checking installation
✓ The `sqlite3` executable was found on your system at: /home/linuxbrew/.linuxbrew/bin/sqlite3

-> SQLite3: Checking minimum version requirements
✓ Your version of SQLite3, 3.29.0, meets the minimum requirements.

-> Cockroach: Checking installation
✘ The `cockroach` executable could not be found on your system.
For help setting up your Cockroach environment please follow the instructions for you platform at:

https://www.cockroachlabs.com/docs/stable/

-> Buffalo (CLI): Checking installation
✓ The `buffalo` executable was found on your system at: /usr/local/bin/buffalo

-> Buffalo (CLI): Checking minimum version requirements
✓ Your version of Buffalo (CLI), v0.15.3, meets the minimum requirements.

-> Buffalo: Application Details
Pwd         /home/mladen/Projects/BuffaloTest/myapp
Root        /home/mladen/Projects/BuffaloTest/myapp
GoPath      /home/mladen/.gvm/pkgsets/go1.13/global
PackagePkg  myapp
ActionsPkg  myapp/actions
ModelsPkg   myapp/models
GriftsPkg   myapp/grifts
WithModules true
Name        myapp
Bin         bin/myapp
VCS         git
WithPop     true
WithSQLite  false
WithDep     false
WithWebpack true
WithNodeJs  true
WithYarn    true
WithDocker  true
WithGrifts  true
AsWeb       true
AsAPI       false
InApp       true
PackageJSON {map[build:webpack -p --progress dev:webpack --watch]}

-> Buffalo: config/buffalo-app.toml
name = "myapp"
bin = "bin/myapp"
vcs = "git"
with_pop = true
with_sqlite = false
with_dep = false
with_webpack = true
with_nodejs = true
with_yarn = true
with_docker = true
with_grifts = true
as_web = true
as_api = false

-> Buffalo: config/buffalo-plugins.toml
[[plugin]]
  binary = "buffalo-pop"
  go_get = "github.com/gobuffalo/buffalo-pop"

-> Buffalo: go.mod
module myapp

go 1.13

require (
	github.com/gobuffalo/buffalo v0.15.3
	github.com/gobuffalo/buffalo-pop v1.23.1
	github.com/gobuffalo/envy v1.8.1
	github.com/gobuffalo/mw-csrf v0.0.0-20190129204204-25460a055517
	github.com/gobuffalo/mw-forcessl v0.0.0-20180802152810-73921ae7a130
	github.com/gobuffalo/mw-i18n v0.0.0-20190129204410-552713a3ebb4
	github.com/gobuffalo/mw-paramlogger v0.0.0-20190129202837-395da1998525
	github.com/gobuffalo/packr/v2 v2.7.1
	github.com/gobuffalo/pop v4.13.0+incompatible
	github.com/gobuffalo/suite v2.8.2+incompatible
	github.com/markbates/grift v1.5.0
	github.com/unrolled/secure v0.0.0-20190103195806-76e6d4e9b90c
)

@kteb

This comment has been minimized.

Copy link
Member

@kteb kteb commented Dec 18, 2019

Hello @Maidomax

Creating sub-folders in your action folder is not the best idea that you can have as a begginer, even though it's possible. In Go to be in the same package the code should be in the same folder (subfolder are not considered as in the same folder). So creating sub-folders in your action folder have a lot of implication and buffalo don't take them into account. So for beginning I'll recommend you not to create those sub-folders. But it's still very easy to have the route localhost:3000/superfly/foobars in your path. You just have to edit the models/app.go with the route you want to have.

app.GET("/superfly/foobars", SuperflyFoobarsGet)

As a new comer to go I also recommend you to play a bit with generate resources so you can see some code for some handlers for basic functions (you need to have a db).

buffalo generate resource test name value:int
buffalo migrate
@Maidomax

This comment has been minimized.

Copy link
Author

@Maidomax Maidomax commented Dec 18, 2019

In Go to be in the same package the code should be in the same folder (subfolder are not considered as in the same folder).

Yeah, I thought that might be the case... :/

Just having all actions in the same folder will make it very crowded very quickly. How would you recommend scaling this?

I like having a lot of very small controllers (or actions) organized in some sort of hierarchy, or use a DDD approach where code is separated into folders by the domain logic feature they belong to, and then each folder having it's own actions/models/etc folders.

I guess I should be able to create a new package for each folder under actions, and then import the actions into actions/app.go and set up the routes.

@kteb

This comment has been minimized.

Copy link
Member

@kteb kteb commented Dec 19, 2019

It depends. If it's only small controllers with not a big number of them, personally I'll replace the folder by one file and include multiple handler in it (I don't know how many you have for each folder, if you have 20 for each yeah it might be a mess).

But yeah an other approach will be to import the various actions in the main app file.

As I said try to use generate resources and look how the code structures look like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.