parent
80a3745fc8
commit
6a4de37f7e
@ -1,29 +0,0 @@ |
||||
## Contributing to pq |
||||
|
||||
`pq` has a backlog of pull requests, but contributions are still very |
||||
much welcome. You can help with patch review, submitting bug reports, |
||||
or adding new functionality. There is no formal style guide, but |
||||
please conform to the style of existing code and general Go formatting |
||||
conventions when submitting patches. |
||||
|
||||
### Patch review |
||||
|
||||
Help review existing open pull requests by commenting on the code or |
||||
proposed functionality. |
||||
|
||||
### Bug reports |
||||
|
||||
We appreciate any bug reports, but especially ones with self-contained |
||||
(doesn't depend on code outside of pq), minimal (can't be simplified |
||||
further) test cases. It's especially helpful if you can submit a pull |
||||
request with just the failing test case (you'll probably want to |
||||
pattern it after the tests in |
||||
[conn_test.go](https://github.com/lib/pq/blob/master/conn_test.go). |
||||
|
||||
### New functionality |
||||
|
||||
There are a number of pending patches for new functionality, so |
||||
additional feature patches will take a while to merge. Still, patches |
||||
are generally reviewed based on usefulness and complexity in addition |
||||
to time-in-queue, so if you have a knockout idea, take a shot. Feel |
||||
free to open an issue discussion your proposed patch beforehand. |
@ -1 +1,3 @@ |
||||
module github.com/lib/pq |
||||
|
||||
go 1.13 |
||||
|
@ -0,0 +1,27 @@ |
||||
package pq |
||||
|
||||
// NewGSSFunc creates a GSS authentication provider, for use with
|
||||
// RegisterGSSProvider.
|
||||
type NewGSSFunc func() (GSS, error) |
||||
|
||||
var newGss NewGSSFunc |
||||
|
||||
// RegisterGSSProvider registers a GSS authentication provider. For example, if
|
||||
// you need to use Kerberos to authenticate with your server, add this to your
|
||||
// main package:
|
||||
//
|
||||
// import "github.com/lib/pq/auth/kerberos"
|
||||
//
|
||||
// func init() {
|
||||
// pq.RegisterGSSProvider(func() (pq.GSS, error) { return kerberos.NewGSS() })
|
||||
// }
|
||||
func RegisterGSSProvider(newGssArg NewGSSFunc) { |
||||
newGss = newGssArg |
||||
} |
||||
|
||||
// GSS provides GSSAPI authentication (e.g., Kerberos).
|
||||
type GSS interface { |
||||
GetInitToken(host string, service string) ([]byte, error) |
||||
GetInitTokenFromSpn(spn string) ([]byte, error) |
||||
Continue(inToken []byte) (done bool, outToken []byte, err error) |
||||
} |
@ -0,0 +1,71 @@ |
||||
// +build go1.10
|
||||
|
||||
package pq |
||||
|
||||
import ( |
||||
"context" |
||||
"database/sql/driver" |
||||
) |
||||
|
||||
// NoticeHandler returns the notice handler on the given connection, if any. A
|
||||
// runtime panic occurs if c is not a pq connection. This is rarely used
|
||||
// directly, use ConnectorNoticeHandler and ConnectorWithNoticeHandler instead.
|
||||
func NoticeHandler(c driver.Conn) func(*Error) { |
||||
return c.(*conn).noticeHandler |
||||
} |
||||
|
||||
// SetNoticeHandler sets the given notice handler on the given connection. A
|
||||
// runtime panic occurs if c is not a pq connection. A nil handler may be used
|
||||
// to unset it. This is rarely used directly, use ConnectorNoticeHandler and
|
||||
// ConnectorWithNoticeHandler instead.
|
||||
//
|
||||
// Note: Notice handlers are executed synchronously by pq meaning commands
|
||||
// won't continue to be processed until the handler returns.
|
||||
func SetNoticeHandler(c driver.Conn, handler func(*Error)) { |
||||
c.(*conn).noticeHandler = handler |
||||
} |
||||
|
||||
// NoticeHandlerConnector wraps a regular connector and sets a notice handler
|
||||
// on it.
|
||||
type NoticeHandlerConnector struct { |
||||
driver.Connector |
||||
noticeHandler func(*Error) |
||||
} |
||||
|
||||
// Connect calls the underlying connector's connect method and then sets the
|
||||
// notice handler.
|
||||
func (n *NoticeHandlerConnector) Connect(ctx context.Context) (driver.Conn, error) { |
||||
c, err := n.Connector.Connect(ctx) |
||||
if err == nil { |
||||
SetNoticeHandler(c, n.noticeHandler) |
||||
} |
||||
return c, err |
||||
} |
||||
|
||||
// ConnectorNoticeHandler returns the currently set notice handler, if any. If
|
||||
// the given connector is not a result of ConnectorWithNoticeHandler, nil is
|
||||
// returned.
|
||||
func ConnectorNoticeHandler(c driver.Connector) func(*Error) { |
||||
if c, ok := c.(*NoticeHandlerConnector); ok { |
||||
return c.noticeHandler |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
// ConnectorWithNoticeHandler creates or sets the given handler for the given
|
||||
// connector. If the given connector is a result of calling this function
|
||||
// previously, it is simply set on the given connector and returned. Otherwise,
|
||||
// this returns a new connector wrapping the given one and setting the notice
|
||||
// handler. A nil notice handler may be used to unset it.
|
||||
//
|
||||
// The returned connector is intended to be used with database/sql.OpenDB.
|
||||
//
|
||||
// Note: Notice handlers are executed synchronously by pq meaning commands
|
||||
// won't continue to be processed until the handler returns.
|
||||
func ConnectorWithNoticeHandler(c driver.Connector, handler func(*Error)) *NoticeHandlerConnector { |
||||
if c, ok := c.(*NoticeHandlerConnector); ok { |
||||
c.noticeHandler = handler |
||||
return c |
||||
} |
||||
return &NoticeHandlerConnector{Connector: c, noticeHandler: handler} |
||||
} |
Loading…
Reference in new issue