Documentation ¶
Index ¶
- func NewClientDialOption(opts *Options) grpc.DialOption
- func NewClientUnaryInterceptor(opts *Options) grpc.UnaryClientInterceptor
- func NewServerOption(opts *Options) grpc.ServerOption
- func NewServerUnaryInterceptor(opts *Options) grpc.UnaryServerInterceptor
- type Cache
- type Hash
- type Headers
- type MetaFilter
- type Methods
- type Options
- type Switch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClientDialOption ¶
func NewClientDialOption(opts *Options) grpc.DialOption
func NewClientUnaryInterceptor ¶
func NewClientUnaryInterceptor(opts *Options) grpc.UnaryClientInterceptor
NewClientUnaryInterceptor makes a new unary client interceptor. There will be panic if options is an empty pointer.
func NewServerOption ¶
func NewServerOption(opts *Options) grpc.ServerOption
func NewServerUnaryInterceptor ¶
func NewServerUnaryInterceptor(opts *Options) grpc.UnaryServerInterceptor
NewServerUnaryInterceptor - makes a new unary server interceptor. There will be panic if options is an empty pointer.
Types ¶
type Cache ¶
type Cache interface { // Put data into the cache by key. Put(ctx context.Context, key string, val []byte, ttl time.Duration) error // Get data from the cache by key. Get(ctx context.Context, key string) ([]byte, error) }
Cache represents a common interface for responses caching. It can be implemented for many caches like Redis, Memcached, etc,
func NewInMemoryCache ¶
NewInMemoryCache - makes a built-in LRU in-memory cache implementation aimed for small projects, MVP, etc.
type Headers ¶
type Headers struct { // Headers for the key computation. Allowed []string // Omitted headers from the key computation. Disallowed []string }
Headers is a pool for filtering.
type MetaFilter ¶
type MetaFilter interface { // Allowed - returns true allowing to include the header in // the key computation, otherwise returns false. Allowed(key string, val []string) bool }
MetaFilter represents an interface for filtering the headers before including the once in the key computation.
It can be useful if you need to pick up only a few header which have to be included in to the key, making the one more unique and filter the noise. For instance, request-id, trace-id, etc are the noise, meanwhile jwt-token (and others according your app logic) is an important header.
Having implemented your own version, you can control the headers which will be involved in the key computation process.
func NewMetaFilter ¶
func NewMetaFilter(headers Headers) MetaFilter
func NewZeroMetaFilter ¶
func NewZeroMetaFilter(allowed bool) MetaFilter
NewZeroMetaFilter - makes a zero-filter implementation. It can be used if you don't have any rule for header filtering.
allowed - defines common behaviour for any header
true - allows all header to be included in the key computation. false - disallows all header to be included in the key computation.
type Methods ¶
type Methods interface { // Cacheable // method - full method name // // Returns true and caching timeout if the method is found, // otherwise false and timeout in this case does not matter. Cacheable(method string) (bool, time.Duration) // Add - allows to add method for caching. // Returns the 'Methods' in order to be // more convenient methods adding like a chain. Add(method string, ttl time.Duration) Methods // Remove the method from allowed to be cached. Remove(method string) // Clean - removes all methods. Clean() }
Methods is representing an interface that allows to define the service's methods which responses you want to cache.
type Options ¶
type Options struct { // The memoization feature is turned on/off. Switch Switch // A pool of methods for memorizing responses. Methods Methods // Header filter for including the ones in the key computation. MetaFilter MetaFilter // Used for the key computation. Hash Hash // A cache Cache Cache }
Options - memoization options. There are some options you can redefine by your own implementation in order to have more flexibility. 'Options' gives enough room space to do that.
func NewOptions ¶
func NewOptions() *Options
NewOptions - makes a default options set, having filled all items by thread-safe implementations.