7
0
gaore-common-sdk-go/sdk/requests/stream_request.go

56 lines
1.2 KiB
Go
Raw Normal View History

2024-05-30 18:40:57 +08:00
package requests
import (
"bytes"
"fmt"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/utils"
"io"
"strings"
)
type StreamRequest struct {
*baseRequest
}
func (s *StreamRequest) init() {
s.baseRequest = defaultBaseRequest()
s.baseRequest.AddHeaderParam("Content-Type", "application/form-data")
s.Method = POST
}
func (s *StreamRequest) GetStyle() string {
return STREAM
}
func (s *StreamRequest) InitWithApiInfo(domain Host, version, urlPath string) {
s.init()
s.SetDomain(domain)
s.version = version
s.actionName = urlPath
}
func (s *StreamRequest) BuildUrl() string {
var hostname string
if s.Domain.Func == nil {
hostname = s.Domain.Default
} else if hostname = s.Domain.Func(s.GetEnv()); hostname == "" {
hostname = s.Domain.Default
}
url := fmt.Sprintf("%s://%s", strings.ToLower(s.Scheme), hostname)
if len(s.Port) > 0 {
url = fmt.Sprintf("%s:%s", url, s.Port)
}
return url + s.BuildQueries()
}
func (s *StreamRequest) BuildQueries() string {
path := strings.TrimLeft(strings.TrimSpace(s.GetActionName()), "/")
s.queries = "/" + path + "?" + utils.GetUrlFormedMap(s.QueryParams)
return s.queries
}
func (s *StreamRequest) GetBodyReader() io.Reader {
return bytes.NewReader(s.Content)
}