github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/balancer/config/routerconfig.go (about)

     1  package config
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
     7  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/xstring"
     8  )
     9  
    10  // Dedicated package need for prevent cyclo dependencies config -> balancer -> config
    11  
    12  type Config struct {
    13  	Filter        Filter
    14  	AllowFallback bool
    15  	SingleConn    bool
    16  	DetectLocalDC bool
    17  }
    18  
    19  func (c Config) String() string {
    20  	if c.SingleConn {
    21  		return "SingleConn"
    22  	}
    23  
    24  	buffer := xstring.Buffer()
    25  	defer buffer.Free()
    26  
    27  	buffer.WriteString("RandomChoice{")
    28  
    29  	buffer.WriteString("DetectLocalDC=")
    30  	fmt.Fprintf(buffer, "%t", c.DetectLocalDC)
    31  
    32  	buffer.WriteString(",AllowFallback=")
    33  	fmt.Fprintf(buffer, "%t", c.AllowFallback)
    34  
    35  	if c.Filter != nil {
    36  		buffer.WriteString(",Filter=")
    37  		fmt.Fprint(buffer, c.Filter.String())
    38  	}
    39  
    40  	buffer.WriteByte('}')
    41  
    42  	return buffer.String()
    43  }
    44  
    45  type Info struct {
    46  	SelfLocation string
    47  }
    48  
    49  type Filter interface {
    50  	Allow(info Info, c conn.Conn) bool
    51  	String() string
    52  }