awarent

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PromHandler

func PromHandler(c *gin.Context)

PromHandler wrappers the standard http.Handler to gin.HandlerFunc

func SentinelMiddleware

func SentinelMiddleware(endPoint string, 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) 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) IPFilter

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

IPFilter ip filter with options

func (*Awarent) LoadRules

func (a *Awarent) LoadRules(rules ...FlowControlOption) (bool, error)

LoadRules load flow control rules

func (*Awarent) Metrics

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

Metrics wrappers the standard http.Handler to gin.HandlerFunc

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) Subscribe

func (a *Awarent) Subscribe() error

Subscribe subscribe service change

type Awarenter

type Awarenter interface {
	Register() (bool, error)
	Deregister() (bool, error)
	GetConfig(configID string) (string, error)
	ConfigOnChange(configID string) 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 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  `json:"resource"`
	Threshold float64 `json:"threshold"`
}

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 WithBlockFallback

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

WithBlockFallback sets the fallback handler when requests are blocked.

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"`
}

Jump to

Keyboard shortcuts

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