Web applications have an application
struct that contains the following:
project/
├── cmd
│ └── web
│ ├── context.go
│ ├── handlers.go
│ ├── handlers_test.go
│ ├── helpers.go
│ ├── main.go
│ ├── middleware.go
│ ├── middleware_test.go
│ ├── routes.go
│ ├── templates.go
│ └── testutils_test.go
├── go.mod
├── go.sum
├── internal
│ ├── assert
│ │ └── assert.go
│ ├── models
│ │ ├── errors.go
│ │ ├── mocks
│ │ │ ├── snippets.go
│ │ │ └── users.go
│ │ ├── snippets.go
│ │ ├── testdata
│ │ │ ├── setup.sql
│ │ │ └── teardown.sql
│ │ ├── testutils_test.go
│ │ ├── users.go
│ │ └── users_test.go
│ └── validator
│ └── validator.go
├── README.md
├── tls
│ ├── cert.pem
│ └── key.pem
└── ui
├── html
│ ├── base.tmpl.html
│ ├── pages
│ │ ├── create.tmpl.html
│ │ ├── home.tmpl.html
│ │ ├── login.tmpl.html
│ │ ├── signup.tmpl.html
│ │ └── view.tmpl.html
│ └── partials
│ └── nav.tmpl.html
└── static
├── css
│ └── main.css
├── img
│ ├── favicon.ico
│ └── logo.png
└── js
└── main.js
/cmd
Holds executables
/web
Holds executables for the web application:
context.go
handlers.go
helpers.go
main.go
middleware.go
routes.go
templates.go
/internal
/models
/validator
/tls
/ui
/html
/static
serverError
helper method that logs the trace to the errorLog and sends an http.Error()
message.clientError
helper that validates that form submissions use the correct HTTP verb.notFound
helper to manage client requests for pages that do not exist.github.com/justinas/alice
to simplify routing. Add them as methods to the application so they can access application dependencies, like loggers.Services do not require an application
struct to manage user details.
shortner/
├── cmd
│ └── servicename
│ └── main.go or service.go
├── internal
│ └── httpio
│ ├── handler.go
│ └── httpio.go
├── linkit
│ └── errors.go
└── short
├── server.go
├── server_test.go
└── business-logic.go