mirror of
https://github.com/hanzo-go/sdk.git
synced 2026-11-20 20:13:42 +00:00
182 lines
6.5 KiB
Go
182 lines
6.5 KiB
Go
/*
|
|
Hanzo Cloud API
|
|
|
|
The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
|
|
|
|
API version: v1
|
|
*/
|
|
|
|
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
|
|
|
|
package hanzoai
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
// CrawlAPIService CrawlAPI service
|
|
type CrawlAPIService service
|
|
|
|
type CrawlAPIReadPageRequest struct {
|
|
ctx context.Context
|
|
ApiService *CrawlAPIService
|
|
crawlCrawlRequest *CrawlCrawlRequest
|
|
}
|
|
|
|
func (r CrawlAPIReadPageRequest) CrawlCrawlRequest(crawlCrawlRequest CrawlCrawlRequest) CrawlAPIReadPageRequest {
|
|
r.crawlCrawlRequest = &crawlCrawlRequest
|
|
return r
|
|
}
|
|
|
|
func (r CrawlAPIReadPageRequest) Execute() (*CrawlCrawlResult, *http.Response, error) {
|
|
return r.ApiService.ReadPageExecute(r)
|
|
}
|
|
|
|
/*
|
|
ReadPage Fetch one URL and read it back as markdown
|
|
|
|
Reads one URL and answers with the page as markdown.
|
|
|
|
It fetches a single URL from inside the cluster and answers with the address it
|
|
actually landed on, the document's title, its content rendered to MARKDOWN, and
|
|
whatever the page said about itself. One URL per call: batching would make the
|
|
answer a partial-failure envelope every caller then has to unpack.
|
|
|
|
A PAGE THAT COULD NOT BE FETCHED IS A NORMAL ANSWER, not a fault. An
|
|
unreachable host, a refused address and a content type that is not a document
|
|
all answer 200 with `success:false` and the reason in `error`, because the
|
|
caller sent a well-formed ask and gets a well-formed answer. Non-2xx is reserved
|
|
for a caller problem — 400 with the same body when there is no url, 401 for a
|
|
bad key, 503 when the surface is unconfigured — so error handling can trust the
|
|
status. Check `success` before reading `data`.
|
|
|
|
Admission is either a validated principal or the shared service key, presented
|
|
as X-API-Key or a Bearer; neither is refused, and an unset key fails closed
|
|
rather than opening the fetcher to the private network. Pages are archived under
|
|
the scope of the VERIFIED principal and NEVER a scope named in the body, so a
|
|
URL already read under that scope is answered from the archive without touching
|
|
the network; a service caller has no org and its pages land in the shared
|
|
corpus.
|
|
|
|
The URL is caller-supplied and dialled from INSIDE the cluster, which makes this
|
|
a request-forgery primitive by construction. Only http and https are accepted,
|
|
and every address actually dialled must be public unicast — loopback,
|
|
link-local, private and multicast are refused. The check lives in the DIALER
|
|
rather than on the hostname, because resolving a name to validate it and then
|
|
letting the transport resolve it again is a gap DNS rebinding walks straight
|
|
through; redirects re-enter the same dialer.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return CrawlAPIReadPageRequest
|
|
*/
|
|
func (a *CrawlAPIService) ReadPage(ctx context.Context) CrawlAPIReadPageRequest {
|
|
return CrawlAPIReadPageRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return CrawlCrawlResult
|
|
func (a *CrawlAPIService) ReadPageExecute(r CrawlAPIReadPageRequest) (*CrawlCrawlResult, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodPost
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *CrawlCrawlResult
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "CrawlAPIService.ReadPage")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/crawl"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
if r.crawlCrawlRequest == nil {
|
|
return localVarReturnValue, nil, reportError("crawlCrawlRequest is required and must be specified")
|
|
}
|
|
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{"application/json"}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
// body params
|
|
localVarPostBody = r.crawlCrawlRequest
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
if localVarHTTPResponse.StatusCode == 400 {
|
|
var v CrawlCrawlResult
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|