Documentation ¶
Overview ¶
Package configfilter implements a Skipper data client that receives route configuration through a filter in a Skipper route.
The route containing the config filter can be defined in the initialization options of the data client (see SelfRoutes), or in routes taken from another data client. The data client needs to be passed to Skipper among the custom data clients.
The config filter provides an HTTP API to get/set/delete all or individual routes. It has two endpoints, one for accessing all the routes, and one for accessing individual routes with their ID. For individual routes, the routing needs to include the :routeid wildcard in the path predicate.
See the value of the APIDescription constant for the API description.
Example ¶
package main import ( "bytes" "io" "log" "net/http" "os" "github.com/aryszka/configfilter" "github.com/zalando/skipper" "github.com/zalando/skipper/filters" "github.com/zalando/skipper/routing" ) func main() { go func() { cf := configfilter.New(configfilter.Options{ DefaultRoutes: configfilter.SelfRoutes, }) defer cf.Close() if err := skipper.Run(skipper.Options{ Address: ":9090", CustomFilters: []filters.Spec{cf}, CustomDataClients: []routing.DataClient{cf}, }); err != nil { log.Println(err) } }() rsp, err := http.Post("http://localhost:9090/__config", "text/plain", bytes.NewBufferString(` foo: Path("/foo") -> "https://foo.example.org"; bar: Path("/bar") -> "https://bar.example.org" `)) if err != nil { log.Println(err) return } defer rsp.Body.Close() rsp, err = http.Get("http://localhost:9090/__config") if err != nil { log.Println(err) return } defer rsp.Body.Close() io.Copy(os.Stdout, rsp.Body) }
Output: foo: Path("/foo") -> "https://foo.example.org"; bar: Path("/bar") -> "https://bar.example.org"; __config: Path("/__config") -> config() -> <shunt>; __config__singleRoute: Path("/__config/:routeid") -> config() -> <shunt>
Index ¶
Examples ¶
Constants ¶
const ( // Name is the name of the config filter in eskip documents. Name = "config" // DefaultSelfID is used as the default route ID for the API root endpoint. DefaultSelfID = "__config" // DefaultRoot is the default path of the API root endpoint. DefaultRoot = "/" + DefaultSelfID )
const APIDescription = `` /* 2052-byte string literal not displayed */
APIDescription is printed when help content is requested.
Variables ¶
var SelfRoutes = []*eskip.Route{{ Id: DefaultSelfID, Path: DefaultRoot, Filters: []*eskip.Filter{{Name: Name}}, Shunt: true, }, { Id: DefaultSelfID + "__singleRoute", Path: DefaultRoot + "/:routeid", Filters: []*eskip.Filter{{Name: Name}}, Shunt: true, }}
SelfRoutes contain route specifications that can be used in the Options as API endpoints for the data client.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct { // DefaultRoutes contains routes that the data client will always include // in the routing. They cannot be changed or deleted through the API. // // It is a good practice to include two routes to the API endpoint: an API root // endpoint with all the routes and an endpoint for the individual routes. The // route for the individual routes is expected to have a path predicate with a // wildcard called routeid, e.g. Path("/__config/:routeid"). DefaultRoutes []*eskip.Route // contains filtered or unexported fields }
Options is used to provide initialization options for the config filter.
type Spec ¶
type Spec struct {
// contains filtered or unexported fields
}
Spec implements a Skipper data client and a filter specification, where the data client for the routing table accepts route updates through an API served by itself as a filter.
func (*Spec) CreateFilter ¶
CreateFilter creates a config filter. It iscalled by the routing package. (Skipper's filters.Spec implementation.)
func (*Spec) LoadAll ¶
LoadAll returns all the current routes. (Skipper's routing.DataClient implementation.)
func (*Spec) LoadUpdate ¶
LoadUpdate returns all changes since the last call to LoadAll or LoadUpdate. (Skipper's routing.DataClient implementation.)