Documentation ¶
Index ¶
- func GetJSON(ctx context.Context, client *http.Client, url string, v interface{}) error
- func InterpolateMySQLString(s string) string
- func IsContextCanceledError(err error) bool
- func IsDirExists(name string) bool
- func IsEmptyDir(name string) bool
- func IsRetryableError(err error) bool
- func KillMySelf() error
- func Retry(purpose string, parentLogger log.Logger, action func() error) error
- func StringSliceEqual(a, b []string) bool
- func TableHasAutoRowID(info *model.TableInfo) bool
- func ToTLSConfig(caPath, certPath, keyPath string) (*tls.Config, error)
- func UniqueTable(schema string, table string) string
- func WriteMySQLIdentifier(builder *strings.Builder, identifier string)
- type DBExecutor
- type KvPair
- type MySQLConnectParam
- type OnceError
- type Pauser
- type QueryExecutor
- type SQLWithRetry
- type StorageSize
- type TLS
- func (tc *TLS) GetJSON(ctx context.Context, path string, v interface{}) error
- func (tc *TLS) TLSConfig() *tls.Config
- func (tc *TLS) ToGRPCDialOption() grpc.DialOption
- func (tc *TLS) ToPDSecurityOption() pd.SecurityOption
- func (tc *TLS) WithHost(host string) *TLS
- func (tc *TLS) WrapListener(l net.Listener) net.Listener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetJSON ¶
GetJSON fetches a page and parses it as JSON. The parsed result will be stored into the `v`. The variable `v` must be a pointer to a type that can be unmarshalled from JSON.
Example:
client := &http.Client{} var resp struct { IP string } if err := util.GetJSON(client, "http://api.ipify.org/?format=json", &resp); err != nil { return errors.Trace(err) } fmt.Println(resp.IP)
func InterpolateMySQLString ¶
func IsContextCanceledError ¶
IsContextCanceledError returns whether the error is caused by context cancellation. This function should only be used when the code logic is affected by whether the error is canceling or not.
This function returns `false` (not a context-canceled error) if `err == nil`.
func IsRetryableError ¶
IsRetryableError returns whether the error is transient (e.g. network connection dropped) or irrecoverable (e.g. user pressing Ctrl+C). This function returns `false` (irrecoverable) if `err == nil`.
If the error is a multierr, returns true only if all suberrors are retryable.
func KillMySelf ¶
func KillMySelf() error
KillMySelf sends sigint to current process, used in integration test only
Only works on Unix. Signaling on Windows is not supported.
func Retry ¶
Retry is shared by SQLWithRetry.perform, implementation of GlueCheckpointsDB and TiDB's glue implementation
func StringSliceEqual ¶
StringSliceEqual checks if two string slices are equal.
func TableHasAutoRowID ¶
TableHasAutoRowID return whether table has auto generated row id
func ToTLSConfig ¶
ToTLSConfig constructs a `*tls.Config` from the CA, certification and key paths.
If the CA path is empty, returns nil.
func UniqueTable ¶
UniqueTable returns an unique table name.
func WriteMySQLIdentifier ¶
Writes a MySQL identifier into the string builder. The identifier is always escaped into the form "`foo`".
Types ¶
type DBExecutor ¶
type KvPair ¶
type KvPair struct { // Key is the key of the KV pair Key []byte // Val is the value of the KV pair Val []byte }
KvPair is a pair of key and value.
type MySQLConnectParam ¶
type MySQLConnectParam struct { Host string Port int User string Password string SQLMode string MaxAllowedPacket uint64 TLS string Vars map[string]string }
MySQLConnectParam records the parameters needed to connect to a MySQL database.
func (*MySQLConnectParam) ToDSN ¶
func (param *MySQLConnectParam) ToDSN() string
type OnceError ¶
type OnceError struct {
// contains filtered or unexported fields
}
OnceError is an error value which will can be assigned once.
The zero value is ready for use.
type Pauser ¶
type Pauser struct {
// contains filtered or unexported fields
}
Pauser is a type which could allow multiple goroutines to wait on demand, similar to a gate or traffic light.
type QueryExecutor ¶
type SQLWithRetry ¶
type SQLWithRetry struct { // either *sql.DB or *sql.Conn DB DBExecutor Logger log.Logger HideQueryLog bool }
SQLWithRetry constructs a retryable transaction.
func (SQLWithRetry) Exec ¶
func (t SQLWithRetry) Exec(ctx context.Context, purpose string, query string, args ...interface{}) error
Exec executes a single SQL with optional retry.
type StorageSize ¶
StorageSize represents the storage's capacity and available size Learn from tidb-binlog source code.
func GetStorageSize ¶
func GetStorageSize(dir string) (size StorageSize, err error)
GetStorageSize gets storage's capacity and available size
type TLS ¶
type TLS struct {
// contains filtered or unexported fields
}
TLS
func NewTLS ¶
NewTLS constructs a new HTTP client with TLS configured with the CA, certificate and key paths.
If the CA path is empty, returns an instance where TLS is disabled.
func NewTLSFromMockServer ¶
NewTLSFromMockServer constructs a new TLS instance from the certificates of an *httptest.Server.
func (*TLS) ToGRPCDialOption ¶
func (tc *TLS) ToGRPCDialOption() grpc.DialOption
ToGRPCDialOption constructs a gRPC dial option.
func (*TLS) ToPDSecurityOption ¶
func (tc *TLS) ToPDSecurityOption() pd.SecurityOption