From cc92e07d92f4543e5774839d6c0c9f006222a988 Mon Sep 17 00:00:00 2001 From: AzenKain Date: Tue, 26 May 2026 12:26:20 +0700 Subject: [PATCH] feat: add goong integration service and route controllers with associated documentation --- docs/docs.go | 153 ++++++++++++++++-------- docs/swagger.json | 153 ++++++++++++++++-------- docs/swagger.yaml | 105 ++++++++++------ internal/controllers/goongController.go | 9 +- internal/routes/goongRoute.go | 5 +- internal/services/goongService.go | 8 +- 6 files changed, 288 insertions(+), 145 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index d83fb6f..a9dce6a 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -24,6 +24,57 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/api/proxy/{path}": { + "get": { + "description": "Transparent proxy for Goong APIs to forward body, params, headers and inject API key automatically.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json", + "application/x-protobuf" + ], + "tags": [ + "Goong" + ], + "summary": "Proxy Goong APIs", + "parameters": [ + { + "type": "string", + "description": "Target URL to proxy, e.g., 'tiles.goong.io/assets/goong_map_web.json'", + "name": "path", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Resource content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "string" + } + } + } + } + }, "/auth/forgot-password": { "post": { "description": "Initiate password recovery process for a user", @@ -1295,6 +1346,57 @@ const docTemplate = `{ } } }, + "/map/proxy/{path}": { + "get": { + "description": "Transparent proxy for Goong APIs to forward body, params, headers and inject API key automatically.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json", + "application/x-protobuf" + ], + "tags": [ + "Goong" + ], + "summary": "Proxy Goong APIs", + "parameters": [ + { + "type": "string", + "description": "Target URL to proxy, e.g., 'tiles.goong.io/assets/goong_map_web.json'", + "name": "path", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Resource content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "string" + } + } + } + } + }, "/media": { "get": { "security": [ @@ -2699,57 +2801,6 @@ const docTemplate = `{ } } }, - "/proxy/{path}": { - "get": { - "description": "Transparent proxy for Goong APIs to forward body, params, headers and inject API key automatically.", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json", - "application/x-protobuf" - ], - "tags": [ - "Goong" - ], - "summary": "Proxy Goong APIs", - "parameters": [ - { - "type": "string", - "description": "Target URL to proxy, e.g., 'tiles.goong.io/assets/goong_map_web.json'", - "name": "path", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Resource content", - "schema": { - "type": "string" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "string" - } - }, - "403": { - "description": "Forbidden", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "string" - } - } - } - } - }, "/raster-tiles/metadata": { "get": { "description": "Retrieve map metadata", diff --git a/docs/swagger.json b/docs/swagger.json index a56317c..d1d4fe0 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -17,6 +17,57 @@ }, "basePath": "/", "paths": { + "/api/proxy/{path}": { + "get": { + "description": "Transparent proxy for Goong APIs to forward body, params, headers and inject API key automatically.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json", + "application/x-protobuf" + ], + "tags": [ + "Goong" + ], + "summary": "Proxy Goong APIs", + "parameters": [ + { + "type": "string", + "description": "Target URL to proxy, e.g., 'tiles.goong.io/assets/goong_map_web.json'", + "name": "path", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Resource content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "string" + } + } + } + } + }, "/auth/forgot-password": { "post": { "description": "Initiate password recovery process for a user", @@ -1288,6 +1339,57 @@ } } }, + "/map/proxy/{path}": { + "get": { + "description": "Transparent proxy for Goong APIs to forward body, params, headers and inject API key automatically.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json", + "application/x-protobuf" + ], + "tags": [ + "Goong" + ], + "summary": "Proxy Goong APIs", + "parameters": [ + { + "type": "string", + "description": "Target URL to proxy, e.g., 'tiles.goong.io/assets/goong_map_web.json'", + "name": "path", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Resource content", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "string" + } + } + } + } + }, "/media": { "get": { "security": [ @@ -2692,57 +2794,6 @@ } } }, - "/proxy/{path}": { - "get": { - "description": "Transparent proxy for Goong APIs to forward body, params, headers and inject API key automatically.", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json", - "application/x-protobuf" - ], - "tags": [ - "Goong" - ], - "summary": "Proxy Goong APIs", - "parameters": [ - { - "type": "string", - "description": "Target URL to proxy, e.g., 'tiles.goong.io/assets/goong_map_web.json'", - "name": "path", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Resource content", - "schema": { - "type": "string" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "string" - } - }, - "403": { - "description": "Forbidden", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "string" - } - } - } - } - }, "/raster-tiles/metadata": { "get": { "description": "Retrieve map metadata", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 7000f2a..8c316d0 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -720,6 +720,41 @@ info: title: History API version: "1.0" paths: + /api/proxy/{path}: + get: + consumes: + - application/json + description: Transparent proxy for Goong APIs to forward body, params, headers + and inject API key automatically. + parameters: + - description: Target URL to proxy, e.g., 'tiles.goong.io/assets/goong_map_web.json' + in: path + name: path + required: true + type: string + produces: + - application/json + - application/x-protobuf + responses: + "200": + description: Resource content + schema: + type: string + "400": + description: Bad Request + schema: + type: string + "403": + description: Forbidden + schema: + type: string + "500": + description: Internal Server Error + schema: + type: string + summary: Proxy Goong APIs + tags: + - Goong /auth/forgot-password: post: consumes: @@ -1545,6 +1580,41 @@ paths: summary: Update application status tags: - Historian Application + /map/proxy/{path}: + get: + consumes: + - application/json + description: Transparent proxy for Goong APIs to forward body, params, headers + and inject API key automatically. + parameters: + - description: Target URL to proxy, e.g., 'tiles.goong.io/assets/goong_map_web.json' + in: path + name: path + required: true + type: string + produces: + - application/json + - application/x-protobuf + responses: + "200": + description: Resource content + schema: + type: string + "400": + description: Bad Request + schema: + type: string + "403": + description: Forbidden + schema: + type: string + "500": + description: Internal Server Error + schema: + type: string + summary: Proxy Goong APIs + tags: + - Goong /media: delete: consumes: @@ -2452,41 +2522,6 @@ paths: summary: Get commit by ID tags: - Commits - /proxy/{path}: - get: - consumes: - - application/json - description: Transparent proxy for Goong APIs to forward body, params, headers - and inject API key automatically. - parameters: - - description: Target URL to proxy, e.g., 'tiles.goong.io/assets/goong_map_web.json' - in: path - name: path - required: true - type: string - produces: - - application/json - - application/x-protobuf - responses: - "200": - description: Resource content - schema: - type: string - "400": - description: Bad Request - schema: - type: string - "403": - description: Forbidden - schema: - type: string - "500": - description: Internal Server Error - schema: - type: string - summary: Proxy Goong APIs - tags: - - Goong /raster-tiles/{z}/{x}/{y}: get: description: Fetch vector or raster map tile data by Z, X, Y coordinates diff --git a/internal/controllers/goongController.go b/internal/controllers/goongController.go index 1e94d88..31b2724 100644 --- a/internal/controllers/goongController.go +++ b/internal/controllers/goongController.go @@ -34,7 +34,8 @@ func NewGoongController(goongService services.GoongService) GoongController { // @Failure 400 {string} string "Bad Request" // @Failure 403 {string} string "Forbidden" // @Failure 500 {string} string "Internal Server Error" -// @Router /proxy/{path} [get] +// @Router /api/proxy/{path} [get] +// @Router /map/proxy/{path} [get] func (ctrl *goongController) Proxy(c fiber.Ctx) error { path := c.Params("*") if path == "" { @@ -69,12 +70,18 @@ func (ctrl *goongController) Proxy(c fiber.Ctx) error { } } + apiKeyName := "GOONG_API_KEY_REQ" + if strings.HasPrefix(c.Path(), "/map/proxy") { + apiKeyName = "GOONG_API_KEY_MAP" + } + statusCode, respHeaders, respBody, err := ctrl.goongService.ProxyRequest( c.Context(), c.Method(), targetURL, headers, c.Body(), + apiKeyName, ) if err != nil { diff --git a/internal/routes/goongRoute.go b/internal/routes/goongRoute.go index ac296fc..266ae5e 100644 --- a/internal/routes/goongRoute.go +++ b/internal/routes/goongRoute.go @@ -7,7 +7,6 @@ import ( ) func GoongRoutes(app *fiber.App, goongController controllers.GoongController) { - api := app.Group("/proxy") - - api.Get("/*", goongController.Proxy) + app.Get("/api/proxy/*", goongController.Proxy) + app.Get("/map/proxy/*", goongController.Proxy) } diff --git a/internal/services/goongService.go b/internal/services/goongService.go index 4fbebf1..529f830 100644 --- a/internal/services/goongService.go +++ b/internal/services/goongService.go @@ -17,7 +17,7 @@ import ( ) type GoongService interface { - ProxyRequest(ctx context.Context, method string, targetURL string, headers map[string]string, reqBody []byte) (int, map[string]string, []byte, error) + ProxyRequest(ctx context.Context, method string, targetURL string, headers map[string]string, reqBody []byte, apiKeyName string) (int, map[string]string, []byte, error) } type CacheEntry struct { @@ -45,10 +45,10 @@ func NewGoongService(redis cache.Cache) GoongService { } } -func (s *goongService) ProxyRequest(ctx context.Context, method string, targetURL string, headers map[string]string, reqBody []byte) (int, map[string]string, []byte, error) { - apiKey, err := config.GetConfig("GOONG_API_KEY") +func (s *goongService) ProxyRequest(ctx context.Context, method string, targetURL string, headers map[string]string, reqBody []byte, apiKeyName string) (int, map[string]string, []byte, error) { + apiKey, err := config.GetConfig(apiKeyName) if err != nil { - return 500, nil, nil, fmt.Errorf("GOONG_API_KEY is not configured") + return 500, nil, nil, fmt.Errorf("%s is not configured", apiKeyName) } fullTargetURL := targetURL