repositorypackage
0.0.0-20250108000632-4dc1058d97ce
Repository: https://github.com/dargasht/gocrud.git
Documentation: pkg.go.dev
# README
gocrud
Template for go crud applications we use. Also some generic handler functions and helpers we use.
Installation
go get github.com/dargasht/gocrud
What we use
- go-fiber for http server
- pgx/v5 for database
- pgxpool for database connection pool
- sonic for json marshall/unmarshall
- zap for logging
- sqlc for database code generation
- sqlc for some wierd queries that can't be done with sqlc
- goose for database migrations
what we enjoy
- excessive use of postgres json_agg function
- simple architecture with no magic (maybe some magic, but not too much)
- no ORM
- writing raw sql queries
- simplicity simplicity and simplicity
Folder structure
.
├── bin # for binaries (should be added in gitignore)
├── cfg # for configs
├── cmd
│ └── api
│ └── main.go # the main entry point
├── database
│ ├── migration # for database migrations
│ ├── query # for database queries
│ ├── repo # for sqlc generated queries and models
│ └── store # for specific database implementations that uses sqlx
├── handler # for http handlers (data transformation and validation)
├── middleware # for http middlewares (if needed)
├── model # for service models and handler models (DTOs)
├── router # for instantiating handlers and injecting dependencies
├── service # for business logic (if needed)
└── utils # for utility functions
Things to keep in mind:
- services should be stateless and not depend on external services
- use service layer if business logic is not simple otherwise use handler layer
- go to each folder in the internal folder and read the README.md
Usefull stuff in this package are:
-
-
GoCRUDConfig: THIS IS VERY IMPORTANT, YOU SHOULD SET THIS TO YOUR NEEDS IN YOUR MAIN FILE 🔥🔥🔥🔥🔥
-
-
Error helper stuff: Just read comments in code
-
handler helper stuff: This contains stuff usefull to use in your handlers, they are (Just read comments in code)
-
jwt helper stuff: Just read comments in code
-
kavenegar helper stuff: 2 functions
- SendOTP: For sending otp
- ValidateOTP: For validating otp
- Seems simple enough 🤷♂️🤷 not much to explain
-
S3 helpers: 2 functions
- SetupS3Client: For setting up the s3 client, you should call this in the main file and set it to gocrud.GoCRUDConfig Object
- UploadFormFileToS3: For uploading files to s3