Skip to content

Commit

Permalink
go-sdk 新增知识库、知识库文档、切片增删改查等OpenAPI (baidubce#409)
Browse files Browse the repository at this point in the history
* go-sdk 新增知识库增删改查等OpenAPI

* update

* update

* update

* update
  • Loading branch information
userpj authored Jul 24, 2024
1 parent 572f981 commit 78b8f65
Show file tree
Hide file tree
Showing 4 changed files with 787 additions and 9 deletions.
22 changes: 14 additions & 8 deletions go/appbuilder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/http"
"net/url"
"os"
"path"
"strings"

"github.com/google/uuid"
Expand Down Expand Up @@ -143,28 +144,33 @@ func (t *SDKConfig) authHeader() http.Header {
}

func (t *SDKConfig) ServiceURL(suffix string) (*url.URL, error) {
absolutePath, err := url.JoinPath(t.GatewayURL, suffix)
absolutePath, err := url.JoinPath(t.GatewayURL)
if err != nil {
return nil, err
}
return t.formatURL(absolutePath)
return t.formatURL(absolutePath, suffix)
}

// ServiceURLV2 适配OpenAPI,当前仅AppbuilderClient使用
func (t *SDKConfig) ServiceURLV2(suffix string) (*url.URL, error) {
absolutePath, err := url.JoinPath(t.GatewayURLV2, t.ConsoleOpenAPIPrefix, t.ConsoleOpenAPIVersion, suffix)
if err != nil {
return nil, err
}
return t.formatURL(absolutePath)
suffix = path.Join(t.ConsoleOpenAPIPrefix, t.ConsoleOpenAPIVersion, suffix)
return t.formatURL(t.GatewayURLV2, suffix)
}

func (t *SDKConfig) formatURL(absolutePath string) (*url.URL, error) {
func (t *SDKConfig) formatURL(absolutePath, suffix string) (*url.URL, error) {
t.logger.Debug().Msgf("Service URL %s", absolutePath)
url, err := url.Parse(absolutePath)
if err != nil {
return nil, err
}

endpoint, err := url.Parse(suffix)
if err != nil {
return nil, err
}

url = url.ResolveReference(endpoint)

return url, nil
}

Expand Down
Loading

0 comments on commit 78b8f65

Please sign in to comment.