Skip to content

Commit

Permalink
Fix organize app
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Sjoberg committed Nov 19, 2023
1 parent 1932b34 commit daeb30b
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions content/english/blog/golang/app-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ There are many architectures out there such as

# Project Structure

Let's start with the basic project structure, I typically try to follow this [resource](https://github.com/golang-standards/project-layout) as it's pretty commonly used throughout the industry. Also, the go team just wrote a [blog-post](https://go.dev/doc/modules/layout) about it.
Let's start with the basic project structure, I typically try to follow this [resource](https://go.dev/doc/modules/layout) as it's pretty commonly used throughout the industry.

According to [Golang-standards Project layout](https://github.com/golang-standards/project-layout) we'll need the following:
According to [Organizing a Go module](https://go.dev/doc/modules/layout) we'll need the following:

`/cmd`

Expand All @@ -35,10 +35,6 @@ This will serve as the entry point to our program eg. `go run /cmd/api/my-app.go

Private app and library code, this code is only to be consumed by this application/library. This is typically where most of your app code will end up.

`/pkg`

Code that is exported, other applications/libraries may import from here, for example, if we have an auth-middleware that can be shared with multiple projects.

`/api`

Here is where OpenAPI/Swagger files should be placed.
Expand Down Expand Up @@ -154,7 +150,7 @@ func NewUserHandler() *UserHandler {
```golang
// internal/admin/handler.go

type AdmimHandler struct{}
type AdminHandler struct{}

func (u *AdmimHandler) PostAdminUser(w http.ResponseWriter, r *http.Request) *api.Response {
var req api.PostAdminUserJSONRequestBody
Expand All @@ -167,8 +163,8 @@ func (u *AdmimHandler) PostAdminUser(w http.ResponseWriter, r *http.Request) *ap
return api.PostAdminUserJSON200Response(api.User{ID: &id, Name: req.Name})
}

func NewAdmimHandler() *AdmimHandler {
return &AdmimHandler{}
func NewAdminHandler() *AdminHandler {
return &AdminHandler{}
}
```

Expand Down

0 comments on commit daeb30b

Please sign in to comment.