From 151355bee616d3f70a0fe8d53982c0c6232b69a2 Mon Sep 17 00:00:00 2001 From: tison Date: Tue, 12 Mar 2024 03:16:58 +0800 Subject: [PATCH] feat: support switching basepath Signed-off-by: tison --- api/client.gen.go | 5 +++++ api/configuration.gen.go | 1 + api/configuration_default.go | 1 + api/templates/client.mustache | 5 +++++ api/templates/configuration.mustache | 1 + 5 files changed, 13 insertions(+) diff --git a/api/client.gen.go b/api/client.gen.go index df9ec021..fb6b65e5 100644 --- a/api/client.gen.go +++ b/api/client.gen.go @@ -366,6 +366,11 @@ func (c *APIClient) prepareRequest( return nil, err } + // Prepend request base path, if applicable + if c.cfg.Path != "" { + url.Path = c.cfg.Path + url.Path + } + // Override request host, if applicable if c.cfg.Host != "" { url.Host = c.cfg.Host diff --git a/api/configuration.gen.go b/api/configuration.gen.go index 97fa99e6..8afc4e31 100644 --- a/api/configuration.gen.go +++ b/api/configuration.gen.go @@ -85,6 +85,7 @@ type ServerConfigurations []ServerConfiguration // Configuration stores the configuration of the API client type Configuration struct { Host string `json:"host,omitempty"` + Path string `json:"path,omitempty"` Scheme string `json:"scheme,omitempty"` DefaultHeader map[string]string `json:"defaultHeader,omitempty"` UserAgent string `json:"userAgent,omitempty"` diff --git a/api/configuration_default.go b/api/configuration_default.go index 2217257e..3dccd684 100644 --- a/api/configuration_default.go +++ b/api/configuration_default.go @@ -24,6 +24,7 @@ func NewAPIConfig(params ConfigParams) *Configuration { apiConfig := NewConfiguration() apiConfig.Host = params.Host.Host + apiConfig.Path = params.Host.Path apiConfig.Scheme = params.Host.Scheme apiConfig.UserAgent = params.UserAgent apiConfig.HTTPClient = &http.Client{Transport: clientTransport} diff --git a/api/templates/client.mustache b/api/templates/client.mustache index 388df2ce..c11ce354 100644 --- a/api/templates/client.mustache +++ b/api/templates/client.mustache @@ -294,6 +294,11 @@ func (c *APIClient) prepareRequest( return nil, err } + // Prepend request base path, if applicable + if c.cfg.Path != "" { + url.Path = c.cfg.Path + url.Path + } + // Override request host, if applicable if c.cfg.Host != "" { url.Host = c.cfg.Host diff --git a/api/templates/configuration.mustache b/api/templates/configuration.mustache index 55c75ce3..b75c6c6d 100644 --- a/api/templates/configuration.mustache +++ b/api/templates/configuration.mustache @@ -93,6 +93,7 @@ type ServerConfigurations []ServerConfiguration // Configuration stores the configuration of the API client type Configuration struct { Host string `json:"host,omitempty"` + Path string `json:"path,omitempty"` Scheme string `json:"scheme,omitempty"` DefaultHeader map[string]string `json:"defaultHeader,omitempty"` UserAgent string `json:"userAgent,omitempty"`