42 lines
887 B
Go
42 lines
887 B
Go
package anyapi
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/sleepinggodoflove/lansexiongdi-marketing-sdk/api"
|
|
"github.com/sleepinggodoflove/lansexiongdi-marketing-sdk/core"
|
|
"net/http"
|
|
)
|
|
|
|
type AnyApi api.Service
|
|
|
|
func (a *AnyApi) AnyApi(ctx context.Context, method string, bizContent any) (http.Header, *http.Response, *core.Response, error) {
|
|
|
|
p, err := a.BuildAnyApiParams(bizContent)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
|
|
reqBodyBytes, err := json.Marshal(p)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
|
|
h := a.GetHeaders(p)
|
|
|
|
url := fmt.Sprintf("%s%s", a.Config.BaseURL, method)
|
|
|
|
httpResponse, bodyBytes, err := a.Request(ctx, h, http.MethodPost, url, reqBodyBytes)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
|
|
res, err := core.BuildResponse(bodyBytes)
|
|
if err != nil {
|
|
return h, httpResponse, nil, err
|
|
}
|
|
|
|
return h, httpResponse, res, nil
|
|
}
|