Documentation
¶
Index ¶
- Constants
- Variables
- func AppendLogfmt(w io.Writer, key, value any) error
- func Bool(b bool) sql.NullBool
- func Fuzz(data []byte) int
- func ParseTZ(s string) (int, error)
- type AccessToken
- type AdminRole
- type CommonParams
- type CommonSimpleParams
- type ConnParams
- type ConnectionParams
- func (P ConnectionParams) IsStandalone() bool
- func (P ConnectionParams) IsZero() bool
- func (P ConnectionParams) LogValue() slog.Value
- func (P *ConnectionParams) SetSessionParamOnInit(k, v string)
- func (P ConnectionParams) String() string
- func (P ConnectionParams) StringNoClass() string
- func (P ConnectionParams) StringWithPassword() string
- type Password
- func (P *Password) CopyFrom(Q Password)
- func (P Password) IsZero() bool
- func (P Password) Len() int
- func (P Password) LogValue() slog.Value
- func (P *Password) MarshalBinary() ([]byte, error)
- func (P *Password) MarshalJSON() ([]byte, error)
- func (P *Password) MarshalText() ([]byte, error)
- func (P *Password) Reset()
- func (P Password) Secret() string
- func (P *Password) Set(secret string)
- func (P Password) String() string
- type PoolParams
Examples ¶
Constants ¶
const ( // DefaultPoolMinSessions specifies the default value for minSessions for pool creation. DefaultPoolMinSessions = 1 // DefaultPoolMaxSessions specifies the default value for maxSessions for pool creation. DefaultPoolMaxSessions = 1000 // DefaultSessionIncrement specifies the default value for increment for pool creation. DefaultSessionIncrement = 1 // DefaultPoolIncrement is a deprecated name for DefaultSessionIncrement. DefaultPoolIncrement = DefaultSessionIncrement // DefaultConnectionClass is empty, which allows to use the poolMinSessions created as part of session pool creation for non-DRCP. For DRCP, connectionClass needs to be explicitly mentioned. DefaultConnectionClass = "" // NoConnectionPoolingConnectionClass is a special connection class name to indicate no connection pooling. // It is the same as setting standaloneConnection=1 NoConnectionPoolingConnectionClass = "NO-CONNECTION-POOLING" // DefaultSessionTimeout is the seconds before idle pool sessions get evicted DefaultSessionTimeout = 5 * time.Minute // DefaultWaitTimeout is the milliseconds to wait for a session to become available DefaultWaitTimeout = 30 * time.Second // DefaultMaxLifeTime is the maximum time in seconds till a pooled session may exist DefaultMaxLifeTime = 1 * time.Hour // DefaultStandaloneConnection holds the default for standaloneConnection. DefaultStandaloneConnection = true // DefaultNoBreakOnContextCancel holds the default for noBreakOnContext DefaultNoBreakOnContextCancel = false DefaultTestDSN = "oracle://demo:demo@localhost:1521/freepdb1" DefaultTestSystemDSN = "oracle://sys:system@localhost:1521/freepdb1?sysdba=1" )
Variables ¶
var ErrCannotMarshal = errors.New("cannot be marshaled")
Functions ¶
func AppendLogfmt ¶
AppendLogfmt appends the key=val logfmt-formatted.
Example ¶
var buf strings.Builder AppendLogfmt(&buf, "user", "scott") AppendLogfmt(&buf, "password", "tiger") AppendLogfmt(&buf, "connectString", "dbhost:1521/orclpdb1?connect_timeout=2") fmt.Println(buf.String())
Output: user=scott password=tiger connectString="dbhost:1521/orclpdb1?connect_timeout=2"
func Fuzz ¶
See https://github.com/dvyukov/go-fuzz
(cd /tmp && go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build) PATH=$HOME/sdk/go1.14.6/bin:$PATH GO111MODULE=on go-fuzz-build go-fuzz
Types ¶
type AccessToken ¶ added in v0.44.0
AccessToken Data for Token Authentication.
type CommonParams ¶
type CommonParams struct {
// Logger is the per-pool or per-connection logger.
// The default nil logger does not log.
Logger *slog.Logger
// OnInit is executed on session init. Overrides AlterSession and OnInitStmts!
OnInit func(context.Context, driver.ConnPrepareContext) error `json:"-"`
// OnInitStmts are executed on session init, iff OnInit is nil.
OnInitStmts []string
// AlterSession key-values are set with "ALTER SESSION SET key=value" on session init, iff OnInit is nil.
AlterSession [][2]string
CommonSimpleParams
}
CommonParams holds the common parameters for pooled or standalone connections.
For details, see https://oracle.github.io/odpi/doc/structs/dpiCommonCreateParams.html#dpicommoncreateparams
func (CommonParams) LogValue ¶ added in v0.53.0
func (P CommonParams) LogValue() slog.Value
LogValue implements slog.LogValuer, so structured handlers (e.g. JSON) log the masked String form instead of serializing Password, Token and PrivateKey.
func (CommonParams) String ¶
func (P CommonParams) String() string
type CommonSimpleParams ¶ added in v0.39.3
type CommonSimpleParams struct {
Timezone *time.Location
ConfigDir, LibDir string
Username, ConnectString string
Token, PrivateKey string
Password Password
Charset string
// StmtCacheSize controls the Oracle Client statement cache.
// Zero means the default; -1 disables it.
StmtCacheSize int
// true: OnInit will be called only by the new session / false: OnInit will called by new or pooled connection
InitOnNewConn bool
EnableEvents, NoTZCheck, PerSessionTimezone bool
NoBreakOnContextCancel bool
}
func (CommonSimpleParams) IsZero ¶ added in v0.51.4
func (P CommonSimpleParams) IsZero() bool
func (CommonSimpleParams) LogValue ¶ added in v0.53.0
func (P CommonSimpleParams) LogValue() slog.Value
LogValue implements slog.LogValuer, see CommonParams.LogValue.
func (CommonSimpleParams) String ¶ added in v0.39.3
func (P CommonSimpleParams) String() string
String returns the string representation of CommonParams.
type ConnParams ¶
type ConnParams struct {
NewPassword Password
ConnClass string
AdminRole AdminRole
ShardingKey, SuperShardingKey []any
IsPrelim bool
}
ConnParams holds the connection-specific parameters.
For details, see https://oracle.github.io/odpi/doc/structs/dpiConnCreateParams.html#dpiconncreateparams
func (ConnParams) IsZero ¶ added in v0.51.4
func (P ConnParams) IsZero() bool
func (ConnParams) String ¶
func (P ConnParams) String() string
String returns the string representation of the ConnParams.
type ConnectionParams ¶
type ConnectionParams struct {
CommonParams
ConnParams
PoolParams
// ConnParams.NewPassword is used iff StandaloneConnection is true!
StandaloneConnection sql.NullBool
}
ConnectionParams holds the params for a connection (pool). You can use ConnectionParams{...}.StringWithPassword() as a connection string in sql.Open.
func Parse ¶
func Parse(dataSourceName string) (ConnectionParams, error)
Parse parses the given connection string into a struct.
For examples, see [../doc/connection.md](../doc/connection.md)
Example ¶
var P ConnectionParams
P.Username, P.Password = "scott", NewPassword("tiger")
P.ConnectString = "dbhost:1521/orclpdb1?connect_timeout=2"
P.SessionTimeout = 42 * time.Second
P.SetSessionParamOnInit("NLS_NUMERIC_CHARACTERS", ",.")
P.SetSessionParamOnInit("NLS_LANGUAGE", "FRENCH")
fmt.Println(P.StringWithPassword())
Output: user=scott password=tiger connectString="dbhost:1521/orclpdb1?connect_timeout=2" alterSession="NLS_NUMERIC_CHARACTERS=,." alterSession="NLS_LANGUAGE=FRENCH" connectionClass= newPassword= poolIncrement=0 poolMinSessions=0 poolSessionMaxLifetime=0s poolSessionTimeout=42s poolWaitTimeout=0s
func (ConnectionParams) IsStandalone ¶
func (P ConnectionParams) IsStandalone() bool
IsStandalone returns whether the connection should be standalone, not pooled.
func (ConnectionParams) IsZero ¶ added in v0.51.4
func (P ConnectionParams) IsZero() bool
func (ConnectionParams) LogValue ¶ added in v0.53.0
func (P ConnectionParams) LogValue() slog.Value
LogValue implements slog.LogValuer, see CommonParams.LogValue.
func (*ConnectionParams) SetSessionParamOnInit ¶
func (P *ConnectionParams) SetSessionParamOnInit(k, v string)
SetSessionParamOnInit adds an "ALTER SESSION k=v" to the OnInit task list.
func (ConnectionParams) String ¶
func (P ConnectionParams) String() string
String returns the string representation of ConnectionParams. The password is replaced with a "***" string!
func (ConnectionParams) StringNoClass ¶
func (P ConnectionParams) StringNoClass() string
StringNoClass returns the string representation of ConnectionParams, without class info. The password is replaced with a "***" string!
func (ConnectionParams) StringWithPassword ¶
func (P ConnectionParams) StringWithPassword() string
StringWithPassword returns the string representation of ConnectionParams (as String() does), but does NOT obfuscate the password, just prints it as is.
type Password ¶
type Password struct {
// contains filtered or unexported fields
}
Password is printed obfuscated with String, use Secret to reveal the secret.
func NewPassword ¶
NewPassword creates a new Password, containing the given secret.
func (*Password) MarshalBinary ¶ added in v0.33.1
func (*Password) MarshalJSON ¶ added in v0.33.1
nosemgrep
func (*Password) MarshalText ¶ added in v0.33.1
type PoolParams ¶
type PoolParams struct {
TokenCBCtx context.Context `json:"-"`
TokenCB func(context.Context, *AccessToken) error `json:"-"`
MinSessions, MaxSessions, SessionIncrement int
MaxSessionsPerShard int
WaitTimeout, MaxLifeTime, SessionTimeout time.Duration
PingInterval time.Duration
Heterogeneous, ExternalAuth, NoWait sql.NullBool
}
PoolParams holds the configuration of the Oracle Session Pool.
For details, see https://oracle.github.io/odpi/doc/structs/dpiPoolCreateParams.html#dpipoolcreateparams
For details, see https://oracle.github.io/odpi/doc/structs/dpiPoolCreateParams.html#dpipoolcreateparams
func (PoolParams) IsZero ¶ added in v0.51.4
func (P PoolParams) IsZero() bool
func (PoolParams) String ¶
func (P PoolParams) String() string
String returns the string representation of PoolParams.