client

package
v1.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const RequestIDHeader = "X-Scanii-Request-Id"

RequestIDHeader carries the API's identifier for a single request, which is what support needs to look one up on the server side.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	Active                     *bool     `json:"active,omitempty"`
	CreationDate               *string   `json:"creation_date,omitempty"`
	DetectionCategoriesEnabled *[]string `json:"detection_categories_enabled,omitempty"`
	LastSeenDate               *string   `json:"last_seen_date,omitempty"`
	Tags                       *[]string `json:"tags,omitempty"`
}

APIKey defines an API key's properties.

type AccountInfo

type AccountInfo struct {
	Balance          *float32           `json:"balance,omitempty"`
	BillingEmail     *string            `json:"billing_email,omitempty"`
	CreationDate     *string            `json:"creation_date,omitempty"`
	Keys             *map[string]APIKey `json:"keys,omitempty"`
	ModificationDate *string            `json:"modification_date,omitempty"`
	Name             *string            `json:"name,omitempty"`
	StartingBalance  *float32           `json:"starting_balance,omitempty"`
	Subscription     *string            `json:"subscription,omitempty"`
	Users            *map[string]User   `json:"users,omitempty"`
}

AccountInfo defines the account information response.

type AccountResult

type AccountResult struct {
	Response
	Account *AccountInfo
}

AccountResult is the response from the account endpoint.

type AuthToken

type AuthToken struct {
	CreationDate   *string `json:"creation_date,omitempty"`
	ExpirationDate *string `json:"expiration_date,omitempty"`
	ID             *string `json:"id,omitempty"`
}

AuthToken defines a temporary authentication token.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a hand-written HTTP client for the Scanii v2.2 API.

func New

func New(baseURL string, opts ...ClientOption) (*Client, error)

New creates a new Client with the given base URL and options.

func (*Client) Account

func (c *Client) Account(ctx context.Context) (*AccountResult, error)

Account retrieves account information.

func (*Client) CreateToken

func (c *Client) CreateToken(ctx context.Context, contentType string, body io.Reader) (*CreateTokenResult, error)

CreateToken creates a temporary authentication token.

func (*Client) DeleteFile added in v1.11.0

func (c *Client) DeleteFile(ctx context.Context, id string) (*DeleteFileResult, error)

DeleteFile hard-deletes a previously processed file result.

func (*Client) DeleteFileTrace added in v1.12.0

func (c *Client) DeleteFileTrace(ctx context.Context, id string) (*DeleteFileTraceResult, error)

DeleteFileTrace deletes the processing trace for a previously processed file.

func (*Client) DeleteToken

func (c *Client) DeleteToken(ctx context.Context, id string) (*Response, error)

DeleteToken deletes an authentication token.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) (*PingResult, error)

Ping validates API credentials.

func (*Client) ProcessFile

func (c *Client) ProcessFile(ctx context.Context, contentType string, body io.Reader) (*ProcessFileResult, error)

ProcessFile processes a file synchronously.

func (*Client) ProcessFileAsync

func (c *Client) ProcessFileAsync(ctx context.Context, contentType string, body io.Reader) (*ProcessFileAsyncResult, error)

ProcessFileAsync processes a file asynchronously.

func (*Client) ProcessFileFetch

func (c *Client) ProcessFileFetch(ctx context.Context, contentType string, body io.Reader) (*ProcessFileFetchResult, error)

ProcessFileFetch submits a URL for asynchronous processing.

func (*Client) RetrieveFile

func (c *Client) RetrieveFile(ctx context.Context, id string) (*RetrieveFileResult, error)

RetrieveFile retrieves a previously processed file result.

func (*Client) RetrieveToken

func (c *Client) RetrieveToken(ctx context.Context, id string) (*RetrieveTokenResult, error)

RetrieveToken retrieves an existing authentication token.

func (*Client) RetrieveTrace added in v1.5.0

func (c *Client) RetrieveTrace(ctx context.Context, id string) (*RetrieveTraceResult, error)

RetrieveTrace retrieves the processing trace for a previously processed file.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) ClientOption

WithHTTPClient sets a custom *http.Client.

func WithRequestEditorFn

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

WithRequestEditorFn adds a request editor callback.

type CreateTokenResult

type CreateTokenResult struct {
	Response
	Token *AuthToken
}

CreateTokenResult is the response from the create token endpoint.

type DeleteFileResult added in v1.11.0

type DeleteFileResult struct {
	Response
}

DeleteFileResult is the response from the file delete endpoint.

type DeleteFileTraceResult added in v1.12.0

type DeleteFileTraceResult struct {
	Response
}

DeleteFileTraceResult is the response from the trace delete endpoint.

type ErrorResponse

type ErrorResponse struct {
	Error    *string            `json:"error,omitempty"`
	ID       *string            `json:"id,omitempty"`
	Metadata *map[string]string `json:"metadata,omitempty"`
}

ErrorResponse defines an API error.

type PingResult

type PingResult struct {
	Response
	Message string `json:"message"`
	Key     string `json:"key"`
}

PingResult is the response from the ping endpoint.

type ProcessFileAsyncResult

type ProcessFileAsyncResult struct {
	Response
	Pending *ProcessingPendingResponse
	Error   *ErrorResponse
}

ProcessFileAsyncResult is the response from the async file processing endpoint.

type ProcessFileFetchResult

type ProcessFileFetchResult struct {
	Response
	Pending *ProcessingPendingResponse
	Error   *ErrorResponse
}

ProcessFileFetchResult is the response from the file fetch endpoint.

type ProcessFileResult

type ProcessFileResult struct {
	Response
	Result *ProcessingResponse
	Error  *ErrorResponse
}

ProcessFileResult is the response from the synchronous file processing endpoint.

type ProcessingPendingResponse

type ProcessingPendingResponse struct {
	ID *string `json:"id,omitempty"`
}

ProcessingPendingResponse is the acknowledgment for an async processing request.

type ProcessingResponse

type ProcessingResponse struct {
	Checksum      *string            `json:"checksum,omitempty"`
	ContentLength *float32           `json:"content_length,omitempty"`
	ContentType   *string            `json:"content_type,omitempty"`
	CreationDate  *string            `json:"creation_date,omitempty"`
	Error         *string            `json:"error,omitempty"`
	Findings      *[]string          `json:"findings,omitempty"`
	ID            *string            `json:"id,omitempty"`
	Metadata      *map[string]string `json:"metadata,omitempty"`
}

ProcessingResponse is the result of a file analysis.

type RequestEditorFn

type RequestEditorFn func(ctx context.Context, req *http.Request) error

RequestEditorFn is a callback for modifying requests before sending.

type Response

type Response struct {
	StatusCode int
	Header     http.Header
	// Timings is the wall-clock breakdown of the exchange that produced this
	// response.
	Timings Timings
}

Response is the base response containing HTTP metadata.

func (*Response) RequestID added in v1.10.0

func (r *Response) RequestID() string

RequestID returns the API's identifier for the request, or an empty string if the response carried none.

type RetrieveFileResult

type RetrieveFileResult struct {
	Response
	Result *ProcessingResponse
}

RetrieveFileResult is the response from the file retrieve endpoint.

type RetrieveTokenResult

type RetrieveTokenResult struct {
	Response
	Token *AuthToken
}

RetrieveTokenResult is the response from the retrieve token endpoint.

type RetrieveTraceResult added in v1.5.0

type RetrieveTraceResult struct {
	Response
	Trace *TraceResponse
	Error *ErrorResponse
}

RetrieveTraceResult is the response from the trace retrieve endpoint.

type Timings added in v1.10.0

type Timings struct {
	// DNS is the time spent resolving the host name.
	DNS time.Duration

	// Connect is the time spent opening the TCP connection.
	Connect time.Duration

	// TLS is the time spent on the TLS handshake.
	TLS time.Duration

	// RequestTransfer is the time from having a usable connection to the last
	// byte of the request being written. For a file upload that is the upload
	// itself — near enough, anyway: the write finishes at the socket rather than
	// at the far end, so up to a send buffer's worth of it is still in flight.
	RequestTransfer time.Duration

	// ServerProcessing is the time between the last request byte going out and
	// the first response byte coming back. That covers the API's own work — for
	// a file scan, the scan — but also the round trip carrying the question
	// there and the answer back, and nothing on this side can see where the one
	// ends and the other begins. Expect it to read higher than whatever the
	// server reports for the same request, by about one round trip.
	//
	// It is zero when the API answered before the request finished going out, as
	// it does when it rejects an oversized upload part way through.
	ServerProcessing time.Duration

	// ResponseTransfer is the time from the first byte of the response to the
	// last byte of its body.
	ResponseTransfer time.Duration

	// Total is the wall clock for the whole exchange, from the request being
	// handed to the transport to the response body being fully read.
	Total time.Duration

	// Reused reports whether the exchange rode on a pooled connection, which is
	// why the phases that establish one can legitimately read as zero.
	Reused bool

	// Complete reports whether the exchange reached the API and its response was
	// read. It is a flag rather than something inferred from the durations,
	// because every one of them can legitimately be zero: a phase that finishes
	// inside the clock's resolution measures as no time at all, and Windows
	// resolves time in milliseconds.
	Complete bool
}

Timings is the wall-clock breakdown of a single HTTP exchange, captured with net/http/httptrace. The phases run in the order they are declared and, pool wait aside, add up to Total.

A phase that did not happen is reported as zero: a pooled connection resolves no name, opens no socket and shakes no hands, and a plaintext endpoint never reaches the TLS phase. So is one that finished inside the clock's resolution, which the two cases cannot be told apart by — a distinction that does not matter for the latencies this is meant to expose.

type TraceEvent added in v1.4.0

type TraceEvent struct {
	Message   *string `json:"message,omitempty"`
	Timestamp *string `json:"timestamp,omitempty"`
}

TraceEvent is a single event in a processing trace.

type TraceResponse added in v1.4.0

type TraceResponse struct {
	Events *[]TraceEvent `json:"events,omitempty"`
	ID     *string       `json:"id,omitempty"`
}

TraceResponse is the ordered list of processing events for a given id.

type User

type User struct {
	CreationDate *string `json:"creation_date,omitempty"`
	LastLogin    *string `json:"last_login,omitempty"`
}

User defines a user account.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL