repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
jackc/pgx
large_objects.go
LargeObjects
func (tx *Tx) LargeObjects() (*LargeObjects, error) { if tx.conn.fp == nil { tx.conn.fp = newFastpath(tx.conn) } if _, exists := tx.conn.fp.fns["lo_open"]; !exists { res, err := tx.Query(largeObjectFns) if err != nil { return nil, err } if err := tx.conn.fp.addFunctions(res); err != nil { return nil, err } } lo := &LargeObjects{fp: tx.conn.fp} _, lo.Has64 = lo.fp.fns["lo_lseek64"] return lo, nil }
go
func (tx *Tx) LargeObjects() (*LargeObjects, error) { if tx.conn.fp == nil { tx.conn.fp = newFastpath(tx.conn) } if _, exists := tx.conn.fp.fns["lo_open"]; !exists { res, err := tx.Query(largeObjectFns) if err != nil { return nil, err } if err := tx.conn.fp.addFunctions(res); err != nil { return nil, err } } lo := &LargeObjects{fp: tx.conn.fp} _, lo.Has64 = lo.fp.fns["lo_lseek64"] return lo, nil }
[ "func", "(", "tx", "*", "Tx", ")", "LargeObjects", "(", ")", "(", "*", "LargeObjects", ",", "error", ")", "{", "if", "tx", ".", "conn", ".", "fp", "==", "nil", "{", "tx", ".", "conn", ".", "fp", "=", "newFastpath", "(", "tx", ".", "conn", ")", ...
// LargeObjects returns a LargeObjects instance for the transaction.
[ "LargeObjects", "returns", "a", "LargeObjects", "instance", "for", "the", "transaction", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L36-L54
train
jackc/pgx
large_objects.go
Create
func (o *LargeObjects) Create(id pgtype.OID) (pgtype.OID, error) { newOID, err := fpInt32(o.fp.CallFn("lo_create", []fpArg{fpIntArg(int32(id))})) return pgtype.OID(newOID), err }
go
func (o *LargeObjects) Create(id pgtype.OID) (pgtype.OID, error) { newOID, err := fpInt32(o.fp.CallFn("lo_create", []fpArg{fpIntArg(int32(id))})) return pgtype.OID(newOID), err }
[ "func", "(", "o", "*", "LargeObjects", ")", "Create", "(", "id", "pgtype", ".", "OID", ")", "(", "pgtype", ".", "OID", ",", "error", ")", "{", "newOID", ",", "err", ":=", "fpInt32", "(", "o", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[",...
// Create creates a new large object. If id is zero, the server assigns an // unused OID.
[ "Create", "creates", "a", "new", "large", "object", ".", "If", "id", "is", "zero", "the", "server", "assigns", "an", "unused", "OID", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L65-L68
train
jackc/pgx
large_objects.go
Open
func (o *LargeObjects) Open(oid pgtype.OID, mode LargeObjectMode) (*LargeObject, error) { fd, err := fpInt32(o.fp.CallFn("lo_open", []fpArg{fpIntArg(int32(oid)), fpIntArg(int32(mode))})) return &LargeObject{fd: fd, lo: o}, err }
go
func (o *LargeObjects) Open(oid pgtype.OID, mode LargeObjectMode) (*LargeObject, error) { fd, err := fpInt32(o.fp.CallFn("lo_open", []fpArg{fpIntArg(int32(oid)), fpIntArg(int32(mode))})) return &LargeObject{fd: fd, lo: o}, err }
[ "func", "(", "o", "*", "LargeObjects", ")", "Open", "(", "oid", "pgtype", ".", "OID", ",", "mode", "LargeObjectMode", ")", "(", "*", "LargeObject", ",", "error", ")", "{", "fd", ",", "err", ":=", "fpInt32", "(", "o", ".", "fp", ".", "CallFn", "(", ...
// Open opens an existing large object with the given mode.
[ "Open", "opens", "an", "existing", "large", "object", "with", "the", "given", "mode", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L71-L74
train
jackc/pgx
large_objects.go
Unlink
func (o *LargeObjects) Unlink(oid pgtype.OID) error { _, err := o.fp.CallFn("lo_unlink", []fpArg{fpIntArg(int32(oid))}) return err }
go
func (o *LargeObjects) Unlink(oid pgtype.OID) error { _, err := o.fp.CallFn("lo_unlink", []fpArg{fpIntArg(int32(oid))}) return err }
[ "func", "(", "o", "*", "LargeObjects", ")", "Unlink", "(", "oid", "pgtype", ".", "OID", ")", "error", "{", "_", ",", "err", ":=", "o", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg", "{", "fpIntArg", "(", "int32", "(", "oid",...
// Unlink removes a large object from the database.
[ "Unlink", "removes", "a", "large", "object", "from", "the", "database", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L77-L80
train
jackc/pgx
large_objects.go
Write
func (o *LargeObject) Write(p []byte) (int, error) { n, err := fpInt32(o.lo.fp.CallFn("lowrite", []fpArg{fpIntArg(o.fd), p})) return int(n), err }
go
func (o *LargeObject) Write(p []byte) (int, error) { n, err := fpInt32(o.lo.fp.CallFn("lowrite", []fpArg{fpIntArg(o.fd), p})) return int(n), err }
[ "func", "(", "o", "*", "LargeObject", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "n", ",", "err", ":=", "fpInt32", "(", "o", ".", "lo", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg...
// Write writes p to the large object and returns the number of bytes written // and an error if not all of p was written.
[ "Write", "writes", "p", "to", "the", "large", "object", "and", "returns", "the", "number", "of", "bytes", "written", "and", "an", "error", "if", "not", "all", "of", "p", "was", "written", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L96-L99
train
jackc/pgx
large_objects.go
Seek
func (o *LargeObject) Seek(offset int64, whence int) (n int64, err error) { if o.lo.Has64 { n, err = fpInt64(o.lo.fp.CallFn("lo_lseek64", []fpArg{fpIntArg(o.fd), fpInt64Arg(offset), fpIntArg(int32(whence))})) } else { var n32 int32 n32, err = fpInt32(o.lo.fp.CallFn("lo_lseek", []fpArg{fpIntArg(o.fd), fpIntArg(int32(offset)), fpIntArg(int32(whence))})) n = int64(n32) } return }
go
func (o *LargeObject) Seek(offset int64, whence int) (n int64, err error) { if o.lo.Has64 { n, err = fpInt64(o.lo.fp.CallFn("lo_lseek64", []fpArg{fpIntArg(o.fd), fpInt64Arg(offset), fpIntArg(int32(whence))})) } else { var n32 int32 n32, err = fpInt32(o.lo.fp.CallFn("lo_lseek", []fpArg{fpIntArg(o.fd), fpIntArg(int32(offset)), fpIntArg(int32(whence))})) n = int64(n32) } return }
[ "func", "(", "o", "*", "LargeObject", ")", "Seek", "(", "offset", "int64", ",", "whence", "int", ")", "(", "n", "int64", ",", "err", "error", ")", "{", "if", "o", ".", "lo", ".", "Has64", "{", "n", ",", "err", "=", "fpInt64", "(", "o", ".", "...
// Seek moves the current location pointer to the new location specified by offset.
[ "Seek", "moves", "the", "current", "location", "pointer", "to", "the", "new", "location", "specified", "by", "offset", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L111-L120
train
jackc/pgx
large_objects.go
Tell
func (o *LargeObject) Tell() (n int64, err error) { if o.lo.Has64 { n, err = fpInt64(o.lo.fp.CallFn("lo_tell64", []fpArg{fpIntArg(o.fd)})) } else { var n32 int32 n32, err = fpInt32(o.lo.fp.CallFn("lo_tell", []fpArg{fpIntArg(o.fd)})) n = int64(n32) } return }
go
func (o *LargeObject) Tell() (n int64, err error) { if o.lo.Has64 { n, err = fpInt64(o.lo.fp.CallFn("lo_tell64", []fpArg{fpIntArg(o.fd)})) } else { var n32 int32 n32, err = fpInt32(o.lo.fp.CallFn("lo_tell", []fpArg{fpIntArg(o.fd)})) n = int64(n32) } return }
[ "func", "(", "o", "*", "LargeObject", ")", "Tell", "(", ")", "(", "n", "int64", ",", "err", "error", ")", "{", "if", "o", ".", "lo", ".", "Has64", "{", "n", ",", "err", "=", "fpInt64", "(", "o", ".", "lo", ".", "fp", ".", "CallFn", "(", "\"...
// Tell returns the current read or write location of the large object // descriptor.
[ "Tell", "returns", "the", "current", "read", "or", "write", "location", "of", "the", "large", "object", "descriptor", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L124-L133
train
jackc/pgx
large_objects.go
Truncate
func (o *LargeObject) Truncate(size int64) (err error) { if o.lo.Has64 { _, err = o.lo.fp.CallFn("lo_truncate64", []fpArg{fpIntArg(o.fd), fpInt64Arg(size)}) } else { _, err = o.lo.fp.CallFn("lo_truncate", []fpArg{fpIntArg(o.fd), fpIntArg(int32(size))}) } return }
go
func (o *LargeObject) Truncate(size int64) (err error) { if o.lo.Has64 { _, err = o.lo.fp.CallFn("lo_truncate64", []fpArg{fpIntArg(o.fd), fpInt64Arg(size)}) } else { _, err = o.lo.fp.CallFn("lo_truncate", []fpArg{fpIntArg(o.fd), fpIntArg(int32(size))}) } return }
[ "func", "(", "o", "*", "LargeObject", ")", "Truncate", "(", "size", "int64", ")", "(", "err", "error", ")", "{", "if", "o", ".", "lo", ".", "Has64", "{", "_", ",", "err", "=", "o", ".", "lo", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", ...
// Trunctes the large object to size.
[ "Trunctes", "the", "large", "object", "to", "size", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L136-L143
train
jackc/pgx
large_objects.go
Close
func (o *LargeObject) Close() error { _, err := o.lo.fp.CallFn("lo_close", []fpArg{fpIntArg(o.fd)}) return err }
go
func (o *LargeObject) Close() error { _, err := o.lo.fp.CallFn("lo_close", []fpArg{fpIntArg(o.fd)}) return err }
[ "func", "(", "o", "*", "LargeObject", ")", "Close", "(", ")", "error", "{", "_", ",", "err", ":=", "o", ".", "lo", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg", "{", "fpIntArg", "(", "o", ".", "fd", ")", "}", ")", "\n",...
// Close closees the large object descriptor.
[ "Close", "closees", "the", "large", "object", "descriptor", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L146-L149
train
jackc/pgx
values.go
chooseParameterFormatCode
func chooseParameterFormatCode(ci *pgtype.ConnInfo, oid pgtype.OID, arg interface{}) int16 { switch arg.(type) { case pgtype.BinaryEncoder: return BinaryFormatCode case string, *string, pgtype.TextEncoder: return TextFormatCode } if dt, ok := ci.DataTypeForOID(oid); ok { if _, ok := dt.Value.(pgtype.BinaryEncoder); ok { return BinaryFormatCode } } return TextFormatCode }
go
func chooseParameterFormatCode(ci *pgtype.ConnInfo, oid pgtype.OID, arg interface{}) int16 { switch arg.(type) { case pgtype.BinaryEncoder: return BinaryFormatCode case string, *string, pgtype.TextEncoder: return TextFormatCode } if dt, ok := ci.DataTypeForOID(oid); ok { if _, ok := dt.Value.(pgtype.BinaryEncoder); ok { return BinaryFormatCode } } return TextFormatCode }
[ "func", "chooseParameterFormatCode", "(", "ci", "*", "pgtype", ".", "ConnInfo", ",", "oid", "pgtype", ".", "OID", ",", "arg", "interface", "{", "}", ")", "int16", "{", "switch", "arg", ".", "(", "type", ")", "{", "case", "pgtype", ".", "BinaryEncoder", ...
// chooseParameterFormatCode determines the correct format code for an // argument to a prepared statement. It defaults to TextFormatCode if no // determination can be made.
[ "chooseParameterFormatCode", "determines", "the", "correct", "format", "code", "for", "an", "argument", "to", "a", "prepared", "statement", ".", "It", "defaults", "to", "TextFormatCode", "if", "no", "determination", "can", "be", "made", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/values.go#L220-L235
train
jackc/pgx
internal/sanitize/sanitize.go
SanitizeSQL
func SanitizeSQL(sql string, args ...interface{}) (string, error) { query, err := NewQuery(sql) if err != nil { return "", err } return query.Sanitize(args...) }
go
func SanitizeSQL(sql string, args ...interface{}) (string, error) { query, err := NewQuery(sql) if err != nil { return "", err } return query.Sanitize(args...) }
[ "func", "SanitizeSQL", "(", "sql", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "query", ",", "err", ":=", "NewQuery", "(", "sql", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ...
// SanitizeSQL replaces placeholder values with args. It quotes and escapes args // as necessary. This function is only safe when standard_conforming_strings is // on.
[ "SanitizeSQL", "replaces", "placeholder", "values", "with", "args", ".", "It", "quotes", "and", "escapes", "args", "as", "necessary", ".", "This", "function", "is", "only", "safe", "when", "standard_conforming_strings", "is", "on", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/internal/sanitize/sanitize.go#L231-L237
train
jackc/pgx
conn_pool.go
NewConnPool
func NewConnPool(config ConnPoolConfig) (p *ConnPool, err error) { p = new(ConnPool) p.config = config.ConnConfig p.connInfo = minimalConnInfo p.maxConnections = config.MaxConnections if p.maxConnections == 0 { p.maxConnections = 5 } if p.maxConnections < 1 { return nil, errors.New("MaxConnections must be at least 1") } p.acquireTimeout = config.AcquireTimeout if p.acquireTimeout < 0 { return nil, errors.New("AcquireTimeout must be equal to or greater than 0") } p.afterConnect = config.AfterConnect if config.LogLevel != 0 { p.logLevel = config.LogLevel } else { // Preserve pre-LogLevel behavior by defaulting to LogLevelDebug p.logLevel = LogLevelDebug } p.logger = config.Logger if p.logger == nil { p.logLevel = LogLevelNone } p.allConnections = make([]*Conn, 0, p.maxConnections) p.availableConnections = make([]*Conn, 0, p.maxConnections) p.preparedStatements = make(map[string]*PreparedStatement) p.cond = sync.NewCond(new(sync.Mutex)) // Initially establish one connection var c *Conn c, err = p.createConnection() if err != nil { return } p.allConnections = append(p.allConnections, c) p.availableConnections = append(p.availableConnections, c) p.connInfo = c.ConnInfo.DeepCopy() return }
go
func NewConnPool(config ConnPoolConfig) (p *ConnPool, err error) { p = new(ConnPool) p.config = config.ConnConfig p.connInfo = minimalConnInfo p.maxConnections = config.MaxConnections if p.maxConnections == 0 { p.maxConnections = 5 } if p.maxConnections < 1 { return nil, errors.New("MaxConnections must be at least 1") } p.acquireTimeout = config.AcquireTimeout if p.acquireTimeout < 0 { return nil, errors.New("AcquireTimeout must be equal to or greater than 0") } p.afterConnect = config.AfterConnect if config.LogLevel != 0 { p.logLevel = config.LogLevel } else { // Preserve pre-LogLevel behavior by defaulting to LogLevelDebug p.logLevel = LogLevelDebug } p.logger = config.Logger if p.logger == nil { p.logLevel = LogLevelNone } p.allConnections = make([]*Conn, 0, p.maxConnections) p.availableConnections = make([]*Conn, 0, p.maxConnections) p.preparedStatements = make(map[string]*PreparedStatement) p.cond = sync.NewCond(new(sync.Mutex)) // Initially establish one connection var c *Conn c, err = p.createConnection() if err != nil { return } p.allConnections = append(p.allConnections, c) p.availableConnections = append(p.availableConnections, c) p.connInfo = c.ConnInfo.DeepCopy() return }
[ "func", "NewConnPool", "(", "config", "ConnPoolConfig", ")", "(", "p", "*", "ConnPool", ",", "err", "error", ")", "{", "p", "=", "new", "(", "ConnPool", ")", "\n", "p", ".", "config", "=", "config", ".", "ConnConfig", "\n", "p", ".", "connInfo", "=",...
// NewConnPool creates a new ConnPool. config.ConnConfig is passed through to // Connect directly.
[ "NewConnPool", "creates", "a", "new", "ConnPool", ".", "config", ".", "ConnConfig", "is", "passed", "through", "to", "Connect", "directly", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L58-L103
train
jackc/pgx
conn_pool.go
Acquire
func (p *ConnPool) Acquire() (*Conn, error) { p.cond.L.Lock() c, err := p.acquire(nil) p.cond.L.Unlock() return c, err }
go
func (p *ConnPool) Acquire() (*Conn, error) { p.cond.L.Lock() c, err := p.acquire(nil) p.cond.L.Unlock() return c, err }
[ "func", "(", "p", "*", "ConnPool", ")", "Acquire", "(", ")", "(", "*", "Conn", ",", "error", ")", "{", "p", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "c", ",", "err", ":=", "p", ".", "acquire", "(", "nil", ")", "\n", "p", ".", "...
// Acquire takes exclusive use of a connection until it is released.
[ "Acquire", "takes", "exclusive", "use", "of", "a", "connection", "until", "it", "is", "released", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L106-L111
train
jackc/pgx
conn_pool.go
deadlinePassed
func (p *ConnPool) deadlinePassed(deadline *time.Time) bool { return deadline != nil && time.Now().After(*deadline) }
go
func (p *ConnPool) deadlinePassed(deadline *time.Time) bool { return deadline != nil && time.Now().After(*deadline) }
[ "func", "(", "p", "*", "ConnPool", ")", "deadlinePassed", "(", "deadline", "*", "time", ".", "Time", ")", "bool", "{", "return", "deadline", "!=", "nil", "&&", "time", ".", "Now", "(", ")", ".", "After", "(", "*", "deadline", ")", "\n", "}" ]
// deadlinePassed returns true if the given deadline has passed.
[ "deadlinePassed", "returns", "true", "if", "the", "given", "deadline", "has", "passed", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L114-L116
train
jackc/pgx
conn_pool.go
acquire
func (p *ConnPool) acquire(deadline *time.Time) (*Conn, error) { if p.closed { return nil, ErrClosedPool } // A connection is available // The pool works like a queue. Available connection will be returned // from the head. A new connection will be added to the tail. numAvailable := len(p.availableConnections) if numAvailable > 0 { c := p.availableConnections[0] c.poolResetCount = p.resetCount copy(p.availableConnections, p.availableConnections[1:]) p.availableConnections = p.availableConnections[:numAvailable-1] return c, nil } // Set initial timeout/deadline value. If the method (acquire) happens to // recursively call itself the deadline should retain its value. if deadline == nil && p.acquireTimeout > 0 { tmp := time.Now().Add(p.acquireTimeout) deadline = &tmp } // Make sure the deadline (if it is) has not passed yet if p.deadlinePassed(deadline) { return nil, ErrAcquireTimeout } // If there is a deadline then start a timeout timer var timer *time.Timer if deadline != nil { timer = time.AfterFunc(deadline.Sub(time.Now()), func() { p.cond.Broadcast() }) defer timer.Stop() } // No connections are available, but we can create more if len(p.allConnections)+p.inProgressConnects < p.maxConnections { // Create a new connection. // Careful here: createConnectionUnlocked() removes the current lock, // creates a connection and then locks it back. c, err := p.createConnectionUnlocked() if err != nil { return nil, err } c.poolResetCount = p.resetCount p.allConnections = append(p.allConnections, c) return c, nil } // All connections are in use and we cannot create more if p.logLevel >= LogLevelWarn { p.logger.Log(LogLevelWarn, "waiting for available connection", nil) } // Wait until there is an available connection OR room to create a new connection for len(p.availableConnections) == 0 && len(p.allConnections)+p.inProgressConnects == p.maxConnections { if p.deadlinePassed(deadline) { return nil, ErrAcquireTimeout } p.cond.Wait() } // Stop the timer so that we do not spawn it on every acquire call. if timer != nil { timer.Stop() } return p.acquire(deadline) }
go
func (p *ConnPool) acquire(deadline *time.Time) (*Conn, error) { if p.closed { return nil, ErrClosedPool } // A connection is available // The pool works like a queue. Available connection will be returned // from the head. A new connection will be added to the tail. numAvailable := len(p.availableConnections) if numAvailable > 0 { c := p.availableConnections[0] c.poolResetCount = p.resetCount copy(p.availableConnections, p.availableConnections[1:]) p.availableConnections = p.availableConnections[:numAvailable-1] return c, nil } // Set initial timeout/deadline value. If the method (acquire) happens to // recursively call itself the deadline should retain its value. if deadline == nil && p.acquireTimeout > 0 { tmp := time.Now().Add(p.acquireTimeout) deadline = &tmp } // Make sure the deadline (if it is) has not passed yet if p.deadlinePassed(deadline) { return nil, ErrAcquireTimeout } // If there is a deadline then start a timeout timer var timer *time.Timer if deadline != nil { timer = time.AfterFunc(deadline.Sub(time.Now()), func() { p.cond.Broadcast() }) defer timer.Stop() } // No connections are available, but we can create more if len(p.allConnections)+p.inProgressConnects < p.maxConnections { // Create a new connection. // Careful here: createConnectionUnlocked() removes the current lock, // creates a connection and then locks it back. c, err := p.createConnectionUnlocked() if err != nil { return nil, err } c.poolResetCount = p.resetCount p.allConnections = append(p.allConnections, c) return c, nil } // All connections are in use and we cannot create more if p.logLevel >= LogLevelWarn { p.logger.Log(LogLevelWarn, "waiting for available connection", nil) } // Wait until there is an available connection OR room to create a new connection for len(p.availableConnections) == 0 && len(p.allConnections)+p.inProgressConnects == p.maxConnections { if p.deadlinePassed(deadline) { return nil, ErrAcquireTimeout } p.cond.Wait() } // Stop the timer so that we do not spawn it on every acquire call. if timer != nil { timer.Stop() } return p.acquire(deadline) }
[ "func", "(", "p", "*", "ConnPool", ")", "acquire", "(", "deadline", "*", "time", ".", "Time", ")", "(", "*", "Conn", ",", "error", ")", "{", "if", "p", ".", "closed", "{", "return", "nil", ",", "ErrClosedPool", "\n", "}", "\n\n", "// A connection is ...
// acquire performs acquision assuming pool is already locked
[ "acquire", "performs", "acquision", "assuming", "pool", "is", "already", "locked" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L119-L188
train
jackc/pgx
conn_pool.go
Release
func (p *ConnPool) Release(conn *Conn) { if conn.ctxInProgress { panic("should never release when context is in progress") } if conn.txStatus != 'I' { conn.Exec("rollback") } if len(conn.channels) > 0 { if err := conn.Unlisten("*"); err != nil { conn.die(err) } conn.channels = make(map[string]struct{}) } conn.notifications = nil p.cond.L.Lock() if conn.poolResetCount != p.resetCount { conn.Close() p.cond.L.Unlock() p.cond.Signal() return } if conn.IsAlive() { p.availableConnections = append(p.availableConnections, conn) } else { p.removeFromAllConnections(conn) } p.cond.L.Unlock() p.cond.Signal() }
go
func (p *ConnPool) Release(conn *Conn) { if conn.ctxInProgress { panic("should never release when context is in progress") } if conn.txStatus != 'I' { conn.Exec("rollback") } if len(conn.channels) > 0 { if err := conn.Unlisten("*"); err != nil { conn.die(err) } conn.channels = make(map[string]struct{}) } conn.notifications = nil p.cond.L.Lock() if conn.poolResetCount != p.resetCount { conn.Close() p.cond.L.Unlock() p.cond.Signal() return } if conn.IsAlive() { p.availableConnections = append(p.availableConnections, conn) } else { p.removeFromAllConnections(conn) } p.cond.L.Unlock() p.cond.Signal() }
[ "func", "(", "p", "*", "ConnPool", ")", "Release", "(", "conn", "*", "Conn", ")", "{", "if", "conn", ".", "ctxInProgress", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "conn", ".", "txStatus", "!=", "'I'", "{", "conn", ".", "Exec"...
// Release gives up use of a connection.
[ "Release", "gives", "up", "use", "of", "a", "connection", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L191-L224
train
jackc/pgx
conn_pool.go
removeFromAllConnections
func (p *ConnPool) removeFromAllConnections(conn *Conn) bool { for i, c := range p.allConnections { if conn == c { p.allConnections = append(p.allConnections[:i], p.allConnections[i+1:]...) return true } } return false }
go
func (p *ConnPool) removeFromAllConnections(conn *Conn) bool { for i, c := range p.allConnections { if conn == c { p.allConnections = append(p.allConnections[:i], p.allConnections[i+1:]...) return true } } return false }
[ "func", "(", "p", "*", "ConnPool", ")", "removeFromAllConnections", "(", "conn", "*", "Conn", ")", "bool", "{", "for", "i", ",", "c", ":=", "range", "p", ".", "allConnections", "{", "if", "conn", "==", "c", "{", "p", ".", "allConnections", "=", "appe...
// removeFromAllConnections Removes the given connection from the list. // It returns true if the connection was found and removed or false otherwise.
[ "removeFromAllConnections", "Removes", "the", "given", "connection", "from", "the", "list", ".", "It", "returns", "true", "if", "the", "connection", "was", "found", "and", "removed", "or", "false", "otherwise", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L228-L236
train
jackc/pgx
conn_pool.go
Close
func (p *ConnPool) Close() { p.cond.L.Lock() defer p.cond.L.Unlock() p.closed = true for _, c := range p.availableConnections { _ = c.Close() } // This will cause any checked out connections to be closed on release p.resetCount++ }
go
func (p *ConnPool) Close() { p.cond.L.Lock() defer p.cond.L.Unlock() p.closed = true for _, c := range p.availableConnections { _ = c.Close() } // This will cause any checked out connections to be closed on release p.resetCount++ }
[ "func", "(", "p", "*", "ConnPool", ")", "Close", "(", ")", "{", "p", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n\n", "p", ".", "closed", "=", "true", "\n\n", "for", "...
// Close ends the use of a connection pool. It prevents any new connections from // being acquired and closes available underlying connections. Any acquired // connections will be closed when they are released.
[ "Close", "ends", "the", "use", "of", "a", "connection", "pool", ".", "It", "prevents", "any", "new", "connections", "from", "being", "acquired", "and", "closes", "available", "underlying", "connections", ".", "Any", "acquired", "connections", "will", "be", "cl...
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L241-L253
train
jackc/pgx
conn_pool.go
invalidateAcquired
func (p *ConnPool) invalidateAcquired() { p.resetCount++ for _, c := range p.availableConnections { c.poolResetCount = p.resetCount } p.allConnections = p.allConnections[:len(p.availableConnections)] copy(p.allConnections, p.availableConnections) }
go
func (p *ConnPool) invalidateAcquired() { p.resetCount++ for _, c := range p.availableConnections { c.poolResetCount = p.resetCount } p.allConnections = p.allConnections[:len(p.availableConnections)] copy(p.allConnections, p.availableConnections) }
[ "func", "(", "p", "*", "ConnPool", ")", "invalidateAcquired", "(", ")", "{", "p", ".", "resetCount", "++", "\n\n", "for", "_", ",", "c", ":=", "range", "p", ".", "availableConnections", "{", "c", ".", "poolResetCount", "=", "p", ".", "resetCount", "\n"...
// invalidateAcquired causes all acquired connections to be closed when released. // The pool must already be locked.
[ "invalidateAcquired", "causes", "all", "acquired", "connections", "to", "be", "closed", "when", "released", ".", "The", "pool", "must", "already", "be", "locked", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L277-L286
train
jackc/pgx
conn_pool.go
Stat
func (p *ConnPool) Stat() (s ConnPoolStat) { p.cond.L.Lock() defer p.cond.L.Unlock() s.MaxConnections = p.maxConnections s.CurrentConnections = len(p.allConnections) s.AvailableConnections = len(p.availableConnections) return }
go
func (p *ConnPool) Stat() (s ConnPoolStat) { p.cond.L.Lock() defer p.cond.L.Unlock() s.MaxConnections = p.maxConnections s.CurrentConnections = len(p.allConnections) s.AvailableConnections = len(p.availableConnections) return }
[ "func", "(", "p", "*", "ConnPool", ")", "Stat", "(", ")", "(", "s", "ConnPoolStat", ")", "{", "p", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n\n", "s", ".", "MaxConnect...
// Stat returns connection pool statistics
[ "Stat", "returns", "connection", "pool", "statistics" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L289-L297
train
jackc/pgx
conn_pool.go
Exec
func (p *ConnPool) Exec(sql string, arguments ...interface{}) (commandTag CommandTag, err error) { var c *Conn if c, err = p.Acquire(); err != nil { return } defer p.Release(c) return c.Exec(sql, arguments...) }
go
func (p *ConnPool) Exec(sql string, arguments ...interface{}) (commandTag CommandTag, err error) { var c *Conn if c, err = p.Acquire(); err != nil { return } defer p.Release(c) return c.Exec(sql, arguments...) }
[ "func", "(", "p", "*", "ConnPool", ")", "Exec", "(", "sql", "string", ",", "arguments", "...", "interface", "{", "}", ")", "(", "commandTag", "CommandTag", ",", "err", "error", ")", "{", "var", "c", "*", "Conn", "\n", "if", "c", ",", "err", "=", ...
// Exec acquires a connection, delegates the call to that connection, and releases the connection
[ "Exec", "acquires", "a", "connection", "delegates", "the", "call", "to", "that", "connection", "and", "releases", "the", "connection" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L354-L362
train
jackc/pgx
conn_pool.go
Begin
func (p *ConnPool) Begin() (*Tx, error) { return p.BeginEx(context.Background(), nil) }
go
func (p *ConnPool) Begin() (*Tx, error) { return p.BeginEx(context.Background(), nil) }
[ "func", "(", "p", "*", "ConnPool", ")", "Begin", "(", ")", "(", "*", "Tx", ",", "error", ")", "{", "return", "p", ".", "BeginEx", "(", "context", ".", "Background", "(", ")", ",", "nil", ")", "\n", "}" ]
// Begin acquires a connection and begins a transaction on it. When the // transaction is closed the connection will be automatically released.
[ "Begin", "acquires", "a", "connection", "and", "begins", "a", "transaction", "on", "it", ".", "When", "the", "transaction", "is", "closed", "the", "connection", "will", "be", "automatically", "released", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L427-L429
train
jackc/pgx
conn_pool.go
Deallocate
func (p *ConnPool) Deallocate(name string) (err error) { p.cond.L.Lock() defer p.cond.L.Unlock() for _, c := range p.availableConnections { if err := c.Deallocate(name); err != nil { return err } } p.invalidateAcquired() delete(p.preparedStatements, name) return nil }
go
func (p *ConnPool) Deallocate(name string) (err error) { p.cond.L.Lock() defer p.cond.L.Unlock() for _, c := range p.availableConnections { if err := c.Deallocate(name); err != nil { return err } } p.invalidateAcquired() delete(p.preparedStatements, name) return nil }
[ "func", "(", "p", "*", "ConnPool", ")", "Deallocate", "(", "name", "string", ")", "(", "err", "error", ")", "{", "p", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n\n", "f...
// Deallocate releases a prepared statement from all connections in the pool.
[ "Deallocate", "releases", "a", "prepared", "statement", "from", "all", "connections", "in", "the", "pool", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L498-L512
train
jackc/pgx
conn_pool.go
BeginEx
func (p *ConnPool) BeginEx(ctx context.Context, txOptions *TxOptions) (*Tx, error) { for { c, err := p.Acquire() if err != nil { return nil, err } tx, err := c.BeginEx(ctx, txOptions) if err != nil { alive := c.IsAlive() p.Release(c) // If connection is still alive then the error is not something trying // again on a new connection would fix, so just return the error. But // if the connection is dead try to acquire a new connection and try // again. if alive || ctx.Err() != nil { return nil, err } continue } tx.connPool = p return tx, nil } }
go
func (p *ConnPool) BeginEx(ctx context.Context, txOptions *TxOptions) (*Tx, error) { for { c, err := p.Acquire() if err != nil { return nil, err } tx, err := c.BeginEx(ctx, txOptions) if err != nil { alive := c.IsAlive() p.Release(c) // If connection is still alive then the error is not something trying // again on a new connection would fix, so just return the error. But // if the connection is dead try to acquire a new connection and try // again. if alive || ctx.Err() != nil { return nil, err } continue } tx.connPool = p return tx, nil } }
[ "func", "(", "p", "*", "ConnPool", ")", "BeginEx", "(", "ctx", "context", ".", "Context", ",", "txOptions", "*", "TxOptions", ")", "(", "*", "Tx", ",", "error", ")", "{", "for", "{", "c", ",", "err", ":=", "p", ".", "Acquire", "(", ")", "\n", "...
// BeginEx acquires a connection and starts a transaction with txOptions // determining the transaction mode. When the transaction is closed the // connection will be automatically released.
[ "BeginEx", "acquires", "a", "connection", "and", "starts", "a", "transaction", "with", "txOptions", "determining", "the", "transaction", "mode", ".", "When", "the", "transaction", "is", "closed", "the", "connection", "will", "be", "automatically", "released", "." ...
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L517-L542
train
jackc/pgx
conn_pool.go
CopyFrom
func (p *ConnPool) CopyFrom(tableName Identifier, columnNames []string, rowSrc CopyFromSource) (int, error) { c, err := p.Acquire() if err != nil { return 0, err } defer p.Release(c) return c.CopyFrom(tableName, columnNames, rowSrc) }
go
func (p *ConnPool) CopyFrom(tableName Identifier, columnNames []string, rowSrc CopyFromSource) (int, error) { c, err := p.Acquire() if err != nil { return 0, err } defer p.Release(c) return c.CopyFrom(tableName, columnNames, rowSrc) }
[ "func", "(", "p", "*", "ConnPool", ")", "CopyFrom", "(", "tableName", "Identifier", ",", "columnNames", "[", "]", "string", ",", "rowSrc", "CopyFromSource", ")", "(", "int", ",", "error", ")", "{", "c", ",", "err", ":=", "p", ".", "Acquire", "(", ")"...
// CopyFrom acquires a connection, delegates the call to that connection, and releases the connection
[ "CopyFrom", "acquires", "a", "connection", "delegates", "the", "call", "to", "that", "connection", "and", "releases", "the", "connection" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L545-L553
train
jackc/pgx
conn_pool.go
CopyFromReader
func (p *ConnPool) CopyFromReader(r io.Reader, sql string) (CommandTag, error) { c, err := p.Acquire() if err != nil { return "", err } defer p.Release(c) return c.CopyFromReader(r, sql) }
go
func (p *ConnPool) CopyFromReader(r io.Reader, sql string) (CommandTag, error) { c, err := p.Acquire() if err != nil { return "", err } defer p.Release(c) return c.CopyFromReader(r, sql) }
[ "func", "(", "p", "*", "ConnPool", ")", "CopyFromReader", "(", "r", "io", ".", "Reader", ",", "sql", "string", ")", "(", "CommandTag", ",", "error", ")", "{", "c", ",", "err", ":=", "p", ".", "Acquire", "(", ")", "\n", "if", "err", "!=", "nil", ...
// CopyFromReader acquires a connection, delegates the call to that connection, and releases the connection
[ "CopyFromReader", "acquires", "a", "connection", "delegates", "the", "call", "to", "that", "connection", "and", "releases", "the", "connection" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L556-L564
train
jackc/pgx
conn_pool.go
CopyToWriter
func (p *ConnPool) CopyToWriter(w io.Writer, sql string, args ...interface{}) (CommandTag, error) { c, err := p.Acquire() if err != nil { return "", err } defer p.Release(c) return c.CopyToWriter(w, sql, args...) }
go
func (p *ConnPool) CopyToWriter(w io.Writer, sql string, args ...interface{}) (CommandTag, error) { c, err := p.Acquire() if err != nil { return "", err } defer p.Release(c) return c.CopyToWriter(w, sql, args...) }
[ "func", "(", "p", "*", "ConnPool", ")", "CopyToWriter", "(", "w", "io", ".", "Writer", ",", "sql", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "CommandTag", ",", "error", ")", "{", "c", ",", "err", ":=", "p", ".", "Acquire", "(...
// CopyToWriter acquires a connection, delegates the call to that connection, and releases the connection
[ "CopyToWriter", "acquires", "a", "connection", "delegates", "the", "call", "to", "that", "connection", "and", "releases", "the", "connection" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L567-L575
train
jackc/pgx
pgtype/pguint32.go
Set
func (dst *pguint32) Set(src interface{}) error { switch value := src.(type) { case int64: if value < 0 { return errors.Errorf("%d is less than minimum value for pguint32", value) } if value > math.MaxUint32 { return errors.Errorf("%d is greater than maximum value for pguint32", value) } *dst = pguint32{Uint: uint32(value), Status: Present} case uint32: *dst = pguint32{Uint: value, Status: Present} default: return errors.Errorf("cannot convert %v to pguint32", value) } return nil }
go
func (dst *pguint32) Set(src interface{}) error { switch value := src.(type) { case int64: if value < 0 { return errors.Errorf("%d is less than minimum value for pguint32", value) } if value > math.MaxUint32 { return errors.Errorf("%d is greater than maximum value for pguint32", value) } *dst = pguint32{Uint: uint32(value), Status: Present} case uint32: *dst = pguint32{Uint: value, Status: Present} default: return errors.Errorf("cannot convert %v to pguint32", value) } return nil }
[ "func", "(", "dst", "*", "pguint32", ")", "Set", "(", "src", "interface", "{", "}", ")", "error", "{", "switch", "value", ":=", "src", ".", "(", "type", ")", "{", "case", "int64", ":", "if", "value", "<", "0", "{", "return", "errors", ".", "Error...
// Set converts from src to dst. Note that as pguint32 is not a general // number type Set does not do automatic type conversion as other number // types do.
[ "Set", "converts", "from", "src", "to", "dst", ".", "Note", "that", "as", "pguint32", "is", "not", "a", "general", "number", "type", "Set", "does", "not", "do", "automatic", "type", "conversion", "as", "other", "number", "types", "do", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/pguint32.go#L23-L40
train
jackc/pgx
pgtype/pguint32.go
AssignTo
func (src *pguint32) AssignTo(dst interface{}) error { switch v := dst.(type) { case *uint32: if src.Status == Present { *v = src.Uint } else { return errors.Errorf("cannot assign %v into %T", src, dst) } case **uint32: if src.Status == Present { n := src.Uint *v = &n } else { *v = nil } } return nil }
go
func (src *pguint32) AssignTo(dst interface{}) error { switch v := dst.(type) { case *uint32: if src.Status == Present { *v = src.Uint } else { return errors.Errorf("cannot assign %v into %T", src, dst) } case **uint32: if src.Status == Present { n := src.Uint *v = &n } else { *v = nil } } return nil }
[ "func", "(", "src", "*", "pguint32", ")", "AssignTo", "(", "dst", "interface", "{", "}", ")", "error", "{", "switch", "v", ":=", "dst", ".", "(", "type", ")", "{", "case", "*", "uint32", ":", "if", "src", ".", "Status", "==", "Present", "{", "*",...
// AssignTo assigns from src to dst. Note that as pguint32 is not a general number // type AssignTo does not do automatic type conversion as other number types do.
[ "AssignTo", "assigns", "from", "src", "to", "dst", ".", "Note", "that", "as", "pguint32", "is", "not", "a", "general", "number", "type", "AssignTo", "does", "not", "do", "automatic", "type", "conversion", "as", "other", "number", "types", "do", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/pguint32.go#L55-L73
train
jackc/pgx
stdlib/opendbpool.go
OpenDBFromPool
func OpenDBFromPool(pool *pgx.ConnPool, opts ...OptionOpenDBFromPool) *sql.DB { c := poolConnector{ pool: pool, driver: pgxDriver, } for _, opt := range opts { opt(&c) } return sql.OpenDB(c) }
go
func OpenDBFromPool(pool *pgx.ConnPool, opts ...OptionOpenDBFromPool) *sql.DB { c := poolConnector{ pool: pool, driver: pgxDriver, } for _, opt := range opts { opt(&c) } return sql.OpenDB(c) }
[ "func", "OpenDBFromPool", "(", "pool", "*", "pgx", ".", "ConnPool", ",", "opts", "...", "OptionOpenDBFromPool", ")", "*", "sql", ".", "DB", "{", "c", ":=", "poolConnector", "{", "pool", ":", "pool", ",", "driver", ":", "pgxDriver", ",", "}", "\n\n", "f...
// OpenDBFromPool create a sql.DB connection from a pgx.ConnPool
[ "OpenDBFromPool", "create", "a", "sql", ".", "DB", "connection", "from", "a", "pgx", ".", "ConnPool" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/stdlib/opendbpool.go#L24-L35
train
jackc/pgx
pgtype/bytea.go
DecodeText
func (dst *Bytea) DecodeText(ci *ConnInfo, src []byte) error { if src == nil { *dst = Bytea{Status: Null} return nil } if len(src) < 2 || src[0] != '\\' || src[1] != 'x' { return errors.Errorf("invalid hex format") } buf := make([]byte, (len(src)-2)/2) _, err := hex.Decode(buf, src[2:]) if err != nil { return err } *dst = Bytea{Bytes: buf, Status: Present} return nil }
go
func (dst *Bytea) DecodeText(ci *ConnInfo, src []byte) error { if src == nil { *dst = Bytea{Status: Null} return nil } if len(src) < 2 || src[0] != '\\' || src[1] != 'x' { return errors.Errorf("invalid hex format") } buf := make([]byte, (len(src)-2)/2) _, err := hex.Decode(buf, src[2:]) if err != nil { return err } *dst = Bytea{Bytes: buf, Status: Present} return nil }
[ "func", "(", "dst", "*", "Bytea", ")", "DecodeText", "(", "ci", "*", "ConnInfo", ",", "src", "[", "]", "byte", ")", "error", "{", "if", "src", "==", "nil", "{", "*", "dst", "=", "Bytea", "{", "Status", ":", "Null", "}", "\n", "return", "nil", "...
// DecodeText only supports the hex format. This has been the default since // PostgreSQL 9.0.
[ "DecodeText", "only", "supports", "the", "hex", "format", ".", "This", "has", "been", "the", "default", "since", "PostgreSQL", "9", ".", "0", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/bytea.go#L72-L90
train
jackc/pgx
stdlib/opendb.go
OptionAfterConnect
func OptionAfterConnect(ac func(*pgx.Conn) error) OptionOpenDB { return func(dc *connector) { dc.AfterConnect = ac } }
go
func OptionAfterConnect(ac func(*pgx.Conn) error) OptionOpenDB { return func(dc *connector) { dc.AfterConnect = ac } }
[ "func", "OptionAfterConnect", "(", "ac", "func", "(", "*", "pgx", ".", "Conn", ")", "error", ")", "OptionOpenDB", "{", "return", "func", "(", "dc", "*", "connector", ")", "{", "dc", ".", "AfterConnect", "=", "ac", "\n", "}", "\n", "}" ]
// OptionAfterConnect provide a callback for after connect.
[ "OptionAfterConnect", "provide", "a", "callback", "for", "after", "connect", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/stdlib/opendb.go#L17-L21
train
parnurzeal/gorequest
gorequest_client_go1.3.go
safeModifyHttpClient
func (s *SuperAgent) safeModifyHttpClient() { if !s.isClone { return } oldClient := s.Client s.Client = &http.Client{} s.Client.Jar = oldClient.Jar s.Client.Transport = oldClient.Transport s.Client.Timeout = oldClient.Timeout s.Client.CheckRedirect = oldClient.CheckRedirect }
go
func (s *SuperAgent) safeModifyHttpClient() { if !s.isClone { return } oldClient := s.Client s.Client = &http.Client{} s.Client.Jar = oldClient.Jar s.Client.Transport = oldClient.Transport s.Client.Timeout = oldClient.Timeout s.Client.CheckRedirect = oldClient.CheckRedirect }
[ "func", "(", "s", "*", "SuperAgent", ")", "safeModifyHttpClient", "(", ")", "{", "if", "!", "s", ".", "isClone", "{", "return", "\n", "}", "\n", "oldClient", ":=", "s", ".", "Client", "\n", "s", ".", "Client", "=", "&", "http", ".", "Client", "{", ...
// we don't want to mess up other clones when we modify the client.. // so unfortantely we need to create a new client
[ "we", "don", "t", "want", "to", "mess", "up", "other", "clones", "when", "we", "modify", "the", "client", "..", "so", "unfortantely", "we", "need", "to", "create", "a", "new", "client" ]
b0604454e3c35c21d4c86e4771dc1e24c896cdd3
https://github.com/parnurzeal/gorequest/blob/b0604454e3c35c21d4c86e4771dc1e24c896cdd3/gorequest_client_go1.3.go#L13-L23
train
parnurzeal/gorequest
gorequest_transport_go1.7.go
safeModifyTransport
func (s *SuperAgent) safeModifyTransport() { if !s.isClone { return } oldTransport := s.Transport s.Transport = &http.Transport{ Proxy: oldTransport.Proxy, Dial: oldTransport.Dial, DialTLS: oldTransport.DialTLS, TLSClientConfig: oldTransport.TLSClientConfig, TLSHandshakeTimeout: oldTransport.TLSHandshakeTimeout, DisableKeepAlives: oldTransport.DisableKeepAlives, DisableCompression: oldTransport.DisableCompression, MaxIdleConns: oldTransport.MaxIdleConns, MaxIdleConnsPerHost: oldTransport.MaxIdleConnsPerHost, ResponseHeaderTimeout: oldTransport.ResponseHeaderTimeout, ExpectContinueTimeout: oldTransport.ExpectContinueTimeout, TLSNextProto: oldTransport.TLSNextProto, // new in go1.7 DialContext: oldTransport.DialContext, IdleConnTimeout: oldTransport.IdleConnTimeout, MaxResponseHeaderBytes: oldTransport.MaxResponseHeaderBytes, } }
go
func (s *SuperAgent) safeModifyTransport() { if !s.isClone { return } oldTransport := s.Transport s.Transport = &http.Transport{ Proxy: oldTransport.Proxy, Dial: oldTransport.Dial, DialTLS: oldTransport.DialTLS, TLSClientConfig: oldTransport.TLSClientConfig, TLSHandshakeTimeout: oldTransport.TLSHandshakeTimeout, DisableKeepAlives: oldTransport.DisableKeepAlives, DisableCompression: oldTransport.DisableCompression, MaxIdleConns: oldTransport.MaxIdleConns, MaxIdleConnsPerHost: oldTransport.MaxIdleConnsPerHost, ResponseHeaderTimeout: oldTransport.ResponseHeaderTimeout, ExpectContinueTimeout: oldTransport.ExpectContinueTimeout, TLSNextProto: oldTransport.TLSNextProto, // new in go1.7 DialContext: oldTransport.DialContext, IdleConnTimeout: oldTransport.IdleConnTimeout, MaxResponseHeaderBytes: oldTransport.MaxResponseHeaderBytes, } }
[ "func", "(", "s", "*", "SuperAgent", ")", "safeModifyTransport", "(", ")", "{", "if", "!", "s", ".", "isClone", "{", "return", "\n", "}", "\n", "oldTransport", ":=", "s", ".", "Transport", "\n", "s", ".", "Transport", "=", "&", "http", ".", "Transpor...
// does a shallow clone of the transport
[ "does", "a", "shallow", "clone", "of", "the", "transport" ]
b0604454e3c35c21d4c86e4771dc1e24c896cdd3
https://github.com/parnurzeal/gorequest/blob/b0604454e3c35c21d4c86e4771dc1e24c896cdd3/gorequest_transport_go1.7.go#L11-L34
train
parnurzeal/gorequest
gorequest.go
New
func New() *SuperAgent { cookiejarOptions := cookiejar.Options{ PublicSuffixList: publicsuffix.List, } jar, _ := cookiejar.New(&cookiejarOptions) debug := os.Getenv("GOREQUEST_DEBUG") == "1" s := &SuperAgent{ TargetType: TypeJSON, Data: make(map[string]interface{}), Header: http.Header{}, RawString: "", SliceData: []interface{}{}, FormData: url.Values{}, QueryData: url.Values{}, FileData: make([]File, 0), BounceToRawString: false, Client: &http.Client{Jar: jar}, Transport: &http.Transport{}, Cookies: make([]*http.Cookie, 0), Errors: nil, BasicAuth: struct{ Username, Password string }{}, Debug: debug, CurlCommand: false, logger: log.New(os.Stderr, "[gorequest]", log.LstdFlags), isClone: false, } // disable keep alives by default, see this issue https://github.com/parnurzeal/gorequest/issues/75 s.Transport.DisableKeepAlives = true return s }
go
func New() *SuperAgent { cookiejarOptions := cookiejar.Options{ PublicSuffixList: publicsuffix.List, } jar, _ := cookiejar.New(&cookiejarOptions) debug := os.Getenv("GOREQUEST_DEBUG") == "1" s := &SuperAgent{ TargetType: TypeJSON, Data: make(map[string]interface{}), Header: http.Header{}, RawString: "", SliceData: []interface{}{}, FormData: url.Values{}, QueryData: url.Values{}, FileData: make([]File, 0), BounceToRawString: false, Client: &http.Client{Jar: jar}, Transport: &http.Transport{}, Cookies: make([]*http.Cookie, 0), Errors: nil, BasicAuth: struct{ Username, Password string }{}, Debug: debug, CurlCommand: false, logger: log.New(os.Stderr, "[gorequest]", log.LstdFlags), isClone: false, } // disable keep alives by default, see this issue https://github.com/parnurzeal/gorequest/issues/75 s.Transport.DisableKeepAlives = true return s }
[ "func", "New", "(", ")", "*", "SuperAgent", "{", "cookiejarOptions", ":=", "cookiejar", ".", "Options", "{", "PublicSuffixList", ":", "publicsuffix", ".", "List", ",", "}", "\n", "jar", ",", "_", ":=", "cookiejar", ".", "New", "(", "&", "cookiejarOptions",...
// Used to create a new SuperAgent object.
[ "Used", "to", "create", "a", "new", "SuperAgent", "object", "." ]
b0604454e3c35c21d4c86e4771dc1e24c896cdd3
https://github.com/parnurzeal/gorequest/blob/b0604454e3c35c21d4c86e4771dc1e24c896cdd3/gorequest.go#L99-L130
train
parnurzeal/gorequest
gorequest.go
copyRetryable
func copyRetryable(old superAgentRetryable) superAgentRetryable { newRetryable := old newRetryable.RetryableStatus = make([]int, len(old.RetryableStatus)) for i := range old.RetryableStatus { newRetryable.RetryableStatus[i] = old.RetryableStatus[i] } return newRetryable }
go
func copyRetryable(old superAgentRetryable) superAgentRetryable { newRetryable := old newRetryable.RetryableStatus = make([]int, len(old.RetryableStatus)) for i := range old.RetryableStatus { newRetryable.RetryableStatus[i] = old.RetryableStatus[i] } return newRetryable }
[ "func", "copyRetryable", "(", "old", "superAgentRetryable", ")", "superAgentRetryable", "{", "newRetryable", ":=", "old", "\n", "newRetryable", ".", "RetryableStatus", "=", "make", "(", "[", "]", "int", ",", "len", "(", "old", ".", "RetryableStatus", ")", ")",...
// just need to change the array pointer?
[ "just", "need", "to", "change", "the", "array", "pointer?" ]
b0604454e3c35c21d4c86e4771dc1e24c896cdd3
https://github.com/parnurzeal/gorequest/blob/b0604454e3c35c21d4c86e4771dc1e24c896cdd3/gorequest.go#L194-L201
train
parnurzeal/gorequest
gorequest.go
SetCurlCommand
func (s *SuperAgent) SetCurlCommand(enable bool) *SuperAgent { s.CurlCommand = enable return s }
go
func (s *SuperAgent) SetCurlCommand(enable bool) *SuperAgent { s.CurlCommand = enable return s }
[ "func", "(", "s", "*", "SuperAgent", ")", "SetCurlCommand", "(", "enable", "bool", ")", "*", "SuperAgent", "{", "s", ".", "CurlCommand", "=", "enable", "\n", "return", "s", "\n", "}" ]
// Enable the curlcommand mode which display a CURL command line
[ "Enable", "the", "curlcommand", "mode", "which", "display", "a", "CURL", "command", "line" ]
b0604454e3c35c21d4c86e4771dc1e24c896cdd3
https://github.com/parnurzeal/gorequest/blob/b0604454e3c35c21d4c86e4771dc1e24c896cdd3/gorequest.go#L248-L251
train
parnurzeal/gorequest
gorequest.go
SetDoNotClearSuperAgent
func (s *SuperAgent) SetDoNotClearSuperAgent(enable bool) *SuperAgent { s.DoNotClearSuperAgent = enable return s }
go
func (s *SuperAgent) SetDoNotClearSuperAgent(enable bool) *SuperAgent { s.DoNotClearSuperAgent = enable return s }
[ "func", "(", "s", "*", "SuperAgent", ")", "SetDoNotClearSuperAgent", "(", "enable", "bool", ")", "*", "SuperAgent", "{", "s", ".", "DoNotClearSuperAgent", "=", "enable", "\n", "return", "s", "\n", "}" ]
// Enable the DoNotClear mode for not clearing super agent and reuse for the next request
[ "Enable", "the", "DoNotClear", "mode", "for", "not", "clearing", "super", "agent", "and", "reuse", "for", "the", "next", "request" ]
b0604454e3c35c21d4c86e4771dc1e24c896cdd3
https://github.com/parnurzeal/gorequest/blob/b0604454e3c35c21d4c86e4771dc1e24c896cdd3/gorequest.go#L254-L257
train
parnurzeal/gorequest
gorequest.go
ClearSuperAgent
func (s *SuperAgent) ClearSuperAgent() { if s.DoNotClearSuperAgent { return } s.Url = "" s.Method = "" s.Header = http.Header{} s.Data = make(map[string]interface{}) s.SliceData = []interface{}{} s.FormData = url.Values{} s.QueryData = url.Values{} s.FileData = make([]File, 0) s.BounceToRawString = false s.RawString = "" s.ForceType = "" s.TargetType = TypeJSON s.Cookies = make([]*http.Cookie, 0) s.Errors = nil }
go
func (s *SuperAgent) ClearSuperAgent() { if s.DoNotClearSuperAgent { return } s.Url = "" s.Method = "" s.Header = http.Header{} s.Data = make(map[string]interface{}) s.SliceData = []interface{}{} s.FormData = url.Values{} s.QueryData = url.Values{} s.FileData = make([]File, 0) s.BounceToRawString = false s.RawString = "" s.ForceType = "" s.TargetType = TypeJSON s.Cookies = make([]*http.Cookie, 0) s.Errors = nil }
[ "func", "(", "s", "*", "SuperAgent", ")", "ClearSuperAgent", "(", ")", "{", "if", "s", ".", "DoNotClearSuperAgent", "{", "return", "\n", "}", "\n", "s", ".", "Url", "=", "\"", "\"", "\n", "s", ".", "Method", "=", "\"", "\"", "\n", "s", ".", "Head...
// Clear SuperAgent data for another new request.
[ "Clear", "SuperAgent", "data", "for", "another", "new", "request", "." ]
b0604454e3c35c21d4c86e4771dc1e24c896cdd3
https://github.com/parnurzeal/gorequest/blob/b0604454e3c35c21d4c86e4771dc1e24c896cdd3/gorequest.go#L265-L283
train
parnurzeal/gorequest
gorequest.go
CustomMethod
func (s *SuperAgent) CustomMethod(method, targetUrl string) *SuperAgent { switch method { case POST: return s.Post(targetUrl) case GET: return s.Get(targetUrl) case HEAD: return s.Head(targetUrl) case PUT: return s.Put(targetUrl) case DELETE: return s.Delete(targetUrl) case PATCH: return s.Patch(targetUrl) case OPTIONS: return s.Options(targetUrl) default: s.ClearSuperAgent() s.Method = method s.Url = targetUrl s.Errors = nil return s } }
go
func (s *SuperAgent) CustomMethod(method, targetUrl string) *SuperAgent { switch method { case POST: return s.Post(targetUrl) case GET: return s.Get(targetUrl) case HEAD: return s.Head(targetUrl) case PUT: return s.Put(targetUrl) case DELETE: return s.Delete(targetUrl) case PATCH: return s.Patch(targetUrl) case OPTIONS: return s.Options(targetUrl) default: s.ClearSuperAgent() s.Method = method s.Url = targetUrl s.Errors = nil return s } }
[ "func", "(", "s", "*", "SuperAgent", ")", "CustomMethod", "(", "method", ",", "targetUrl", "string", ")", "*", "SuperAgent", "{", "switch", "method", "{", "case", "POST", ":", "return", "s", ".", "Post", "(", "targetUrl", ")", "\n", "case", "GET", ":",...
// Just a wrapper to initialize SuperAgent instance by method string
[ "Just", "a", "wrapper", "to", "initialize", "SuperAgent", "instance", "by", "method", "string" ]
b0604454e3c35c21d4c86e4771dc1e24c896cdd3
https://github.com/parnurzeal/gorequest/blob/b0604454e3c35c21d4c86e4771dc1e24c896cdd3/gorequest.go#L286-L309
train
parnurzeal/gorequest
gorequest.go
RedirectPolicy
func (s *SuperAgent) RedirectPolicy(policy func(req Request, via []Request) error) *SuperAgent { s.safeModifyHttpClient() s.Client.CheckRedirect = func(r *http.Request, v []*http.Request) error { vv := make([]Request, len(v)) for i, r := range v { vv[i] = Request(r) } return policy(Request(r), vv) } return s }
go
func (s *SuperAgent) RedirectPolicy(policy func(req Request, via []Request) error) *SuperAgent { s.safeModifyHttpClient() s.Client.CheckRedirect = func(r *http.Request, v []*http.Request) error { vv := make([]Request, len(v)) for i, r := range v { vv[i] = Request(r) } return policy(Request(r), vv) } return s }
[ "func", "(", "s", "*", "SuperAgent", ")", "RedirectPolicy", "(", "policy", "func", "(", "req", "Request", ",", "via", "[", "]", "Request", ")", "error", ")", "*", "SuperAgent", "{", "s", ".", "safeModifyHttpClient", "(", ")", "\n", "s", ".", "Client", ...
// RedirectPolicy accepts a function to define how to handle redirects. If the // policy function returns an error, the next Request is not made and the previous // request is returned. // // The policy function's arguments are the Request about to be made and the // past requests in order of oldest first.
[ "RedirectPolicy", "accepts", "a", "function", "to", "define", "how", "to", "handle", "redirects", ".", "If", "the", "policy", "function", "returns", "an", "error", "the", "next", "Request", "is", "not", "made", "and", "the", "previous", "request", "is", "ret...
b0604454e3c35c21d4c86e4771dc1e24c896cdd3
https://github.com/parnurzeal/gorequest/blob/b0604454e3c35c21d4c86e4771dc1e24c896cdd3/gorequest.go#L649-L659
train
parnurzeal/gorequest
gorequest.go
EndStruct
func (s *SuperAgent) EndStruct(v interface{}, callback ...func(response Response, v interface{}, body []byte, errs []error)) (Response, []byte, []error) { resp, body, errs := s.EndBytes() if errs != nil { return nil, body, errs } err := json.Unmarshal(body, &v) if err != nil { s.Errors = append(s.Errors, err) return resp, body, s.Errors } respCallback := *resp if len(callback) != 0 { callback[0](&respCallback, v, body, s.Errors) } return resp, body, nil }
go
func (s *SuperAgent) EndStruct(v interface{}, callback ...func(response Response, v interface{}, body []byte, errs []error)) (Response, []byte, []error) { resp, body, errs := s.EndBytes() if errs != nil { return nil, body, errs } err := json.Unmarshal(body, &v) if err != nil { s.Errors = append(s.Errors, err) return resp, body, s.Errors } respCallback := *resp if len(callback) != 0 { callback[0](&respCallback, v, body, s.Errors) } return resp, body, nil }
[ "func", "(", "s", "*", "SuperAgent", ")", "EndStruct", "(", "v", "interface", "{", "}", ",", "callback", "...", "func", "(", "response", "Response", ",", "v", "interface", "{", "}", ",", "body", "[", "]", "byte", ",", "errs", "[", "]", "error", ")"...
// EndStruct should be used when you want the body as a struct. The callbacks work the same way as with `End`, except that a struct is used instead of a string.
[ "EndStruct", "should", "be", "used", "when", "you", "want", "the", "body", "as", "a", "struct", ".", "The", "callbacks", "work", "the", "same", "way", "as", "with", "End", "except", "that", "a", "struct", "is", "used", "instead", "of", "a", "string", "...
b0604454e3c35c21d4c86e4771dc1e24c896cdd3
https://github.com/parnurzeal/gorequest/blob/b0604454e3c35c21d4c86e4771dc1e24c896cdd3/gorequest.go#L1124-L1139
train
parnurzeal/gorequest
gorequest.go
AsCurlCommand
func (s *SuperAgent) AsCurlCommand() (string, error) { req, err := s.MakeRequest() if err != nil { return "", err } cmd, err := http2curl.GetCurlCommand(req) if err != nil { return "", err } return cmd.String(), nil }
go
func (s *SuperAgent) AsCurlCommand() (string, error) { req, err := s.MakeRequest() if err != nil { return "", err } cmd, err := http2curl.GetCurlCommand(req) if err != nil { return "", err } return cmd.String(), nil }
[ "func", "(", "s", "*", "SuperAgent", ")", "AsCurlCommand", "(", ")", "(", "string", ",", "error", ")", "{", "req", ",", "err", ":=", "s", ".", "MakeRequest", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", ...
// AsCurlCommand returns a string representing the runnable `curl' command // version of the request.
[ "AsCurlCommand", "returns", "a", "string", "representing", "the", "runnable", "curl", "command", "version", "of", "the", "request", "." ]
b0604454e3c35c21d4c86e4771dc1e24c896cdd3
https://github.com/parnurzeal/gorequest/blob/b0604454e3c35c21d4c86e4771dc1e24c896cdd3/gorequest.go#L1405-L1415
train
yuin/gopher-lua
table.go
Len
func (tb *LTable) Len() int { if tb.array == nil { return 0 } var prev LValue = LNil for i := len(tb.array) - 1; i >= 0; i-- { v := tb.array[i] if prev == LNil && v != LNil { return i + 1 } prev = v } return 0 }
go
func (tb *LTable) Len() int { if tb.array == nil { return 0 } var prev LValue = LNil for i := len(tb.array) - 1; i >= 0; i-- { v := tb.array[i] if prev == LNil && v != LNil { return i + 1 } prev = v } return 0 }
[ "func", "(", "tb", "*", "LTable", ")", "Len", "(", ")", "int", "{", "if", "tb", ".", "array", "==", "nil", "{", "return", "0", "\n", "}", "\n", "var", "prev", "LValue", "=", "LNil", "\n", "for", "i", ":=", "len", "(", "tb", ".", "array", ")",...
// Len returns length of this LTable.
[ "Len", "returns", "length", "of", "this", "LTable", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/table.go#L50-L63
train
yuin/gopher-lua
table.go
Append
func (tb *LTable) Append(value LValue) { if value == LNil { return } if tb.array == nil { tb.array = make([]LValue, 0, defaultArrayCap) } tb.array = append(tb.array, value) }
go
func (tb *LTable) Append(value LValue) { if value == LNil { return } if tb.array == nil { tb.array = make([]LValue, 0, defaultArrayCap) } tb.array = append(tb.array, value) }
[ "func", "(", "tb", "*", "LTable", ")", "Append", "(", "value", "LValue", ")", "{", "if", "value", "==", "LNil", "{", "return", "\n", "}", "\n", "if", "tb", ".", "array", "==", "nil", "{", "tb", ".", "array", "=", "make", "(", "[", "]", "LValue"...
// Append appends a given LValue to this LTable.
[ "Append", "appends", "a", "given", "LValue", "to", "this", "LTable", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/table.go#L66-L74
train
yuin/gopher-lua
table.go
Insert
func (tb *LTable) Insert(i int, value LValue) { if tb.array == nil { tb.array = make([]LValue, 0, defaultArrayCap) } if i > len(tb.array) { tb.RawSetInt(i, value) return } if i <= 0 { tb.RawSet(LNumber(i), value) return } i -= 1 tb.array = append(tb.array, LNil) copy(tb.array[i+1:], tb.array[i:]) tb.array[i] = value }
go
func (tb *LTable) Insert(i int, value LValue) { if tb.array == nil { tb.array = make([]LValue, 0, defaultArrayCap) } if i > len(tb.array) { tb.RawSetInt(i, value) return } if i <= 0 { tb.RawSet(LNumber(i), value) return } i -= 1 tb.array = append(tb.array, LNil) copy(tb.array[i+1:], tb.array[i:]) tb.array[i] = value }
[ "func", "(", "tb", "*", "LTable", ")", "Insert", "(", "i", "int", ",", "value", "LValue", ")", "{", "if", "tb", ".", "array", "==", "nil", "{", "tb", ".", "array", "=", "make", "(", "[", "]", "LValue", ",", "0", ",", "defaultArrayCap", ")", "\n...
// Insert inserts a given LValue at position `i` in this table.
[ "Insert", "inserts", "a", "given", "LValue", "at", "position", "i", "in", "this", "table", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/table.go#L77-L93
train
yuin/gopher-lua
table.go
MaxN
func (tb *LTable) MaxN() int { if tb.array == nil { return 0 } for i := len(tb.array) - 1; i >= 0; i-- { if tb.array[i] != LNil { return i + 1 } } return 0 }
go
func (tb *LTable) MaxN() int { if tb.array == nil { return 0 } for i := len(tb.array) - 1; i >= 0; i-- { if tb.array[i] != LNil { return i + 1 } } return 0 }
[ "func", "(", "tb", "*", "LTable", ")", "MaxN", "(", ")", "int", "{", "if", "tb", ".", "array", "==", "nil", "{", "return", "0", "\n", "}", "\n", "for", "i", ":=", "len", "(", "tb", ".", "array", ")", "-", "1", ";", "i", ">=", "0", ";", "i...
// MaxN returns a maximum number key that nil value does not exist before it.
[ "MaxN", "returns", "a", "maximum", "number", "key", "that", "nil", "value", "does", "not", "exist", "before", "it", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/table.go#L96-L106
train
yuin/gopher-lua
table.go
Remove
func (tb *LTable) Remove(pos int) LValue { if tb.array == nil { return LNil } larray := len(tb.array) if larray == 0 { return LNil } i := pos - 1 oldval := LNil switch { case i >= larray: // nothing to do case i == larray-1 || i < 0: oldval = tb.array[larray-1] tb.array = tb.array[:larray-1] default: oldval = tb.array[i] copy(tb.array[i:], tb.array[i+1:]) tb.array[larray-1] = nil tb.array = tb.array[:larray-1] } return oldval }
go
func (tb *LTable) Remove(pos int) LValue { if tb.array == nil { return LNil } larray := len(tb.array) if larray == 0 { return LNil } i := pos - 1 oldval := LNil switch { case i >= larray: // nothing to do case i == larray-1 || i < 0: oldval = tb.array[larray-1] tb.array = tb.array[:larray-1] default: oldval = tb.array[i] copy(tb.array[i:], tb.array[i+1:]) tb.array[larray-1] = nil tb.array = tb.array[:larray-1] } return oldval }
[ "func", "(", "tb", "*", "LTable", ")", "Remove", "(", "pos", "int", ")", "LValue", "{", "if", "tb", ".", "array", "==", "nil", "{", "return", "LNil", "\n", "}", "\n", "larray", ":=", "len", "(", "tb", ".", "array", ")", "\n", "if", "larray", "=...
// Remove removes from this table the element at a given position.
[ "Remove", "removes", "from", "this", "table", "the", "element", "at", "a", "given", "position", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/table.go#L109-L132
train
yuin/gopher-lua
table.go
ForEach
func (tb *LTable) ForEach(cb func(LValue, LValue)) { if tb.array != nil { for i, v := range tb.array { if v != LNil { cb(LNumber(i+1), v) } } } if tb.strdict != nil { for k, v := range tb.strdict { if v != LNil { cb(LString(k), v) } } } if tb.dict != nil { for k, v := range tb.dict { if v != LNil { cb(k, v) } } } }
go
func (tb *LTable) ForEach(cb func(LValue, LValue)) { if tb.array != nil { for i, v := range tb.array { if v != LNil { cb(LNumber(i+1), v) } } } if tb.strdict != nil { for k, v := range tb.strdict { if v != LNil { cb(LString(k), v) } } } if tb.dict != nil { for k, v := range tb.dict { if v != LNil { cb(k, v) } } } }
[ "func", "(", "tb", "*", "LTable", ")", "ForEach", "(", "cb", "func", "(", "LValue", ",", "LValue", ")", ")", "{", "if", "tb", ".", "array", "!=", "nil", "{", "for", "i", ",", "v", ":=", "range", "tb", ".", "array", "{", "if", "v", "!=", "LNil...
// ForEach iterates over this table of elements, yielding each in turn to a given function.
[ "ForEach", "iterates", "over", "this", "table", "of", "elements", "yielding", "each", "in", "turn", "to", "a", "given", "function", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/table.go#L316-L338
train
yuin/gopher-lua
linit.go
OpenLibs
func (ls *LState) OpenLibs() { // NB: Map iteration order in Go is deliberately randomised, so must open Load/Base // prior to iterating. for _, lib := range luaLibs { ls.Push(ls.NewFunction(lib.libFunc)) ls.Push(LString(lib.libName)) ls.Call(1, 0) } }
go
func (ls *LState) OpenLibs() { // NB: Map iteration order in Go is deliberately randomised, so must open Load/Base // prior to iterating. for _, lib := range luaLibs { ls.Push(ls.NewFunction(lib.libFunc)) ls.Push(LString(lib.libName)) ls.Call(1, 0) } }
[ "func", "(", "ls", "*", "LState", ")", "OpenLibs", "(", ")", "{", "// NB: Map iteration order in Go is deliberately randomised, so must open Load/Base", "// prior to iterating.", "for", "_", ",", "lib", ":=", "range", "luaLibs", "{", "ls", ".", "Push", "(", "ls", "....
// OpenLibs loads the built-in libraries. It is equivalent to running OpenLoad, // then OpenBase, then iterating over the other OpenXXX functions in any order.
[ "OpenLibs", "loads", "the", "built", "-", "in", "libraries", ".", "It", "is", "equivalent", "to", "running", "OpenLoad", "then", "OpenBase", "then", "iterating", "over", "the", "other", "OpenXXX", "functions", "in", "any", "order", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/linit.go#L46-L54
train
yuin/gopher-lua
_state.go
NewThread
func (ls *LState) NewThread() (*LState, context.CancelFunc) { thread := newLState(ls.Options) thread.G = ls.G thread.Env = ls.Env var f context.CancelFunc = nil if ls.ctx != nil { thread.mainLoop = mainLoopWithContext thread.ctx, f = context.WithCancel(ls.ctx) } return thread, f }
go
func (ls *LState) NewThread() (*LState, context.CancelFunc) { thread := newLState(ls.Options) thread.G = ls.G thread.Env = ls.Env var f context.CancelFunc = nil if ls.ctx != nil { thread.mainLoop = mainLoopWithContext thread.ctx, f = context.WithCancel(ls.ctx) } return thread, f }
[ "func", "(", "ls", "*", "LState", ")", "NewThread", "(", ")", "(", "*", "LState", ",", "context", ".", "CancelFunc", ")", "{", "thread", ":=", "newLState", "(", "ls", ".", "Options", ")", "\n", "thread", ".", "G", "=", "ls", ".", "G", "\n", "thre...
// NewThread returns a new LState that shares with the original state all global objects. // If the original state has context.Context, the new state has a new child context of the original state and this function returns its cancel function.
[ "NewThread", "returns", "a", "new", "LState", "that", "shares", "with", "the", "original", "state", "all", "global", "objects", ".", "If", "the", "original", "state", "has", "context", ".", "Context", "the", "new", "state", "has", "a", "new", "child", "con...
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/_state.go#L1121-L1131
train
yuin/gopher-lua
_state.go
SetContext
func (ls *LState) SetContext(ctx context.Context) { ls.mainLoop = mainLoopWithContext ls.ctx = ctx }
go
func (ls *LState) SetContext(ctx context.Context) { ls.mainLoop = mainLoopWithContext ls.ctx = ctx }
[ "func", "(", "ls", "*", "LState", ")", "SetContext", "(", "ctx", "context", ".", "Context", ")", "{", "ls", ".", "mainLoop", "=", "mainLoopWithContext", "\n", "ls", ".", "ctx", "=", "ctx", "\n", "}" ]
// SetContext set a context ctx to this LState. The provided ctx must be non-nil.
[ "SetContext", "set", "a", "context", "ctx", "to", "this", "LState", ".", "The", "provided", "ctx", "must", "be", "non", "-", "nil", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/_state.go#L1760-L1763
train
yuin/gopher-lua
_state.go
RemoveContext
func (ls *LState) RemoveContext() context.Context { oldctx := ls.ctx ls.mainLoop = mainLoop ls.ctx = nil return oldctx }
go
func (ls *LState) RemoveContext() context.Context { oldctx := ls.ctx ls.mainLoop = mainLoop ls.ctx = nil return oldctx }
[ "func", "(", "ls", "*", "LState", ")", "RemoveContext", "(", ")", "context", ".", "Context", "{", "oldctx", ":=", "ls", ".", "ctx", "\n", "ls", ".", "mainLoop", "=", "mainLoop", "\n", "ls", ".", "ctx", "=", "nil", "\n", "return", "oldctx", "\n", "}...
// RemoveContext removes the context associated with this LState and returns this context.
[ "RemoveContext", "removes", "the", "context", "associated", "with", "this", "LState", "and", "returns", "this", "context", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/_state.go#L1771-L1776
train
yuin/gopher-lua
_state.go
ToChannel
func (ls *LState) ToChannel(n int) chan LValue { if lv, ok := ls.Get(n).(LChannel); ok { return (chan LValue)(lv) } return nil }
go
func (ls *LState) ToChannel(n int) chan LValue { if lv, ok := ls.Get(n).(LChannel); ok { return (chan LValue)(lv) } return nil }
[ "func", "(", "ls", "*", "LState", ")", "ToChannel", "(", "n", "int", ")", "chan", "LValue", "{", "if", "lv", ",", "ok", ":=", "ls", ".", "Get", "(", "n", ")", ".", "(", "LChannel", ")", ";", "ok", "{", "return", "(", "chan", "LValue", ")", "(...
// Converts the Lua value at the given acceptable index to the chan LValue.
[ "Converts", "the", "Lua", "value", "at", "the", "given", "acceptable", "index", "to", "the", "chan", "LValue", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/_state.go#L1779-L1784
train
yuin/gopher-lua
value.go
LVAsString
func LVAsString(v LValue) string { switch sn := v.(type) { case LString, LNumber: return sn.String() default: return "" } }
go
func LVAsString(v LValue) string { switch sn := v.(type) { case LString, LNumber: return sn.String() default: return "" } }
[ "func", "LVAsString", "(", "v", "LValue", ")", "string", "{", "switch", "sn", ":=", "v", ".", "(", "type", ")", "{", "case", "LString", ",", "LNumber", ":", "return", "sn", ".", "String", "(", ")", "\n", "default", ":", "return", "\"", "\"", "\n", ...
// LVAsString returns string representation of a given LValue // if the LValue is a string or number, otherwise an empty string.
[ "LVAsString", "returns", "string", "representation", "of", "a", "given", "LValue", "if", "the", "LValue", "is", "a", "string", "or", "number", "otherwise", "an", "empty", "string", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/value.go#L48-L55
train
yuin/gopher-lua
value.go
LVAsNumber
func LVAsNumber(v LValue) LNumber { switch lv := v.(type) { case LNumber: return lv case LString: if num, err := parseNumber(string(lv)); err == nil { return num } } return LNumber(0) }
go
func LVAsNumber(v LValue) LNumber { switch lv := v.(type) { case LNumber: return lv case LString: if num, err := parseNumber(string(lv)); err == nil { return num } } return LNumber(0) }
[ "func", "LVAsNumber", "(", "v", "LValue", ")", "LNumber", "{", "switch", "lv", ":=", "v", ".", "(", "type", ")", "{", "case", "LNumber", ":", "return", "lv", "\n", "case", "LString", ":", "if", "num", ",", "err", ":=", "parseNumber", "(", "string", ...
// LVAsNumber tries to convert a given LValue to a number.
[ "LVAsNumber", "tries", "to", "convert", "a", "given", "LValue", "to", "a", "number", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/value.go#L69-L79
train
yuin/gopher-lua
auxlib.go
PreloadModule
func (ls *LState) PreloadModule(name string, loader LGFunction) { preload := ls.GetField(ls.GetField(ls.Get(EnvironIndex), "package"), "preload") if _, ok := preload.(*LTable); !ok { ls.RaiseError("package.preload must be a table") } ls.SetField(preload, name, ls.NewFunction(loader)) }
go
func (ls *LState) PreloadModule(name string, loader LGFunction) { preload := ls.GetField(ls.GetField(ls.Get(EnvironIndex), "package"), "preload") if _, ok := preload.(*LTable); !ok { ls.RaiseError("package.preload must be a table") } ls.SetField(preload, name, ls.NewFunction(loader)) }
[ "func", "(", "ls", "*", "LState", ")", "PreloadModule", "(", "name", "string", ",", "loader", "LGFunction", ")", "{", "preload", ":=", "ls", ".", "GetField", "(", "ls", ".", "GetField", "(", "ls", ".", "Get", "(", "EnvironIndex", ")", ",", "\"", "\""...
// Set a module loader to the package.preload table.
[ "Set", "a", "module", "loader", "to", "the", "package", ".", "preload", "table", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/auxlib.go#L425-L431
train
yuin/gopher-lua
auxlib.go
CheckChannel
func (ls *LState) CheckChannel(n int) chan LValue { v := ls.Get(n) if ch, ok := v.(LChannel); ok { return (chan LValue)(ch) } ls.TypeError(n, LTChannel) return nil }
go
func (ls *LState) CheckChannel(n int) chan LValue { v := ls.Get(n) if ch, ok := v.(LChannel); ok { return (chan LValue)(ch) } ls.TypeError(n, LTChannel) return nil }
[ "func", "(", "ls", "*", "LState", ")", "CheckChannel", "(", "n", "int", ")", "chan", "LValue", "{", "v", ":=", "ls", ".", "Get", "(", "n", ")", "\n", "if", "ch", ",", "ok", ":=", "v", ".", "(", "LChannel", ")", ";", "ok", "{", "return", "(", ...
// Checks whether the given index is an LChannel and returns this channel.
[ "Checks", "whether", "the", "given", "index", "is", "an", "LChannel", "and", "returns", "this", "channel", "." ]
8bfc7677f583b35a5663a9dd934c08f3b5774bbb
https://github.com/yuin/gopher-lua/blob/8bfc7677f583b35a5663a9dd934c08f3b5774bbb/auxlib.go#L434-L441
train
bwmarrin/snowflake
snowflake.go
NewNode
func NewNode(node int64) (*Node, error) { // re-calc in case custom NodeBits or StepBits were set // DEPRECATED: the below block will be removed in a future release. mu.Lock() nodeMax = -1 ^ (-1 << NodeBits) nodeMask = nodeMax << StepBits stepMask = -1 ^ (-1 << StepBits) timeShift = NodeBits + StepBits nodeShift = StepBits mu.Unlock() n := Node{} n.node = node n.nodeMax = -1 ^ (-1 << NodeBits) n.nodeMask = n.nodeMax << StepBits n.stepMask = -1 ^ (-1 << StepBits) n.timeShift = NodeBits + StepBits n.nodeShift = StepBits if n.node < 0 || n.node > n.nodeMax { return nil, errors.New("Node number must be between 0 and " + strconv.FormatInt(n.nodeMax, 10)) } var curTime = time.Now() // add time.Duration to curTime to make sure we use the monotonic clock if available n.epoch = curTime.Add(time.Unix(Epoch/1000, (Epoch%1000)*1000000).Sub(curTime)) return &n, nil }
go
func NewNode(node int64) (*Node, error) { // re-calc in case custom NodeBits or StepBits were set // DEPRECATED: the below block will be removed in a future release. mu.Lock() nodeMax = -1 ^ (-1 << NodeBits) nodeMask = nodeMax << StepBits stepMask = -1 ^ (-1 << StepBits) timeShift = NodeBits + StepBits nodeShift = StepBits mu.Unlock() n := Node{} n.node = node n.nodeMax = -1 ^ (-1 << NodeBits) n.nodeMask = n.nodeMax << StepBits n.stepMask = -1 ^ (-1 << StepBits) n.timeShift = NodeBits + StepBits n.nodeShift = StepBits if n.node < 0 || n.node > n.nodeMax { return nil, errors.New("Node number must be between 0 and " + strconv.FormatInt(n.nodeMax, 10)) } var curTime = time.Now() // add time.Duration to curTime to make sure we use the monotonic clock if available n.epoch = curTime.Add(time.Unix(Epoch/1000, (Epoch%1000)*1000000).Sub(curTime)) return &n, nil }
[ "func", "NewNode", "(", "node", "int64", ")", "(", "*", "Node", ",", "error", ")", "{", "// re-calc in case custom NodeBits or StepBits were set", "// DEPRECATED: the below block will be removed in a future release.", "mu", ".", "Lock", "(", ")", "\n", "nodeMax", "=", "...
// NewNode returns a new snowflake node that can be used to generate snowflake // IDs
[ "NewNode", "returns", "a", "new", "snowflake", "node", "that", "can", "be", "used", "to", "generate", "snowflake", "IDs" ]
c09e69ae59935edf6d85799e858c26de86b04cb3
https://github.com/bwmarrin/snowflake/blob/c09e69ae59935edf6d85799e858c26de86b04cb3/snowflake.go#L100-L129
train
bwmarrin/snowflake
snowflake.go
Generate
func (n *Node) Generate() ID { n.mu.Lock() now := time.Since(n.epoch).Nanoseconds() / 1000000 if now == n.time { n.step = (n.step + 1) & n.stepMask if n.step == 0 { for now <= n.time { now = time.Since(n.epoch).Nanoseconds() / 1000000 } } } else { n.step = 0 } n.time = now r := ID((now)<<n.timeShift | (n.node << n.nodeShift) | (n.step), ) n.mu.Unlock() return r }
go
func (n *Node) Generate() ID { n.mu.Lock() now := time.Since(n.epoch).Nanoseconds() / 1000000 if now == n.time { n.step = (n.step + 1) & n.stepMask if n.step == 0 { for now <= n.time { now = time.Since(n.epoch).Nanoseconds() / 1000000 } } } else { n.step = 0 } n.time = now r := ID((now)<<n.timeShift | (n.node << n.nodeShift) | (n.step), ) n.mu.Unlock() return r }
[ "func", "(", "n", "*", "Node", ")", "Generate", "(", ")", "ID", "{", "n", ".", "mu", ".", "Lock", "(", ")", "\n\n", "now", ":=", "time", ".", "Since", "(", "n", ".", "epoch", ")", ".", "Nanoseconds", "(", ")", "/", "1000000", "\n\n", "if", "n...
// Generate creates and returns a unique snowflake ID // To help guarantee uniqueness // - Make sure your system is keeping accurate system time // - Make sure you never have multiple nodes running with the same node ID
[ "Generate", "creates", "and", "returns", "a", "unique", "snowflake", "ID", "To", "help", "guarantee", "uniqueness", "-", "Make", "sure", "your", "system", "is", "keeping", "accurate", "system", "time", "-", "Make", "sure", "you", "never", "have", "multiple", ...
c09e69ae59935edf6d85799e858c26de86b04cb3
https://github.com/bwmarrin/snowflake/blob/c09e69ae59935edf6d85799e858c26de86b04cb3/snowflake.go#L135-L162
train
bwmarrin/snowflake
snowflake.go
ParseString
func ParseString(id string) (ID, error) { i, err := strconv.ParseInt(id, 10, 64) return ID(i), err }
go
func ParseString(id string) (ID, error) { i, err := strconv.ParseInt(id, 10, 64) return ID(i), err }
[ "func", "ParseString", "(", "id", "string", ")", "(", "ID", ",", "error", ")", "{", "i", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "id", ",", "10", ",", "64", ")", "\n", "return", "ID", "(", "i", ")", ",", "err", "\n\n", "}" ]
// ParseString converts a string into a snowflake ID
[ "ParseString", "converts", "a", "string", "into", "a", "snowflake", "ID" ]
c09e69ae59935edf6d85799e858c26de86b04cb3
https://github.com/bwmarrin/snowflake/blob/c09e69ae59935edf6d85799e858c26de86b04cb3/snowflake.go#L180-L184
train
bwmarrin/snowflake
snowflake.go
Base58
func (f ID) Base58() string { if f < 58 { return string(encodeBase58Map[f]) } b := make([]byte, 0, 11) for f >= 58 { b = append(b, encodeBase58Map[f%58]) f /= 58 } b = append(b, encodeBase58Map[f]) for x, y := 0, len(b)-1; x < y; x, y = x+1, y-1 { b[x], b[y] = b[y], b[x] } return string(b) }
go
func (f ID) Base58() string { if f < 58 { return string(encodeBase58Map[f]) } b := make([]byte, 0, 11) for f >= 58 { b = append(b, encodeBase58Map[f%58]) f /= 58 } b = append(b, encodeBase58Map[f]) for x, y := 0, len(b)-1; x < y; x, y = x+1, y-1 { b[x], b[y] = b[y], b[x] } return string(b) }
[ "func", "(", "f", "ID", ")", "Base58", "(", ")", "string", "{", "if", "f", "<", "58", "{", "return", "string", "(", "encodeBase58Map", "[", "f", "]", ")", "\n", "}", "\n\n", "b", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "11", ")", ...
// Base58 returns a base58 string of the snowflake ID
[ "Base58", "returns", "a", "base58", "string", "of", "the", "snowflake", "ID" ]
c09e69ae59935edf6d85799e858c26de86b04cb3
https://github.com/bwmarrin/snowflake/blob/c09e69ae59935edf6d85799e858c26de86b04cb3/snowflake.go#L250-L268
train
bwmarrin/snowflake
snowflake.go
ParseBase64
func ParseBase64(id string) (ID, error) { b, err := base64.StdEncoding.DecodeString(id) if err != nil { return -1, err } return ParseBytes(b) }
go
func ParseBase64(id string) (ID, error) { b, err := base64.StdEncoding.DecodeString(id) if err != nil { return -1, err } return ParseBytes(b) }
[ "func", "ParseBase64", "(", "id", "string", ")", "(", "ID", ",", "error", ")", "{", "b", ",", "err", ":=", "base64", ".", "StdEncoding", ".", "DecodeString", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n...
// ParseBase64 converts a base64 string into a snowflake ID
[ "ParseBase64", "converts", "a", "base64", "string", "into", "a", "snowflake", "ID" ]
c09e69ae59935edf6d85799e858c26de86b04cb3
https://github.com/bwmarrin/snowflake/blob/c09e69ae59935edf6d85799e858c26de86b04cb3/snowflake.go#L291-L298
train
bwmarrin/snowflake
snowflake.go
ParseBytes
func ParseBytes(id []byte) (ID, error) { i, err := strconv.ParseInt(string(id), 10, 64) return ID(i), err }
go
func ParseBytes(id []byte) (ID, error) { i, err := strconv.ParseInt(string(id), 10, 64) return ID(i), err }
[ "func", "ParseBytes", "(", "id", "[", "]", "byte", ")", "(", "ID", ",", "error", ")", "{", "i", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "string", "(", "id", ")", ",", "10", ",", "64", ")", "\n", "return", "ID", "(", "i", ")", ",", ...
// ParseBytes converts a byte slice into a snowflake ID
[ "ParseBytes", "converts", "a", "byte", "slice", "into", "a", "snowflake", "ID" ]
c09e69ae59935edf6d85799e858c26de86b04cb3
https://github.com/bwmarrin/snowflake/blob/c09e69ae59935edf6d85799e858c26de86b04cb3/snowflake.go#L306-L309
train
bwmarrin/snowflake
snowflake.go
IntBytes
func (f ID) IntBytes() [8]byte { var b [8]byte binary.BigEndian.PutUint64(b[:], uint64(f)) return b }
go
func (f ID) IntBytes() [8]byte { var b [8]byte binary.BigEndian.PutUint64(b[:], uint64(f)) return b }
[ "func", "(", "f", "ID", ")", "IntBytes", "(", ")", "[", "8", "]", "byte", "{", "var", "b", "[", "8", "]", "byte", "\n", "binary", ".", "BigEndian", ".", "PutUint64", "(", "b", "[", ":", "]", ",", "uint64", "(", "f", ")", ")", "\n", "return", ...
// IntBytes returns an array of bytes of the snowflake ID, encoded as a // big endian integer.
[ "IntBytes", "returns", "an", "array", "of", "bytes", "of", "the", "snowflake", "ID", "encoded", "as", "a", "big", "endian", "integer", "." ]
c09e69ae59935edf6d85799e858c26de86b04cb3
https://github.com/bwmarrin/snowflake/blob/c09e69ae59935edf6d85799e858c26de86b04cb3/snowflake.go#L313-L317
train
bwmarrin/snowflake
snowflake.go
ParseIntBytes
func ParseIntBytes(id [8]byte) ID { return ID(int64(binary.BigEndian.Uint64(id[:]))) }
go
func ParseIntBytes(id [8]byte) ID { return ID(int64(binary.BigEndian.Uint64(id[:]))) }
[ "func", "ParseIntBytes", "(", "id", "[", "8", "]", "byte", ")", "ID", "{", "return", "ID", "(", "int64", "(", "binary", ".", "BigEndian", ".", "Uint64", "(", "id", "[", ":", "]", ")", ")", ")", "\n", "}" ]
// ParseIntBytes converts an array of bytes encoded as big endian integer as // a snowflake ID
[ "ParseIntBytes", "converts", "an", "array", "of", "bytes", "encoded", "as", "big", "endian", "integer", "as", "a", "snowflake", "ID" ]
c09e69ae59935edf6d85799e858c26de86b04cb3
https://github.com/bwmarrin/snowflake/blob/c09e69ae59935edf6d85799e858c26de86b04cb3/snowflake.go#L321-L323
train
bwmarrin/snowflake
snowflake.go
MarshalJSON
func (f ID) MarshalJSON() ([]byte, error) { buff := make([]byte, 0, 22) buff = append(buff, '"') buff = strconv.AppendInt(buff, int64(f), 10) buff = append(buff, '"') return buff, nil }
go
func (f ID) MarshalJSON() ([]byte, error) { buff := make([]byte, 0, 22) buff = append(buff, '"') buff = strconv.AppendInt(buff, int64(f), 10) buff = append(buff, '"') return buff, nil }
[ "func", "(", "f", "ID", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "buff", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "22", ")", "\n", "buff", "=", "append", "(", "buff", ",", "'\"'", ")", "\n", "b...
// MarshalJSON returns a json byte array string of the snowflake ID.
[ "MarshalJSON", "returns", "a", "json", "byte", "array", "string", "of", "the", "snowflake", "ID", "." ]
c09e69ae59935edf6d85799e858c26de86b04cb3
https://github.com/bwmarrin/snowflake/blob/c09e69ae59935edf6d85799e858c26de86b04cb3/snowflake.go#L344-L350
train
bwmarrin/snowflake
snowflake.go
UnmarshalJSON
func (f *ID) UnmarshalJSON(b []byte) error { if len(b) < 3 || b[0] != '"' || b[len(b)-1] != '"' { return JSONSyntaxError{b} } i, err := strconv.ParseInt(string(b[1:len(b)-1]), 10, 64) if err != nil { return err } *f = ID(i) return nil }
go
func (f *ID) UnmarshalJSON(b []byte) error { if len(b) < 3 || b[0] != '"' || b[len(b)-1] != '"' { return JSONSyntaxError{b} } i, err := strconv.ParseInt(string(b[1:len(b)-1]), 10, 64) if err != nil { return err } *f = ID(i) return nil }
[ "func", "(", "f", "*", "ID", ")", "UnmarshalJSON", "(", "b", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "b", ")", "<", "3", "||", "b", "[", "0", "]", "!=", "'\"'", "||", "b", "[", "len", "(", "b", ")", "-", "1", "]", "!=", "...
// UnmarshalJSON converts a json byte array of a snowflake ID into an ID type.
[ "UnmarshalJSON", "converts", "a", "json", "byte", "array", "of", "a", "snowflake", "ID", "into", "an", "ID", "type", "." ]
c09e69ae59935edf6d85799e858c26de86b04cb3
https://github.com/bwmarrin/snowflake/blob/c09e69ae59935edf6d85799e858c26de86b04cb3/snowflake.go#L353-L365
train
grafov/m3u8
writer.go
Append
func (p *MasterPlaylist) Append(uri string, chunklist *MediaPlaylist, params VariantParams) { v := new(Variant) v.URI = uri v.Chunklist = chunklist v.VariantParams = params p.Variants = append(p.Variants, v) if len(v.Alternatives) > 0 { // From section 7: // The EXT-X-MEDIA tag and the AUDIO, VIDEO and SUBTITLES attributes of // the EXT-X-STREAM-INF tag are backward compatible to protocol version // 1, but playback on older clients may not be desirable. A server MAY // consider indicating a EXT-X-VERSION of 4 or higher in the Master // Playlist but is not required to do so. version(&p.ver, 4) // so it is optional and in theory may be set to ver.1 // but more tests required } p.buf.Reset() }
go
func (p *MasterPlaylist) Append(uri string, chunklist *MediaPlaylist, params VariantParams) { v := new(Variant) v.URI = uri v.Chunklist = chunklist v.VariantParams = params p.Variants = append(p.Variants, v) if len(v.Alternatives) > 0 { // From section 7: // The EXT-X-MEDIA tag and the AUDIO, VIDEO and SUBTITLES attributes of // the EXT-X-STREAM-INF tag are backward compatible to protocol version // 1, but playback on older clients may not be desirable. A server MAY // consider indicating a EXT-X-VERSION of 4 or higher in the Master // Playlist but is not required to do so. version(&p.ver, 4) // so it is optional and in theory may be set to ver.1 // but more tests required } p.buf.Reset() }
[ "func", "(", "p", "*", "MasterPlaylist", ")", "Append", "(", "uri", "string", ",", "chunklist", "*", "MediaPlaylist", ",", "params", "VariantParams", ")", "{", "v", ":=", "new", "(", "Variant", ")", "\n", "v", ".", "URI", "=", "uri", "\n", "v", ".", ...
// Append variant to master playlist. // This operation does reset playlist cache.
[ "Append", "variant", "to", "master", "playlist", ".", "This", "operation", "does", "reset", "playlist", "cache", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/writer.go#L49-L66
train
grafov/m3u8
writer.go
Encode
func (p *MasterPlaylist) Encode() *bytes.Buffer { if p.buf.Len() > 0 { return &p.buf } p.buf.WriteString("#EXTM3U\n#EXT-X-VERSION:") p.buf.WriteString(strver(p.ver)) p.buf.WriteRune('\n') if p.IndependentSegments() { p.buf.WriteString("#EXT-X-INDEPENDENT-SEGMENTS\n") } var altsWritten map[string]bool = make(map[string]bool) for _, pl := range p.Variants { if pl.Alternatives != nil { for _, alt := range pl.Alternatives { // Make sure that we only write out an alternative once altKey := fmt.Sprintf("%s-%s-%s-%s", alt.Type, alt.GroupId, alt.Name, alt.Language) if altsWritten[altKey] { continue } altsWritten[altKey] = true p.buf.WriteString("#EXT-X-MEDIA:") if alt.Type != "" { p.buf.WriteString("TYPE=") // Type should not be quoted p.buf.WriteString(alt.Type) } if alt.GroupId != "" { p.buf.WriteString(",GROUP-ID=\"") p.buf.WriteString(alt.GroupId) p.buf.WriteRune('"') } if alt.Name != "" { p.buf.WriteString(",NAME=\"") p.buf.WriteString(alt.Name) p.buf.WriteRune('"') } p.buf.WriteString(",DEFAULT=") if alt.Default { p.buf.WriteString("YES") } else { p.buf.WriteString("NO") } if alt.Autoselect != "" { p.buf.WriteString(",AUTOSELECT=") p.buf.WriteString(alt.Autoselect) } if alt.Language != "" { p.buf.WriteString(",LANGUAGE=\"") p.buf.WriteString(alt.Language) p.buf.WriteRune('"') } if alt.Forced != "" { p.buf.WriteString(",FORCED=\"") p.buf.WriteString(alt.Forced) p.buf.WriteRune('"') } if alt.Characteristics != "" { p.buf.WriteString(",CHARACTERISTICS=\"") p.buf.WriteString(alt.Characteristics) p.buf.WriteRune('"') } if alt.Subtitles != "" { p.buf.WriteString(",SUBTITLES=\"") p.buf.WriteString(alt.Subtitles) p.buf.WriteRune('"') } if alt.URI != "" { p.buf.WriteString(",URI=\"") p.buf.WriteString(alt.URI) p.buf.WriteRune('"') } p.buf.WriteRune('\n') } } if pl.Iframe { p.buf.WriteString("#EXT-X-I-FRAME-STREAM-INF:PROGRAM-ID=") p.buf.WriteString(strconv.FormatUint(uint64(pl.ProgramId), 10)) p.buf.WriteString(",BANDWIDTH=") p.buf.WriteString(strconv.FormatUint(uint64(pl.Bandwidth), 10)) if pl.Codecs != "" { p.buf.WriteString(",CODECS=\"") p.buf.WriteString(pl.Codecs) p.buf.WriteRune('"') } if pl.Resolution != "" { p.buf.WriteString(",RESOLUTION=") // Resolution should not be quoted p.buf.WriteString(pl.Resolution) } if pl.Video != "" { p.buf.WriteString(",VIDEO=\"") p.buf.WriteString(pl.Video) p.buf.WriteRune('"') } if pl.URI != "" { p.buf.WriteString(",URI=\"") p.buf.WriteString(pl.URI) p.buf.WriteRune('"') } p.buf.WriteRune('\n') } else { p.buf.WriteString("#EXT-X-STREAM-INF:PROGRAM-ID=") p.buf.WriteString(strconv.FormatUint(uint64(pl.ProgramId), 10)) p.buf.WriteString(",BANDWIDTH=") p.buf.WriteString(strconv.FormatUint(uint64(pl.Bandwidth), 10)) if pl.AverageBandwidth != 0 { p.buf.WriteString(",AVERAGE-BANDWIDTH=") p.buf.WriteString(strconv.FormatUint(uint64(pl.Bandwidth), 10)) } if pl.Codecs != "" { p.buf.WriteString(",CODECS=\"") p.buf.WriteString(pl.Codecs) p.buf.WriteRune('"') } if pl.Resolution != "" { p.buf.WriteString(",RESOLUTION=") // Resolution should not be quoted p.buf.WriteString(pl.Resolution) } if pl.Audio != "" { p.buf.WriteString(",AUDIO=\"") p.buf.WriteString(pl.Audio) p.buf.WriteRune('"') } if pl.Video != "" { p.buf.WriteString(",VIDEO=\"") p.buf.WriteString(pl.Video) p.buf.WriteRune('"') } if pl.Captions != "" { p.buf.WriteString(",CLOSED-CAPTIONS=") if pl.Captions == "NONE" { p.buf.WriteString(pl.Captions) // CC should not be quoted when eq NONE } else { p.buf.WriteRune('"') p.buf.WriteString(pl.Captions) p.buf.WriteRune('"') } } if pl.Subtitles != "" { p.buf.WriteString(",SUBTITLES=\"") p.buf.WriteString(pl.Subtitles) p.buf.WriteRune('"') } if pl.Name != "" { p.buf.WriteString(",NAME=\"") p.buf.WriteString(pl.Name) p.buf.WriteRune('"') } if pl.FrameRate != 0 { p.buf.WriteString(",FRAME-RATE=") p.buf.WriteString(strconv.FormatFloat(pl.FrameRate, 'f', 3, 64)) } p.buf.WriteRune('\n') p.buf.WriteString(pl.URI) if p.Args != "" { if strings.Contains(pl.URI, "?") { p.buf.WriteRune('&') } else { p.buf.WriteRune('?') } p.buf.WriteString(p.Args) } p.buf.WriteRune('\n') } } return &p.buf }
go
func (p *MasterPlaylist) Encode() *bytes.Buffer { if p.buf.Len() > 0 { return &p.buf } p.buf.WriteString("#EXTM3U\n#EXT-X-VERSION:") p.buf.WriteString(strver(p.ver)) p.buf.WriteRune('\n') if p.IndependentSegments() { p.buf.WriteString("#EXT-X-INDEPENDENT-SEGMENTS\n") } var altsWritten map[string]bool = make(map[string]bool) for _, pl := range p.Variants { if pl.Alternatives != nil { for _, alt := range pl.Alternatives { // Make sure that we only write out an alternative once altKey := fmt.Sprintf("%s-%s-%s-%s", alt.Type, alt.GroupId, alt.Name, alt.Language) if altsWritten[altKey] { continue } altsWritten[altKey] = true p.buf.WriteString("#EXT-X-MEDIA:") if alt.Type != "" { p.buf.WriteString("TYPE=") // Type should not be quoted p.buf.WriteString(alt.Type) } if alt.GroupId != "" { p.buf.WriteString(",GROUP-ID=\"") p.buf.WriteString(alt.GroupId) p.buf.WriteRune('"') } if alt.Name != "" { p.buf.WriteString(",NAME=\"") p.buf.WriteString(alt.Name) p.buf.WriteRune('"') } p.buf.WriteString(",DEFAULT=") if alt.Default { p.buf.WriteString("YES") } else { p.buf.WriteString("NO") } if alt.Autoselect != "" { p.buf.WriteString(",AUTOSELECT=") p.buf.WriteString(alt.Autoselect) } if alt.Language != "" { p.buf.WriteString(",LANGUAGE=\"") p.buf.WriteString(alt.Language) p.buf.WriteRune('"') } if alt.Forced != "" { p.buf.WriteString(",FORCED=\"") p.buf.WriteString(alt.Forced) p.buf.WriteRune('"') } if alt.Characteristics != "" { p.buf.WriteString(",CHARACTERISTICS=\"") p.buf.WriteString(alt.Characteristics) p.buf.WriteRune('"') } if alt.Subtitles != "" { p.buf.WriteString(",SUBTITLES=\"") p.buf.WriteString(alt.Subtitles) p.buf.WriteRune('"') } if alt.URI != "" { p.buf.WriteString(",URI=\"") p.buf.WriteString(alt.URI) p.buf.WriteRune('"') } p.buf.WriteRune('\n') } } if pl.Iframe { p.buf.WriteString("#EXT-X-I-FRAME-STREAM-INF:PROGRAM-ID=") p.buf.WriteString(strconv.FormatUint(uint64(pl.ProgramId), 10)) p.buf.WriteString(",BANDWIDTH=") p.buf.WriteString(strconv.FormatUint(uint64(pl.Bandwidth), 10)) if pl.Codecs != "" { p.buf.WriteString(",CODECS=\"") p.buf.WriteString(pl.Codecs) p.buf.WriteRune('"') } if pl.Resolution != "" { p.buf.WriteString(",RESOLUTION=") // Resolution should not be quoted p.buf.WriteString(pl.Resolution) } if pl.Video != "" { p.buf.WriteString(",VIDEO=\"") p.buf.WriteString(pl.Video) p.buf.WriteRune('"') } if pl.URI != "" { p.buf.WriteString(",URI=\"") p.buf.WriteString(pl.URI) p.buf.WriteRune('"') } p.buf.WriteRune('\n') } else { p.buf.WriteString("#EXT-X-STREAM-INF:PROGRAM-ID=") p.buf.WriteString(strconv.FormatUint(uint64(pl.ProgramId), 10)) p.buf.WriteString(",BANDWIDTH=") p.buf.WriteString(strconv.FormatUint(uint64(pl.Bandwidth), 10)) if pl.AverageBandwidth != 0 { p.buf.WriteString(",AVERAGE-BANDWIDTH=") p.buf.WriteString(strconv.FormatUint(uint64(pl.Bandwidth), 10)) } if pl.Codecs != "" { p.buf.WriteString(",CODECS=\"") p.buf.WriteString(pl.Codecs) p.buf.WriteRune('"') } if pl.Resolution != "" { p.buf.WriteString(",RESOLUTION=") // Resolution should not be quoted p.buf.WriteString(pl.Resolution) } if pl.Audio != "" { p.buf.WriteString(",AUDIO=\"") p.buf.WriteString(pl.Audio) p.buf.WriteRune('"') } if pl.Video != "" { p.buf.WriteString(",VIDEO=\"") p.buf.WriteString(pl.Video) p.buf.WriteRune('"') } if pl.Captions != "" { p.buf.WriteString(",CLOSED-CAPTIONS=") if pl.Captions == "NONE" { p.buf.WriteString(pl.Captions) // CC should not be quoted when eq NONE } else { p.buf.WriteRune('"') p.buf.WriteString(pl.Captions) p.buf.WriteRune('"') } } if pl.Subtitles != "" { p.buf.WriteString(",SUBTITLES=\"") p.buf.WriteString(pl.Subtitles) p.buf.WriteRune('"') } if pl.Name != "" { p.buf.WriteString(",NAME=\"") p.buf.WriteString(pl.Name) p.buf.WriteRune('"') } if pl.FrameRate != 0 { p.buf.WriteString(",FRAME-RATE=") p.buf.WriteString(strconv.FormatFloat(pl.FrameRate, 'f', 3, 64)) } p.buf.WriteRune('\n') p.buf.WriteString(pl.URI) if p.Args != "" { if strings.Contains(pl.URI, "?") { p.buf.WriteRune('&') } else { p.buf.WriteRune('?') } p.buf.WriteString(p.Args) } p.buf.WriteRune('\n') } } return &p.buf }
[ "func", "(", "p", "*", "MasterPlaylist", ")", "Encode", "(", ")", "*", "bytes", ".", "Buffer", "{", "if", "p", ".", "buf", ".", "Len", "(", ")", ">", "0", "{", "return", "&", "p", ".", "buf", "\n", "}", "\n\n", "p", ".", "buf", ".", "WriteStr...
// Generate output in M3U8 format.
[ "Generate", "output", "in", "M3U8", "format", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/writer.go#L73-L243
train
grafov/m3u8
writer.go
NewMediaPlaylist
func NewMediaPlaylist(winsize uint, capacity uint) (*MediaPlaylist, error) { p := new(MediaPlaylist) p.ver = minver p.capacity = capacity if err := p.SetWinSize(winsize); err != nil { return nil, err } p.Segments = make([]*MediaSegment, capacity) return p, nil }
go
func NewMediaPlaylist(winsize uint, capacity uint) (*MediaPlaylist, error) { p := new(MediaPlaylist) p.ver = minver p.capacity = capacity if err := p.SetWinSize(winsize); err != nil { return nil, err } p.Segments = make([]*MediaSegment, capacity) return p, nil }
[ "func", "NewMediaPlaylist", "(", "winsize", "uint", ",", "capacity", "uint", ")", "(", "*", "MediaPlaylist", ",", "error", ")", "{", "p", ":=", "new", "(", "MediaPlaylist", ")", "\n", "p", ".", "ver", "=", "minver", "\n", "p", ".", "capacity", "=", "...
// Creates new media playlist structure. // Winsize defines how much items will displayed on playlist generation. // Capacity is total size of a playlist.
[ "Creates", "new", "media", "playlist", "structure", ".", "Winsize", "defines", "how", "much", "items", "will", "displayed", "on", "playlist", "generation", ".", "Capacity", "is", "total", "size", "of", "a", "playlist", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/writer.go#L278-L287
train
grafov/m3u8
writer.go
last
func (p *MediaPlaylist) last() uint { if p.tail == 0 { return p.capacity - 1 } return p.tail - 1 }
go
func (p *MediaPlaylist) last() uint { if p.tail == 0 { return p.capacity - 1 } return p.tail - 1 }
[ "func", "(", "p", "*", "MediaPlaylist", ")", "last", "(", ")", "uint", "{", "if", "p", ".", "tail", "==", "0", "{", "return", "p", ".", "capacity", "-", "1", "\n", "}", "\n", "return", "p", ".", "tail", "-", "1", "\n", "}" ]
// last returns the previously written segment's index
[ "last", "returns", "the", "previously", "written", "segment", "s", "index" ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/writer.go#L290-L295
train
grafov/m3u8
writer.go
Remove
func (p *MediaPlaylist) Remove() (err error) { if p.count == 0 { return errors.New("playlist is empty") } p.head = (p.head + 1) % p.capacity p.count-- if !p.Closed { p.SeqNo++ } p.buf.Reset() return nil }
go
func (p *MediaPlaylist) Remove() (err error) { if p.count == 0 { return errors.New("playlist is empty") } p.head = (p.head + 1) % p.capacity p.count-- if !p.Closed { p.SeqNo++ } p.buf.Reset() return nil }
[ "func", "(", "p", "*", "MediaPlaylist", ")", "Remove", "(", ")", "(", "err", "error", ")", "{", "if", "p", ".", "count", "==", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "p", ".", "head", "=", "(", "p", ...
// Remove current segment from the head of chunk slice form a media playlist. Useful for sliding playlists. // This operation does reset playlist cache.
[ "Remove", "current", "segment", "from", "the", "head", "of", "chunk", "slice", "form", "a", "media", "playlist", ".", "Useful", "for", "sliding", "playlists", ".", "This", "operation", "does", "reset", "playlist", "cache", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/writer.go#L299-L310
train
grafov/m3u8
writer.go
Append
func (p *MediaPlaylist) Append(uri string, duration float64, title string) error { seg := new(MediaSegment) seg.URI = uri seg.Duration = duration seg.Title = title return p.AppendSegment(seg) }
go
func (p *MediaPlaylist) Append(uri string, duration float64, title string) error { seg := new(MediaSegment) seg.URI = uri seg.Duration = duration seg.Title = title return p.AppendSegment(seg) }
[ "func", "(", "p", "*", "MediaPlaylist", ")", "Append", "(", "uri", "string", ",", "duration", "float64", ",", "title", "string", ")", "error", "{", "seg", ":=", "new", "(", "MediaSegment", ")", "\n", "seg", ".", "URI", "=", "uri", "\n", "seg", ".", ...
// Append general chunk to the tail of chunk slice for a media playlist. // This operation does reset playlist cache.
[ "Append", "general", "chunk", "to", "the", "tail", "of", "chunk", "slice", "for", "a", "media", "playlist", ".", "This", "operation", "does", "reset", "playlist", "cache", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/writer.go#L314-L320
train
grafov/m3u8
writer.go
AppendSegment
func (p *MediaPlaylist) AppendSegment(seg *MediaSegment) error { if p.head == p.tail && p.count > 0 { return ErrPlaylistFull } seg.SeqId = p.SeqNo if p.count > 0 { seg.SeqId = p.Segments[(p.capacity+p.tail-1)%p.capacity].SeqId + 1 } p.Segments[p.tail] = seg p.tail = (p.tail + 1) % p.capacity p.count++ if p.TargetDuration < seg.Duration { p.TargetDuration = math.Ceil(seg.Duration) } p.buf.Reset() return nil }
go
func (p *MediaPlaylist) AppendSegment(seg *MediaSegment) error { if p.head == p.tail && p.count > 0 { return ErrPlaylistFull } seg.SeqId = p.SeqNo if p.count > 0 { seg.SeqId = p.Segments[(p.capacity+p.tail-1)%p.capacity].SeqId + 1 } p.Segments[p.tail] = seg p.tail = (p.tail + 1) % p.capacity p.count++ if p.TargetDuration < seg.Duration { p.TargetDuration = math.Ceil(seg.Duration) } p.buf.Reset() return nil }
[ "func", "(", "p", "*", "MediaPlaylist", ")", "AppendSegment", "(", "seg", "*", "MediaSegment", ")", "error", "{", "if", "p", ".", "head", "==", "p", ".", "tail", "&&", "p", ".", "count", ">", "0", "{", "return", "ErrPlaylistFull", "\n", "}", "\n", ...
// AppendSegment appends a MediaSegment to the tail of chunk slice for a media playlist. // This operation does reset playlist cache.
[ "AppendSegment", "appends", "a", "MediaSegment", "to", "the", "tail", "of", "chunk", "slice", "for", "a", "media", "playlist", ".", "This", "operation", "does", "reset", "playlist", "cache", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/writer.go#L324-L340
train
grafov/m3u8
writer.go
DurationAsInt
func (p *MediaPlaylist) DurationAsInt(yes bool) { if yes { // duration must be integers if protocol version is less than 3 version(&p.ver, 3) } p.durationAsInt = yes }
go
func (p *MediaPlaylist) DurationAsInt(yes bool) { if yes { // duration must be integers if protocol version is less than 3 version(&p.ver, 3) } p.durationAsInt = yes }
[ "func", "(", "p", "*", "MediaPlaylist", ")", "DurationAsInt", "(", "yes", "bool", ")", "{", "if", "yes", "{", "// duration must be integers if protocol version is less than 3", "version", "(", "&", "p", ".", "ver", ",", "3", ")", "\n", "}", "\n", "p", ".", ...
// TargetDuration will be int on Encode
[ "TargetDuration", "will", "be", "int", "on", "Encode" ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/writer.go#L655-L661
train
grafov/m3u8
writer.go
Close
func (p *MediaPlaylist) Close() { if p.buf.Len() > 0 { p.buf.WriteString("#EXT-X-ENDLIST\n") } p.Closed = true }
go
func (p *MediaPlaylist) Close() { if p.buf.Len() > 0 { p.buf.WriteString("#EXT-X-ENDLIST\n") } p.Closed = true }
[ "func", "(", "p", "*", "MediaPlaylist", ")", "Close", "(", ")", "{", "if", "p", ".", "buf", ".", "Len", "(", ")", ">", "0", "{", "p", ".", "buf", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "}", "\n", "p", ".", "Closed", "=", "tr...
// Close sliding playlist and make them fixed.
[ "Close", "sliding", "playlist", "and", "make", "them", "fixed", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/writer.go#L669-L674
train
grafov/m3u8
writer.go
SetSCTE35
func (p *MediaPlaylist) SetSCTE35(scte35 *SCTE) error { if p.count == 0 { return errors.New("playlist is empty") } p.Segments[p.last()].SCTE = scte35 return nil }
go
func (p *MediaPlaylist) SetSCTE35(scte35 *SCTE) error { if p.count == 0 { return errors.New("playlist is empty") } p.Segments[p.last()].SCTE = scte35 return nil }
[ "func", "(", "p", "*", "MediaPlaylist", ")", "SetSCTE35", "(", "scte35", "*", "SCTE", ")", "error", "{", "if", "p", ".", "count", "==", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "p", ".", "Segments", "[", ...
// SetSCTE35 sets the SCTE cue format for the current media segment
[ "SetSCTE35", "sets", "the", "SCTE", "cue", "format", "for", "the", "current", "media", "segment" ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/writer.go#L751-L757
train
grafov/m3u8
writer.go
SetWinSize
func (p *MediaPlaylist) SetWinSize(winsize uint) error { if winsize > p.capacity { return errors.New("capacity must be greater than winsize or equal") } p.winsize = winsize return nil }
go
func (p *MediaPlaylist) SetWinSize(winsize uint) error { if winsize > p.capacity { return errors.New("capacity must be greater than winsize or equal") } p.winsize = winsize return nil }
[ "func", "(", "p", "*", "MediaPlaylist", ")", "SetWinSize", "(", "winsize", "uint", ")", "error", "{", "if", "winsize", ">", "p", ".", "capacity", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "p", ".", "winsize", "=", ...
// SetWinSize overwrites the playlist's window size.
[ "SetWinSize", "overwrites", "the", "playlist", "s", "window", "size", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/writer.go#L801-L807
train
grafov/m3u8
reader.go
Decode
func (p *MasterPlaylist) Decode(data bytes.Buffer, strict bool) error { return p.decode(&data, strict) }
go
func (p *MasterPlaylist) Decode(data bytes.Buffer, strict bool) error { return p.decode(&data, strict) }
[ "func", "(", "p", "*", "MasterPlaylist", ")", "Decode", "(", "data", "bytes", ".", "Buffer", ",", "strict", "bool", ")", "error", "{", "return", "p", ".", "decode", "(", "&", "data", ",", "strict", ")", "\n", "}" ]
// Decode parses a master playlist passed from the buffer. If `strict` // parameter is true then it returns first syntax error.
[ "Decode", "parses", "a", "master", "playlist", "passed", "from", "the", "buffer", ".", "If", "strict", "parameter", "is", "true", "then", "it", "returns", "first", "syntax", "error", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/reader.go#L35-L37
train
grafov/m3u8
reader.go
decode
func (p *MasterPlaylist) decode(buf *bytes.Buffer, strict bool) error { var eof bool state := new(decodingState) for !eof { line, err := buf.ReadString('\n') if err == io.EOF { eof = true } else if err != nil { break } err = decodeLineOfMasterPlaylist(p, state, line, strict) if strict && err != nil { return err } } if strict && !state.m3u { return errors.New("#EXTM3U absent") } return nil }
go
func (p *MasterPlaylist) decode(buf *bytes.Buffer, strict bool) error { var eof bool state := new(decodingState) for !eof { line, err := buf.ReadString('\n') if err == io.EOF { eof = true } else if err != nil { break } err = decodeLineOfMasterPlaylist(p, state, line, strict) if strict && err != nil { return err } } if strict && !state.m3u { return errors.New("#EXTM3U absent") } return nil }
[ "func", "(", "p", "*", "MasterPlaylist", ")", "decode", "(", "buf", "*", "bytes", ".", "Buffer", ",", "strict", "bool", ")", "error", "{", "var", "eof", "bool", "\n\n", "state", ":=", "new", "(", "decodingState", ")", "\n\n", "for", "!", "eof", "{", ...
// Parse master playlist. Internal function.
[ "Parse", "master", "playlist", ".", "Internal", "function", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/reader.go#L52-L73
train
grafov/m3u8
reader.go
Decode
func Decode(data bytes.Buffer, strict bool) (Playlist, ListType, error) { return decode(&data, strict) }
go
func Decode(data bytes.Buffer, strict bool) (Playlist, ListType, error) { return decode(&data, strict) }
[ "func", "Decode", "(", "data", "bytes", ".", "Buffer", ",", "strict", "bool", ")", "(", "Playlist", ",", "ListType", ",", "error", ")", "{", "return", "decode", "(", "&", "data", ",", "strict", ")", "\n", "}" ]
// Decode detects type of playlist and decodes it. It accepts bytes // buffer as input.
[ "Decode", "detects", "type", "of", "playlist", "and", "decodes", "it", ".", "It", "accepts", "bytes", "buffer", "as", "input", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/reader.go#L125-L127
train
grafov/m3u8
reader.go
DecodeFrom
func DecodeFrom(reader io.Reader, strict bool) (Playlist, ListType, error) { buf := new(bytes.Buffer) _, err := buf.ReadFrom(reader) if err != nil { return nil, 0, err } return decode(buf, strict) }
go
func DecodeFrom(reader io.Reader, strict bool) (Playlist, ListType, error) { buf := new(bytes.Buffer) _, err := buf.ReadFrom(reader) if err != nil { return nil, 0, err } return decode(buf, strict) }
[ "func", "DecodeFrom", "(", "reader", "io", ".", "Reader", ",", "strict", "bool", ")", "(", "Playlist", ",", "ListType", ",", "error", ")", "{", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "_", ",", "err", ":=", "buf", ".", "ReadFrom...
// DecodeFrom detects type of playlist and decodes it. It accepts data // conformed with io.Reader.
[ "DecodeFrom", "detects", "type", "of", "playlist", "and", "decodes", "it", ".", "It", "accepts", "data", "conformed", "with", "io", ".", "Reader", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/reader.go#L131-L138
train
grafov/m3u8
reader.go
decode
func decode(buf *bytes.Buffer, strict bool) (Playlist, ListType, error) { var eof bool var line string var master *MasterPlaylist var media *MediaPlaylist var listType ListType var err error state := new(decodingState) wv := new(WV) master = NewMasterPlaylist() media, err = NewMediaPlaylist(8, 1024) // Winsize for VoD will become 0, capacity auto extends if err != nil { return nil, 0, fmt.Errorf("Create media playlist failed: %s", err) } for !eof { if line, err = buf.ReadString('\n'); err == io.EOF { eof = true } else if err != nil { break } // fixes the issues https://github.com/grafov/m3u8/issues/25 // TODO: the same should be done in decode functions of both Master- and MediaPlaylists // so some DRYing would be needed. if len(line) < 1 || line == "\r" { continue } err = decodeLineOfMasterPlaylist(master, state, line, strict) if strict && err != nil { return master, state.listType, err } err = decodeLineOfMediaPlaylist(media, wv, state, line, strict) if strict && err != nil { return media, state.listType, err } } if state.listType == MEDIA && state.tagWV { media.WV = wv } if strict && !state.m3u { return nil, listType, errors.New("#EXTM3U absent") } switch state.listType { case MASTER: return master, MASTER, nil case MEDIA: if media.Closed || media.MediaType == EVENT { // VoD and Event's should show the entire playlist media.SetWinSize(0) } return media, MEDIA, nil } return nil, state.listType, errors.New("Can't detect playlist type") }
go
func decode(buf *bytes.Buffer, strict bool) (Playlist, ListType, error) { var eof bool var line string var master *MasterPlaylist var media *MediaPlaylist var listType ListType var err error state := new(decodingState) wv := new(WV) master = NewMasterPlaylist() media, err = NewMediaPlaylist(8, 1024) // Winsize for VoD will become 0, capacity auto extends if err != nil { return nil, 0, fmt.Errorf("Create media playlist failed: %s", err) } for !eof { if line, err = buf.ReadString('\n'); err == io.EOF { eof = true } else if err != nil { break } // fixes the issues https://github.com/grafov/m3u8/issues/25 // TODO: the same should be done in decode functions of both Master- and MediaPlaylists // so some DRYing would be needed. if len(line) < 1 || line == "\r" { continue } err = decodeLineOfMasterPlaylist(master, state, line, strict) if strict && err != nil { return master, state.listType, err } err = decodeLineOfMediaPlaylist(media, wv, state, line, strict) if strict && err != nil { return media, state.listType, err } } if state.listType == MEDIA && state.tagWV { media.WV = wv } if strict && !state.m3u { return nil, listType, errors.New("#EXTM3U absent") } switch state.listType { case MASTER: return master, MASTER, nil case MEDIA: if media.Closed || media.MediaType == EVENT { // VoD and Event's should show the entire playlist media.SetWinSize(0) } return media, MEDIA, nil } return nil, state.listType, errors.New("Can't detect playlist type") }
[ "func", "decode", "(", "buf", "*", "bytes", ".", "Buffer", ",", "strict", "bool", ")", "(", "Playlist", ",", "ListType", ",", "error", ")", "{", "var", "eof", "bool", "\n", "var", "line", "string", "\n", "var", "master", "*", "MasterPlaylist", "\n", ...
// Detect playlist type and decode it. May be used as decoder for both // master and media playlists.
[ "Detect", "playlist", "type", "and", "decode", "it", ".", "May", "be", "used", "as", "decoder", "for", "both", "master", "and", "media", "playlists", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/reader.go#L142-L203
train
grafov/m3u8
reader.go
StrictTimeParse
func StrictTimeParse(value string) (time.Time, error) { return time.Parse(DATETIME, value) }
go
func StrictTimeParse(value string) (time.Time, error) { return time.Parse(DATETIME, value) }
[ "func", "StrictTimeParse", "(", "value", "string", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "time", ".", "Parse", "(", "DATETIME", ",", "value", ")", "\n", "}" ]
// StrictTimeParse implements RFC3339 with Nanoseconds accuracy.
[ "StrictTimeParse", "implements", "RFC3339", "with", "Nanoseconds", "accuracy", "." ]
1d88be54fa785021109edc0bd1a65518cec073a9
https://github.com/grafov/m3u8/blob/1d88be54fa785021109edc0bd1a65518cec073a9/reader.go#L712-L714
train
envoyproxy/go-control-plane
envoy/config/rbac/v2alpha/rbac.pb.validate.go
Validate
func (m *Policy) Validate() error { if m == nil { return nil } if len(m.GetPermissions()) < 1 { return PolicyValidationError{ field: "Permissions", reason: "value must contain at least 1 item(s)", } } for idx, item := range m.GetPermissions() { _, _ = idx, item { tmp := item if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return PolicyValidationError{ field: fmt.Sprintf("Permissions[%v]", idx), reason: "embedded message failed validation", cause: err, } } } } } if len(m.GetPrincipals()) < 1 { return PolicyValidationError{ field: "Principals", reason: "value must contain at least 1 item(s)", } } for idx, item := range m.GetPrincipals() { _, _ = idx, item { tmp := item if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return PolicyValidationError{ field: fmt.Sprintf("Principals[%v]", idx), reason: "embedded message failed validation", cause: err, } } } } } return nil }
go
func (m *Policy) Validate() error { if m == nil { return nil } if len(m.GetPermissions()) < 1 { return PolicyValidationError{ field: "Permissions", reason: "value must contain at least 1 item(s)", } } for idx, item := range m.GetPermissions() { _, _ = idx, item { tmp := item if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return PolicyValidationError{ field: fmt.Sprintf("Permissions[%v]", idx), reason: "embedded message failed validation", cause: err, } } } } } if len(m.GetPrincipals()) < 1 { return PolicyValidationError{ field: "Principals", reason: "value must contain at least 1 item(s)", } } for idx, item := range m.GetPrincipals() { _, _ = idx, item { tmp := item if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return PolicyValidationError{ field: fmt.Sprintf("Principals[%v]", idx), reason: "embedded message failed validation", cause: err, } } } } } return nil }
[ "func", "(", "m", "*", "Policy", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "len", "(", "m", ".", "GetPermissions", "(", ")", ")", "<", "1", "{", "return", "PolicyValidationError"...
// Validate checks the field values on Policy with the rules defined in the // proto definition for this message. If any rules are violated, an error is returned.
[ "Validate", "checks", "the", "field", "values", "on", "Policy", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "." ]
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/config/rbac/v2alpha/rbac.pb.validate.go#L106-L166
train
envoyproxy/go-control-plane
envoy/config/rbac/v2alpha/rbac.pb.validate.go
Validate
func (m *Permission_Set) Validate() error { if m == nil { return nil } if len(m.GetRules()) < 1 { return Permission_SetValidationError{ field: "Rules", reason: "value must contain at least 1 item(s)", } } for idx, item := range m.GetRules() { _, _ = idx, item { tmp := item if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return Permission_SetValidationError{ field: fmt.Sprintf("Rules[%v]", idx), reason: "embedded message failed validation", cause: err, } } } } } return nil }
go
func (m *Permission_Set) Validate() error { if m == nil { return nil } if len(m.GetRules()) < 1 { return Permission_SetValidationError{ field: "Rules", reason: "value must contain at least 1 item(s)", } } for idx, item := range m.GetRules() { _, _ = idx, item { tmp := item if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return Permission_SetValidationError{ field: fmt.Sprintf("Rules[%v]", idx), reason: "embedded message failed validation", cause: err, } } } } } return nil }
[ "func", "(", "m", "*", "Permission_Set", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "len", "(", "m", ".", "GetRules", "(", ")", ")", "<", "1", "{", "return", "Permission_SetValida...
// Validate checks the field values on Permission_Set with the rules defined in // the proto definition for this message. If any rules are violated, an error // is returned.
[ "Validate", "checks", "the", "field", "values", "on", "Permission_Set", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "." ]
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/config/rbac/v2alpha/rbac.pb.validate.go#L638-L671
train
envoyproxy/go-control-plane
envoy/config/rbac/v2alpha/rbac.pb.validate.go
Validate
func (m *Principal_Set) Validate() error { if m == nil { return nil } if len(m.GetIds()) < 1 { return Principal_SetValidationError{ field: "Ids", reason: "value must contain at least 1 item(s)", } } for idx, item := range m.GetIds() { _, _ = idx, item { tmp := item if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return Principal_SetValidationError{ field: fmt.Sprintf("Ids[%v]", idx), reason: "embedded message failed validation", cause: err, } } } } } return nil }
go
func (m *Principal_Set) Validate() error { if m == nil { return nil } if len(m.GetIds()) < 1 { return Principal_SetValidationError{ field: "Ids", reason: "value must contain at least 1 item(s)", } } for idx, item := range m.GetIds() { _, _ = idx, item { tmp := item if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return Principal_SetValidationError{ field: fmt.Sprintf("Ids[%v]", idx), reason: "embedded message failed validation", cause: err, } } } } } return nil }
[ "func", "(", "m", "*", "Principal_Set", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "len", "(", "m", ".", "GetIds", "(", ")", ")", "<", "1", "{", "return", "Principal_SetValidation...
// Validate checks the field values on Principal_Set with the rules defined in // the proto definition for this message. If any rules are violated, an error // is returned.
[ "Validate", "checks", "the", "field", "values", "on", "Principal_Set", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "." ]
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/config/rbac/v2alpha/rbac.pb.validate.go#L730-L763
train
envoyproxy/go-control-plane
envoy/config/rbac/v2alpha/rbac.pb.validate.go
Validate
func (m *Principal_Authenticated) Validate() error { if m == nil { return nil } { tmp := m.GetPrincipalName() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return Principal_AuthenticatedValidationError{ field: "PrincipalName", reason: "embedded message failed validation", cause: err, } } } } return nil }
go
func (m *Principal_Authenticated) Validate() error { if m == nil { return nil } { tmp := m.GetPrincipalName() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return Principal_AuthenticatedValidationError{ field: "PrincipalName", reason: "embedded message failed validation", cause: err, } } } } return nil }
[ "func", "(", "m", "*", "Principal_Authenticated", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "{", "tmp", ":=", "m", ".", "GetPrincipalName", "(", ")", "\n\n", "if", "v", ",", "ok", ":="...
// Validate checks the field values on Principal_Authenticated with the rules // defined in the proto definition for this message. If any rules are // violated, an error is returned.
[ "Validate", "checks", "the", "field", "values", "on", "Principal_Authenticated", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "."...
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/config/rbac/v2alpha/rbac.pb.validate.go#L822-L843
train
envoyproxy/go-control-plane
envoy/admin/v2alpha/tap.pb.validate.go
Validate
func (m *TapRequest) Validate() error { if m == nil { return nil } if len(m.GetConfigId()) < 1 { return TapRequestValidationError{ field: "ConfigId", reason: "value length must be at least 1 bytes", } } if m.GetTapConfig() == nil { return TapRequestValidationError{ field: "TapConfig", reason: "value is required", } } { tmp := m.GetTapConfig() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return TapRequestValidationError{ field: "TapConfig", reason: "embedded message failed validation", cause: err, } } } } return nil }
go
func (m *TapRequest) Validate() error { if m == nil { return nil } if len(m.GetConfigId()) < 1 { return TapRequestValidationError{ field: "ConfigId", reason: "value length must be at least 1 bytes", } } if m.GetTapConfig() == nil { return TapRequestValidationError{ field: "TapConfig", reason: "value is required", } } { tmp := m.GetTapConfig() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return TapRequestValidationError{ field: "TapConfig", reason: "embedded message failed validation", cause: err, } } } } return nil }
[ "func", "(", "m", "*", "TapRequest", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "len", "(", "m", ".", "GetConfigId", "(", ")", ")", "<", "1", "{", "return", "TapRequestValidationE...
// Validate checks the field values on TapRequest with the rules defined in the // proto definition for this message. If any rules are violated, an error is returned.
[ "Validate", "checks", "the", "field", "values", "on", "TapRequest", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "." ]
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/admin/v2alpha/tap.pb.validate.go#L38-L73
train
envoyproxy/go-control-plane
envoy/config/accesslog/v2/als.pb.validate.go
Validate
func (m *HttpGrpcAccessLogConfig) Validate() error { if m == nil { return nil } if m.GetCommonConfig() == nil { return HttpGrpcAccessLogConfigValidationError{ field: "CommonConfig", reason: "value is required", } } { tmp := m.GetCommonConfig() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return HttpGrpcAccessLogConfigValidationError{ field: "CommonConfig", reason: "embedded message failed validation", cause: err, } } } } return nil }
go
func (m *HttpGrpcAccessLogConfig) Validate() error { if m == nil { return nil } if m.GetCommonConfig() == nil { return HttpGrpcAccessLogConfigValidationError{ field: "CommonConfig", reason: "value is required", } } { tmp := m.GetCommonConfig() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return HttpGrpcAccessLogConfigValidationError{ field: "CommonConfig", reason: "embedded message failed validation", cause: err, } } } } return nil }
[ "func", "(", "m", "*", "HttpGrpcAccessLogConfig", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "m", ".", "GetCommonConfig", "(", ")", "==", "nil", "{", "return", "HttpGrpcAccessLogConfigV...
// Validate checks the field values on HttpGrpcAccessLogConfig with the rules // defined in the proto definition for this message. If any rules are // violated, an error is returned.
[ "Validate", "checks", "the", "field", "values", "on", "HttpGrpcAccessLogConfig", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "."...
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/config/accesslog/v2/als.pb.validate.go#L39-L67
train
envoyproxy/go-control-plane
envoy/config/accesslog/v2/als.pb.validate.go
Validate
func (m *TcpGrpcAccessLogConfig) Validate() error { if m == nil { return nil } if m.GetCommonConfig() == nil { return TcpGrpcAccessLogConfigValidationError{ field: "CommonConfig", reason: "value is required", } } { tmp := m.GetCommonConfig() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return TcpGrpcAccessLogConfigValidationError{ field: "CommonConfig", reason: "embedded message failed validation", cause: err, } } } } return nil }
go
func (m *TcpGrpcAccessLogConfig) Validate() error { if m == nil { return nil } if m.GetCommonConfig() == nil { return TcpGrpcAccessLogConfigValidationError{ field: "CommonConfig", reason: "value is required", } } { tmp := m.GetCommonConfig() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return TcpGrpcAccessLogConfigValidationError{ field: "CommonConfig", reason: "embedded message failed validation", cause: err, } } } } return nil }
[ "func", "(", "m", "*", "TcpGrpcAccessLogConfig", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "m", ".", "GetCommonConfig", "(", ")", "==", "nil", "{", "return", "TcpGrpcAccessLogConfigVal...
// Validate checks the field values on TcpGrpcAccessLogConfig with the rules // defined in the proto definition for this message. If any rules are // violated, an error is returned.
[ "Validate", "checks", "the", "field", "values", "on", "TcpGrpcAccessLogConfig", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "." ...
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/config/accesslog/v2/als.pb.validate.go#L128-L156
train
envoyproxy/go-control-plane
envoy/config/accesslog/v2/als.pb.validate.go
Validate
func (m *CommonGrpcAccessLogConfig) Validate() error { if m == nil { return nil } if len(m.GetLogName()) < 1 { return CommonGrpcAccessLogConfigValidationError{ field: "LogName", reason: "value length must be at least 1 bytes", } } if m.GetGrpcService() == nil { return CommonGrpcAccessLogConfigValidationError{ field: "GrpcService", reason: "value is required", } } { tmp := m.GetGrpcService() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return CommonGrpcAccessLogConfigValidationError{ field: "GrpcService", reason: "embedded message failed validation", cause: err, } } } } return nil }
go
func (m *CommonGrpcAccessLogConfig) Validate() error { if m == nil { return nil } if len(m.GetLogName()) < 1 { return CommonGrpcAccessLogConfigValidationError{ field: "LogName", reason: "value length must be at least 1 bytes", } } if m.GetGrpcService() == nil { return CommonGrpcAccessLogConfigValidationError{ field: "GrpcService", reason: "value is required", } } { tmp := m.GetGrpcService() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return CommonGrpcAccessLogConfigValidationError{ field: "GrpcService", reason: "embedded message failed validation", cause: err, } } } } return nil }
[ "func", "(", "m", "*", "CommonGrpcAccessLogConfig", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "len", "(", "m", ".", "GetLogName", "(", ")", ")", "<", "1", "{", "return", "CommonG...
// Validate checks the field values on CommonGrpcAccessLogConfig with the rules // defined in the proto definition for this message. If any rules are // violated, an error is returned.
[ "Validate", "checks", "the", "field", "values", "on", "CommonGrpcAccessLogConfig", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "...
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/config/accesslog/v2/als.pb.validate.go#L217-L252
train
envoyproxy/go-control-plane
envoy/service/auth/v2/attribute_context.pb.validate.go
Validate
func (m *AttributeContext) Validate() error { if m == nil { return nil } { tmp := m.GetSource() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return AttributeContextValidationError{ field: "Source", reason: "embedded message failed validation", cause: err, } } } } { tmp := m.GetDestination() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return AttributeContextValidationError{ field: "Destination", reason: "embedded message failed validation", cause: err, } } } } { tmp := m.GetRequest() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return AttributeContextValidationError{ field: "Request", reason: "embedded message failed validation", cause: err, } } } } // no validation rules for ContextExtensions return nil }
go
func (m *AttributeContext) Validate() error { if m == nil { return nil } { tmp := m.GetSource() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return AttributeContextValidationError{ field: "Source", reason: "embedded message failed validation", cause: err, } } } } { tmp := m.GetDestination() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return AttributeContextValidationError{ field: "Destination", reason: "embedded message failed validation", cause: err, } } } } { tmp := m.GetRequest() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return AttributeContextValidationError{ field: "Request", reason: "embedded message failed validation", cause: err, } } } } // no validation rules for ContextExtensions return nil }
[ "func", "(", "m", "*", "AttributeContext", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "{", "tmp", ":=", "m", ".", "GetSource", "(", ")", "\n\n", "if", "v", ",", "ok", ":=", "interface...
// Validate checks the field values on AttributeContext with the rules defined // in the proto definition for this message. If any rules are violated, an // error is returned.
[ "Validate", "checks", "the", "field", "values", "on", "AttributeContext", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "." ]
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/service/auth/v2/attribute_context.pb.validate.go#L39-L92
train
envoyproxy/go-control-plane
envoy/service/auth/v2/attribute_context.pb.validate.go
Validate
func (m *AttributeContext_Peer) Validate() error { if m == nil { return nil } { tmp := m.GetAddress() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return AttributeContext_PeerValidationError{ field: "Address", reason: "embedded message failed validation", cause: err, } } } } // no validation rules for Service // no validation rules for Labels // no validation rules for Principal return nil }
go
func (m *AttributeContext_Peer) Validate() error { if m == nil { return nil } { tmp := m.GetAddress() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return AttributeContext_PeerValidationError{ field: "Address", reason: "embedded message failed validation", cause: err, } } } } // no validation rules for Service // no validation rules for Labels // no validation rules for Principal return nil }
[ "func", "(", "m", "*", "AttributeContext_Peer", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "{", "tmp", ":=", "m", ".", "GetAddress", "(", ")", "\n\n", "if", "v", ",", "ok", ":=", "int...
// Validate checks the field values on AttributeContext_Peer with the rules // defined in the proto definition for this message. If any rules are // violated, an error is returned.
[ "Validate", "checks", "the", "field", "values", "on", "AttributeContext_Peer", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "." ]
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/service/auth/v2/attribute_context.pb.validate.go#L151-L178
train
envoyproxy/go-control-plane
envoy/service/auth/v2/attribute_context.pb.validate.go
Validate
func (m *AttributeContext_Request) Validate() error { if m == nil { return nil } { tmp := m.GetTime() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return AttributeContext_RequestValidationError{ field: "Time", reason: "embedded message failed validation", cause: err, } } } } { tmp := m.GetHttp() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return AttributeContext_RequestValidationError{ field: "Http", reason: "embedded message failed validation", cause: err, } } } } return nil }
go
func (m *AttributeContext_Request) Validate() error { if m == nil { return nil } { tmp := m.GetTime() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return AttributeContext_RequestValidationError{ field: "Time", reason: "embedded message failed validation", cause: err, } } } } { tmp := m.GetHttp() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return AttributeContext_RequestValidationError{ field: "Http", reason: "embedded message failed validation", cause: err, } } } } return nil }
[ "func", "(", "m", "*", "AttributeContext_Request", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "{", "tmp", ":=", "m", ".", "GetTime", "(", ")", "\n\n", "if", "v", ",", "ok", ":=", "int...
// Validate checks the field values on AttributeContext_Request with the rules // defined in the proto definition for this message. If any rules are // violated, an error is returned.
[ "Validate", "checks", "the", "field", "values", "on", "AttributeContext_Request", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "....
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/service/auth/v2/attribute_context.pb.validate.go#L239-L275
train
envoyproxy/go-control-plane
envoy/config/filter/http/transcoder/v2/transcoder.pb.validate.go
Validate
func (m *GrpcJsonTranscoder) Validate() error { if m == nil { return nil } if len(m.GetServices()) < 1 { return GrpcJsonTranscoderValidationError{ field: "Services", reason: "value must contain at least 1 item(s)", } } { tmp := m.GetPrintOptions() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return GrpcJsonTranscoderValidationError{ field: "PrintOptions", reason: "embedded message failed validation", cause: err, } } } } // no validation rules for MatchIncomingRequestRoute switch m.DescriptorSet.(type) { case *GrpcJsonTranscoder_ProtoDescriptor: // no validation rules for ProtoDescriptor case *GrpcJsonTranscoder_ProtoDescriptorBin: // no validation rules for ProtoDescriptorBin default: return GrpcJsonTranscoderValidationError{ field: "DescriptorSet", reason: "value is required", } } return nil }
go
func (m *GrpcJsonTranscoder) Validate() error { if m == nil { return nil } if len(m.GetServices()) < 1 { return GrpcJsonTranscoderValidationError{ field: "Services", reason: "value must contain at least 1 item(s)", } } { tmp := m.GetPrintOptions() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return GrpcJsonTranscoderValidationError{ field: "PrintOptions", reason: "embedded message failed validation", cause: err, } } } } // no validation rules for MatchIncomingRequestRoute switch m.DescriptorSet.(type) { case *GrpcJsonTranscoder_ProtoDescriptor: // no validation rules for ProtoDescriptor case *GrpcJsonTranscoder_ProtoDescriptorBin: // no validation rules for ProtoDescriptorBin default: return GrpcJsonTranscoderValidationError{ field: "DescriptorSet", reason: "value is required", } } return nil }
[ "func", "(", "m", "*", "GrpcJsonTranscoder", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "len", "(", "m", ".", "GetServices", "(", ")", ")", "<", "1", "{", "return", "GrpcJsonTrans...
// Validate checks the field values on GrpcJsonTranscoder with the rules // defined in the proto definition for this message. If any rules are // violated, an error is returned.
[ "Validate", "checks", "the", "field", "values", "on", "GrpcJsonTranscoder", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "." ]
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/config/filter/http/transcoder/v2/transcoder.pb.validate.go#L39-L85
train
envoyproxy/go-control-plane
envoy/service/metrics/v2/metrics_service.pb.validate.go
Validate
func (m *StreamMetricsMessage) Validate() error { if m == nil { return nil } { tmp := m.GetIdentifier() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return StreamMetricsMessageValidationError{ field: "Identifier", reason: "embedded message failed validation", cause: err, } } } } for idx, item := range m.GetEnvoyMetrics() { _, _ = idx, item { tmp := item if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return StreamMetricsMessageValidationError{ field: fmt.Sprintf("EnvoyMetrics[%v]", idx), reason: "embedded message failed validation", cause: err, } } } } } return nil }
go
func (m *StreamMetricsMessage) Validate() error { if m == nil { return nil } { tmp := m.GetIdentifier() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return StreamMetricsMessageValidationError{ field: "Identifier", reason: "embedded message failed validation", cause: err, } } } } for idx, item := range m.GetEnvoyMetrics() { _, _ = idx, item { tmp := item if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return StreamMetricsMessageValidationError{ field: fmt.Sprintf("EnvoyMetrics[%v]", idx), reason: "embedded message failed validation", cause: err, } } } } } return nil }
[ "func", "(", "m", "*", "StreamMetricsMessage", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "{", "tmp", ":=", "m", ".", "GetIdentifier", "(", ")", "\n\n", "if", "v", ",", "ok", ":=", "i...
// Validate checks the field values on StreamMetricsMessage with the rules // defined in the proto definition for this message. If any rules are // violated, an error is returned.
[ "Validate", "checks", "the", "field", "values", "on", "StreamMetricsMessage", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "." ]
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/service/metrics/v2/metrics_service.pb.validate.go#L106-L147
train
envoyproxy/go-control-plane
envoy/service/metrics/v2/metrics_service.pb.validate.go
Validate
func (m *StreamMetricsMessage_Identifier) Validate() error { if m == nil { return nil } if m.GetNode() == nil { return StreamMetricsMessage_IdentifierValidationError{ field: "Node", reason: "value is required", } } { tmp := m.GetNode() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return StreamMetricsMessage_IdentifierValidationError{ field: "Node", reason: "embedded message failed validation", cause: err, } } } } return nil }
go
func (m *StreamMetricsMessage_Identifier) Validate() error { if m == nil { return nil } if m.GetNode() == nil { return StreamMetricsMessage_IdentifierValidationError{ field: "Node", reason: "value is required", } } { tmp := m.GetNode() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return StreamMetricsMessage_IdentifierValidationError{ field: "Node", reason: "embedded message failed validation", cause: err, } } } } return nil }
[ "func", "(", "m", "*", "StreamMetricsMessage_Identifier", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "m", ".", "GetNode", "(", ")", "==", "nil", "{", "return", "StreamMetricsMessage_Ide...
// Validate checks the field values on StreamMetricsMessage_Identifier with the // rules defined in the proto definition for this message. If any rules are // violated, an error is returned.
[ "Validate", "checks", "the", "field", "values", "on", "StreamMetricsMessage_Identifier", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned...
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/service/metrics/v2/metrics_service.pb.validate.go#L208-L236
train
envoyproxy/go-control-plane
envoy/config/grpc_credential/v2alpha/file_based_metadata.pb.validate.go
Validate
func (m *FileBasedMetadataConfig) Validate() error { if m == nil { return nil } { tmp := m.GetSecretData() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return FileBasedMetadataConfigValidationError{ field: "SecretData", reason: "embedded message failed validation", cause: err, } } } } // no validation rules for HeaderKey // no validation rules for HeaderPrefix return nil }
go
func (m *FileBasedMetadataConfig) Validate() error { if m == nil { return nil } { tmp := m.GetSecretData() if v, ok := interface{}(tmp).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return FileBasedMetadataConfigValidationError{ field: "SecretData", reason: "embedded message failed validation", cause: err, } } } } // no validation rules for HeaderKey // no validation rules for HeaderPrefix return nil }
[ "func", "(", "m", "*", "FileBasedMetadataConfig", ")", "Validate", "(", ")", "error", "{", "if", "m", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "{", "tmp", ":=", "m", ".", "GetSecretData", "(", ")", "\n\n", "if", "v", ",", "ok", ":=", ...
// Validate checks the field values on FileBasedMetadataConfig with the rules // defined in the proto definition for this message. If any rules are // violated, an error is returned.
[ "Validate", "checks", "the", "field", "values", "on", "FileBasedMetadataConfig", "with", "the", "rules", "defined", "in", "the", "proto", "definition", "for", "this", "message", ".", "If", "any", "rules", "are", "violated", "an", "error", "is", "returned", "."...
9ffbaf293221f9fef735838632a9109d00aa2f4c
https://github.com/envoyproxy/go-control-plane/blob/9ffbaf293221f9fef735838632a9109d00aa2f4c/envoy/config/grpc_credential/v2alpha/file_based_metadata.pb.validate.go#L39-L64
train