httppipeline

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Category is the category of HTTPPipeline.
	Category = supervisor.CategoryPipeline

	// Kind is the kind of HTTPPipeline.
	Kind = "HTTPPipeline"

	// LabelEND is the built-in label for jumping of flow.
	LabelEND = "END"
)

Variables

This section is empty.

Functions

func GetFilterRegistry

func GetFilterRegistry() map[string]Filter

GetFilterRegistry get the filter registry.

func Register

func Register(f Filter)

Register registers filter.

Types

type Filter

type Filter interface {
	// Kind returns the unique kind name to represent itself.
	Kind() string

	// DefaultSpec returns the default spec.
	DefaultSpec() interface{}

	// Description returns the description of the filter.
	Description() string

	// Results returns all possible results, the normal result
	// (i.e. empty string) could not be in it.
	Results() []string

	// Init initializes the Filter.
	Init(filterSpec *FilterSpec, super *supervisor.Supervisor)

	// Inherit also initializes the Filter.
	// But it needs to handle the lifecycle of the previous generation.
	// So it's own responsibility for the filter to inherit and clean the previous generation stuff.
	// The http pipeline won't call Close for the previous generation.
	Inherit(filterSpec *FilterSpec, previousGeneration Filter, super *supervisor.Supervisor)

	// Handle handles one HTTP request, all possible results
	// need be registered in Results.
	Handle(context.HTTPContext) (result string)

	// Status returns its runtime status.
	// It could return nil.
	Status() interface{}

	// Close closes itself.
	Close()
}

Filter is the common interface for filters handling HTTP traffic.

type FilterMetaSpec

type FilterMetaSpec struct {
	Name string `yaml:"name" jsonschema:"required,format=urlname"`
	Kind string `yaml:"kind" jsonschema:"required"`
}

FilterMetaSpec is metadata for all specs.

func (*FilterMetaSpec) Validate added in v1.0.1

func (meta *FilterMetaSpec) Validate() error

type FilterSpec

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

FilterSpec is the universal spec for all filters.

func NewFilterSpec

func NewFilterSpec(meta *FilterMetaSpec, filterSpec interface{}) (*FilterSpec, error)

NewFilterSpec creates a fileter spec.

func (*FilterSpec) FilterSpec

func (s *FilterSpec) FilterSpec() interface{}

FilterSpec returns the filter spec.

func (*FilterSpec) Kind

func (s *FilterSpec) Kind() string

Kind returns kind.

func (*FilterSpec) Name

func (s *FilterSpec) Name() string

Name returns name.

func (*FilterSpec) RootFilter

func (s *FilterSpec) RootFilter() Filter

RootFilter returns the root filter of the filter spec.

func (*FilterSpec) YAMLConfig

func (s *FilterSpec) YAMLConfig() string

YAMLConfig returns the config in yaml format.

type FilterStat

type FilterStat struct {
	Name     string
	Kind     string
	Result   string
	Duration time.Duration
	Next     []*FilterStat
}

FilterStat records the statistics of the running filter.

type Flow

type Flow struct {
	Filter string            `yaml:"filter" jsonschema:"required,format=urlname"`
	JumpIf map[string]string `yaml:"jumpIf" jsonschema:"omitempty"`
}

Flow controls the flow of pipeline.

type HTTPPipeline

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

HTTPPipeline is Object HTTPPipeline.

func (*HTTPPipeline) Category

func (hp *HTTPPipeline) Category() supervisor.ObjectCategory

Category returns the category of HTTPPipeline.

func (*HTTPPipeline) Close

func (hp *HTTPPipeline) Close()

Close closes HTTPPipeline.

func (*HTTPPipeline) DefaultSpec

func (hp *HTTPPipeline) DefaultSpec() interface{}

DefaultSpec returns the default spec of HTTPPipeline.

func (*HTTPPipeline) Handle

func (hp *HTTPPipeline) Handle(ctx context.HTTPContext)

func (*HTTPPipeline) Inherit

func (hp *HTTPPipeline) Inherit(superSpec *supervisor.Spec, previousGeneration supervisor.Object,
	super *supervisor.Supervisor, muxMapper protocol.MuxMapper)

Inherit inherits previous generation of HTTPPipeline.

func (*HTTPPipeline) Init

func (hp *HTTPPipeline) Init(superSpec *supervisor.Spec,
	super *supervisor.Supervisor, muxMapper protocol.MuxMapper)

Init initilizes HTTPPipeline.

func (*HTTPPipeline) Kind

func (hp *HTTPPipeline) Kind() string

Kind returns the kind of HTTPPipeline.

func (*HTTPPipeline) Status

func (hp *HTTPPipeline) Status() *supervisor.Status

Status returns Status genreated by Runtime.

type PipelineContext

type PipelineContext struct {
	FilterStats *FilterStat
}

PipelineContext contains the context of the HTTPPipeline.

func GetPipelineContext

func GetPipelineContext(ctx context.HTTPContext) (*PipelineContext, bool)

GetPipelineContext returns the corresponding PipelineContext of the HTTPContext, and a bool flag to represent it succeed or not.

type Spec

type Spec struct {
	Flow    []Flow                   `yaml:"flow" jsonschema:"omitempty"`
	Filters []map[string]interface{} `yaml:"filters" jsonschema:"-"`
}

Spec describes the HTTPPipeline.

func (Spec) Validate

func (s Spec) Validate(config []byte) (err error)

Validate validates Spec.

type Status

type Status struct {
	Health string `yaml:"health"`

	Filters map[string]interface{} `yaml:"filters"`
}

Status is the status of HTTPPipeline.

Jump to

Keyboard shortcuts

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