Documentation
¶
Index ¶
- Constants
- Variables
- func AllKeys[T comparable, V any](mapOfKeysAndValues map[T]V) []T
- func CombineMaps[K comparable, V any](mapToCopy map[K]V, mapToAdd map[K]V) map[K]V
- func ConvertDriverValueToString(value driver.Value) (string, bool)
- func CreateMapCopy[K comparable, V any](mapToCopy map[K]V) map[K]V
- func DoesCloseTransaction(methodName string, methodArgs ...any) bool
- func DoesOpenTransaction(methodName string, methodArgs ...any) bool
- func DoesSetReadOnly(query string, dialectFunc func(string) (bool, bool)) (bool, bool)
- func ExecQueryDirectly(conn driver.Conn, query string) error
- func FilterMapFindFirstValue[T comparable, U any](set map[T]U, filter func(U) bool) U
- func FilterSetFindFirst[T comparable, U any](set map[T]U, filter func(T) bool) T
- func FilterSlice[T any](slice []T, filter func(T) bool) []T
- func FilterSliceFindFirst[T any](slice []T, filter func(T) bool) T
- func FindHostInTopology(hosts []*host_info_util.HostInfo, hostNames ...string) *host_info_util.HostInfo
- func FindRegisteredDriver(dialectCode string) bool
- func GetFirstRowFromQuery(conn driver.Conn, query string) []driver.Value
- func GetFirstRowFromQueryAsString(conn driver.Conn, query string) []string
- func GetHostNameFromEndpoint(endpoint string) string
- func GetPreparedHost(host string) string
- func GetQueryFromSqlOrMethodArgs(sql string, methodArgs ...any) string
- func GetRdsClusterHostUrl(host string) string
- func GetRdsClusterId(host string) string
- func GetRdsInstanceHostPattern(host string) string
- func GetRdsRegion(host string) string
- func GetRowsFromQuery(conn driver.Conn, query string, n int) [][]driver.Value
- func GetSeparateSqlStatements(query string) []string
- func GetSetReadOnlyFromCtx(ctx context.Context) (bool, bool)
- func GetStructName(v any) string
- func IndexOf[T any](slice []T, item T, compareFunc func(T, T) bool) int
- func IsGreenInstance(host string) bool
- func IsIP(host string) bool
- func IsIPV6(host string) bool
- func IsIPv4(host string) bool
- func IsLimitlessDbShardGroupDns(host string) bool
- func IsNotGreenAndNotOldInstance(host string) bool
- func IsNotOldInstance(host string) bool
- func IsRdsClusterDns(host string) bool
- func IsRdsCustomClusterDns(host string) bool
- func IsRdsDns(host string) bool
- func IsRdsInstance(host string) bool
- func IsRdsProxyDns(host string) bool
- func IsReachable(conn driver.Conn, ctx context.Context) bool
- func IsReaderClusterDns(host string) bool
- func IsWriterClusterDns(host string) bool
- func LengthOfSyncMap(syncMap *sync.Map) int
- func LogTopology(hosts []*host_info_util.HostInfo, msgPrefix string) string
- func MySqlConvertValToString(value driver.Value) (string, bool)
- func PgConvertValToString(value driver.Value) (string, bool)
- func RemoveFromSlice[T any](slice []T, item T, compareFunc func(T, T) bool) []T
- func RemoveGreenInstancePrefix(host string) string
- func RemovePort(hostAndPort string) string
- func ResetPreparedHostFunc()
- func Rollback(conn driver.Conn, currentTx driver.Tx)
- func SetPreparedHostFunc(newPrepareHostFunc func(string) string)
- func SliceAndMapHaveCommonElement[T comparable, V any](slice []T, mapOfKeysAndValues map[T]V) bool
- type CacheMap
- func (c *CacheMap[T]) CleanUp()
- func (c *CacheMap[T]) Clear()
- func (c *CacheMap[T]) ComputeIfAbsent(key string, computeFunc func() T, itemExpiration time.Duration) T
- func (c *CacheMap[T]) Get(key string) (T, bool)
- func (c *CacheMap[T]) GetAllEntries() map[string]T
- func (c *CacheMap[T]) Put(key string, value T, expiration time.Duration)
- func (c *CacheMap[T]) PutIfAbsent(key string, value T, expiration time.Duration)
- func (c *CacheMap[T]) Remove(key string)
- func (c *CacheMap[T]) Size() int
- type DisposalFunc
- type Pair
- type RWMap
- func CombineRWMaps[K comparable, V any](mapToCopy *RWMap[K, V], mapToAdd *RWMap[K, V]) *RWMap[K, V]
- func NewRWMap[K comparable, V any]() *RWMap[K, V]
- func NewRWMapFromCopy[K comparable, V any](rwMap *RWMap[K, V]) *RWMap[K, V]
- func NewRWMapFromMap[K comparable, V any](mapForCache map[K]V) *RWMap[K, V]
- func NewRWMapWithDisposalFunc[K comparable, V any](disposalFunc DisposalFunc[V]) *RWMap[K, V]
- func (c *RWMap[K, V]) Clear()
- func (c *RWMap[K, V]) ComputeIfAbsent(key K, computeFunc func() V) V
- func (c *RWMap[K, V]) Filter(condition func(K, V) bool)
- func (c *RWMap[K, V]) ForEach(fn func(K, V))
- func (c *RWMap[K, V]) Get(key K) (V, bool)
- func (c *RWMap[K, V]) GetAllEntries() map[K]V
- func (c *RWMap[K, V]) ProcessAndRemoveIf(condition func(K) bool, processor func(K, V))
- func (c *RWMap[K, V]) Put(key K, value V)
- func (c *RWMap[K, V]) PutIfAbsent(key K, value V)
- func (c *RWMap[K, V]) Remove(key K)
- func (c *RWMap[K, V]) ReplaceCacheWithCopy(mapToCopy *RWMap[K, V])
- func (c *RWMap[K, V]) ReplaceCacheWithMap(entryMap map[K]V)
- func (c *RWMap[K, V]) Size() int
- type RWQueue
- type RdsUrlType
- type SlidingExpirationCache
- func (c *SlidingExpirationCache[T]) CleanUp()
- func (c *SlidingExpirationCache[T]) Clear()
- func (c *SlidingExpirationCache[T]) ComputeIfAbsent(key string, computeFunc func() T, itemExpiration time.Duration) T
- func (c *SlidingExpirationCache[T]) ComputeIfAbsentWithError(key string, computeFunc func() (T, error), itemExpiration time.Duration) (T, error)
- func (c *SlidingExpirationCache[T]) Get(key string, itemExpiration time.Duration) (T, bool)
- func (c *SlidingExpirationCache[T]) GetAllEntries() map[string]T
- func (c *SlidingExpirationCache[T]) Put(key string, value T, itemExpiration time.Duration)
- func (c *SlidingExpirationCache[T]) PutIfAbsent(key string, value T, expiration time.Duration)
- func (c *SlidingExpirationCache[T]) Remove(key string)
- func (c *SlidingExpirationCache[T]) SetCleanupIntervalNanos(newIntervalNanos time.Duration)
- func (c *SlidingExpirationCache[T]) Size() int
Constants ¶
const ( CONN_PREPARE = "Conn.Prepare" CONN_PREPARE_CONTEXT = "Conn.PrepareContext" CONN_CLOSE = "Conn.Close" CONN_BEGIN = "Conn.Begin" CONN_BEGIN_TX = "Conn.BeginTx" CONN_QUERY_CONTEXT = "Conn.QueryContext" CONN_EXEC_CONTEXT = "Conn.ExecContext" CONN_PING = "Conn.Ping" CONN_IS_VALID = "Conn.IsValid" CONN_RESET_SESSION = "Conn.ResetSession" CONN_CHECK_NAMED_VALUE = "Conn.CheckNamedValue" STMT_CLOSE = "Stmt.Close" STMT_EXEC = "Stmt.Exec" STMT_EXEC_CONTEXT = "Stmt.ExecContext" STMT_NUM_INPUT = "Stmt.NumInput" STMT_QUERY = "Stmt.Query" STMT_QUERY_CONTEXT = "Stmt.QueryContext" STMT_CHECK_NAMED_VALUE = "Stmt.CheckNamedValue" RESULT_LAST_INSERT_ID = "Result.LastInsertId" RESULT_ROWS_AFFECTED = "Result.RowsAffected" TX_COMMIT = "Tx.Commit" TX_ROLLBACK = "Tx.Rollback" ROWS_CLOSE = "Rows.Close" ROWS_COLUMNS = "Rows.Columns" ROWS_NEXT = "Rows.Next" ROWS_COLUMN_TYPE_PRECISION_SCALE = "Rows.ColumnTypePrecisionScale" ROWS_COLUMN_TYPE_DATABASE_TYPE_NAME = "Rows.ColumnTypeDatabaseTypeName" ROWS_COLUMN_TYPE_LENGTH = "Rows.ColumnTypeLength" ROWS_HAS_NEXT_RESULT_SET = "Rows.HasNextResultSet" ROWS_NEXT_RESULT_SET = "Rows.NextResultSet" ROWS_COLUMN_TYPE_SCAN_TYPE = "Rows.ColumnTypeScanType" ROWS_COLUMN_TYPE_NULLABLE = "Rows.ColumnTypeNullable" )
const ( INSTANCE_GROUP = "instance" DNS_GROUP = "dns" DOMAIN_GROUP = "domain" REGION_GROUP = "region" )
const SET_AUTOCOMMIT_0 = "set autocommit = 0"
Variables ¶
var ( AURORA_DNS_PATTERN = regexp.MustCompile( "(?i)^(?P<instance>.+)\\." + "(?P<dns>proxy-|cluster-|cluster-ro-|cluster-custom-|shardgrp-)?" + "(?P<domain>[a-zA-Z0-9]+\\.(?P<region>[a-zA-Z0-9\\-]+)" + "\\.rds\\.amazonaws\\.com\\.?)$") AURORA_CHINA_DNS_PATTERN = regexp.MustCompile( "(?i)^(?P<instance>.+)\\." + "(?P<dns>proxy-|cluster-|cluster-ro-|cluster-custom-|shardgrp-)?" + "(?P<domain>[a-zA-Z0-9]+\\.rds\\.(?P<region>[a-zA-Z0-9\\-]+)" + "\\.amazonaws\\.com\\.cn\\.?)$") AURORA_OLD_CHINA_DNS_PATTERN = regexp.MustCompile( "(?i)^(?P<instance>.+)\\." + "(?P<dns>proxy-|cluster-|cluster-ro-|cluster-custom-|shardgrp-)?" + "(?P<domain>[a-zA-Z0-9]+\\.(?P<region>[a-zA-Z0-9\\-]+)" + "\\.rds\\.amazonaws\\.com\\.cn\\.?)$") AURORA_GOV_DNS_PATTERN = regexp.MustCompile( "(?i)^(?<instance>.+)\\." + "(?P<dns>proxy-|cluster-|cluster-ro-|cluster-custom-|shardgrp-)?" + "(?P<domain>[a-zA-Z0-9]+\\.rds\\.(?P<region>[a-zA-Z0-9\\-]+)" + "\\.(amazonaws\\.com\\.?|c2s\\.ic\\.gov\\.?|sc2s\\.sgov\\.gov\\.?))$") IP_V4_REGEXP = regexp.MustCompile( "^(([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){1}" + "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){2}" + "([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$") IP_V6_REGEXP = regexp.MustCompile("^[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){7}$") IP_V6_COMPRESSED_REGEXP = regexp.MustCompile("^(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,5})?)" + "::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,5})?)$") BG_OLD_HOST_PATTERN = regexp.MustCompile("(?i).*(?P<prefix>-old1\\.)..*") //nolint:all BG_GREEN_HOSTID_PATTERN = regexp.MustCompile("(?i)(.*)-green-[0-9a-z]{6}") BG_GREEN_HOST_PATTERN = regexp.MustCompile("(?i).*(?P<prefix>-green-[0-9a-z]{6})..*") )
var CLOSING_METHODS = []string{ CONN_CLOSE, CONN_IS_VALID, STMT_CLOSE, ROWS_CLOSE, }
var CleanupIntervalNanos time.Duration = 10 * time.Minute
var NETWORK_BOUND_METHODS = []string{ CONN_PREPARE, CONN_PREPARE_CONTEXT, CONN_QUERY_CONTEXT, CONN_EXEC_CONTEXT, CONN_PING, CONN_IS_VALID, CONN_RESET_SESSION, STMT_EXEC, STMT_EXEC_CONTEXT, STMT_QUERY, STMT_QUERY_CONTEXT, TX_COMMIT, TX_ROLLBACK, ROWS_NEXT, ROWS_HAS_NEXT_RESULT_SET, ROWS_NEXT_RESULT_SET, }
var REQUIRED_METHODS = []string{ CONN_PREPARE, CONN_PREPARE_CONTEXT, CONN_CLOSE, CONN_BEGIN, CONN_BEGIN_TX, CONN_QUERY_CONTEXT, CONN_EXEC_CONTEXT, CONN_PING, CONN_IS_VALID, CONN_RESET_SESSION, CONN_CHECK_NAMED_VALUE, STMT_CLOSE, STMT_EXEC, STMT_EXEC_CONTEXT, STMT_NUM_INPUT, STMT_QUERY, STMT_QUERY_CONTEXT, STMT_CHECK_NAMED_VALUE, RESULT_LAST_INSERT_ID, RESULT_ROWS_AFFECTED, TX_COMMIT, TX_ROLLBACK, ROWS_CLOSE, ROWS_COLUMNS, ROWS_NEXT, ROWS_COLUMN_TYPE_PRECISION_SCALE, ROWS_COLUMN_TYPE_DATABASE_TYPE_NAME, }
Functions ¶
func AllKeys ¶
func AllKeys[T comparable, V any](mapOfKeysAndValues map[T]V) []T
func CombineMaps ¶
func CombineMaps[K comparable, V any](mapToCopy map[K]V, mapToAdd map[K]V) map[K]V
func CreateMapCopy ¶
func CreateMapCopy[K comparable, V any](mapToCopy map[K]V) map[K]V
func DoesCloseTransaction ¶
func DoesOpenTransaction ¶
func DoesSetReadOnly ¶ added in v1.1.0
func ExecQueryDirectly ¶
ExecQueryDirectly Directly executes query on conn.
func FilterMapFindFirstValue ¶ added in v1.1.0
func FilterMapFindFirstValue[T comparable, U any](set map[T]U, filter func(U) bool) U
func FilterSetFindFirst ¶ added in v1.1.0
func FilterSetFindFirst[T comparable, U any](set map[T]U, filter func(T) bool) T
func FilterSlice ¶
func FilterSliceFindFirst ¶ added in v1.1.0
func FindHostInTopology ¶
func FindHostInTopology(hosts []*host_info_util.HostInfo, hostNames ...string) *host_info_util.HostInfo
func FindRegisteredDriver ¶
func GetFirstRowFromQuery ¶
func GetFirstRowFromQueryAsString ¶
GetFirstRowFromQueryAsString Directly executes query on conn and converts all possible values in the first row to strings. Any values that cannot be converted are returned as "". Returns nil if unable to obtain a row.
func GetHostNameFromEndpoint ¶
func GetPreparedHost ¶
func GetRdsClusterHostUrl ¶
func GetRdsClusterId ¶ added in v1.1.0
func GetRdsRegion ¶
func GetRowsFromQuery ¶ added in v1.1.0
GetRowsFromQuery Directly executes query on conn, and returns the first n rows.
func GetSetReadOnlyFromCtx ¶ added in v1.1.0
func GetStructName ¶
func IsGreenInstance ¶ added in v1.1.0
func IsNotGreenAndNotOldInstance ¶ added in v1.1.0
IsNotGreenAndNotOldInstance Verify host contains neither green prefix nor old prefix.
func IsNotOldInstance ¶ added in v1.1.0
func IsRdsClusterDns ¶
func IsRdsCustomClusterDns ¶
func IsRdsInstance ¶ added in v1.1.0
func IsRdsProxyDns ¶
func IsReaderClusterDns ¶
func IsWriterClusterDns ¶
func LengthOfSyncMap ¶
func LogTopology ¶
func LogTopology(hosts []*host_info_util.HostInfo, msgPrefix string) string
func MySqlConvertValToString ¶ added in v1.1.0
func PgConvertValToString ¶ added in v1.1.0
func RemoveFromSlice ¶
func RemoveGreenInstancePrefix ¶ added in v1.1.0
func RemovePort ¶ added in v1.2.0
func ResetPreparedHostFunc ¶
func ResetPreparedHostFunc()
func SetPreparedHostFunc ¶
func SliceAndMapHaveCommonElement ¶
func SliceAndMapHaveCommonElement[T comparable, V any](slice []T, mapOfKeysAndValues map[T]V) bool
Types ¶
type CacheMap ¶
type CacheMap[T any] struct { // contains filtered or unexported fields }
func (*CacheMap[T]) ComputeIfAbsent ¶
func (*CacheMap[T]) GetAllEntries ¶
Get a map copy of all entries in the cache, including expired entries.
func (*CacheMap[T]) PutIfAbsent ¶
type DisposalFunc ¶
type RWMap ¶ added in v1.1.0
type RWMap[K comparable, V any] struct { // contains filtered or unexported fields }
func CombineRWMaps ¶ added in v1.1.0
func CombineRWMaps[K comparable, V any](mapToCopy *RWMap[K, V], mapToAdd *RWMap[K, V]) *RWMap[K, V]
func NewRWMap ¶ added in v1.1.0
func NewRWMap[K comparable, V any]() *RWMap[K, V]
func NewRWMapFromCopy ¶ added in v1.1.0
func NewRWMapFromCopy[K comparable, V any](rwMap *RWMap[K, V]) *RWMap[K, V]
func NewRWMapFromMap ¶ added in v1.1.0
func NewRWMapFromMap[K comparable, V any](mapForCache map[K]V) *RWMap[K, V]
func NewRWMapWithDisposalFunc ¶ added in v1.1.0
func NewRWMapWithDisposalFunc[K comparable, V any](disposalFunc DisposalFunc[V]) *RWMap[K, V]
func (*RWMap[K, V]) ComputeIfAbsent ¶ added in v1.1.0
func (c *RWMap[K, V]) ComputeIfAbsent(key K, computeFunc func() V) V
func (*RWMap[K, V]) Filter ¶ added in v1.2.0
Filter removes entries from the map that don't match the filter condition.
func (*RWMap[K, V]) GetAllEntries ¶ added in v1.1.0
func (c *RWMap[K, V]) GetAllEntries() map[K]V
func (*RWMap[K, V]) ProcessAndRemoveIf ¶ added in v1.1.0
ProcessAndRemoveIf executes the provided function on each key-value pair where the key satisfies the condition function. Matching entries are removed after processing.
func (*RWMap[K, V]) PutIfAbsent ¶ added in v1.1.0
func (c *RWMap[K, V]) PutIfAbsent(key K, value V)
func (*RWMap[K, V]) ReplaceCacheWithCopy ¶ added in v1.1.0
func (*RWMap[K, V]) ReplaceCacheWithMap ¶ added in v1.1.0
func (c *RWMap[K, V]) ReplaceCacheWithMap(entryMap map[K]V)
type RWQueue ¶ added in v1.1.0
type RWQueue[T any] struct { // contains filtered or unexported fields }
func NewRWQueue ¶ added in v1.1.0
type RdsUrlType ¶
var ( OTHER RdsUrlType = RdsUrlType{0, false, false} RDS_WRITER_CLUSTER RdsUrlType = RdsUrlType{1, true, true} RDS_READER_CLUSTER RdsUrlType = RdsUrlType{2, true, true} RDS_CUSTOM_CLUSTER RdsUrlType = RdsUrlType{3, true, true} RDS_PROXY RdsUrlType = RdsUrlType{4, true, false} RDS_INSTANCE RdsUrlType = RdsUrlType{5, true, false} RDS_AURORA_LIMITLESS_DB_SHARD_GROUP RdsUrlType = RdsUrlType{6, true, false} IP_ADDRESS RdsUrlType = RdsUrlType{7, false, false} )
func IdentifyRdsUrlType ¶
func IdentifyRdsUrlType(host string) RdsUrlType
type SlidingExpirationCache ¶
type SlidingExpirationCache[T any] struct { // contains filtered or unexported fields }
func NewSlidingExpirationCache ¶
func NewSlidingExpirationCache[T any](id string, funcs ...DisposalFunc[T]) *SlidingExpirationCache[T]
func (*SlidingExpirationCache[T]) CleanUp ¶
func (c *SlidingExpirationCache[T]) CleanUp()
func (*SlidingExpirationCache[T]) Clear ¶
func (c *SlidingExpirationCache[T]) Clear()
func (*SlidingExpirationCache[T]) ComputeIfAbsent ¶
func (c *SlidingExpirationCache[T]) ComputeIfAbsent(key string, computeFunc func() T, itemExpiration time.Duration) T
func (*SlidingExpirationCache[T]) ComputeIfAbsentWithError ¶ added in v1.2.0
func (*SlidingExpirationCache[T]) Get ¶
func (c *SlidingExpirationCache[T]) Get(key string, itemExpiration time.Duration) (T, bool)
func (*SlidingExpirationCache[T]) GetAllEntries ¶
func (c *SlidingExpirationCache[T]) GetAllEntries() map[string]T
Get a map copy of all entries in the cache, including expired entries.
func (*SlidingExpirationCache[T]) Put ¶
func (c *SlidingExpirationCache[T]) Put(key string, value T, itemExpiration time.Duration)
func (*SlidingExpirationCache[T]) PutIfAbsent ¶
func (c *SlidingExpirationCache[T]) PutIfAbsent(key string, value T, expiration time.Duration)
func (*SlidingExpirationCache[T]) Remove ¶
func (c *SlidingExpirationCache[T]) Remove(key string)
func (*SlidingExpirationCache[T]) SetCleanupIntervalNanos ¶
func (c *SlidingExpirationCache[T]) SetCleanupIntervalNanos(newIntervalNanos time.Duration)
func (*SlidingExpirationCache[T]) Size ¶
func (c *SlidingExpirationCache[T]) Size() int