...

Source file src/github.com/datawire/ambassador/v2/pkg/envoy-control-plane/cache/v3/mux.go

Documentation: github.com/datawire/ambassador/v2/pkg/envoy-control-plane/cache/v3

     1  // Code generated by create_version. DO NOT EDIT.
     2  // Copyright 2020 Envoyproxy Authors
     3  //
     4  //   Licensed under the Apache License, Version 2.0 (the "License");
     5  //   you may not use this file except in compliance with the License.
     6  //   You may obtain a copy of the License at
     7  //
     8  //       http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  //   Unless required by applicable law or agreed to in writing, software
    11  //   distributed under the License is distributed on an "AS IS" BASIS,
    12  //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  //   See the License for the specific language governing permissions and
    14  //   limitations under the License.
    15  
    16  package cache
    17  
    18  import (
    19  	"context"
    20  	"errors"
    21  )
    22  
    23  // MuxCache multiplexes across several caches using a classification function.
    24  // If there is no matching cache for a classification result, the cache
    25  // responds with an empty closed channel, which effectively terminates the
    26  // stream on the server. It might be preferred to respond with a "nil" channel
    27  // instead which will leave the stream open in case the stream is aggregated by
    28  // making sure there is always a matching cache.
    29  type MuxCache struct {
    30  	// Classification functions.
    31  	Classify func(Request) string
    32  	// Muxed caches.
    33  	Caches map[string]Cache
    34  }
    35  
    36  var _ Cache = &MuxCache{}
    37  
    38  func (mux *MuxCache) CreateWatch(request *Request) (chan Response, func()) {
    39  	key := mux.Classify(*request)
    40  	cache, exists := mux.Caches[key]
    41  	if !exists {
    42  		value := make(chan Response, 0)
    43  		close(value)
    44  		return value, nil
    45  	}
    46  	return cache.CreateWatch(request)
    47  }
    48  
    49  func (mux *MuxCache) Fetch(ctx context.Context, request *Request) (Response, error) {
    50  	return nil, errors.New("not implemented")
    51  }
    52  

View as plain text