本文整理匯總了Golang中github.com/housinganywhere/pg/internal/pool.Conn.ReadN方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.ReadN方法的具體用法?Golang Conn.ReadN怎麽用?Golang Conn.ReadN使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/housinganywhere/pg/internal/pool.Conn
的用法示例。
在下文中一共展示了Conn.ReadN方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: readCopyOutResponse
func readCopyOutResponse(cn *pool.Conn) error {
for {
c, msgLen, err := readMessageType(cn)
if err != nil {
return err
}
switch c {
case copyOutResponseMsg:
_, err := cn.ReadN(msgLen)
if err != nil {
return err
}
return nil
case errorResponseMsg:
e, err := readError(cn)
if err != nil {
return err
}
return e
case noticeResponseMsg:
if err := logNotice(cn, msgLen); err != nil {
return err
}
case parameterStatusMsg:
if err := logParameterStatus(cn, msgLen); err != nil {
return err
}
default:
return fmt.Errorf("pg: readCopyOutResponse: unexpected message %#x", c)
}
}
}
示例2: readInt32
func readInt32(cn *pool.Conn) (int32, error) {
b, err := cn.ReadN(4)
if err != nil {
return 0, err
}
return int32(binary.BigEndian.Uint32(b)), nil
}
示例3: startup
func startup(cn *pool.Conn, user, password, database string) error {
writeStartupMsg(cn.Wr, user, database)
if err := cn.Wr.Flush(); err != nil {
return err
}
for {
c, msgLen, err := readMessageType(cn)
if err != nil {
return err
}
switch c {
case backendKeyDataMsg:
processId, err := readInt32(cn)
if err != nil {
return err
}
secretKey, err := readInt32(cn)
if err != nil {
return err
}
cn.ProcessId = processId
cn.SecretKey = secretKey
case parameterStatusMsg:
if err := logParameterStatus(cn, msgLen); err != nil {
return err
}
case authenticationOKMsg:
if err := authenticate(cn, user, password); err != nil {
return err
}
case readyForQueryMsg:
_, err := cn.ReadN(msgLen)
if err != nil {
return err
}
return nil
case errorResponseMsg:
e, err := readError(cn)
if err != nil {
return err
}
return e
default:
return fmt.Errorf("pg: unknown startup message response: %q", c)
}
}
}
示例4: readNotification
func readNotification(cn *pool.Conn) (channel, payload string, err error) {
for {
c, msgLen, err := readMessageType(cn)
if err != nil {
return "", "", err
}
switch c {
case commandCompleteMsg:
_, err := cn.ReadN(msgLen)
if err != nil {
return "", "", err
}
case readyForQueryMsg:
_, err := cn.ReadN(msgLen)
if err != nil {
return "", "", err
}
case errorResponseMsg:
e, err := readError(cn)
if err != nil {
return "", "", err
}
return "", "", e
case noticeResponseMsg:
if err := logNotice(cn, msgLen); err != nil {
return "", "", err
}
case notificationResponseMsg:
_, err := readInt32(cn)
if err != nil {
return "", "", err
}
channel, err = readString(cn)
if err != nil {
return "", "", err
}
payload, err = readString(cn)
if err != nil {
return "", "", err
}
return channel, payload, nil
default:
return "", "", fmt.Errorf("pg: unexpected message %q", c)
}
}
}
示例5: readParseDescribeSync
func readParseDescribeSync(cn *pool.Conn) (columns []string, e error) {
for {
c, msgLen, err := readMessageType(cn)
if err != nil {
return nil, err
}
switch c {
case parseCompleteMsg:
_, err := cn.ReadN(msgLen)
if err != nil {
return nil, err
}
case rowDescriptionMsg: // Response to the DESCRIBE message.
columns, err = readRowDescription(cn)
if err != nil {
return nil, err
}
case parameterDescriptionMsg: // Response to the DESCRIBE message.
_, err := cn.ReadN(msgLen)
if err != nil {
return nil, err
}
case noDataMsg: // Response to the DESCRIBE message.
_, err := cn.ReadN(msgLen)
if err != nil {
return nil, err
}
case readyForQueryMsg:
_, err := cn.ReadN(msgLen)
if err != nil {
return nil, err
}
return
case errorResponseMsg:
var err error
e, err = readError(cn)
if err != nil {
return nil, err
}
case noticeResponseMsg:
if err := logNotice(cn, msgLen); err != nil {
return nil, err
}
case parameterStatusMsg:
if err := logParameterStatus(cn, msgLen); err != nil {
return nil, err
}
default:
if e != nil {
return nil, e
}
return nil, fmt.Errorf("pg: readParseDescribeSync: unexpected message %#x", c)
}
}
}
示例6: readRowDescription
func readRowDescription(cn *pool.Conn) ([]string, error) {
colNum, err := readInt16(cn)
if err != nil {
return nil, err
}
cols := make([]string, colNum)
for i := int16(0); i < colNum; i++ {
col, err := readString(cn)
if err != nil {
return nil, err
}
cols[i] = col
if _, err := cn.ReadN(18); err != nil {
return nil, err
}
}
return cols, nil
}
示例7: logParameterStatus
func logParameterStatus(cn *pool.Conn, msgLen int) error {
if !glog.V(2) {
_, err := cn.ReadN(msgLen)
return err
}
name, err := readString(cn)
if err != nil {
return err
}
value, err := readString(cn)
if err != nil {
return err
}
glog.Infof("pg parameter status: %s=%q", name, value)
return nil
}
示例8: logNotice
func logNotice(cn *pool.Conn, msgLen int) error {
if !glog.V(2) {
_, err := cn.ReadN(msgLen)
return err
}
var level string
var logger func(string, ...interface{})
for {
c, err := cn.Rd.ReadByte()
if err != nil {
return err
}
if c == 0 {
break
}
s, err := readString(cn)
if err != nil {
return err
}
switch c {
case 'S':
level = s
switch level {
case "DEBUG", "LOG", "INFO", "NOTICE":
logger = glog.Infof
case "WARNING":
logger = glog.Warningf
case "EXCEPTION":
logger = glog.Errorf
default:
logger = glog.Fatalf
}
case 'M':
logger("pg %s message: %s", level, s)
}
}
return nil
}
示例9: readReadyForQuery
func readReadyForQuery(cn *pool.Conn) (res types.Result, e error) {
for {
c, msgLen, err := readMessageType(cn)
if err != nil {
return nil, err
}
switch c {
case commandCompleteMsg:
b, err := cn.ReadN(msgLen)
if err != nil {
return nil, err
}
res = types.ParseResult(b)
case readyForQueryMsg:
_, err := cn.ReadN(msgLen)
if err != nil {
return nil, err
}
return
case errorResponseMsg:
var err error
e, err = readError(cn)
if err != nil {
return nil, err
}
case noticeResponseMsg:
if err := logNotice(cn, msgLen); err != nil {
return nil, err
}
case parameterStatusMsg:
if err := logParameterStatus(cn, msgLen); err != nil {
return nil, err
}
default:
if e != nil {
return nil, e
}
return nil, fmt.Errorf("pg: readReadyForQuery: unexpected message %#x", c)
}
}
}
示例10: readBindMsg
func readBindMsg(cn *pool.Conn) (e error) {
for {
c, msgLen, err := readMessageType(cn)
if err != nil {
return err
}
switch c {
case bindCompleteMsg:
_, err := cn.ReadN(msgLen)
if err != nil {
return err
}
case readyForQueryMsg: // This is response to the SYNC message.
_, err := cn.ReadN(msgLen)
if err != nil {
return err
}
return
case errorResponseMsg:
var err error
e, err = readError(cn)
if err != nil {
return err
}
case noticeResponseMsg:
if err := logNotice(cn, msgLen); err != nil {
return err
}
case parameterStatusMsg:
if err := logParameterStatus(cn, msgLen); err != nil {
return err
}
default:
if e != nil {
return e
}
return fmt.Errorf("pg: readBindMsg: unexpected message %#x", c)
}
}
}
示例11: readDataRow
func readDataRow(cn *pool.Conn, scanner orm.ColumnScanner, columns []string) (scanErr error) {
colNum, err := readInt16(cn)
if err != nil {
return err
}
for colIdx := 0; colIdx < int(colNum); colIdx++ {
l, err := readInt32(cn)
if err != nil {
return err
}
var b []byte
if l != -1 {
b, err = cn.ReadN(int(l))
if err != nil {
return err
}
}
if err := scanner.ScanColumn(colIdx, columns[colIdx], b); err != nil {
scanErr = err
}
}
return scanErr
}
示例12: readCopyData
func readCopyData(cn *pool.Conn, w io.WriteCloser) (types.Result, error) {
defer w.Close()
for {
c, msgLen, err := readMessageType(cn)
if err != nil {
return nil, err
}
switch c {
case copyDataMsg:
b, err := cn.ReadN(msgLen)
if err != nil {
return nil, err
}
_, err = w.Write(b)
if err != nil {
return nil, err
}
case copyDoneMsg:
_, err := cn.ReadN(msgLen)
if err != nil {
return nil, err
}
case commandCompleteMsg:
b, err := cn.ReadN(msgLen)
if err != nil {
return nil, err
}
return types.ParseResult(b), nil
case errorResponseMsg:
e, err := readError(cn)
if err != nil {
return nil, err
}
return nil, e
case noticeResponseMsg:
if err := logNotice(cn, msgLen); err != nil {
return nil, err
}
case parameterStatusMsg:
if err := logParameterStatus(cn, msgLen); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("pg: readCopyData: unexpected message %#x", c)
}
}
}
示例13: readExtQueryData
func readExtQueryData(cn *pool.Conn, mod interface{}, columns []string) (res types.Result, e error) {
coll, ok := mod.(orm.Collection)
if !ok {
coll, e = orm.NewModel(mod)
if e != nil {
coll = Discard
}
}
var model orm.ColumnScanner
for {
c, msgLen, err := readMessageType(cn)
if err != nil {
return nil, err
}
switch c {
case bindCompleteMsg:
_, err := cn.ReadN(msgLen)
if err != nil {
return nil, err
}
case dataRowMsg:
model = coll.NewModel()
if err := readDataRow(cn, model, columns); err != nil {
e = err
}
if err := coll.AddModel(model); err != nil {
return nil, err
}
case commandCompleteMsg: // Response to the EXECUTE message.
b, err := cn.ReadN(msgLen)
if err != nil {
return nil, err
}
res = types.ParseResult(b)
case readyForQueryMsg: // Response to the SYNC message.
_, err := cn.ReadN(msgLen)
if err != nil {
return nil, err
}
return
case errorResponseMsg:
var err error
e, err = readError(cn)
if err != nil {
return nil, err
}
case noticeResponseMsg:
if err := logNotice(cn, msgLen); err != nil {
return nil, err
}
case parameterStatusMsg:
if err := logParameterStatus(cn, msgLen); err != nil {
return nil, err
}
default:
if e != nil {
return nil, e
}
return nil, fmt.Errorf("pg: readExtQueryData: unexpected message %#x", c)
}
}
}
示例14: authenticate
func authenticate(cn *pool.Conn, user, password string) error {
num, err := readInt32(cn)
if err != nil {
return err
}
switch num {
case 0:
return nil
case 3:
writePasswordMsg(cn.Wr, password)
if err := cn.Wr.Flush(); err != nil {
return err
}
c, _, err := readMessageType(cn)
if err != nil {
return err
}
switch c {
case authenticationOKMsg:
num, err := readInt32(cn)
if err != nil {
return err
}
if num != 0 {
return fmt.Errorf("pg: unexpected authentication code: %d", num)
}
return nil
case errorResponseMsg:
e, err := readError(cn)
if err != nil {
return err
}
return e
default:
return fmt.Errorf("pg: unknown password message response: %q", c)
}
case 5:
b, err := cn.ReadN(4)
if err != nil {
return err
}
secret := "md5" + md5s(md5s(password+user)+string(b))
writePasswordMsg(cn.Wr, secret)
if err := cn.Wr.Flush(); err != nil {
return err
}
c, _, err := readMessageType(cn)
if err != nil {
return err
}
switch c {
case authenticationOKMsg:
num, err := readInt32(cn)
if err != nil {
return err
}
if num != 0 {
return fmt.Errorf("pg: unexpected authentication code: %d", num)
}
return nil
case errorResponseMsg:
e, err := readError(cn)
if err != nil {
return err
}
return e
default:
return fmt.Errorf("pg: unknown password message response: %q", c)
}
default:
return fmt.Errorf("pg: unknown authentication message response: %d", num)
}
}