Web应用程序的Go Lang文件夹结构

As you know Go is a modern approach to OOP imo, with brilliant things like forcing you to use composition over inheritance. I am just trying to understand how a well written go code has to be designed in terms of folder and package structure.

I am just wondering if this React like approach which can be seen below - dividing app as components to different packages can work?

Or can you give me an example, link, idea for a good structure in terms of folder/packaging of a web api. Go will only be an api in the background to my open source project, on client side I am planing to have a single-page React app btw.

Thanks a lot,

enter image description here

I tend to structure my apps as: $GOPATH/github.com/yourname/projectname/ cmd/ app1/ main.go app2/ main.go db/ 001_initial_schema.sql 002_add_timestamps.sql ... etc ... lib/ lib1/ lib2/ html/ ..all the html stuff.. where app1 / app2 are the command line apps. Often it is only be one app (your web server).

lib/* is just whatever segregated pieces of functionality you have.

Usually, i start with just cmd/app1 and then expand in to lib when the project gets sufficiently complex.

And make your static file server (assuming you have one), use "html" as the directory.

For database migrations, I use a really simple migrator I wrote as I find the others to be too complicated / too large.

Here's the code I'm using in my projects.
I thought of making it a real library, but I'm pretty sure this is postgresql specific as it assumes that DDL is transactional.

With this structure, you can simply do (from the project root):

go install ./... && app1

To build / test your app.

This structure will also naturally work if you then want to deploy to Heroku as heroku sets your working dir to your project root.