network

package
v0.0.0-...-88db892 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetResterClient = func(timeout time.Duration) HttpClient {
	defaultRoundTripper := http.DefaultTransport
	defaultTransportPointer, ok := defaultRoundTripper.(*http.Transport)
	if !ok {
		panic("defaultRoundTripper not an *http.Transport")
	}

	defaultTransport := *defaultTransportPointer
	defaultTransport.MaxIdleConns = 100
	defaultTransport.MaxIdleConnsPerHost = 50
	defaultTransport.TLSHandshakeTimeout = timeout
	defaultTransport.DialContext = (&net.Dialer{
		Timeout:   timeout,
		KeepAlive: timeout,
	}).DialContext

	cookieJar, _ := cookiejar.New(&cookiejar.Options{
		PublicSuffixList: publicsuffix.List,
	})

	netClient := &http.Client{
		Timeout:   timeout,
		Transport: &defaultTransport,
		Jar:       cookieJar,
	}

	return &httpClient{
		client: netClient,
	}
}
View Source
var GetTimeout = func(confTimeout string, defaultTimeout time.Duration) time.Duration {
	timeout := defaultTimeout

	if confTimeout != "" {
		var err error
		timeout, err = time.ParseDuration(confTimeout)
		if err != nil {
			timeout = defaultTimeout
		}
	}

	return timeout
}

Functions

This section is empty.

Types

type ConnectionOptions

type ConnectionOptions struct {
	UseCompression bool
	UseSSL         bool
	Proxy          func(*http.Request) (*url.URL, error)
	Subprotocols   []string
}

type Empty

type Empty struct {
}

type HttpClient

type HttpClient interface {
	Do(ctx context.Context, method, rURL string, params url.Values, headers http.Header) (*HttpResponse, error)
	DoRaw(ctx context.Context, method, rURL string, reqBody []byte, headers http.Header) (*HttpResponse, error)
	DoEnvelope(ctx context.Context, method, url string, params url.Values, headers http.Header, obj interface{}) error
	DoJSON(ctx context.Context, method, url string, params url.Values, headers http.Header, obj interface{}) (*HttpResponse, error)
}

type HttpResponse

type HttpResponse struct {
	Body     []byte
	Response *http.Response
}

HTTPResponse encompasses byte body + the response of an HTTP request.

type Mode

type Mode string

Mode represents available ticker modes.

type ReconnectionOptions

type ReconnectionOptions struct{}

todo Yet to be done

type Socket

type Socket struct {
	Conn              *websocket.Conn
	WebsocketDialer   *websocket.Dialer
	Url               string
	ConnectionOptions ConnectionOptions
	RequestHeader     http.Header
	OnConnected       func(socket Socket)
	OnTextMessage     func(message string, socket Socket)
	OnBinaryMessage   func(data []byte, socket Socket)
	OnConnectError    func(err error, socket Socket)
	OnDisconnected    func(err error, socket Socket)
	OnPingReceived    func(data string, socket Socket)
	OnPongReceived    func(data string, socket Socket)
	IsConnected       bool
	Timeout           time.Duration
	// contains filtered or unexported fields
}

func New

func New(url string) Socket

func (*Socket) Close

func (socket *Socket) Close(ctx context.Context)

func (*Socket) Connect

func (socket *Socket) Connect(ctx context.Context)

func (*Socket) SendBinary

func (socket *Socket) SendBinary(ctx context.Context, data []byte) error

func (*Socket) SendText

func (socket *Socket) SendText(ctx context.Context, message string) error

type Ticker

type Ticker struct {
	Conn *websocket.Conn
	// contains filtered or unexported fields
}

Ticker is a Kite connect ticker instance.

func NewTicker

func NewTicker(apiKey, accessToken string) *Ticker

New creates a new ticker instance.

func (*Ticker) Close

func (t *Ticker) Close() error

Close tries to close the connection gracefully. If the server doesn't close it

func (*Ticker) OnClose

func (t *Ticker) OnClose(f func(code int, reason string))

OnClose callback.

func (*Ticker) OnConnect

func (t *Ticker) OnConnect(f func())

OnConnect callback.

func (*Ticker) OnError

func (t *Ticker) OnError(f func(err error))

OnError callback.

func (*Ticker) OnMessage

func (t *Ticker) OnMessage(f func(messageType int, message []byte))

OnMessage callback.

func (*Ticker) OnNoReconnect

func (t *Ticker) OnNoReconnect(f func(attempt int))

OnNoReconnect callback.

func (*Ticker) OnReconnect

func (t *Ticker) OnReconnect(f func(attempt int, delay time.Duration))

OnReconnect callback.

func (*Ticker) OnTick

func (t *Ticker) OnTick(f func(tick interface{}))

OnTick callback.

func (*Ticker) Resubscribe

func (t *Ticker) Resubscribe() error

Resubscribe resubscribes to the current stored subscriptions

func (*Ticker) Serve

func (t *Ticker) Serve()

Serve starts the connection to ticker server. Since its blocking its recommended to use it in a go routine.

func (*Ticker) ServeWithContext

func (t *Ticker) ServeWithContext(ctx context.Context)

ServeWithContext starts the connection to ticker server and additionally accepts a context. Since its blocking its recommended to use it in a go routine.

func (*Ticker) SetAccessToken

func (t *Ticker) SetAccessToken(aToken string)

SetAccessToken set access token.

func (*Ticker) SetAutoReconnect

func (t *Ticker) SetAutoReconnect(val bool)

SetAutoReconnect enable/disable auto reconnect.

func (*Ticker) SetConnectTimeout

func (t *Ticker) SetConnectTimeout(val time.Duration)

SetConnectTimeout sets default timeout for initial connect handshake

func (*Ticker) SetMode

func (t *Ticker) SetMode(mode Mode, tokens []uint32) error

SetMode changes mode for given list of tokens and mode.

func (*Ticker) SetReconnectMaxDelay

func (t *Ticker) SetReconnectMaxDelay(val time.Duration) error

SetReconnectMaxDelay sets maximum auto reconnect delay.

func (*Ticker) SetReconnectMaxRetries

func (t *Ticker) SetReconnectMaxRetries(val int)

SetReconnectMaxRetries sets maximum reconnect attempts.

func (*Ticker) SetRootURL

func (t *Ticker) SetRootURL(u url.URL)

SetRootURL sets ticker root url.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop the ticker instance and all the goroutines it has spawned.

func (*Ticker) Subscribe

func (t *Ticker) Subscribe(tokens []uint32) error

Subscribe subscribes tick for the given list of tokens.

func (*Ticker) Unsubscribe

func (t *Ticker) Unsubscribe(tokens []uint32) error

Unsubscribe unsubscribes tick for the given list of tokens.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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