{"id":15095975,"url":"https://github.com/abhijithk1/api-service-generator","last_synced_at":"2026-02-06T09:34:37.675Z","repository":{"id":241286913,"uuid":"806012422","full_name":"abhijithk1/api-service-generator","owner":"abhijithk1","description":"A CLI application that creates a Golang API Service application template.","archived":false,"fork":false,"pushed_at":"2024-06-16T13:20:42.000Z","size":79,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-30T21:22:25.372Z","etag":null,"topics":["api-service","cli-application","code-generation","docker","gin","gin-gonic","golang","golang-migrate","makefile","middleware","postgresql","rest-api","server","sqlc","template","template-generator","viper"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abhijithk1.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-26T05:48:21.000Z","updated_at":"2024-09-29T04:32:44.000Z","dependencies_parsed_at":"2024-06-06T17:34:52.271Z","dependency_job_id":"8cb357ee-77c6-473d-9ec8-4e8d4995bf26","html_url":"https://github.com/abhijithk1/api-service-generator","commit_stats":null,"previous_names":["abhijithk1/api-service-generator"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/abhijithk1/api-service-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhijithk1%2Fapi-service-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhijithk1%2Fapi-service-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhijithk1%2Fapi-service-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhijithk1%2Fapi-service-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhijithk1","download_url":"https://codeload.github.com/abhijithk1/api-service-generator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhijithk1%2Fapi-service-generator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29157426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T07:18:23.844Z","status":"ssl_error","status_checked_at":"2026-02-06T07:13:32.659Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["api-service","cli-application","code-generation","docker","gin","gin-gonic","golang","golang-migrate","makefile","middleware","postgresql","rest-api","server","sqlc","template","template-generator","viper"],"created_at":"2024-09-25T15:44:29.078Z","updated_at":"2026-02-06T09:34:37.652Z","avatar_url":"https://github.com/abhijithk1.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API Service Generator\n\n`api-service-generator` is a CLI tool built with the Cobra CLI package that allows developers to quickly generate a basic Golang REST API service. The generated service uses the following packages:\n\n- [Gin Framework](https://github.com/gin-gonic/gin) for building the API.\n- [IBM/alchemy-logging](https://github.com/IBM/alchemy-logging) for logging.\n- [golang-migrate](https://github.com/golang-migrate/migrate) for database migrations.\n- [sqlc](https://github.com/sqlc-dev/sqlc) for generating type-safe Go code from SQL queries.\n- [Viper](https://github.com/spf13/viper) for configuration management.\n\n## Prerequisites\n\nEnsure the following commands are installed and available in your system's PATH:\n\n1. [Go](https://go.dev/doc/install) (1.16 or later)\n2. [golang-migrate CLI](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate)\n3. [sqlc CLI](https://docs.sqlc.dev/en/latest/overview/install.html)\n4. [Docker](https://docs.docker.com/get-docker/)\n\n## Installation\n\nClone the repository and build the CLI application:\n\n```sh\ngit clone https://github.com/abhijithk1/api-service-generator.git\ncd api-service-generator\ngo build -o api-service-generator\n```\n\nMove the `api-service-generator` binary to a directory in your PATH.\n\n```sh\nmv api-service-generator /usr/local/bin/\n```\n\n\u003e Note: Can Skip the build and moving the binary process. Instead run: `go install`\n\n## Usage\n\nThe `template` subcommand is used to create a basic Golang REST API service. The CLI takes a single `--name` flag and then prompts for the other inputs:\n\n```sh\napi-service-generator go-template --name myservice\n```\n\n### Prompts\n\nThe CLI will prompt you to enter the following details:\n\n1. **Database Driver**: Choose between postgres and mysql *(Default: `postgres`)*\n2. **Container Name**: Name for the Docker container *(Default: `dummy_db`)*\n3. **Container Port**:  Port for the Docker container *(Default: `6432`)*\n4. **Database Name**: Name of the database  *(Default: `dummy_db`)*\n5. **Table Name**: Name of the database table *(Default: `api_table`)*\n6. **API Group**: API group for the generated service *(Default: `dummy`)*\n7. **Module Path**: Base path for the Go module *(Default: `example/api-service`)*\n   \n#### PostgresQL Specific Prompts\n1. **POSTGRES_USER**: PostgreSQL user *(Default: `postgres`)*\n2. **POSTGRES_PASSWORD**: PostgreSQL password *(Default: `password`)*\n\n#### MySQL Specific Prompts\n1. **MYSQL_ROOT_PASSWORD**: MySQL root password *(Default: `my-root-secret`)*\n2. **MYSQL_USER**: MySQL user *(Default: `mysql`)*\n3. **MYSQL_PASSWORD**: MySQL password *(Default: `password`)*\n\nThe CLI will automatically spin up a Docker container based on the provided inputs and configure the API service to connect to it.\n\n## Project Structure\n\nThe generated project has the following structure:\n\n```\n\u003capi-service\u003e\n  | _ api\n  |    | _ v1\n  |         | _ \u003capi_group\u003e\n  |              | _ controller.go\n  |              | _ service.go\n  |         | _ mw\n  |              | _ cors.go\n  |              | _ auth.go\n  | _ pkg\n  |    | _ db\n  |        | _ migrations\n  |              | _ 000001_init_schema_up.sql\n  |              | _ 000001_init_schema_down.sql\n  |        | _ query\n  |              | _ \u003ctable_name\u003e.sql\n  |        | _ connection.go\n  |        | _ \u003ctable_name\u003e.sql.go\n  |        | _ migrate.go\n  |        | _ main_test.go\n  |        | _ db.go\n  |        | _ models.go\n  | _ utils\n  |    | _ config.go\n  |    | _ utils.go\n  | _ go.mod\n  | _ go.sum\n  | _ main.go\n  | _ Makefile\n  | _ sqlc.yaml\n  | _ app.env\n  | _ api.http\n```\n\n### Files and Directories\n\n- **api/v1/\u003capi_group\u003e/**: Contains the controller and service logic for the API group.\n- **api/v1/mw/**: Middleware functions (e.g., CORS, authentication).\n- **pkg/db/**: Database-related files, including migrations, queries, and connection setup.\n- **utils/**: Utility functions and configuration handling.\n- **main.go**: Entry point of the application.\n- **Makefile**: Contains commands to build and run the application.\n- **sqlc.yaml**: Configuration for sqlc to generate Go code from SQL queries.\n- **app.env**: Environment variables for the application.\n- **api.http**: HTTP file for testing API endpoints.\n\n## Running the Service\n\nTo run the generated API service:\n\n1. Ensure the Docker container is already running.\n2. Run the API service:\n\n    ```sh\n    make run\n    ```\n\nThe server will start on port 8080. The migration is done automatically. If needed, you can migrate it manually using the Makefile commands.\n\n### Makefile\n\nThe generated Makefile includes commands for running the service, database migrations, testing, building, and generating SQL code:\n\n```Makefile\n# Generated By API Service Generator\n\ninclude app.env\n\nmigrateup:\n\tmigrate -path pkg/db/migrations -database \"$(DB_SOURCE)\" -verbose up\n\nmigratedown:\n\tmigrate -path db/migration -database \"$(DB_SOURCE)\" -verbose down\n\nrun: ## run the api-service\n\tgo run main.go\n\ntest: # run unit tests\n\tgo test -v -coverprofile=coverage.out ./...\n\tgo tool cover -func=coverage.out\n\tgo tool cover -html=coverage.out -o coverage.html\n\nbuild: ## build the offload-service binary\n\tCGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main main.go\n\nsqlc: ## run all new database migrations\n\t@echo \"Running sqlc code generation...\"\n\tsqlc generate\n\n.PHONY: migrateup, migratedown, run, test, build, sqlc\n```\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request on GitHub.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Changelog\n\nThe in-progres changes, upcoming changes, and proposals are listed. See the [Changelog](CHANGELOG.md) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhijithk1%2Fapi-service-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhijithk1%2Fapi-service-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhijithk1%2Fapi-service-generator/lists"}