From 50b5d74df2547562466df66c4f9c3d56d36d2580 Mon Sep 17 00:00:00 2001 From: Mathieu CARBONNEAUX Date: Fri, 5 Jul 2024 15:15:48 +0200 Subject: [PATCH] Add optional config option to change base path of wapi api uri. --- README.md | 1 + connector.go | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 245a61f7..f6ad10a9 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ This library is compatible with Go 1.2+ hostConfig := ibclient.HostConfig{ Scheme: "https", Host: "", + BasePath: "", Version: "", Port: "PORT", } diff --git a/connector.go b/connector.go index 110d116f..b2bfeb8a 100644 --- a/connector.go +++ b/connector.go @@ -28,10 +28,11 @@ type AuthConfig struct { } type HostConfig struct { - Scheme string - Host string - Version string - Port string + Scheme string + Host string + BasePath string + Version string + Port string } type TransportConfig struct { @@ -244,7 +245,12 @@ func (wrb *WapiRequestBuilder) Init(hostCfg HostConfig, authCfg AuthConfig) { } func (wrb *WapiRequestBuilder) BuildUrl(t RequestType, objType string, ref string, returnFields []string, queryParams *QueryParams) (urlStr string) { - path := []string{"wapi", "v" + wrb.hostCfg.Version} + if wrb.hostCfg.BasePath != "" { + path := []string{wrb.hostCfg.BasePath,"wapi", "v" + wrb.hostCfg.Version} + } else { + path := []string{"wapi", "v" + wrb.hostCfg.Version} + } + if len(ref) > 0 { path = append(path, ref) } else {