awarent

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SMap *summaryMap

Functions

func PromHandler

func PromHandler(c *gin.Context)

PromHandler wrappers the standard http.Handler to gin.HandlerFunc

func SentinelMiddleware

func SentinelMiddleware(opts ...Option) gin.HandlerFunc

SentinelMiddleware returns new gin.HandlerFunc Default resource name is {method}:{path}, such as "GET:/api/users/:id" Default block fallback is returning 429 code Define your own behavior by setting options

Types

type Authorized

type Authorized struct {
	Resource string   `yaml:"resource"`
	IPS      []string `yaml:"ips"`
}

type Awarent

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

Awarent struct of awarent

func InitAwarent

func InitAwarent(entity Config) (*Awarent, error)

InitAwarent init awarent module

func (*Awarent) ConfigOnChange

func (a *Awarent) ConfigOnChange(configID string, callback func(data string)) error

ConfigOnChange listen on config change.

func (*Awarent) Deregister

func (a *Awarent) Deregister() (bool, error)

Deregister deregister service

func (*Awarent) GetConfig

func (a *Awarent) GetConfig(configID string) (string, error)

GetConfig get config from nacos with config dataid

func (*Awarent) GetService added in v1.0.1

func (a *Awarent) GetService(serviceName string, group string) (model.Service, error)

GetService get single random service

func (*Awarent) IPFilter

func (a *Awarent) IPFilter() gin.HandlerFunc

IPFilter ip filter with options

func (*Awarent) Metrics

func (a *Awarent) Metrics() gin.HandlerFunc

Metrics wrappers the standard http.Handler to gin.HandlerFunc

func (*Awarent) PublishConfig added in v1.0.4

func (a *Awarent) PublishConfig(configID, content string) (bool, error)

Publish the configuration to the nacos with config dataid

func (*Awarent) Register

func (a *Awarent) Register() (bool, error)

Register register service

func (*Awarent) Sentinel

func (a *Awarent) Sentinel() gin.HandlerFunc

Sentinel awarent gin use middleware

func (*Awarent) ServiceClient added in v1.0.1

func (a *Awarent) ServiceClient(serviceName string, group string) (*http.Client, error)

ServiceClient return a httpclient for service. the httpclient auto balancer with roundrobin

func (*Awarent) Subscribe

func (a *Awarent) Subscribe() error

Subscribe subscribe service change, do flow control re-balance flow control

type Awarenter

type Awarenter interface {
	//Register register service
	Register() (bool, error)
	//Deregister unregister service
	Deregister() (bool, error)
	//GetConfig get config with configid from nacos
	GetConfig(configID string) (string, error)
	//ConfigOnChange listen on config change with callback function
	ConfigOnChange(configID string, callback ConfigChangeCallback) error

	ServiceClient(serviceName string, group string) (http.Client, error)
	GetService(serviceName string, group string) (model.Service, error)

	PublishConfig(configID, content string) (bool, error)
}

Awarenter interface of awarent

type Config

type Config struct {
	ServiceName string `yaml:"serviceName" toml:"serviceName" json:"serviceName"`
	Port        uint64 `yaml:"port" toml:"port" json:"port"`
	Group       string `yaml:"group" toml:"group" json:"group"`
	Nacos       Nacos  `yaml:"nacos" toml:"nacos" json:"nacos"`
	ConfigID    string `yaml:"configId" toml:"configId" json:"configId"`
	RuleID      string `yaml:"ruleId" toml:"ruleId" json:"ruleId"`
}

Config warentConfig entry struct

type ConfigChangeCallback

type ConfigChangeCallback func(data string)

ConfigChangeCallback callback function when config changed

type Filter

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

Filter filter struct

func New

func New(opts FilterOptions) *Filter

New new ipfilter

func (*Filter) Allowed

func (f *Filter) Allowed(ip string) bool

func (*Filter) Authorized

func (f *Filter) Authorized(ip string, param string) bool

type FilterOptions

type FilterOptions struct {
	//explicity allowed IPs
	AllowedIPs     []string     `yaml:"allowed"`
	BlockedIPs     []string     `yaml:"blocked"`
	URLPath        string       `yaml:"urlPath"`
	URLParam       string       `yaml:"urlParam"`
	AuthorizedIPs  []Authorized `yaml:"authorized"`
	BlockByDefault bool         `yaml:"blockedDefault"`
}

FilterOptions for IPFilter. Allow/Block setting

type FlowControlOption

type FlowControlOption struct {
	Resource      string  `yaml:"resource"`
	Threshold     float64 `yaml:"threshold"`
	QueriesPerDay float64 `yaml:"queriesPerDay"`
	QueryBlock    bool    `yaml:"queryBlock"`
}

FlowControlOption option for flow control resource for specify resource need to be controled, threshold, means every second passed request by flowcontrol. here means QPS

type Nacos

type Nacos struct {
	IP   string `yaml:"ip" toml:"ip" json:"ip"`
	Port uint64 `yaml:"port" toml:"port" json:"port"`
}

Nacos config

type Option

type Option func(*options)

Option func with options param

func WithBlockExtractor added in v1.0.5

func WithBlockExtractor(fn func(*gin.Context) bool) Option

func WithBlockFallback

func WithBlockFallback(fn func(ctx *gin.Context)) Option

WithBlockFallback sets the fallback handler when requests are blocked.

func WithParamExtractor added in v1.0.5

func WithParamExtractor(fn func(*gin.Context) bool) Option

func WithResourceExtractor

func WithResourceExtractor(fn func(*gin.Context) string) Option

WithResourceExtractor sets the resource extractor of the web requests.

type Rule

type Rule struct {
	ResourceParam    string              `yaml:"resource-param"`
	FlowControlRules []FlowControlOption `yaml:"flow-control-rules"`
	IPFilterRules    FilterOptions       `yaml:"ip-filter-rules"`
}

Rule struct for flowcontrol/ipfilter rule collection.

Jump to

Keyboard shortcuts

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