Пример #1
0
func takePatchFilters(media []*medium) (prep, app []*eskip.Filter, err error) {
	for _, m := range media {
		var fstr string
		switch m.typ {
		case patchPrepend, patchAppend:
			fstr = m.patchFilters
		case patchPrependFile, patchAppendFile:
			var b []byte
			b, err = ioutil.ReadFile(m.patchFile)
			if err != nil {
				return
			}

			fstr = string(b)
		default:
			continue
		}

		var fs []*eskip.Filter
		fs, err = eskip.ParseFilters(fstr)
		if err != nil {
			return
		}

		switch m.typ {
		case patchPrepend, patchPrependFile:
			prep = append(prep, fs...)
		case patchAppend, patchAppendFile:
			app = append(app, fs...)
		}
	}

	return
}
Пример #2
0
// Returns a new Client.
func New(o Options) (*Client, error) {
	preFilters, err := eskip.ParseFilters(o.PreRouteFilters)
	if err != nil {
		return nil, err
	}

	postFilters, err := eskip.ParseFilters(o.PostRouteFilters)
	if err != nil {
		return nil, err
	}

	return &Client{
		opts:             o,
		preRouteFilters:  preFilters,
		postRouteFilters: postFilters,
		httpClient: &http.Client{Transport: &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: o.Insecure}}}}, nil
}
Пример #3
0
func ExampleParseFilters() {
	code := `filter0() -> filter1(3.14, "Hello, world!")`
	filters, err := eskip.ParseFilters(code)
	if err != nil {
		log.Println(err)
		return
	}

	fmt.Println("Parsed a chain of filters:")
	fmt.Printf("filters count: %d\n", len(filters))
	fmt.Printf("first filter: %s\n", filters[0].Name)
	fmt.Printf("second filter: %s\n", filters[1].Name)
	fmt.Printf("second filter, first arg: %g\n", filters[1].Args[0].(float64))
	fmt.Printf("second filter, second arg: %s\n", filters[1].Args[1].(string))

	// output:
	// Parsed a chain of filters:
	// filters count: 2
	// first filter: filter0
	// second filter: filter1
	// second filter, first arg: 3.14
	// second filter, second arg: Hello, world!
}