Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMissingBaseURL is returned when Config.BaseURL is empty. ErrMissingBaseURL = errors.New("faynosync: missing base URL") // ErrInvalidBaseURL is returned when Config.BaseURL cannot be used as an absolute URL. ErrInvalidBaseURL = errors.New("faynosync: invalid base URL") // ErrInvalidEdgeURL is returned when Config.EdgeURL cannot be used as an absolute URL. ErrInvalidEdgeURL = errors.New("faynosync: invalid edge URL") // ErrMissingOwner is returned when CheckOptions.Owner is empty. ErrMissingOwner = errors.New("faynosync: missing owner") // ErrMissingAppName is returned when CheckOptions.AppName is empty. ErrMissingAppName = errors.New("faynosync: missing app name") // ErrMissingVersion is returned when CheckOptions.Version is empty. ErrMissingVersion = errors.New("faynosync: missing version") // ErrRequestFailed is returned when an update check request fails. ErrRequestFailed = errors.New("faynosync: request failed") )
Functions ¶
func RolloutBucket ¶ added in v0.3.0
RolloutBucket maps a device to a deterministic bucket in [0, 99]: sha256(deviceID + ":" + seed), first 8 bytes as a big-endian uint64, modulo 100.
This is the reference algorithm every faynoSync SDK must replicate byte-for-byte so a device's rollout decision matches across SDKs.
func SystemArch ¶
func SystemArch() string
SystemArch returns runtime.GOARCH.
The SDK never calls this automatically. It is provided only for callers that choose to use Go runtime architecture names as their faynoSync arch values.
func SystemPlatform ¶
func SystemPlatform() string
SystemPlatform returns runtime.GOOS.
The SDK never calls this automatically. It is provided only for callers that choose to use Go runtime platform names as their faynoSync platform values.
Types ¶
type CheckError ¶
CheckError describes a failed update check after all configured endpoints fail.
func (*CheckError) Error ¶
func (e *CheckError) Error() string
Error returns a human-readable update check error message.
func (*CheckError) Is ¶
func (e *CheckError) Is(target error) bool
Is reports whether the check error matches a sentinel error.
func (*CheckError) Unwrap ¶
func (e *CheckError) Unwrap() []error
Unwrap returns all endpoint errors that contributed to the failed check.
type CheckOptions ¶
type CheckOptions struct {
Owner string
AppName string
Version string
Channel string
Platform string
Arch string
// DeviceID optionally enables server-side telemetry when supported by the API.
// When empty, the X-Device-ID header is omitted.
DeviceID string
}
CheckOptions contains the typed parameters used to check for updates.
Channel, Platform, and Arch are intentionally user-controlled values. The SDK does not detect, normalize, remap, or default them.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a concurrency-safe faynoSync SDK client.
func NewClient ¶
NewClient creates a new faynoSync SDK client.
The returned client is safe for concurrent use. If cfg.HTTPClient is nil, the SDK creates an HTTP client with a default timeout and reusable connections.
func (*Client) CheckForUpdates ¶
func (c *Client) CheckForUpdates(ctx context.Context, opts CheckOptions) (*UpdateResponse, error)
CheckForUpdates checks whether an update is available for the provided app.
If Config.EdgeURL is configured, the client first tries the static edge JSON response and falls back to the BaseURL API when the edge misses or fails.
type Config ¶
type Config struct {
// BaseURL is the required faynoSync API base URL.
BaseURL string
// EdgeURL is an optional static response edge base URL.
// When configured, the client tries EdgeURL before falling back to BaseURL.
EdgeURL string
// HTTPClient is an optional HTTP client.
// When nil, the SDK creates a client with a reasonable default timeout.
HTTPClient *http.Client
}
Config configures a faynoSync SDK client.
type EndpointError ¶
type EndpointError struct {
Source UpdateSource
URL string
StatusCode int
Err error
}
EndpointError describes a failed request to one faynoSync endpoint.
func (*EndpointError) Error ¶
func (e *EndpointError) Error() string
Error returns a human-readable endpoint error message.
func (*EndpointError) Is ¶
func (e *EndpointError) Is(target error) bool
Is reports whether the endpoint error matches a sentinel error.
func (*EndpointError) Unwrap ¶
func (e *EndpointError) Unwrap() error
Unwrap returns the underlying endpoint error.
type PackageUpdateURL ¶
PackageUpdateURL contains one package-specific update URL.
type RolloutInfo ¶ added in v0.3.0
type RolloutInfo struct {
Percent int `json:"percent"`
Seed string `json:"seed"`
// Bucket is the deterministic bucket in [0, 99] for this device, or nil when no
// DeviceID was supplied and the bucket could not be computed.
Bucket *int `json:"-"`
Eligible bool `json:"-"`
}
RolloutInfo describes a staged (canary) rollout decision for the offered version.
It is present on UpdateResponse only when the server offered a rollout below 100%. When Eligible is false the SDK has already forced UpdateAvailable to false and cleared the download URLs.
type UpdateResponse ¶
type UpdateResponse struct {
UpdateAvailable bool `json:"update_available"`
UpdateURL string `json:"update_url,omitempty"`
Changelog string `json:"changelog,omitempty"`
Critical bool `json:"critical,omitempty"`
IsIntermediateRequired bool `json:"is_intermediate_required,omitempty"`
PossibleRollback bool `json:"possible_rollback,omitempty"`
// Rollout is set only when the server offered a staged (canary) rollout for the
// version. When Rollout.Eligible is false the SDK has already forced
// UpdateAvailable to false and cleared UpdateURL/PackageURLs. It is decoded
// manually from the raw rollout object, so a malformed one is ignored rather than
// failing the whole response.
Rollout *RolloutInfo `json:"-"`
// PackageURLs contains package-specific URLs decoded from fields such as
// update_url_deb, update_url_rpm, or any future update_url_<package> key.
PackageURLs []PackageUpdateURL `json:"-"`
// Source identifies whether the response came from the edge or API fallback.
Source UpdateSource `json:"-"`
}
UpdateResponse contains the typed faynoSync update check response.
func (*UpdateResponse) UnmarshalJSON ¶
func (r *UpdateResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes fixed response fields and dynamic update_url_<package> fields into a typed representation.
type UpdateSource ¶
type UpdateSource int
UpdateSource identifies where an update response was loaded from.
const ( // SourceUnknown indicates that the response source is unknown. SourceUnknown UpdateSource = iota // SourceEdge indicates that the response came from the configured EdgeURL. SourceEdge // SourceAPI indicates that the response came from the configured BaseURL API. SourceAPI )