{"id":15095984,"url":"https://github.com/kyhsa93/gin-rest-cqrs-example","last_synced_at":"2025-04-14T22:12:11.574Z","repository":{"id":57511767,"uuid":"226016302","full_name":"kyhsa93/gin-rest-cqrs-example","owner":"kyhsa93","description":"Example for Go, Gin, MySQL, Redis, REST api, CQRS, Swagger","archived":false,"fork":false,"pushed_at":"2021-02-03T13:15:14.000Z","size":422,"stargazers_count":31,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T10:11:42.014Z","etag":null,"topics":["cqrs","docker","docker-compose","dockerfile","example","gin","gin-gonic","go","golang","gorm","localstack","mysql","redis","rest","rest-api","restful","restful-api","swagger"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kyhsa93.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-05T04:31:06.000Z","updated_at":"2024-11-04T18:18:50.000Z","dependencies_parsed_at":"2022-08-29T04:42:12.977Z","dependency_job_id":null,"html_url":"https://github.com/kyhsa93/gin-rest-cqrs-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyhsa93%2Fgin-rest-cqrs-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyhsa93%2Fgin-rest-cqrs-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyhsa93%2Fgin-rest-cqrs-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyhsa93%2Fgin-rest-cqrs-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kyhsa93","download_url":"https://codeload.github.com/kyhsa93/gin-rest-cqrs-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968916,"owners_count":21191162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cqrs","docker","docker-compose","dockerfile","example","gin","gin-gonic","go","golang","gorm","localstack","mysql","redis","rest","rest-api","restful","restful-api","swagger"],"created_at":"2024-09-25T15:44:32.673Z","updated_at":"2025-04-14T22:12:11.554Z","avatar_url":"https://github.com/kyhsa93.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gin CQRS Rest api example\n\nThis is sample Go project.\n\nGo: [https://golang.org/](https://golang.org/)\n\nGin: [https://gin-gonic.com/](https://gin-gonic.com/)\n\nGorm: [http://gorm.io/](http://gorm.io/)\n\nDocker: [https://www.docker.com/](https://www.docker.com/)\n\n## Getting started\n\nThis is REST api made by Gin, redis, mysql with Go.\n\n### Prerequisites\n\nPlease install Go and docker.\n\nI recommand to use docker for your environment.\n\n * Install Go: [https://golang.org/dl/](https://golang.org/dl/)\n\n * Install Docker for MAC: [https://docs.docker.com/docker-for-mac/install/](https://docs.docker.com/docker-for-mac/install/)\n\n * Install Docker for Windows: [https://docs.docker.com/docker-for-windows/install/](https://docs.docker.com/docker-for-windows/install/)\n\n * Install compose: [https://docs.docker.com/compose/install/](https://docs.docker.com/compose/install/)\n\n## Create development environment\n\nFirstable, create directory `$GOPATH/src/github.com/kyhsa93/` and clone this repository into your under that.\n\n```bash\n  mkdir $GOPATH/src/github.com/kyhsa93\n  cd $GOPATH/src/github.com/kyhsa93\n  git clone https://github.com/kyhsa93/gin-rest-cqrs-example.git\n```\n\nAnd then, build this program for set all dependencies.\n\n\n```bash\n  go build\n```\n\n`go.mod` and `go.sum` is already exists. so you don't need run `go mod init`.\n\nNext up, generate mysql and redis.\n\nIf you already have mysql and redis in your environment, you can use that.\n\nBut if you don't have one or both of them, try followed process.\n\nInstall docker for your OS from link in top of this document.\n\nIf your docker is successfully installed, you can use docker cli.\n\n```bash\n  docker run --name gin-rest-cqrs-example -d -p 3306:3306 -e MYSQL_DATABASE=gin-rest-cqrs-example -e MYSQL_ROOT_PASSWORD=test -v ~/database/gin-rest-cqrs-example:/var/lib/mysql mysql:5.7\n  docker run --name redis -d -p 6379:6379 redis:alpine\n\n  OR\n\n  docker-compose -f docker-compose.dev.yml up -d # create mysql, redis container for development environment\n  docker-compose -f docker-compose.dev.yml down  # remove created containers\n```\n\n\u003e Note. If you use docker container or any other docker resources included docker compose, recommended remove that after you use.\n\nNow you can connect mysql in localhost:3306, that user 'root' and password is 'test'.\n\nFinally, your development environment is created.\n\nAnd now you can start api with followed command.\n\n```bash\n  go run main.go\n```\n\nIf you want apply your code change into running process, save all changes and rerun `go run main.go`.\n\n## Start with docker\n\nIf you can use docker cli, you can build docker image.\n\n```bash\n  docker build -t gin-rest-cqrs-example .\n  docker images # list up docker images\n```\n\nAnd then you can create and run docker container using builded image.\n\n```bash\n  docker run -d -p 5000:5000 gin-rest-cqrs-example\n  docker ps # list up runnint docker containers\n```\n\nAnd now you can connect api through http://localhost:5000.\n\n## Start with docker compose\n\nDocker compose in this project is include api, redis and mysql.\n\nRun followed command in this project directory root.\n\n```bash\n  docker-compose up -d # pull images, create and run containers in background process\n```\n\nIf all containers are created, you can access api on http://localhost, and database also you can connect through by http://localhost:3306.\n\nDefault database user is 'root' and password is 'test'.\n\nAfter use docker-compose, you have to stop and remove all resources created by docker-compose in this project.\n\nRun followed command in project root.\n\n```bash\n  docker-compose down # stop and remove containers in defined docker-compose.yml\n```\n\n\u003e Note. docker-compose in this project, does not build from this source code. If you want to build and use image from this code, you have to modify docker-compose.yml\n\n## Configurations\n\nAll configurations are in [./config](https://github.com/kyhsa93/gin-rest-cqrs-example/tree/master/config)\n\nMost default configuration can use with your environment values.\n\nAnd also you can modify configurations.\n\n## Documentation\n\nDocument about this project us made swagger.\n\nStart this api and connect api host in your browser.\n\n * swagger config: [./config/swagger.go](https://github.com/kyhsa93/gin-rest-cqrs-example/blob/master/config/swagger.go)\n\n\u003e Note. Swagger in this project is use swag ([https://github.com/swaggo/swag](https://github.com/swaggo/swag)). Please check before you use it.\n\n## Scripts\n\n```bash\n  git clone https://github.com/kyhsa93/gin-rest-cqrs-example.git # clone this project\n  \n  go build # build this project\n  \n  docker run --name gin-rest-cqrs-example -d -p 3306:3306 -e MYSQL_DATABASE=gin-rest-cqrs-example -e MYSQL_ROOT_PASSWORD=test -v ~/database/\n  gin-rest-cqrs-example:/var/lib/mysql mysql:5.7 # create mysql container\n  \n  docker run --name redis -d -p 6379:6379 redis:alpine # create redis container\n  \n  docker-compose -f docker-compose.dev.yml up -d # create mysql, redis container for development environment\n  \n  docker-compose -f docker-compose.dev.yml down  # remove created containers\n\n  go run main.go # start \n\n  docker build -t gin-rest-cqrs-example . # build docker image\n  \n  docker images # list up docker images\n\n  docker run -d -p 5000:5000 gin-rest-cqrs-example\n  \n  docker ps # list up runnint docker containers\n\n  docker-compose up -d # build images, create and run containers in background process\n\n  docker-compose down # stop and remove containers in defined docker-compose.yml\n\n  swag init # build swagger\n```\n\n## Links\nGithub: [https://github.com/kyhsa93/gin-rest-cqrs-example](https://github.com/kyhsa93/gin-rest-cqrs-example)\n\nDockerhub: [https://hub.docker.com/repository/docker/kyhsa93/gin-rest-cqrs-example](https://hub.docker.com/repository/docker/kyhsa93/gin-rest-cqrs-example)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyhsa93%2Fgin-rest-cqrs-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyhsa93%2Fgin-rest-cqrs-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyhsa93%2Fgin-rest-cqrs-example/lists"}