pipeline-and-more

command module
v0.0.0-...-891dcf9 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: MIT Imports: 8 Imported by: 0

README

Pipeline a.k.a middleware in Go

Just a playground with some interesting concepts like pipelines aka middleware, handleFuncs, request validations etc. Check it out.

Pipeline

pipe := pipeline.NewPipeline(1)

yield := pipe.Through(
    func(value interface{}, next pipeline.Handler) {
        next(value.(int)+2, nil)
    },
    func(value interface{}, next pipeline.Handler) {
        next(value.(int)*2, nil)
    },
).Return()

fmt.Printf("yield: %v\n", yield) // yield: 6

Validation middleware

Validatable interface
type Validatable interface {
	validate() error
}
Generic http middleware to validate http requests
func Validate(model Validatable, handler func(c *Request)) func(rw http.ResponseWriter, r *http.Request) {
	return func(rw http.ResponseWriter, r *http.Request) {
        // ...
    }
}

And a coupe of more go goodies. Should you notice a bug or any thing that can be improved send in a PR. Hope it helps someone. 😎

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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