Gohtwind is an opinionated and lightweight full-stack framework designed for rapid web application development using Go, TailwindCSS, and htmx. Streamline your development process, from backend to frontend, with Gohtwind's fast and simple approach!
To get started with Gohtwind:
go build
sudo cp gohtwind /usr/local/bin/
Now, you can use the gohtwind
command from anywhere in your terminal!
# gohtwind name your_project_name
# ex:
gohtwind new town
# cd your_project_name
# ex:
cd town
# gohtwind gen-feature [feature_name]
# ex:
gohtwind gen-feature market
main.go
in the root of your project directory:package main
// the ide will automatically import the packages for you
// if not, you can manually import them like so:
import (
// ...
// "<project_name>/infra"
"town/infra"
// "<project_name>/auth"
"town/auth"
// "<project_name>/<feature_name>"
"town/market"
// ...
)
func main() {
// ...
}
func setUpEnv() {
// ...
}
func setUpDBs() {
// ...
}
func setUpRoutes() {
// ...
http.Handle("/static/", infra.LoggingMiddleware(http.StripPrefix("/static/", http.FileServer(http.Dir("./frontend/static/")))))
auth.SetupRoutes(dbs, infra.LoggingMiddleware)
/**
Replace feature_name with the name of your feature like so:
feature_name_1.SetupRoutes(dbs, infra.LoggingMiddleware)
...
feature_name_2.SetupRoutes(dbs, infra.LoggingMiddleware)
...
feature_name_n.SetupRoutes(dbs, infra.LoggingMiddleware)
**/
// ex:
market.SetupRoutes(dbs, infra.LoggingMiddleware)
// Activate the routes
infra.ActivateRoutes()
}
docker build -t gohtwind-db -f Dockerfile.db .
docker run -d -p 3306:3306 --name gohtwind-db gohtwind-db
# gohtwind gen-models -adapter=mysql -dsn="<username>:<password>@tcp(<host>:<port>)/<dbname>"
# or
# gohtwind gen-models -adapter=postgres -dsn="postgresql://<user>:<password>@<host>:<port>/<dbname>?sslmode=disable -schema=<schema>"
# using the containerized database
gohtwind gen-models -adapter=mysql -dsn="root:root@tcp(localhost:3306)/dev"
# Make sure that the model_name is the same as the generated model name (Usually the table name in TitleCase)
# gohtwind gen-repository -feature-name=<feature_name> -model-name=<model_name> -db-name=<dbname> -adapter=<mysql | postgres> -schema=<schema postgres only>
# using the model from containerized database
gohtwind gen-repository -feature-name=market -model-name=Products -db-name=dev -adapter=mysql
cp example.env .env
./dev-run.sh
/myapp
|-- dev-run.sh
|-- Dockerfile.prod
|-- example.env
|-- .gitignore
|-- .gen/ # Generated sql models
|-- config/ # Configuration files
|-- go.mod
|-- go.sum
|-- templates/ # base template and shared templates
| |-- shared/
| |-- base.html
|-- frontend/
| |-- static/
| | |-- css/
| | | |-- main.css # Base CSS file for Tailwind
| |
| |-- output.css # Generated CSS after processing with Tailwind
| |-- tailwind.config.js
|-- author-books/ # Example feature module
| |-- handler.go
| |-- repository.go
| |-- view.go
| |-- routes.go
| |-- static/
| | |-- js/
| | |-- css/
| |-- templates/
| |-- create.html
| |-- read.html
| |-- update.html
| |-- delete.html
| |-- list.html
|-- other-feature/ # Another example feature module
| ... # Similar structure as above
|-- ... # Other project-wide files, utilities, shared components, etc.
## Utility Scripts
1. To generates a new feature within your project run the gohtwind command with the gen-feature flag:
```bash
gohtwind gen-feature [feature_name]
feature_name
in the root of your project directory.gohtwind gen-models -adapter=<mysql | postgres> -dsn=<dsn> -schema=<schema>
.gen
directory at the root of your project directory.-adapter
flag specifies the database source. Currently, only MySQL and Postgres is supported.-dsn
flag specifies the database connection string.-schema
flag specifies the database schema to generate models for. (Only applicable for Postgres)gohtwind gen-repository -feature-name=<feature_name> -model-name=<model_name> -db-name=<dbname> -adapter=<mysql | postgres> -schema=<schema postgres only>
-feature-name
flag specifies the name of the feature the repository is for.-model-name
flag specifies the name of the model (sql table) the repository is for.-db-name
flag specifies the name of the database-schema
schema (postgres only) the model is in.-adapter
flag specifies the database adapter to use. Currently, only MySQL and Postgres is supported.gohtwind gen-form -feature-name=<feature_name> -model-name=<model_name>
-feature-name
flag specifies the name of the feature the form is for.-model-name
flag specifies the name of the model the form is for. -template-name
flag specifies the name of the template the form is for. -instance-name
flag specifies the name of the instance the form is for. Use this flag for update forms. Omit this flag for create forms.-action
flag specifies the action of the form../dev-run.sh
Contributions to Gohtwind are welcome. Please read our Contributing Guide (coming soon) for more information.
Gohtwind is licensed under the MIT License.
Feel free to modify or expand any sections to better fit the specifics of your project.