config

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package config contains common goconfigure compatible configuration blocks.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter struct {
	// Type of limiter
	Type string

	// Depth of the limiter (i.e. number of distinct items to hold)
	Depth int

	// Limit at which the limiter will trip (i.e. the number of time something
	// needs to be seen before the limiter trips)
	Limit int

	// TTL for the items in the limiter
	TTL time.Duration

	// DefaultLimit for this limiter
	DefaultLimit int
}

Limiter configuration.

func NewLimiter

func NewLimiter(t string, d int) *Limiter

NewLimiter returns a limiter of the specified type and default limit.

func (*Limiter) Data

func (l *Limiter) Data() interface{}

Data for the Limiter.

func (*Limiter) Description

func (l *Limiter) Description() string

Description for the Limiter.

func (*Limiter) Register

func (l *Limiter) Register(opts goconfigure.OptionSet)

Register the limiter.

type Limiters

type Limiters struct {
	// Source limiter rate limits connections from the same source.
	Source *Limiter

	// User limiter rate limits connections from the same user.
	User *Limiter
}

Limiters in use by the system.

func (*Limiters) Configure

func (l *Limiters) Configure(config *goconfigure.Settings)

Configure the limiter.

Example
package main

import (
	"fmt"

	"bitbucket.org/idomdavis/goconfigure"
	"bitbucket.org/idomdavis/gohttp/config"
)

func main() {
	l := config.Limiters{}
	s := goconfigure.NewSettings("TLS")

	l.Configure(s)

	err := s.ParseUsing([]string{
		"--user-limiter-depth", "10", "--source-limiter-depth", "50",
	}, goconfigure.ConsoleReporter{})

	if err != nil {
		fmt.Println(err)
	}

}
Output:

Source Limiter Settings: [Depth:50, Limit:100, TTL:1s, Type:Source]
User Limiter Settings: [Depth:10, Limit:5, TTL:1s, Type:User]

type TLS

type TLS struct {
	// Key is the path to the TLS key.
	Key string `json:"TLS Key Path"`

	// Certificate is the path to the TLS Certificate.
	Certificate string `json:"TLS Certificate Path"`
}

TLS options.

func (*TLS) Data

func (t *TLS) Data() interface{}

Data for the TLS settings.

func (*TLS) Description

func (t *TLS) Description() string

Description for the TLS settings.

func (*TLS) Register

func (t *TLS) Register(opts goconfigure.OptionSet)

Register the TLS options.

Example
package main

import (
	"fmt"

	"bitbucket.org/idomdavis/goconfigure"
	"bitbucket.org/idomdavis/gohttp/config"
)

func main() {
	tls := config.TLS{}
	s := goconfigure.NewSettings("TLS")
	s.Add(&tls)

	err := s.ParseUsing([]string{
		"-tls-key", "./tls.key", "--tls-certificate", "./tls.cert",
	}, goconfigure.ConsoleReporter{})

	if err != nil {
		fmt.Println(err)
	}

}
Output:

TLS settings: [TLS Certificate Path:./tls.cert, TLS Key Path:./tls.key]

Jump to

Keyboard shortcuts

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