kite: Index | Files

package config

import ""

Package config contains a Config struct for kites.


Package Files

config.go transport.go


const (
    WebSocket = iota


var CookieJar = cookiejar.New(nil)

CookieJar ignoring err: the implementation of New() doesn't have any error to be returned yet it returns, so it's totally safe to neglect the error

var DefaultConfig = &Config{
    Username:    "unknown",
    Environment: "unknown",
    Region:      "unknown",
    IP:          "",
    Port:        0,
    Transport:   Auto,
    Timeout:     15 * time.Second,
    XHR: &http.Client{
        Jar: CookieJar,
    Client: &http.Client{
        Timeout: 15 * time.Second,
        Jar:     CookieJar,
    Websocket: &websocket.Dialer{
        HandshakeTimeout: 15 * time.Second,
        Jar:              CookieJar,
    SockJS: &sockjs.Options{
        Websocket:       sockjs.DefaultOptions.Websocket,
        JSessionID:      sockjs.DefaultOptions.JSessionID,
        SockJSURL:       sockjs.DefaultOptions.SockJSURL,
        HeartbeatDelay:  10 * time.Second,
        DisconnectDelay: 10 * time.Second,
        ResponseLimit:   sockjs.DefaultOptions.ResponseLimit,

DefaultConfig contains the default settings.

var Transports = map[string]Transport{
    "WebSocket":  WebSocket,
    "XHRPolling": XHRPolling,
    "auto":       Auto,

type Config Uses

type Config struct {
    // Options for Kite
    Username              string    // Username to set when registering to Kontrol.
    Environment           string    // Kite environment to set when registering to Kontrol.
    Region                string    // Kite region to set when registering to Kontrol.
    Id                    string    // Kite ID to use when registering to Kontrol.
    KiteKey               string    // The kite.key value to use for "kiteKey" authentication.
    DisableAuthentication bool      // Do not require authentication for requests.
    DisableConcurrency    bool      // Do not process messages concurrently.
    Transport             Transport // SockJS transport to use.

    IP   string // IP of the kite server.
    Port int    // Port number of the kite server.

    // VerifyFunc is used to verify the public key of the signed token.
    // If the pub key is not to be trusted, the function must return
    // kite.ErrKeyNotTrusted error.
    // If nil, the default verify is used. By default the public key
    // is verified by calling Kontrol and the result cached for
    // VerifyTTL seconds if KontrolVerify is true. Otherwise
    // only public keys that are the same as the KontrolKey one are
    // accepted.
    VerifyFunc func(pub string) error

    // VerifyTTL is used to control time after result of a single
    // VerifyFunc's call expires.
    // When <0, the result is not cached.
    // When 0, the default value of 300s is used.
    VerifyTTL time.Duration

    // VerifyAudienceFunc is used to verify the audience of JWT token.
    // If nil, the default audience verify function is used which
    // expects the aud to be a kite path that matches the username,
    // environment and name of the client.
    VerifyAudienceFunc func(client *protocol.Kite, aud string) error

    // XHR is a HTTP client used for polling on responses for a XHR transport.
    // Required.
    XHR *http.Client

    // Timeout specified max time waiting for the following operations to complete:
    //   - polling on an XHR connection
    //   - default timeout for certain kite requests (Kontrol API)
    //   - HTTP heartbeats and register method
    // NOTE: Ensure the Timeout is higher than SockJS.HeartbeatDelay, otherwise
    // XHR connections may get randomly closed.
    // TODO(rjeczalik): Make kite heartbeats configurable as well.
    Timeout time.Duration

    // Client is a HTTP client used for issuing HTTP register request and
    // HTTP heartbeats.
    Client *http.Client

    // Websocket is used for creating a client for a websocket transport.
    // If custom one is used, ensure any complemenrary field is also
    // set in sockjs.WebSocketUpgrader value (for server connections).
    // Required.
    Websocket *websocket.Dialer

    // SockJS are used to configure SockJS handler.
    // Required.
    SockJS *sockjs.Options

    // Serve is serving HTTP requests using handler on requests
    // comming from the given listener.
    // If Serve is nil, http.Serve is used by default.
    Serve func(net.Listener, http.Handler) error

    KontrolURL  string
    KontrolKey  string
    KontrolUser string

    // UseWebRTC is the flag for Kite's to communicate over WebRTC if possible.
    UseWebRTC bool

Options is passed to kite.New when creating new instance.

func Get Uses

func Get() (*Config, error)

func MustGet Uses

func MustGet() *Config

func New Uses

func New() *Config

New returns a new Config initialized with defaults.

func NewFromKiteKey Uses

func NewFromKiteKey(file string) (*Config, error)

NewFromKiteKey parses the given kite key file and gives a new Config value.

func (*Config) Copy Uses

func (c *Config) Copy() *Config

Copy returns a new copy of the config object.

func (*Config) ReadEnvironmentVariables Uses

func (c *Config) ReadEnvironmentVariables() error

func (*Config) ReadKiteKey Uses

func (c *Config) ReadKiteKey() error

ReadKiteKey parsed the user's kite key and returns a new Config.

func (*Config) ReadToken Uses

func (c *Config) ReadToken(key *jwt.Token) error

ReadToken reads Kite Claims from JWT token and uses them to initialize Config.

type Transport Uses

type Transport int

Transport defines the underlying transport to be used

func (Transport) String Uses

func (t Transport) String() string

Package config imports 13 packages (graph) and is imported by 131 packages. Updated 2018-07-15. Refresh now. Tools for package owners.