{"id":30215474,"url":"https://github.com/thanthtooaung-coding/spring-cloud-gateway-go","last_synced_at":"2025-08-14T02:11:47.548Z","repository":{"id":301776200,"uuid":"1010234219","full_name":"thanthtooaung-coding/spring-cloud-gateway-go","owner":"thanthtooaung-coding","description":"Spring Cloud Gateway","archived":false,"fork":false,"pushed_at":"2025-06-28T18:30:40.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-28T19:38:48.559Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/thanthtooaung-coding.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"zenodo":null}},"created_at":"2025-06-28T16:29:16.000Z","updated_at":"2025-06-28T18:31:53.000Z","dependencies_parsed_at":"2025-06-28T19:38:53.738Z","dependency_job_id":"91e93217-94d0-4696-97fe-63fe00e7d54d","html_url":"https://github.com/thanthtooaung-coding/spring-cloud-gateway-go","commit_stats":null,"previous_names":["thanthtooaung-coding/spring-cloud-gateway-go"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thanthtooaung-coding/spring-cloud-gateway-go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thanthtooaung-coding%2Fspring-cloud-gateway-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thanthtooaung-coding%2Fspring-cloud-gateway-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thanthtooaung-coding%2Fspring-cloud-gateway-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thanthtooaung-coding%2Fspring-cloud-gateway-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thanthtooaung-coding","download_url":"https://codeload.github.com/thanthtooaung-coding/spring-cloud-gateway-go/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thanthtooaung-coding%2Fspring-cloud-gateway-go/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270347825,"owners_count":24568605,"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","status":"online","status_checked_at":"2025-08-14T02:00:10.309Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-08-14T02:11:43.247Z","updated_at":"2025-08-14T02:11:47.506Z","avatar_url":"https://github.com/thanthtooaung-coding.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spring Cloud Gateway with Go Microservices\n\nThis project demonstrates a polyglot microservice architecture featuring Java-based Spring Cloud components acting as the control plane for backend microservices written in Go. It showcases the use of an API Gateway for routing and a Discovery Service for dynamic service registration and discovery.\n\n## Architecture\n\nThe system is composed of four main services that work together:\n\n1.  **Discovery Service (Eureka):** A service registry where all other services register themselves. This allows services to find each other by name without needing to know their hardcoded IP addresses or ports.\n2.  **Go Microservices (Product \u0026 Order APIs):** Two independent backend services written in Go. They handle specific business logic (managing products and orders) and register themselves with the Discovery Service upon startup.\n3.  **API Gateway:** The single entry point for all external clients. It routes incoming requests to the appropriate Go microservice by looking up their location in the Discovery Service.\n\n\u003c!-- end list --\u003e\n\n```\n+-----------+      +-------------------------+      +--------------------+\n|           |      |      API Gateway        |      |  Go Product API    |\n|  Client   | ----\u003e|  (Spring, port 8080)    | ----\u003e|  (Go, port 9091)   |\n| (cURL/UI) |      |                         |      |                    |\n+-----------+      +-------------------------+      +--------------------+\n                              |                            ^\n                              |                            |\n                              |              +-------------------------+\n                              |              |                         |\n                              +-------------\u003e| Discovery Service       |\n                                             |(Spring Eureka,port:8761)|\n                                             |                         |\n                              +-------------\u003e|                         |\n                              |              +-------------------------+\n                              |                            ^\n                              |                            |\n                              |              +--------------------+\n                              |              |   Go Order API     |\n                              +-------------\u003e|   (Go, port 9092)  |\n                                             |                    |\n                                             +--------------------+\n```\n\n## Technologies Used\n\n  * **Java / Spring:**\n      * Spring Boot 3\n      * Spring Cloud Gateway\n      * Spring Cloud Netflix Eureka (Server \u0026 Client)\n      * Maven\n  * **Go:**\n      * Standard Library (`net/http`)\n      * Go Modules for dependency management\n      * `hudl/fargo` library for Eureka client registration\n  * **Platform:**\n      * Java 17+\n      * Go 1.18+\n\n## Project Structure\n\nYour screenshot shows a well-organized multi-module project:\n\n```\n.\n├── api-gateway/            # The Spring Cloud Gateway application\n├── discovery-service/      # The Spring Cloud Eureka Server application\n├── order-api/              # The Go microservice for orders (CRUD)\n├── product-api/            # The Go microservice for products\n├── mvnw                    # Maven wrapper for building Java modules\n└── pom.xml                 # Root Maven POM file for the project\n```\n\n## Prerequisites\n\nBefore you begin, ensure you have the following installed:\n\n  * **Java Development Kit (JDK)**: Version 17 or higher.\n  * **Apache Maven**: To build the Java projects.\n  * **Go**: Version 1.18 or higher.\n\n## How to Run the System\n\nTo run the entire application stack, you must follow these steps in order.\n\n### 1\\. Build the Java Modules\n\nFrom the root directory (`SPRING-CLOUD-GATEWAY-GO`), run the Maven wrapper to build the `discovery-service` and `api-gateway` JAR files.\n\n```bash\n./mvnw clean install\n```\n\n### 2\\. Prepare the Go Modules\n\nNavigate into each Go directory and run `go mod tidy` to ensure the dependencies (like the Fargo Eureka client) are downloaded.\n\n```bash\n# For the product API\ncd product-api\ngo mod tidy\ncd ..\n\n# For the order API\ncd order-api\ngo mod tidy\ncd ..\n```\n\n### 3\\. Run the Applications (In Order)\n\nYou will need **four separate terminal windows** to run all the services.\n\n**a. Start the Discovery Service (Eureka Server)**\nThis must be the first service to start.\n\n```bash\n# In Terminal 1\njava -jar discovery-service/target/discovery-service-1.0.0-SNAPSHOT.jar\n```\n\nWait for it to start. You can view the Eureka dashboard by navigating to **`http://localhost:8761`** in your browser.\n\n**b. Start the Go Microservices**\nThese can be started in any order after the discovery service is up.\n\n```bash\n# In Terminal 2\ncd product-api\ngo run main.go\n\n# In Terminal 3\ncd order-api\ngo run main.go\n```\n\nWatch their logs for the \"Successfully registered with Eureka...\" message. Refresh the Eureka dashboard to see `PRODUCT-SERVICE` and `ORDER-SERVICE` appear.\n\n**c. Start the API Gateway**\nThis is the final piece. It will register with Eureka and begin routing requests.\n\n```bash\n# In Terminal 4\njava -jar api-gateway/target/api-gateway-1.0.0-SNAPSHOT.jar\n```\n\n## Testing the API Endpoints\n\nAll requests should be sent to the API Gateway on port `8080`.\n\n### Product Service\n\n| Method | Path                  | Description           |\n| :---   | :---                  | :---                  |\n| `GET`  | `/api/products`       | Retrieves all products. |\n\n**Example `curl` command:**\n\n```bash\ncurl http://localhost:8080/api/products\n```\n\n### Order Service (CRUD)\n\n| Method   | Path                  | Description                |\n| :---     | :---                  | :---                       |\n| `POST`   | `/api/orders`         | Creates a new order.       |\n| `GET`    | `/api/orders/{id}`    | Retrieves a single order.  |\n| `PUT`    | `/api/orders/{id}`    | Updates an existing order. |\n| `DELETE` | `/api/orders/{id}`    | Deletes an order.          |\n\n**Example `curl` commands:**\n\n```bash\n# CREATE a new order\ncurl -X POST -H \"Content-Type: application/json\" -d '{\"product\": \"Keyboard\", \"total\": 75.99}' http://localhost:8080/api/orders\n\n# GET all orders\ncurl http://localhost:8080/api/orders\n\n# GET a single order by its ID\ncurl http://localhost:8080/api/orders/o101\n\n# UPDATE an existing order\ncurl -X PUT -H \"Content-Type: application/json\" -d '{\"product\": \"Wireless Gaming Mouse\", \"total\": 45.50}' http://localhost:8080/api/orders/o102\n\n# DELETE an order\ncurl -X DELETE http://localhost:8080/api/orders/o101\n```\n\n## Configuration\n\n  * **Java Services**: Configuration is located in the `src/main/resources/application.properties` file of each module (`api-gateway`, `discovery-service`).\n  * **Go Services**: The Eureka server URL is currently hardcoded in the `main.go` file of each module. In a real-world scenario, this would be externalized.\n\nThe key configuration is the routing rules in the **API Gateway**, which dynamically forward requests to the correct service based on its name in Eureka.\n\n```properties\n# Example from api-gateway/application.properties\n# This rule forwards requests from /api/orders/** to the ORDER-SERVICE\n\nspring.cloud.gateway.routes[1].id=order-service-route\nspring.cloud.gateway.routes[1].uri=lb://ORDER-SERVICE\nspring.cloud.gateway.routes[1].predicates[0]=Path=/api/orders/**\nspring.cloud.gateway.routes[1].filters[0]=StripPrefix=1\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthanthtooaung-coding%2Fspring-cloud-gateway-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthanthtooaung-coding%2Fspring-cloud-gateway-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthanthtooaung-coding%2Fspring-cloud-gateway-go/lists"}