sinkingyachts

package module
v0.0.0-...-5605b0b Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: 0BSD Imports: 14 Imported by: 0

README

Sinking Yachts API Client

This is an unofficial API client for the Sinking Yachts API written in golang.

See go doc for the documentation

run go get github.com/thunder33345/sinkingyachts to include the client in your project

Client Interfaces

This library provides 2 different interfaces for interacting with the API.

Client

Client is high level interface, all domains will be cached locally.

It provides simple means to listen to the websocket api and get realtime updates.

AutoSync will allow you to listen to the websocket api and periodical full sync.

RawClient

RawClient provides low level access to the API, all methods calls the api directly.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoSync

func AutoSync(ctx context.Context, c *Client, realtime bool, recentInterval, fullSyncInterval time.Duration) error

AutoSync is a helper that setup auto syncing functionality for Client this function blocks and return only when cancelled by ctx, or occurrence of an error you can use 0 to disable recent syncing and full syncing though it's recommended to use full sync, especially when realtime is enabled the recent interval is only useful when realtime is disabled

func ReadCacheFrom

func ReadCacheFrom(c *Client, r io.Reader) error

ReadCacheFrom loads stored cache from the reader into Client

func SaveOnChange

func SaveOnChange(ctx context.Context, c *Client, w io.Writer) error

SaveOnChange register listen for updates and writes it into the writer this function blocks and returns only when update channel gets closed, use ctx to cancel

func WriteCacheInto

func WriteCacheInto(c *Client, w io.Writer) error

WriteCacheInto saves cache into the writer.

Types

type Client

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

func New

func New(endpoint, identity string, client http.Client, options ...Option) *Client

func (*Client) Check

func (c *Client) Check(domain string) bool

Check if a domain is phishing parent domains will not be checked, FuzzyCheck should be used instead

func (*Client) Close

func (c *Client) Close() error

Close closes the client and releases all resources.

func (*Client) Domains

func (c *Client) Domains() []string

Domains return a list of known phishing domains. there are no specific order of the domains.

func (*Client) FullSync

func (c *Client) FullSync() error

FullSync clears the local cache and loading all known domain form the api

func (*Client) FuzzyCheck

func (c *Client) FuzzyCheck(domain string) bool

FuzzyCheck if a domain is phishing fuzzy check includes checking parent domains (foo.bar.bad.com will check bar.bad.com and bad.com) and returns true if any of the domains is phishing

func (*Client) ListenForUpdates

func (c *Client) ListenForUpdates(ctx context.Context) error

ListenForUpdates starts a wss connection to the api and listens for updates. use ctx to cancel close the connection

func (*Client) MarshalJSON

func (c *Client) MarshalJSON() ([]byte, error)

MarshalJSON marshal the Client's cache to JSON

func (*Client) Raw

func (c *Client) Raw() RawClient

Raw returns the underlying api client.

func (*Client) Size

func (c *Client) Size() int

Size return the amount of known phishing domains.

func (*Client) UnmarshalJSON

func (c *Client) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the Client's cache from JSON

func (*Client) Update

func (c *Client) Update() error

Update updates the list of known phishing domains from the api based on last update time.

func (*Client) UpdateChannel

func (c *Client) UpdateChannel() chan struct{}

UpdateChannel returns a channel that emits empty struct whenever Client's domain get updated calls will unregister the previous channel update may get dropped if channel is full, sends do not wait for receiver

type DomainUpdate

type DomainUpdate struct {
	//Add defines if it is adding or removing domains
	Add bool
	//Domains is a slice of domains
	Domains []string
}

DomainUpdate represent an update to the domains list, which depending on type, it could mean adding or deleting domains

func (*DomainUpdate) UnmarshalJSON

func (m *DomainUpdate) UnmarshalJSON(bytes []byte) error

type Option

type Option func(client *RawClient)

Option is a function that can configure a RawClient Option should only be used by NewRawClient, using it in any other way may risk race error and undefined behaviour

func WithFeedTimeout

func WithFeedTimeout(duration time.Duration) Option

WithFeedTimeout sets a custom feed timeout for dialing to the websocket update feed

func WithHeader

func WithHeader(key string, value string) Option

func WithHeaders

func WithHeaders(header http.Header) Option

WithHeaders sets a custom header to RawClient, if "X-Identity" is present, it will be overwritten by RawClient's identity

func WithoutHeader

func WithoutHeader(header string) Option

type RawClient

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

RawClient is the low level api to sinking yachts it does not cache and all responses are blocking it is safe for concurrent use

func NewRawClient

func NewRawClient(domain, identity string, webClient http.Client, options ...Option) RawClient

NewRawClient creates a new RawClient the endpoint should point to the root of api, without trailing slashes for example "https://example.com" no trailing versions the identity is something that identifies your application, and your contact for example "Foo Bot (foobar@example.com)" or "Foo Bot (foobar#12345 on discord)" the api may error if identity is incorrect or missing webClient is the http.Client that will be used by RawClient, you probably don't want to use default http as there's no timeouts! Option is a variadic of optional options to further configure the RawClient Note that X-Identity cannot be overwritten with it

func (RawClient) After

func (c RawClient) After(after time.Time) ([]DomainUpdate, error)

After will return a slice of changes that are after said time the underlying api uses seconds, therefore anything with finer will be rounded up

func (RawClient) All

func (c RawClient) All() ([]string, error)

All get all phishing domains from the api and return it as a slice of domains

func (RawClient) Check

func (c RawClient) Check(domain string) (bool, error)

Check will check if a domain is a phishing domain true if it's flagged as phishing, false otherwise

func (RawClient) Feed

func (c RawClient) Feed(ctx context.Context, modFeed chan DomainUpdate) error

Feed connects into the wss endpoint to get live updates Feed will block forever, and only returns if ctx cancels it, or there's an error to cancel use context.WithCancel as ctx error will be nil when process exited cleanly

func (RawClient) Recent

func (c RawClient) Recent(seconds int) ([]DomainUpdate, error)

Recent returns changes that are recently done in given seconds Changes will be represented as DomainUpdate

func (RawClient) Size

func (c RawClient) Size() (int, error)

Size returns the total amount of domains that are stored

Jump to

Keyboard shortcuts

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