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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
sajari/docconv | xml.go | ConvertXML | func ConvertXML(r io.Reader) (string, map[string]string, error) {
meta := make(map[string]string)
cleanXML, err := Tidy(r, true)
if err != nil {
return "", nil, fmt.Errorf("tidy error: %v", err)
}
result, err := XMLToText(bytes.NewReader(cleanXML), []string{}, []string{}, true)
if err != nil {
return "", nil,... | go | func ConvertXML(r io.Reader) (string, map[string]string, error) {
meta := make(map[string]string)
cleanXML, err := Tidy(r, true)
if err != nil {
return "", nil, fmt.Errorf("tidy error: %v", err)
}
result, err := XMLToText(bytes.NewReader(cleanXML), []string{}, []string{}, true)
if err != nil {
return "", nil,... | [
"func",
"ConvertXML",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"string",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"meta",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"cleanXML",
",",
"err",
":=",
"T... | // ConvertXML converts an XML file to text. | [
"ConvertXML",
"converts",
"an",
"XML",
"file",
"to",
"text",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/xml.go#L11-L22 | train |
sajari/docconv | xml.go | XMLToText | func XMLToText(r io.Reader, breaks []string, skip []string, strict bool) (string, error) {
var result string
dec := xml.NewDecoder(r)
dec.Strict = strict
for {
t, err := dec.Token()
if err != nil {
if err == io.EOF {
break
}
return "", err
}
switch v := t.(type) {
case xml.CharData:
resu... | go | func XMLToText(r io.Reader, breaks []string, skip []string, strict bool) (string, error) {
var result string
dec := xml.NewDecoder(r)
dec.Strict = strict
for {
t, err := dec.Token()
if err != nil {
if err == io.EOF {
break
}
return "", err
}
switch v := t.(type) {
case xml.CharData:
resu... | [
"func",
"XMLToText",
"(",
"r",
"io",
".",
"Reader",
",",
"breaks",
"[",
"]",
"string",
",",
"skip",
"[",
"]",
"string",
",",
"strict",
"bool",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"result",
"string",
"\n\n",
"dec",
":=",
"xml",
".",
... | // XMLToText converts XML to plain text given how to treat elements. | [
"XMLToText",
"converts",
"XML",
"to",
"plain",
"text",
"given",
"how",
"to",
"treat",
"elements",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/xml.go#L25-L74 | train |
sajari/docconv | xml.go | XMLToMap | func XMLToMap(r io.Reader) (map[string]string, error) {
m := make(map[string]string)
dec := xml.NewDecoder(r)
var tagName string
for {
t, err := dec.Token()
if err != nil {
if err == io.EOF {
break
}
return nil, err
}
switch v := t.(type) {
case xml.StartElement:
tagName = string(v.Name.L... | go | func XMLToMap(r io.Reader) (map[string]string, error) {
m := make(map[string]string)
dec := xml.NewDecoder(r)
var tagName string
for {
t, err := dec.Token()
if err != nil {
if err == io.EOF {
break
}
return nil, err
}
switch v := t.(type) {
case xml.StartElement:
tagName = string(v.Name.L... | [
"func",
"XMLToMap",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"dec",
":=",
"xml",
".",
"NewDecoder",
"(",
"r",
"... | // XMLToMap converts XML to a nested string map. | [
"XMLToMap",
"converts",
"XML",
"to",
"a",
"nested",
"string",
"map",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/xml.go#L77-L98 | train |
go-pg/pg | orm/delete.go | ForceDelete | func ForceDelete(db DB, model interface{}) error {
res, err := NewQuery(db, model).WherePK().ForceDelete()
if err != nil {
return err
}
return internal.AssertOneRow(res.RowsAffected())
} | go | func ForceDelete(db DB, model interface{}) error {
res, err := NewQuery(db, model).WherePK().ForceDelete()
if err != nil {
return err
}
return internal.AssertOneRow(res.RowsAffected())
} | [
"func",
"ForceDelete",
"(",
"db",
"DB",
",",
"model",
"interface",
"{",
"}",
")",
"error",
"{",
"res",
",",
"err",
":=",
"NewQuery",
"(",
"db",
",",
"model",
")",
".",
"WherePK",
"(",
")",
".",
"ForceDelete",
"(",
")",
"\n",
"if",
"err",
"!=",
"n... | // ForceDelete force deletes a given model from the db | [
"ForceDelete",
"force",
"deletes",
"a",
"given",
"model",
"from",
"the",
"db"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/delete.go#L17-L23 | train |
go-pg/pg | urlvalues/decode.go | Decode | func Decode(strct interface{}, values Values) error {
v := reflect.Indirect(reflect.ValueOf(strct))
meta := structfilter.GetStruct(v.Type())
for name, values := range values {
name = strings.TrimPrefix(name, ":")
name = strings.TrimSuffix(name, "[]")
field := meta.Field(name)
if field != nil && !field.NoDe... | go | func Decode(strct interface{}, values Values) error {
v := reflect.Indirect(reflect.ValueOf(strct))
meta := structfilter.GetStruct(v.Type())
for name, values := range values {
name = strings.TrimPrefix(name, ":")
name = strings.TrimSuffix(name, "[]")
field := meta.Field(name)
if field != nil && !field.NoDe... | [
"func",
"Decode",
"(",
"strct",
"interface",
"{",
"}",
",",
"values",
"Values",
")",
"error",
"{",
"v",
":=",
"reflect",
".",
"Indirect",
"(",
"reflect",
".",
"ValueOf",
"(",
"strct",
")",
")",
"\n",
"meta",
":=",
"structfilter",
".",
"GetStruct",
"(",... | // Decode decodes url values into the struct. | [
"Decode",
"decodes",
"url",
"values",
"into",
"the",
"struct",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/urlvalues/decode.go#L11-L29 | train |
go-pg/pg | options.go | ParseURL | func ParseURL(sURL string) (*Options, error) {
parsedURL, err := url.Parse(sURL)
if err != nil {
return nil, err
}
// scheme
if parsedURL.Scheme != "postgres" && parsedURL.Scheme != "postgresql" {
return nil, errors.New("pg: invalid scheme: " + parsedURL.Scheme)
}
// host and port
options := &Options{
A... | go | func ParseURL(sURL string) (*Options, error) {
parsedURL, err := url.Parse(sURL)
if err != nil {
return nil, err
}
// scheme
if parsedURL.Scheme != "postgres" && parsedURL.Scheme != "postgresql" {
return nil, errors.New("pg: invalid scheme: " + parsedURL.Scheme)
}
// host and port
options := &Options{
A... | [
"func",
"ParseURL",
"(",
"sURL",
"string",
")",
"(",
"*",
"Options",
",",
"error",
")",
"{",
"parsedURL",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"sURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n"... | // ParseURL parses an URL into options that can be used to connect to PostgreSQL. | [
"ParseURL",
"parses",
"an",
"URL",
"into",
"options",
"that",
"can",
"be",
"used",
"to",
"connect",
"to",
"PostgreSQL",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/options.go#L143-L214 | train |
go-pg/pg | internal/underscore.go | Underscore | func Underscore(s string) string {
r := make([]byte, 0, len(s)+5)
for i := 0; i < len(s); i++ {
c := s[i]
if IsUpper(c) {
if i > 0 && i+1 < len(s) && (IsLower(s[i-1]) || IsLower(s[i+1])) {
r = append(r, '_', ToLower(c))
} else {
r = append(r, ToLower(c))
}
} else {
r = append(r, c)
}
}
r... | go | func Underscore(s string) string {
r := make([]byte, 0, len(s)+5)
for i := 0; i < len(s); i++ {
c := s[i]
if IsUpper(c) {
if i > 0 && i+1 < len(s) && (IsLower(s[i-1]) || IsLower(s[i+1])) {
r = append(r, '_', ToLower(c))
} else {
r = append(r, ToLower(c))
}
} else {
r = append(r, c)
}
}
r... | [
"func",
"Underscore",
"(",
"s",
"string",
")",
"string",
"{",
"r",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"len",
"(",
"s",
")",
"+",
"5",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"s",
")",
";",
"i",
"++",
... | // Underscore converts "CamelCasedString" to "camel_cased_string". | [
"Underscore",
"converts",
"CamelCasedString",
"to",
"camel_cased_string",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/internal/underscore.go#L20-L35 | train |
go-pg/pg | tx.go | Begin | func (db *baseDB) Begin() (*Tx, error) {
tx := &Tx{
db: db.withPool(pool.NewSingleConnPool(db.pool)),
ctx: db.db.Context(),
}
err := tx.begin()
if err != nil {
tx.close()
return nil, err
}
return tx, nil
} | go | func (db *baseDB) Begin() (*Tx, error) {
tx := &Tx{
db: db.withPool(pool.NewSingleConnPool(db.pool)),
ctx: db.db.Context(),
}
err := tx.begin()
if err != nil {
tx.close()
return nil, err
}
return tx, nil
} | [
"func",
"(",
"db",
"*",
"baseDB",
")",
"Begin",
"(",
")",
"(",
"*",
"Tx",
",",
"error",
")",
"{",
"tx",
":=",
"&",
"Tx",
"{",
"db",
":",
"db",
".",
"withPool",
"(",
"pool",
".",
"NewSingleConnPool",
"(",
"db",
".",
"pool",
")",
")",
",",
"ctx... | // Begin starts a transaction. Most callers should use RunInTransaction instead. | [
"Begin",
"starts",
"a",
"transaction",
".",
"Most",
"callers",
"should",
"use",
"RunInTransaction",
"instead",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/tx.go#L38-L51 | train |
go-pg/pg | tx.go | RunInTransaction | func (db *baseDB) RunInTransaction(fn func(*Tx) error) error {
tx, err := db.Begin()
if err != nil {
return err
}
return tx.RunInTransaction(fn)
} | go | func (db *baseDB) RunInTransaction(fn func(*Tx) error) error {
tx, err := db.Begin()
if err != nil {
return err
}
return tx.RunInTransaction(fn)
} | [
"func",
"(",
"db",
"*",
"baseDB",
")",
"RunInTransaction",
"(",
"fn",
"func",
"(",
"*",
"Tx",
")",
"error",
")",
"error",
"{",
"tx",
",",
"err",
":=",
"db",
".",
"Begin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}"... | // RunInTransaction runs a function in a transaction. If function
// returns an error transaction is rollbacked, otherwise transaction
// is committed. | [
"RunInTransaction",
"runs",
"a",
"function",
"in",
"a",
"transaction",
".",
"If",
"function",
"returns",
"an",
"error",
"transaction",
"is",
"rollbacked",
"otherwise",
"transaction",
"is",
"committed",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/tx.go#L56-L62 | train |
go-pg/pg | tx.go | RunInTransaction | func (tx *Tx) RunInTransaction(fn func(*Tx) error) error {
defer func() {
if err := recover(); err != nil {
_ = tx.Rollback()
panic(err)
}
}()
if err := fn(tx); err != nil {
_ = tx.Rollback()
return err
}
return tx.Commit()
} | go | func (tx *Tx) RunInTransaction(fn func(*Tx) error) error {
defer func() {
if err := recover(); err != nil {
_ = tx.Rollback()
panic(err)
}
}()
if err := fn(tx); err != nil {
_ = tx.Rollback()
return err
}
return tx.Commit()
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"RunInTransaction",
"(",
"fn",
"func",
"(",
"*",
"Tx",
")",
"error",
")",
"error",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
":=",
"recover",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"_",
"=",
"tx",
"... | // RunInTransaction runs a function in the transaction. If function
// returns an error transaction is rollbacked, otherwise transaction
// is committed. | [
"RunInTransaction",
"runs",
"a",
"function",
"in",
"the",
"transaction",
".",
"If",
"function",
"returns",
"an",
"error",
"transaction",
"is",
"rollbacked",
"otherwise",
"transaction",
"is",
"committed",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/tx.go#L72-L84 | train |
go-pg/pg | tx.go | Stmt | func (tx *Tx) Stmt(stmt *Stmt) *Stmt {
stmt, err := tx.Prepare(stmt.q)
if err != nil {
return &Stmt{stickyErr: err}
}
return stmt
} | go | func (tx *Tx) Stmt(stmt *Stmt) *Stmt {
stmt, err := tx.Prepare(stmt.q)
if err != nil {
return &Stmt{stickyErr: err}
}
return stmt
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"Stmt",
"(",
"stmt",
"*",
"Stmt",
")",
"*",
"Stmt",
"{",
"stmt",
",",
"err",
":=",
"tx",
".",
"Prepare",
"(",
"stmt",
".",
"q",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"Stmt",
"{",
"stickyEr... | // Stmt returns a transaction-specific prepared statement
// from an existing statement. | [
"Stmt",
"returns",
"a",
"transaction",
"-",
"specific",
"prepared",
"statement",
"from",
"an",
"existing",
"statement",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/tx.go#L96-L102 | train |
go-pg/pg | tx.go | ExecContext | func (tx *Tx) ExecContext(c context.Context, query interface{}, params ...interface{}) (Result, error) {
return tx.exec(c, query, params...)
} | go | func (tx *Tx) ExecContext(c context.Context, query interface{}, params ...interface{}) (Result, error) {
return tx.exec(c, query, params...)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"ExecContext",
"(",
"c",
"context",
".",
"Context",
",",
"query",
"interface",
"{",
"}",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"Result",
",",
"error",
")",
"{",
"return",
"tx",
".",
"exec",
"(",
... | // ExecContext acts like Exec but additionally receives a context | [
"ExecContext",
"acts",
"like",
"Exec",
"but",
"additionally",
"receives",
"a",
"context"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/tx.go#L129-L131 | train |
go-pg/pg | tx.go | Model | func (tx *Tx) Model(model ...interface{}) *orm.Query {
return orm.NewQuery(tx, model...)
} | go | func (tx *Tx) Model(model ...interface{}) *orm.Query {
return orm.NewQuery(tx, model...)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"Model",
"(",
"model",
"...",
"interface",
"{",
"}",
")",
"*",
"orm",
".",
"Query",
"{",
"return",
"orm",
".",
"NewQuery",
"(",
"tx",
",",
"model",
"...",
")",
"\n",
"}"
] | // Model is an alias for DB.Model. | [
"Model",
"is",
"an",
"alias",
"for",
"DB",
".",
"Model",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/tx.go#L243-L245 | train |
go-pg/pg | tx.go | ModelContext | func (tx *Tx) ModelContext(c context.Context, model ...interface{}) *orm.Query {
return orm.NewQueryContext(c, tx, model...)
} | go | func (tx *Tx) ModelContext(c context.Context, model ...interface{}) *orm.Query {
return orm.NewQueryContext(c, tx, model...)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"ModelContext",
"(",
"c",
"context",
".",
"Context",
",",
"model",
"...",
"interface",
"{",
"}",
")",
"*",
"orm",
".",
"Query",
"{",
"return",
"orm",
".",
"NewQueryContext",
"(",
"c",
",",
"tx",
",",
"model",
"...... | // ModelContext acts like Model but additionally receives a context | [
"ModelContext",
"acts",
"like",
"Model",
"but",
"additionally",
"receives",
"a",
"context"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/tx.go#L248-L250 | train |
go-pg/pg | tx.go | CreateTable | func (tx *Tx) CreateTable(model interface{}, opt *orm.CreateTableOptions) error {
return orm.CreateTable(tx, model, opt)
} | go | func (tx *Tx) CreateTable(model interface{}, opt *orm.CreateTableOptions) error {
return orm.CreateTable(tx, model, opt)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"CreateTable",
"(",
"model",
"interface",
"{",
"}",
",",
"opt",
"*",
"orm",
".",
"CreateTableOptions",
")",
"error",
"{",
"return",
"orm",
".",
"CreateTable",
"(",
"tx",
",",
"model",
",",
"opt",
")",
"\n",
"}"
] | // CreateTable is an alias for DB.CreateTable. | [
"CreateTable",
"is",
"an",
"alias",
"for",
"DB",
".",
"CreateTable",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/tx.go#L278-L280 | train |
go-pg/pg | tx.go | DropTable | func (tx *Tx) DropTable(model interface{}, opt *orm.DropTableOptions) error {
return orm.DropTable(tx, model, opt)
} | go | func (tx *Tx) DropTable(model interface{}, opt *orm.DropTableOptions) error {
return orm.DropTable(tx, model, opt)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"DropTable",
"(",
"model",
"interface",
"{",
"}",
",",
"opt",
"*",
"orm",
".",
"DropTableOptions",
")",
"error",
"{",
"return",
"orm",
".",
"DropTable",
"(",
"tx",
",",
"model",
",",
"opt",
")",
"\n",
"}"
] | // DropTable is an alias for DB.DropTable. | [
"DropTable",
"is",
"an",
"alias",
"for",
"DB",
".",
"DropTable",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/tx.go#L283-L285 | train |
go-pg/pg | tx.go | CopyFrom | func (tx *Tx) CopyFrom(r io.Reader, query interface{}, params ...interface{}) (res Result, err error) {
err = tx.withConn(context.TODO(), func(cn *pool.Conn) error {
res, err = tx.db.copyFrom(cn, r, query, params...)
return err
})
return res, err
} | go | func (tx *Tx) CopyFrom(r io.Reader, query interface{}, params ...interface{}) (res Result, err error) {
err = tx.withConn(context.TODO(), func(cn *pool.Conn) error {
res, err = tx.db.copyFrom(cn, r, query, params...)
return err
})
return res, err
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"CopyFrom",
"(",
"r",
"io",
".",
"Reader",
",",
"query",
"interface",
"{",
"}",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"res",
"Result",
",",
"err",
"error",
")",
"{",
"err",
"=",
"tx",
".",
"wi... | // CopyFrom is an alias for DB.CopyFrom. | [
"CopyFrom",
"is",
"an",
"alias",
"for",
"DB",
".",
"CopyFrom",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/tx.go#L288-L294 | train |
go-pg/pg | tx.go | CopyTo | func (tx *Tx) CopyTo(w io.Writer, query interface{}, params ...interface{}) (res Result, err error) {
err = tx.withConn(context.TODO(), func(cn *pool.Conn) error {
res, err = tx.db.copyTo(cn, w, query, params...)
return err
})
return res, err
} | go | func (tx *Tx) CopyTo(w io.Writer, query interface{}, params ...interface{}) (res Result, err error) {
err = tx.withConn(context.TODO(), func(cn *pool.Conn) error {
res, err = tx.db.copyTo(cn, w, query, params...)
return err
})
return res, err
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"CopyTo",
"(",
"w",
"io",
".",
"Writer",
",",
"query",
"interface",
"{",
"}",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"res",
"Result",
",",
"err",
"error",
")",
"{",
"err",
"=",
"tx",
".",
"with... | // CopyTo is an alias for DB.CopyTo. | [
"CopyTo",
"is",
"an",
"alias",
"for",
"DB",
".",
"CopyTo",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/tx.go#L297-L303 | train |
go-pg/pg | tx.go | FormatQuery | func (tx *Tx) FormatQuery(dst []byte, query string, params ...interface{}) []byte {
return tx.db.FormatQuery(dst, query, params...)
} | go | func (tx *Tx) FormatQuery(dst []byte, query string, params ...interface{}) []byte {
return tx.db.FormatQuery(dst, query, params...)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"FormatQuery",
"(",
"dst",
"[",
"]",
"byte",
",",
"query",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"return",
"tx",
".",
"db",
".",
"FormatQuery",
"(",
"dst",
",",
"quer... | // FormatQuery is an alias for DB.FormatQuery | [
"FormatQuery",
"is",
"an",
"alias",
"for",
"DB",
".",
"FormatQuery"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/tx.go#L306-L308 | train |
go-pg/pg | hook.go | UnformattedQuery | func (ev *QueryEvent) UnformattedQuery() (string, error) {
b, err := queryString(ev.Query)
if err != nil {
return "", err
}
return string(b), nil
} | go | func (ev *QueryEvent) UnformattedQuery() (string, error) {
b, err := queryString(ev.Query)
if err != nil {
return "", err
}
return string(b), nil
} | [
"func",
"(",
"ev",
"*",
"QueryEvent",
")",
"UnformattedQuery",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"queryString",
"(",
"ev",
".",
"Query",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"e... | // UnformattedQuery returns the unformatted query of a query event | [
"UnformattedQuery",
"returns",
"the",
"unformatted",
"query",
"of",
"a",
"query",
"event"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/hook.go#L36-L42 | train |
go-pg/pg | hook.go | FormattedQuery | func (ev *QueryEvent) FormattedQuery() (string, error) {
b, err := appendQuery(ev.DB, nil, ev.Query, ev.Params...)
if err != nil {
return "", err
}
return string(b), nil
} | go | func (ev *QueryEvent) FormattedQuery() (string, error) {
b, err := appendQuery(ev.DB, nil, ev.Query, ev.Params...)
if err != nil {
return "", err
}
return string(b), nil
} | [
"func",
"(",
"ev",
"*",
"QueryEvent",
")",
"FormattedQuery",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"appendQuery",
"(",
"ev",
".",
"DB",
",",
"nil",
",",
"ev",
".",
"Query",
",",
"ev",
".",
"Params",
"...",
")",
... | // FormattedQuery returns the formatted query of a query event | [
"FormattedQuery",
"returns",
"the",
"formatted",
"query",
"of",
"a",
"query",
"event"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/hook.go#L45-L51 | train |
go-pg/pg | hook.go | AddQueryHook | func (db *baseDB) AddQueryHook(hook QueryHook) {
db.queryHooks = append(db.queryHooks, hook)
} | go | func (db *baseDB) AddQueryHook(hook QueryHook) {
db.queryHooks = append(db.queryHooks, hook)
} | [
"func",
"(",
"db",
"*",
"baseDB",
")",
"AddQueryHook",
"(",
"hook",
"QueryHook",
")",
"{",
"db",
".",
"queryHooks",
"=",
"append",
"(",
"db",
".",
"queryHooks",
",",
"hook",
")",
"\n",
"}"
] | // AddQueryHook adds a hook into query processing. | [
"AddQueryHook",
"adds",
"a",
"hook",
"into",
"query",
"processing",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/hook.go#L65-L67 | train |
go-pg/pg | listener.go | Close | func (ln *Listener) Close() error {
ln.mu.Lock()
defer ln.mu.Unlock()
if ln.closed {
return errListenerClosed
}
ln.closed = true
close(ln.exit)
return ln._closeTheCn(errListenerClosed)
} | go | func (ln *Listener) Close() error {
ln.mu.Lock()
defer ln.mu.Unlock()
if ln.closed {
return errListenerClosed
}
ln.closed = true
close(ln.exit)
return ln._closeTheCn(errListenerClosed)
} | [
"func",
"(",
"ln",
"*",
"Listener",
")",
"Close",
"(",
")",
"error",
"{",
"ln",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ln",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"ln",
".",
"closed",
"{",
"return",
"errListenerClosed",
"\n"... | // Close closes the listener, releasing any open resources. | [
"Close",
"closes",
"the",
"listener",
"releasing",
"any",
"open",
"resources",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/listener.go#L132-L143 | train |
go-pg/pg | listener.go | Listen | func (ln *Listener) Listen(channels ...string) error {
// Always append channels so DB.Listen works correctly.
ln.channels = appendIfNotExists(ln.channels, channels...)
cn, err := ln.conn()
if err != nil {
return err
}
err = ln.listen(cn, channels...)
if err != nil {
ln.releaseConn(cn, err, false)
return... | go | func (ln *Listener) Listen(channels ...string) error {
// Always append channels so DB.Listen works correctly.
ln.channels = appendIfNotExists(ln.channels, channels...)
cn, err := ln.conn()
if err != nil {
return err
}
err = ln.listen(cn, channels...)
if err != nil {
ln.releaseConn(cn, err, false)
return... | [
"func",
"(",
"ln",
"*",
"Listener",
")",
"Listen",
"(",
"channels",
"...",
"string",
")",
"error",
"{",
"// Always append channels so DB.Listen works correctly.",
"ln",
".",
"channels",
"=",
"appendIfNotExists",
"(",
"ln",
".",
"channels",
",",
"channels",
"...",
... | // Listen starts listening for notifications on channels. | [
"Listen",
"starts",
"listening",
"for",
"notifications",
"on",
"channels",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/listener.go#L146-L162 | train |
go-pg/pg | listener.go | Receive | func (ln *Listener) Receive() (channel string, payload string, err error) {
return ln.ReceiveTimeout(0)
} | go | func (ln *Listener) Receive() (channel string, payload string, err error) {
return ln.ReceiveTimeout(0)
} | [
"func",
"(",
"ln",
"*",
"Listener",
")",
"Receive",
"(",
")",
"(",
"channel",
"string",
",",
"payload",
"string",
",",
"err",
"error",
")",
"{",
"return",
"ln",
".",
"ReceiveTimeout",
"(",
"0",
")",
"\n",
"}"
] | // Receive indefinitely waits for a notification. This is low-level API
// and in most cases Channel should be used instead. | [
"Receive",
"indefinitely",
"waits",
"for",
"a",
"notification",
".",
"This",
"is",
"low",
"-",
"level",
"API",
"and",
"in",
"most",
"cases",
"Channel",
"should",
"be",
"used",
"instead",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/listener.go#L179-L181 | train |
go-pg/pg | listener.go | ReceiveTimeout | func (ln *Listener) ReceiveTimeout(timeout time.Duration) (channel, payload string, err error) {
cn, err := ln.conn()
if err != nil {
return "", "", err
}
err = cn.WithReader(timeout, func(rd *internal.BufReader) error {
channel, payload, err = readNotification(rd)
return err
})
if err != nil {
ln.releas... | go | func (ln *Listener) ReceiveTimeout(timeout time.Duration) (channel, payload string, err error) {
cn, err := ln.conn()
if err != nil {
return "", "", err
}
err = cn.WithReader(timeout, func(rd *internal.BufReader) error {
channel, payload, err = readNotification(rd)
return err
})
if err != nil {
ln.releas... | [
"func",
"(",
"ln",
"*",
"Listener",
")",
"ReceiveTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"channel",
",",
"payload",
"string",
",",
"err",
"error",
")",
"{",
"cn",
",",
"err",
":=",
"ln",
".",
"conn",
"(",
")",
"\n",
"if",
"err"... | // ReceiveTimeout waits for a notification until timeout is reached.
// This is low-level API and in most cases Channel should be used instead. | [
"ReceiveTimeout",
"waits",
"for",
"a",
"notification",
"until",
"timeout",
"is",
"reached",
".",
"This",
"is",
"low",
"-",
"level",
"API",
"and",
"in",
"most",
"cases",
"Channel",
"should",
"be",
"used",
"instead",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/listener.go#L185-L201 | train |
go-pg/pg | messages.go | writeBindExecuteMsg | func writeBindExecuteMsg(buf *pool.WriteBuffer, name string, params ...interface{}) error {
buf.StartMessage(bindMsg)
buf.WriteString("")
buf.WriteString(name)
buf.WriteInt16(0)
buf.WriteInt16(int16(len(params)))
for _, param := range params {
buf.StartParam()
bytes := types.Append(buf.Bytes, param, 0)
if b... | go | func writeBindExecuteMsg(buf *pool.WriteBuffer, name string, params ...interface{}) error {
buf.StartMessage(bindMsg)
buf.WriteString("")
buf.WriteString(name)
buf.WriteInt16(0)
buf.WriteInt16(int16(len(params)))
for _, param := range params {
buf.StartParam()
bytes := types.Append(buf.Bytes, param, 0)
if b... | [
"func",
"writeBindExecuteMsg",
"(",
"buf",
"*",
"pool",
".",
"WriteBuffer",
",",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"buf",
".",
"StartMessage",
"(",
"bindMsg",
")",
"\n",
"buf",
".",
"WriteString",
"(",
"\""... | // Writes BIND, EXECUTE and SYNC messages. | [
"Writes",
"BIND",
"EXECUTE",
"and",
"SYNC",
"messages",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/messages.go#L535-L562 | train |
go-pg/pg | stmt.go | Exec | func (stmt *Stmt) Exec(params ...interface{}) (Result, error) {
return stmt.exec(context.TODO(), params...)
} | go | func (stmt *Stmt) Exec(params ...interface{}) (Result, error) {
return stmt.exec(context.TODO(), params...)
} | [
"func",
"(",
"stmt",
"*",
"Stmt",
")",
"Exec",
"(",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"Result",
",",
"error",
")",
"{",
"return",
"stmt",
".",
"exec",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"params",
"...",
")",
"\n",
"}"
] | // Exec executes a prepared statement with the given parameters. | [
"Exec",
"executes",
"a",
"prepared",
"statement",
"with",
"the",
"given",
"parameters",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/stmt.go#L78-L80 | train |
go-pg/pg | stmt.go | ExecContext | func (stmt *Stmt) ExecContext(c context.Context, params ...interface{}) (Result, error) {
return stmt.exec(c, params...)
} | go | func (stmt *Stmt) ExecContext(c context.Context, params ...interface{}) (Result, error) {
return stmt.exec(c, params...)
} | [
"func",
"(",
"stmt",
"*",
"Stmt",
")",
"ExecContext",
"(",
"c",
"context",
".",
"Context",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"Result",
",",
"error",
")",
"{",
"return",
"stmt",
".",
"exec",
"(",
"c",
",",
"params",
"...",
")",
... | // ExecContext executes a prepared statement with the given parameters. | [
"ExecContext",
"executes",
"a",
"prepared",
"statement",
"with",
"the",
"given",
"parameters",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/stmt.go#L83-L85 | train |
go-pg/pg | stmt.go | Query | func (stmt *Stmt) Query(model interface{}, params ...interface{}) (Result, error) {
return stmt.query(context.TODO(), model, params...)
} | go | func (stmt *Stmt) Query(model interface{}, params ...interface{}) (Result, error) {
return stmt.query(context.TODO(), model, params...)
} | [
"func",
"(",
"stmt",
"*",
"Stmt",
")",
"Query",
"(",
"model",
"interface",
"{",
"}",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"Result",
",",
"error",
")",
"{",
"return",
"stmt",
".",
"query",
"(",
"context",
".",
"TODO",
"(",
")",
"... | // Query executes a prepared query statement with the given parameters. | [
"Query",
"executes",
"a",
"prepared",
"query",
"statement",
"with",
"the",
"given",
"parameters",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/stmt.go#L135-L137 | train |
go-pg/pg | base.go | Exec | func (db *baseDB) Exec(query interface{}, params ...interface{}) (res Result, err error) {
return db.exec(context.TODO(), query, params...)
} | go | func (db *baseDB) Exec(query interface{}, params ...interface{}) (res Result, err error) {
return db.exec(context.TODO(), query, params...)
} | [
"func",
"(",
"db",
"*",
"baseDB",
")",
"Exec",
"(",
"query",
"interface",
"{",
"}",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"res",
"Result",
",",
"err",
"error",
")",
"{",
"return",
"db",
".",
"exec",
"(",
"context",
".",
"TODO",
"... | // Exec executes a query ignoring returned rows. The params are for any
// placeholders in the query. | [
"Exec",
"executes",
"a",
"query",
"ignoring",
"returned",
"rows",
".",
"The",
"params",
"are",
"for",
"any",
"placeholders",
"in",
"the",
"query",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/base.go#L186-L188 | train |
go-pg/pg | base.go | Query | func (db *baseDB) Query(model, query interface{}, params ...interface{}) (res Result, err error) {
return db.query(context.TODO(), model, query, params...)
} | go | func (db *baseDB) Query(model, query interface{}, params ...interface{}) (res Result, err error) {
return db.query(context.TODO(), model, query, params...)
} | [
"func",
"(",
"db",
"*",
"baseDB",
")",
"Query",
"(",
"model",
",",
"query",
"interface",
"{",
"}",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"res",
"Result",
",",
"err",
"error",
")",
"{",
"return",
"db",
".",
"query",
"(",
"context",
... | // Query executes a query that returns rows, typically a SELECT.
// The params are for any placeholders in the query. | [
"Query",
"executes",
"a",
"query",
"that",
"returns",
"rows",
"typically",
"a",
"SELECT",
".",
"The",
"params",
"are",
"for",
"any",
"placeholders",
"in",
"the",
"query",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/base.go#L239-L241 | train |
go-pg/pg | base.go | Model | func (db *baseDB) Model(model ...interface{}) *orm.Query {
return orm.NewQuery(db.db, model...)
} | go | func (db *baseDB) Model(model ...interface{}) *orm.Query {
return orm.NewQuery(db.db, model...)
} | [
"func",
"(",
"db",
"*",
"baseDB",
")",
"Model",
"(",
"model",
"...",
"interface",
"{",
"}",
")",
"*",
"orm",
".",
"Query",
"{",
"return",
"orm",
".",
"NewQuery",
"(",
"db",
".",
"db",
",",
"model",
"...",
")",
"\n",
"}"
] | // Model returns new query for the model. | [
"Model",
"returns",
"new",
"query",
"for",
"the",
"model",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/base.go#L389-L391 | train |
go-pg/pg | base.go | Select | func (db *baseDB) Select(model interface{}) error {
return orm.Select(db.db, model)
} | go | func (db *baseDB) Select(model interface{}) error {
return orm.Select(db.db, model)
} | [
"func",
"(",
"db",
"*",
"baseDB",
")",
"Select",
"(",
"model",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"orm",
".",
"Select",
"(",
"db",
".",
"db",
",",
"model",
")",
"\n",
"}"
] | // Select selects the model by primary key. | [
"Select",
"selects",
"the",
"model",
"by",
"primary",
"key",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/base.go#L398-L400 | train |
go-pg/pg | base.go | Insert | func (db *baseDB) Insert(model ...interface{}) error {
return orm.Insert(db.db, model...)
} | go | func (db *baseDB) Insert(model ...interface{}) error {
return orm.Insert(db.db, model...)
} | [
"func",
"(",
"db",
"*",
"baseDB",
")",
"Insert",
"(",
"model",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"orm",
".",
"Insert",
"(",
"db",
".",
"db",
",",
"model",
"...",
")",
"\n",
"}"
] | // Insert inserts the model updating primary keys if they are empty. | [
"Insert",
"inserts",
"the",
"model",
"updating",
"primary",
"keys",
"if",
"they",
"are",
"empty",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/base.go#L403-L405 | train |
go-pg/pg | base.go | Update | func (db *baseDB) Update(model interface{}) error {
return orm.Update(db.db, model)
} | go | func (db *baseDB) Update(model interface{}) error {
return orm.Update(db.db, model)
} | [
"func",
"(",
"db",
"*",
"baseDB",
")",
"Update",
"(",
"model",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"orm",
".",
"Update",
"(",
"db",
".",
"db",
",",
"model",
")",
"\n",
"}"
] | // Update updates the model by primary key. | [
"Update",
"updates",
"the",
"model",
"by",
"primary",
"key",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/base.go#L408-L410 | train |
go-pg/pg | base.go | Delete | func (db *baseDB) Delete(model interface{}) error {
return orm.Delete(db.db, model)
} | go | func (db *baseDB) Delete(model interface{}) error {
return orm.Delete(db.db, model)
} | [
"func",
"(",
"db",
"*",
"baseDB",
")",
"Delete",
"(",
"model",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"orm",
".",
"Delete",
"(",
"db",
".",
"db",
",",
"model",
")",
"\n",
"}"
] | // Delete deletes the model by primary key. | [
"Delete",
"deletes",
"the",
"model",
"by",
"primary",
"key",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/base.go#L413-L415 | train |
go-pg/pg | base.go | DropTable | func (db *baseDB) DropTable(model interface{}, opt *orm.DropTableOptions) error {
return orm.DropTable(db.db, model, opt)
} | go | func (db *baseDB) DropTable(model interface{}, opt *orm.DropTableOptions) error {
return orm.DropTable(db.db, model, opt)
} | [
"func",
"(",
"db",
"*",
"baseDB",
")",
"DropTable",
"(",
"model",
"interface",
"{",
"}",
",",
"opt",
"*",
"orm",
".",
"DropTableOptions",
")",
"error",
"{",
"return",
"orm",
".",
"DropTable",
"(",
"db",
".",
"db",
",",
"model",
",",
"opt",
")",
"\n... | // DropTable drops table for the model. | [
"DropTable",
"drops",
"table",
"for",
"the",
"model",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/base.go#L431-L433 | train |
go-pg/pg | pg.go | ModelContext | func ModelContext(c context.Context, model ...interface{}) *orm.Query {
return orm.NewQueryContext(c, nil, model...)
} | go | func ModelContext(c context.Context, model ...interface{}) *orm.Query {
return orm.NewQueryContext(c, nil, model...)
} | [
"func",
"ModelContext",
"(",
"c",
"context",
".",
"Context",
",",
"model",
"...",
"interface",
"{",
"}",
")",
"*",
"orm",
".",
"Query",
"{",
"return",
"orm",
".",
"NewQueryContext",
"(",
"c",
",",
"nil",
",",
"model",
"...",
")",
"\n",
"}"
] | // ModelContext returns a new query for the optional model with a context | [
"ModelContext",
"returns",
"a",
"new",
"query",
"for",
"the",
"optional",
"model",
"with",
"a",
"context"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/pg.go#L33-L35 | train |
go-pg/pg | pg.go | Q | func Q(query string, params ...interface{}) types.ValueAppender {
return orm.Q(query, params...)
} | go | func Q(query string, params ...interface{}) types.ValueAppender {
return orm.Q(query, params...)
} | [
"func",
"Q",
"(",
"query",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"types",
".",
"ValueAppender",
"{",
"return",
"orm",
".",
"Q",
"(",
"query",
",",
"params",
"...",
")",
"\n",
"}"
] | // Q replaces any placeholders found in the query. | [
"Q",
"replaces",
"any",
"placeholders",
"found",
"in",
"the",
"query",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/pg.go#L44-L46 | train |
go-pg/pg | pg.go | Init | func (strings *Strings) Init() error {
if s := *strings; len(s) > 0 {
*strings = s[:0]
}
return nil
} | go | func (strings *Strings) Init() error {
if s := *strings; len(s) > 0 {
*strings = s[:0]
}
return nil
} | [
"func",
"(",
"strings",
"*",
"Strings",
")",
"Init",
"(",
")",
"error",
"{",
"if",
"s",
":=",
"*",
"strings",
";",
"len",
"(",
"s",
")",
">",
"0",
"{",
"*",
"strings",
"=",
"s",
"[",
":",
"0",
"]",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}... | // Init initializes the Strings slice | [
"Init",
"initializes",
"the",
"Strings",
"slice"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/pg.go#L113-L118 | train |
go-pg/pg | pg.go | ScanColumn | func (strings *Strings) ScanColumn(colIdx int, _ string, rd types.Reader, n int) error {
b := make([]byte, n)
_, err := io.ReadFull(rd, b)
if err != nil {
return err
}
*strings = append(*strings, internal.BytesToString(b))
return nil
} | go | func (strings *Strings) ScanColumn(colIdx int, _ string, rd types.Reader, n int) error {
b := make([]byte, n)
_, err := io.ReadFull(rd, b)
if err != nil {
return err
}
*strings = append(*strings, internal.BytesToString(b))
return nil
} | [
"func",
"(",
"strings",
"*",
"Strings",
")",
"ScanColumn",
"(",
"colIdx",
"int",
",",
"_",
"string",
",",
"rd",
"types",
".",
"Reader",
",",
"n",
"int",
")",
"error",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"_",
",",... | // ScanColumn scans the columns and appends them to `strings` | [
"ScanColumn",
"scans",
"the",
"columns",
"and",
"appends",
"them",
"to",
"strings"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/pg.go#L131-L140 | train |
go-pg/pg | pg.go | AppendValue | func (strings Strings) AppendValue(dst []byte, quote int) []byte {
if len(strings) == 0 {
return dst
}
for _, s := range strings {
dst = types.AppendString(dst, s, 1)
dst = append(dst, ',')
}
dst = dst[:len(dst)-1]
return dst
} | go | func (strings Strings) AppendValue(dst []byte, quote int) []byte {
if len(strings) == 0 {
return dst
}
for _, s := range strings {
dst = types.AppendString(dst, s, 1)
dst = append(dst, ',')
}
dst = dst[:len(dst)-1]
return dst
} | [
"func",
"(",
"strings",
"Strings",
")",
"AppendValue",
"(",
"dst",
"[",
"]",
"byte",
",",
"quote",
"int",
")",
"[",
"]",
"byte",
"{",
"if",
"len",
"(",
"strings",
")",
"==",
"0",
"{",
"return",
"dst",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"s",
":... | // AppendValue appends the values from `strings` to the given byte slice | [
"AppendValue",
"appends",
"the",
"values",
"from",
"strings",
"to",
"the",
"given",
"byte",
"slice"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/pg.go#L143-L154 | train |
go-pg/pg | pg.go | Init | func (ints *Ints) Init() error {
if s := *ints; len(s) > 0 {
*ints = s[:0]
}
return nil
} | go | func (ints *Ints) Init() error {
if s := *ints; len(s) > 0 {
*ints = s[:0]
}
return nil
} | [
"func",
"(",
"ints",
"*",
"Ints",
")",
"Init",
"(",
")",
"error",
"{",
"if",
"s",
":=",
"*",
"ints",
";",
"len",
"(",
"s",
")",
">",
"0",
"{",
"*",
"ints",
"=",
"s",
"[",
":",
"0",
"]",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Init initializes the Int slice | [
"Init",
"initializes",
"the",
"Int",
"slice"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/pg.go#L165-L170 | train |
go-pg/pg | pg.go | ScanColumn | func (ints *Ints) ScanColumn(colIdx int, colName string, rd types.Reader, n int) error {
num, err := types.ScanInt64(rd, n)
if err != nil {
return err
}
*ints = append(*ints, num)
return nil
} | go | func (ints *Ints) ScanColumn(colIdx int, colName string, rd types.Reader, n int) error {
num, err := types.ScanInt64(rd, n)
if err != nil {
return err
}
*ints = append(*ints, num)
return nil
} | [
"func",
"(",
"ints",
"*",
"Ints",
")",
"ScanColumn",
"(",
"colIdx",
"int",
",",
"colName",
"string",
",",
"rd",
"types",
".",
"Reader",
",",
"n",
"int",
")",
"error",
"{",
"num",
",",
"err",
":=",
"types",
".",
"ScanInt64",
"(",
"rd",
",",
"n",
"... | // ScanColumn scans the columns and appends them to `ints` | [
"ScanColumn",
"scans",
"the",
"columns",
"and",
"appends",
"them",
"to",
"ints"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/pg.go#L183-L191 | train |
go-pg/pg | pg.go | AppendValue | func (ints Ints) AppendValue(dst []byte, quote int) []byte {
if len(ints) == 0 {
return dst
}
for _, v := range ints {
dst = strconv.AppendInt(dst, v, 10)
dst = append(dst, ',')
}
dst = dst[:len(dst)-1]
return dst
} | go | func (ints Ints) AppendValue(dst []byte, quote int) []byte {
if len(ints) == 0 {
return dst
}
for _, v := range ints {
dst = strconv.AppendInt(dst, v, 10)
dst = append(dst, ',')
}
dst = dst[:len(dst)-1]
return dst
} | [
"func",
"(",
"ints",
"Ints",
")",
"AppendValue",
"(",
"dst",
"[",
"]",
"byte",
",",
"quote",
"int",
")",
"[",
"]",
"byte",
"{",
"if",
"len",
"(",
"ints",
")",
"==",
"0",
"{",
"return",
"dst",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"v",
":=",
"ra... | // AppendValue appends the values from `ints` to the given byte slice | [
"AppendValue",
"appends",
"the",
"values",
"from",
"ints",
"to",
"the",
"given",
"byte",
"slice"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/pg.go#L194-L205 | train |
go-pg/pg | pg.go | Init | func (set *IntSet) Init() error {
if len(*set) > 0 {
*set = make(map[int64]struct{})
}
return nil
} | go | func (set *IntSet) Init() error {
if len(*set) > 0 {
*set = make(map[int64]struct{})
}
return nil
} | [
"func",
"(",
"set",
"*",
"IntSet",
")",
"Init",
"(",
")",
"error",
"{",
"if",
"len",
"(",
"*",
"set",
")",
">",
"0",
"{",
"*",
"set",
"=",
"make",
"(",
"map",
"[",
"int64",
"]",
"struct",
"{",
"}",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n... | // Init initializes the IntSet | [
"Init",
"initializes",
"the",
"IntSet"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/pg.go#L215-L220 | train |
go-pg/pg | pg.go | ScanColumn | func (set *IntSet) ScanColumn(colIdx int, colName string, rd types.Reader, n int) error {
num, err := types.ScanInt64(rd, n)
if err != nil {
return err
}
setVal := *set
if setVal == nil {
*set = make(IntSet)
setVal = *set
}
setVal[num] = struct{}{}
return nil
} | go | func (set *IntSet) ScanColumn(colIdx int, colName string, rd types.Reader, n int) error {
num, err := types.ScanInt64(rd, n)
if err != nil {
return err
}
setVal := *set
if setVal == nil {
*set = make(IntSet)
setVal = *set
}
setVal[num] = struct{}{}
return nil
} | [
"func",
"(",
"set",
"*",
"IntSet",
")",
"ScanColumn",
"(",
"colIdx",
"int",
",",
"colName",
"string",
",",
"rd",
"types",
".",
"Reader",
",",
"n",
"int",
")",
"error",
"{",
"num",
",",
"err",
":=",
"types",
".",
"ScanInt64",
"(",
"rd",
",",
"n",
... | // ScanColumn scans the columns and appends them to `IntSet` | [
"ScanColumn",
"scans",
"the",
"columns",
"and",
"appends",
"them",
"to",
"IntSet"
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/pg.go#L233-L247 | train |
go-pg/pg | internal/buf_reader.go | Buffered | func (b *BufReader) Buffered() int {
d := b.w - b.r
if b.available != -1 && d > b.available {
return b.available
}
return d
} | go | func (b *BufReader) Buffered() int {
d := b.w - b.r
if b.available != -1 && d > b.available {
return b.available
}
return d
} | [
"func",
"(",
"b",
"*",
"BufReader",
")",
"Buffered",
"(",
")",
"int",
"{",
"d",
":=",
"b",
".",
"w",
"-",
"b",
".",
"r",
"\n",
"if",
"b",
".",
"available",
"!=",
"-",
"1",
"&&",
"d",
">",
"b",
".",
"available",
"{",
"return",
"b",
".",
"ava... | // Buffered returns the number of bytes that can be read from the current buffer. | [
"Buffered",
"returns",
"the",
"number",
"of",
"bytes",
"that",
"can",
"be",
"read",
"from",
"the",
"current",
"buffer",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/internal/buf_reader.go#L68-L74 | train |
go-pg/pg | orm/query.go | New | func (q *Query) New() *Query {
cp := &Query{
ctx: q.ctx,
db: q.db,
model: q.model,
implicitModel: true,
deleted: q.deleted,
}
return cp
} | go | func (q *Query) New() *Query {
cp := &Query{
ctx: q.ctx,
db: q.db,
model: q.model,
implicitModel: true,
deleted: q.deleted,
}
return cp
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"New",
"(",
")",
"*",
"Query",
"{",
"cp",
":=",
"&",
"Query",
"{",
"ctx",
":",
"q",
".",
"ctx",
",",
"db",
":",
"q",
".",
"db",
",",
"model",
":",
"q",
".",
"model",
",",
"implicitModel",
":",
"true",
",... | // New returns new zero Query binded to the current db. | [
"New",
"returns",
"new",
"zero",
"Query",
"binded",
"to",
"the",
"current",
"db",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L68-L77 | train |
go-pg/pg | orm/query.go | Copy | func (q *Query) Copy() *Query {
var modelValues map[string]*queryParamsAppender
if len(q.modelValues) > 0 {
modelValues = make(map[string]*queryParamsAppender, len(q.modelValues))
for k, v := range q.modelValues {
modelValues[k] = v
}
}
copy := &Query{
ctx: q.ctx,
db: q.db,
stickyErr: q... | go | func (q *Query) Copy() *Query {
var modelValues map[string]*queryParamsAppender
if len(q.modelValues) > 0 {
modelValues = make(map[string]*queryParamsAppender, len(q.modelValues))
for k, v := range q.modelValues {
modelValues[k] = v
}
}
copy := &Query{
ctx: q.ctx,
db: q.db,
stickyErr: q... | [
"func",
"(",
"q",
"*",
"Query",
")",
"Copy",
"(",
")",
"*",
"Query",
"{",
"var",
"modelValues",
"map",
"[",
"string",
"]",
"*",
"queryParamsAppender",
"\n",
"if",
"len",
"(",
"q",
".",
"modelValues",
")",
">",
"0",
"{",
"modelValues",
"=",
"make",
... | // Copy returns copy of the Query. | [
"Copy",
"returns",
"copy",
"of",
"the",
"Query",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L80-L117 | train |
go-pg/pg | orm/query.go | Deleted | func (q *Query) Deleted() *Query {
if q.model != nil {
if err := q.model.Table().mustSoftDelete(); err != nil {
return q.err(err)
}
}
q.deleted = true
return q
} | go | func (q *Query) Deleted() *Query {
if q.model != nil {
if err := q.model.Table().mustSoftDelete(); err != nil {
return q.err(err)
}
}
q.deleted = true
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Deleted",
"(",
")",
"*",
"Query",
"{",
"if",
"q",
".",
"model",
"!=",
"nil",
"{",
"if",
"err",
":=",
"q",
".",
"model",
".",
"Table",
"(",
")",
".",
"mustSoftDelete",
"(",
")",
";",
"err",
"!=",
"nil",
"{... | // Deleted adds `WHERE deleted_at IS NOT NULL` clause for soft deleted models. | [
"Deleted",
"adds",
"WHERE",
"deleted_at",
"IS",
"NOT",
"NULL",
"clause",
"for",
"soft",
"deleted",
"models",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L165-L173 | train |
go-pg/pg | orm/query.go | With | func (q *Query) With(name string, subq *Query) *Query {
return q._with(name, newSelectQuery(subq))
} | go | func (q *Query) With(name string, subq *Query) *Query {
return q._with(name, newSelectQuery(subq))
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"With",
"(",
"name",
"string",
",",
"subq",
"*",
"Query",
")",
"*",
"Query",
"{",
"return",
"q",
".",
"_with",
"(",
"name",
",",
"newSelectQuery",
"(",
"subq",
")",
")",
"\n",
"}"
] | // With adds subq as common table expression with the given name. | [
"With",
"adds",
"subq",
"as",
"common",
"table",
"expression",
"with",
"the",
"given",
"name",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L176-L178 | train |
go-pg/pg | orm/query.go | WrapWith | func (q *Query) WrapWith(name string) *Query {
wrapper := q.New()
wrapper.with = q.with
q.with = nil
wrapper = wrapper.With(name, q)
return wrapper
} | go | func (q *Query) WrapWith(name string) *Query {
wrapper := q.New()
wrapper.with = q.with
q.with = nil
wrapper = wrapper.With(name, q)
return wrapper
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"WrapWith",
"(",
"name",
"string",
")",
"*",
"Query",
"{",
"wrapper",
":=",
"q",
".",
"New",
"(",
")",
"\n",
"wrapper",
".",
"with",
"=",
"q",
".",
"with",
"\n",
"q",
".",
"with",
"=",
"nil",
"\n",
"wrapper"... | // WrapWith creates new Query and adds to it current query as
// common table expression with the given name. | [
"WrapWith",
"creates",
"new",
"Query",
"and",
"adds",
"to",
"it",
"current",
"query",
"as",
"common",
"table",
"expression",
"with",
"the",
"given",
"name",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L194-L200 | train |
go-pg/pg | orm/query.go | ColumnExpr | func (q *Query) ColumnExpr(expr string, params ...interface{}) *Query {
q.columns = append(q.columns, &queryParamsAppender{expr, params})
return q
} | go | func (q *Query) ColumnExpr(expr string, params ...interface{}) *Query {
q.columns = append(q.columns, &queryParamsAppender{expr, params})
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"ColumnExpr",
"(",
"expr",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"*",
"Query",
"{",
"q",
".",
"columns",
"=",
"append",
"(",
"q",
".",
"columns",
",",
"&",
"queryParamsAppender",
"{",
"expr",... | // ColumnExpr adds column expression to the Query. | [
"ColumnExpr",
"adds",
"column",
"expression",
"to",
"the",
"Query",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L242-L245 | train |
go-pg/pg | orm/query.go | ExcludeColumn | func (q *Query) ExcludeColumn(columns ...string) *Query {
if q.columns == nil {
for _, f := range q.model.Table().Fields {
q.columns = append(q.columns, fieldAppender{f.SQLName})
}
}
for _, col := range columns {
if !q.excludeColumn(col) {
return q.err(fmt.Errorf("pg: can't find column=%q", col))
}
}... | go | func (q *Query) ExcludeColumn(columns ...string) *Query {
if q.columns == nil {
for _, f := range q.model.Table().Fields {
q.columns = append(q.columns, fieldAppender{f.SQLName})
}
}
for _, col := range columns {
if !q.excludeColumn(col) {
return q.err(fmt.Errorf("pg: can't find column=%q", col))
}
}... | [
"func",
"(",
"q",
"*",
"Query",
")",
"ExcludeColumn",
"(",
"columns",
"...",
"string",
")",
"*",
"Query",
"{",
"if",
"q",
".",
"columns",
"==",
"nil",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"q",
".",
"model",
".",
"Table",
"(",
")",
".",
"Fi... | // ExcludeColumn excludes a column from the list of to be selected columns. | [
"ExcludeColumn",
"excludes",
"a",
"column",
"from",
"the",
"list",
"of",
"to",
"be",
"selected",
"columns",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L248-L261 | train |
go-pg/pg | orm/query.go | Value | func (q *Query) Value(column string, value string, params ...interface{}) *Query {
if !q.hasModel() {
q.err(errModelNil)
return q
}
table := q.model.Table()
if _, ok := table.FieldsMap[column]; !ok {
q.err(fmt.Errorf("%s does not have column=%q", table, column))
return q
}
if q.modelValues == nil {
q.... | go | func (q *Query) Value(column string, value string, params ...interface{}) *Query {
if !q.hasModel() {
q.err(errModelNil)
return q
}
table := q.model.Table()
if _, ok := table.FieldsMap[column]; !ok {
q.err(fmt.Errorf("%s does not have column=%q", table, column))
return q
}
if q.modelValues == nil {
q.... | [
"func",
"(",
"q",
"*",
"Query",
")",
"Value",
"(",
"column",
"string",
",",
"value",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"*",
"Query",
"{",
"if",
"!",
"q",
".",
"hasModel",
"(",
")",
"{",
"q",
".",
"err",
"(",
"errModelNil... | // Value overwrites model value for the column in INSERT and UPDATE queries. | [
"Value",
"overwrites",
"model",
"value",
"for",
"the",
"column",
"in",
"INSERT",
"and",
"UPDATE",
"queries",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L345-L362 | train |
go-pg/pg | orm/query.go | JoinOn | func (q *Query) JoinOn(condition string, params ...interface{}) *Query {
if q.joinAppendOn == nil {
q.err(errors.New("pg: no joins to apply JoinOn"))
return q
}
q.joinAppendOn(&condAppender{
sep: " AND ",
cond: condition,
params: params,
})
return q
} | go | func (q *Query) JoinOn(condition string, params ...interface{}) *Query {
if q.joinAppendOn == nil {
q.err(errors.New("pg: no joins to apply JoinOn"))
return q
}
q.joinAppendOn(&condAppender{
sep: " AND ",
cond: condition,
params: params,
})
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"JoinOn",
"(",
"condition",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"*",
"Query",
"{",
"if",
"q",
".",
"joinAppendOn",
"==",
"nil",
"{",
"q",
".",
"err",
"(",
"errors",
".",
"New",
"(",
"\"... | // JoinOn appends join condition to the last join. | [
"JoinOn",
"appends",
"join",
"condition",
"to",
"the",
"last",
"join",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L506-L517 | train |
go-pg/pg | orm/query.go | Order | func (q *Query) Order(orders ...string) *Query {
loop:
for _, order := range orders {
if order == "" {
continue
}
ind := strings.Index(order, " ")
if ind != -1 {
field := order[:ind]
sort := order[ind+1:]
switch internal.UpperString(sort) {
case "ASC", "DESC", "ASC NULLS FIRST", "DESC NULLS FIRS... | go | func (q *Query) Order(orders ...string) *Query {
loop:
for _, order := range orders {
if order == "" {
continue
}
ind := strings.Index(order, " ")
if ind != -1 {
field := order[:ind]
sort := order[ind+1:]
switch internal.UpperString(sort) {
case "ASC", "DESC", "ASC NULLS FIRST", "DESC NULLS FIRS... | [
"func",
"(",
"q",
"*",
"Query",
")",
"Order",
"(",
"orders",
"...",
"string",
")",
"*",
"Query",
"{",
"loop",
":",
"for",
"_",
",",
"order",
":=",
"range",
"orders",
"{",
"if",
"order",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"ind",
... | // Order adds sort order to the Query quoting column name. Does not expand params like ?TableAlias etc.
// OrderExpr can be used to bypass quoting restriction or for params expansion. | [
"Order",
"adds",
"sort",
"order",
"to",
"the",
"Query",
"quoting",
"column",
"name",
".",
"Does",
"not",
"expand",
"params",
"like",
"?TableAlias",
"etc",
".",
"OrderExpr",
"can",
"be",
"used",
"to",
"bypass",
"quoting",
"restriction",
"or",
"for",
"params",... | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L551-L572 | train |
go-pg/pg | orm/query.go | OrderExpr | func (q *Query) OrderExpr(order string, params ...interface{}) *Query {
if order != "" {
q.order = append(q.order, &queryParamsAppender{order, params})
}
return q
} | go | func (q *Query) OrderExpr(order string, params ...interface{}) *Query {
if order != "" {
q.order = append(q.order, &queryParamsAppender{order, params})
}
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"OrderExpr",
"(",
"order",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"*",
"Query",
"{",
"if",
"order",
"!=",
"\"",
"\"",
"{",
"q",
".",
"order",
"=",
"append",
"(",
"q",
".",
"order",
",",
... | // Order adds sort order to the Query. | [
"Order",
"adds",
"sort",
"order",
"to",
"the",
"Query",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L575-L580 | train |
go-pg/pg | orm/query.go | Apply | func (q *Query) Apply(fn func(*Query) (*Query, error)) *Query {
qq, err := fn(q)
if err != nil {
q.err(err)
return q
}
return qq
} | go | func (q *Query) Apply(fn func(*Query) (*Query, error)) *Query {
qq, err := fn(q)
if err != nil {
q.err(err)
return q
}
return qq
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Apply",
"(",
"fn",
"func",
"(",
"*",
"Query",
")",
"(",
"*",
"Query",
",",
"error",
")",
")",
"*",
"Query",
"{",
"qq",
",",
"err",
":=",
"fn",
"(",
"q",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"q",
... | // Apply calls the fn passing the Query as an argument. | [
"Apply",
"calls",
"the",
"fn",
"passing",
"the",
"Query",
"as",
"an",
"argument",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L613-L620 | train |
go-pg/pg | orm/query.go | Count | func (q *Query) Count() (int, error) {
if q.stickyErr != nil {
return 0, q.stickyErr
}
var count int
_, err := q.db.QueryOneContext(
q.ctx, Scan(&count), q.countSelectQuery("count(*)"), q.model)
return count, err
} | go | func (q *Query) Count() (int, error) {
if q.stickyErr != nil {
return 0, q.stickyErr
}
var count int
_, err := q.db.QueryOneContext(
q.ctx, Scan(&count), q.countSelectQuery("count(*)"), q.model)
return count, err
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Count",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"q",
".",
"stickyErr",
"!=",
"nil",
"{",
"return",
"0",
",",
"q",
".",
"stickyErr",
"\n",
"}",
"\n\n",
"var",
"count",
"int",
"\n",
"_",
",",
"e... | // Count returns number of rows matching the query using count aggregate function. | [
"Count",
"returns",
"number",
"of",
"rows",
"matching",
"the",
"query",
"using",
"count",
"aggregate",
"function",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L623-L632 | train |
go-pg/pg | orm/query.go | Select | func (q *Query) Select(values ...interface{}) error {
if q.stickyErr != nil {
return q.stickyErr
}
model, err := q.newModel(values...)
if err != nil {
return err
}
q, err = model.BeforeSelectQuery(q.ctx, q.db, q)
if err != nil {
return err
}
res, err := q.query(model, newSelectQuery(q))
if err != nil... | go | func (q *Query) Select(values ...interface{}) error {
if q.stickyErr != nil {
return q.stickyErr
}
model, err := q.newModel(values...)
if err != nil {
return err
}
q, err = model.BeforeSelectQuery(q.ctx, q.db, q)
if err != nil {
return err
}
res, err := q.query(model, newSelectQuery(q))
if err != nil... | [
"func",
"(",
"q",
"*",
"Query",
")",
"Select",
"(",
"values",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"q",
".",
"stickyErr",
"!=",
"nil",
"{",
"return",
"q",
".",
"stickyErr",
"\n",
"}",
"\n\n",
"model",
",",
"err",
":=",
"q",
".",... | // Select selects the model. | [
"Select",
"selects",
"the",
"model",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L672-L704 | train |
go-pg/pg | orm/query.go | SelectAndCount | func (q *Query) SelectAndCount(values ...interface{}) (count int, firstErr error) {
if q.stickyErr != nil {
return 0, q.stickyErr
}
var wg sync.WaitGroup
var mu sync.Mutex
if q.limit >= 0 {
wg.Add(1)
go func() {
defer wg.Done()
err := q.Select(values...)
if err != nil {
mu.Lock()
if firstE... | go | func (q *Query) SelectAndCount(values ...interface{}) (count int, firstErr error) {
if q.stickyErr != nil {
return 0, q.stickyErr
}
var wg sync.WaitGroup
var mu sync.Mutex
if q.limit >= 0 {
wg.Add(1)
go func() {
defer wg.Done()
err := q.Select(values...)
if err != nil {
mu.Lock()
if firstE... | [
"func",
"(",
"q",
"*",
"Query",
")",
"SelectAndCount",
"(",
"values",
"...",
"interface",
"{",
"}",
")",
"(",
"count",
"int",
",",
"firstErr",
"error",
")",
"{",
"if",
"q",
".",
"stickyErr",
"!=",
"nil",
"{",
"return",
"0",
",",
"q",
".",
"stickyEr... | // SelectAndCount runs Select and Count in two goroutines,
// waits for them to finish and returns the result. If query limit is -1
// it does not select any data and only counts the results. | [
"SelectAndCount",
"runs",
"Select",
"and",
"Count",
"in",
"two",
"goroutines",
"waits",
"for",
"them",
"to",
"finish",
"and",
"returns",
"the",
"result",
".",
"If",
"query",
"limit",
"is",
"-",
"1",
"it",
"does",
"not",
"select",
"any",
"data",
"and",
"o... | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L723-L762 | train |
go-pg/pg | orm/query.go | ForEach | func (q *Query) ForEach(fn interface{}) error {
m := newFuncModel(fn)
return q.Select(m)
} | go | func (q *Query) ForEach(fn interface{}) error {
m := newFuncModel(fn)
return q.Select(m)
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"ForEach",
"(",
"fn",
"interface",
"{",
"}",
")",
"error",
"{",
"m",
":=",
"newFuncModel",
"(",
"fn",
")",
"\n",
"return",
"q",
".",
"Select",
"(",
"m",
")",
"\n",
"}"
] | // ForEach calls the function for each row returned by the query
// without loading all rows into the memory.
// Function accepts a struct, pointer to a struct, orm.Model,
// or values for columns in a row. Function must return an error. | [
"ForEach",
"calls",
"the",
"function",
"for",
"each",
"row",
"returned",
"by",
"the",
"query",
"without",
"loading",
"all",
"rows",
"into",
"the",
"memory",
".",
"Function",
"accepts",
"a",
"struct",
"pointer",
"to",
"a",
"struct",
"orm",
".",
"Model",
"or... | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L812-L815 | train |
go-pg/pg | orm/query.go | Insert | func (q *Query) Insert(values ...interface{}) (Result, error) {
if q.stickyErr != nil {
return nil, q.stickyErr
}
model, err := q.newModel(values...)
if err != nil {
return nil, err
}
if q.model != nil && q.model.Table().HasFlag(BeforeInsertHookFlag) {
err = q.model.BeforeInsert(q.ctx, q.db)
if err != n... | go | func (q *Query) Insert(values ...interface{}) (Result, error) {
if q.stickyErr != nil {
return nil, q.stickyErr
}
model, err := q.newModel(values...)
if err != nil {
return nil, err
}
if q.model != nil && q.model.Table().HasFlag(BeforeInsertHookFlag) {
err = q.model.BeforeInsert(q.ctx, q.db)
if err != n... | [
"func",
"(",
"q",
"*",
"Query",
")",
"Insert",
"(",
"values",
"...",
"interface",
"{",
"}",
")",
"(",
"Result",
",",
"error",
")",
"{",
"if",
"q",
".",
"stickyErr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"q",
".",
"stickyErr",
"\n",
"}",
"\n\n",... | // Insert inserts the model. | [
"Insert",
"inserts",
"the",
"model",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L860-L891 | train |
go-pg/pg | orm/query.go | SelectOrInsert | func (q *Query) SelectOrInsert(values ...interface{}) (inserted bool, _ error) {
if q.stickyErr != nil {
return false, q.stickyErr
}
var insertq *Query
var insertErr error
for i := 0; i < 5; i++ {
if i >= 2 {
time.Sleep(internal.RetryBackoff(i-2, 250*time.Millisecond, 5*time.Second))
}
err := q.Select... | go | func (q *Query) SelectOrInsert(values ...interface{}) (inserted bool, _ error) {
if q.stickyErr != nil {
return false, q.stickyErr
}
var insertq *Query
var insertErr error
for i := 0; i < 5; i++ {
if i >= 2 {
time.Sleep(internal.RetryBackoff(i-2, 250*time.Millisecond, 5*time.Second))
}
err := q.Select... | [
"func",
"(",
"q",
"*",
"Query",
")",
"SelectOrInsert",
"(",
"values",
"...",
"interface",
"{",
"}",
")",
"(",
"inserted",
"bool",
",",
"_",
"error",
")",
"{",
"if",
"q",
".",
"stickyErr",
"!=",
"nil",
"{",
"return",
"false",
",",
"q",
".",
"stickyE... | // SelectOrInsert selects the model inserting one if it does not exist.
// It returns true when model was inserted. | [
"SelectOrInsert",
"selects",
"the",
"model",
"inserting",
"one",
"if",
"it",
"does",
"not",
"exist",
".",
"It",
"returns",
"true",
"when",
"model",
"was",
"inserted",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L895-L949 | train |
go-pg/pg | orm/query.go | Update | func (q *Query) Update(scan ...interface{}) (Result, error) {
return q.update(scan, false)
} | go | func (q *Query) Update(scan ...interface{}) (Result, error) {
return q.update(scan, false)
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Update",
"(",
"scan",
"...",
"interface",
"{",
"}",
")",
"(",
"Result",
",",
"error",
")",
"{",
"return",
"q",
".",
"update",
"(",
"scan",
",",
"false",
")",
"\n",
"}"
] | // Update updates the model. | [
"Update",
"updates",
"the",
"model",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L952-L954 | train |
go-pg/pg | orm/query.go | UpdateNotNull | func (q *Query) UpdateNotNull(scan ...interface{}) (Result, error) {
return q.update(scan, true)
} | go | func (q *Query) UpdateNotNull(scan ...interface{}) (Result, error) {
return q.update(scan, true)
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"UpdateNotNull",
"(",
"scan",
"...",
"interface",
"{",
"}",
")",
"(",
"Result",
",",
"error",
")",
"{",
"return",
"q",
".",
"update",
"(",
"scan",
",",
"true",
")",
"\n",
"}"
] | // Update updates the model omitting null columns. | [
"Update",
"updates",
"the",
"model",
"omitting",
"null",
"columns",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L957-L959 | train |
go-pg/pg | orm/query.go | Delete | func (q *Query) Delete(values ...interface{}) (Result, error) {
if q.hasModel() {
table := q.model.Table()
if table.SoftDeleteField != nil {
q.model.setSoftDeleteField()
columns := q.columns
q.columns = nil
res, err := q.Column(table.SoftDeleteField.SQLName).Update(values...)
q.columns = columns
... | go | func (q *Query) Delete(values ...interface{}) (Result, error) {
if q.hasModel() {
table := q.model.Table()
if table.SoftDeleteField != nil {
q.model.setSoftDeleteField()
columns := q.columns
q.columns = nil
res, err := q.Column(table.SoftDeleteField.SQLName).Update(values...)
q.columns = columns
... | [
"func",
"(",
"q",
"*",
"Query",
")",
"Delete",
"(",
"values",
"...",
"interface",
"{",
"}",
")",
"(",
"Result",
",",
"error",
")",
"{",
"if",
"q",
".",
"hasModel",
"(",
")",
"{",
"table",
":=",
"q",
".",
"model",
".",
"Table",
"(",
")",
"\n",
... | // Delete deletes the model. When model has deleted_at column the row
// is soft deleted instead. | [
"Delete",
"deletes",
"the",
"model",
".",
"When",
"model",
"has",
"deleted_at",
"column",
"the",
"row",
"is",
"soft",
"deleted",
"instead",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L1006-L1019 | train |
go-pg/pg | orm/query.go | CopyFrom | func (q *Query) CopyFrom(r io.Reader, query interface{}, params ...interface{}) (Result, error) {
params = append(params, q.model)
return q.db.CopyFrom(r, query, params...)
} | go | func (q *Query) CopyFrom(r io.Reader, query interface{}, params ...interface{}) (Result, error) {
params = append(params, q.model)
return q.db.CopyFrom(r, query, params...)
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"CopyFrom",
"(",
"r",
"io",
".",
"Reader",
",",
"query",
"interface",
"{",
"}",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"Result",
",",
"error",
")",
"{",
"params",
"=",
"append",
"(",
"params",
... | // CopyFrom is an alias from DB.CopyFrom. | [
"CopyFrom",
"is",
"an",
"alias",
"from",
"DB",
".",
"CopyFrom",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L1093-L1096 | train |
go-pg/pg | orm/query.go | CopyTo | func (q *Query) CopyTo(w io.Writer, query interface{}, params ...interface{}) (Result, error) {
params = append(params, q.model)
return q.db.CopyTo(w, query, params...)
} | go | func (q *Query) CopyTo(w io.Writer, query interface{}, params ...interface{}) (Result, error) {
params = append(params, q.model)
return q.db.CopyTo(w, query, params...)
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"CopyTo",
"(",
"w",
"io",
".",
"Writer",
",",
"query",
"interface",
"{",
"}",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"Result",
",",
"error",
")",
"{",
"params",
"=",
"append",
"(",
"params",
",... | // CopyTo is an alias from DB.CopyTo. | [
"CopyTo",
"is",
"an",
"alias",
"from",
"DB",
".",
"CopyTo",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L1099-L1102 | train |
go-pg/pg | orm/query.go | Exists | func (q *Query) Exists() (bool, error) {
cp := q.Copy() // copy to not change original query
cp.columns = []QueryAppender{Q("1")}
cp.order = nil
cp.limit = 1
res, err := q.db.ExecContext(q.ctx, newSelectQuery(cp))
if err != nil {
return false, err
}
return res.RowsAffected() > 0, nil
} | go | func (q *Query) Exists() (bool, error) {
cp := q.Copy() // copy to not change original query
cp.columns = []QueryAppender{Q("1")}
cp.order = nil
cp.limit = 1
res, err := q.db.ExecContext(q.ctx, newSelectQuery(cp))
if err != nil {
return false, err
}
return res.RowsAffected() > 0, nil
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Exists",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"cp",
":=",
"q",
".",
"Copy",
"(",
")",
"// copy to not change original query",
"\n",
"cp",
".",
"columns",
"=",
"[",
"]",
"QueryAppender",
"{",
"Q",
"(",
... | // Exists returns true or false depending if there are any rows matching the query. | [
"Exists",
"returns",
"true",
"or",
"false",
"depending",
"if",
"there",
"are",
"any",
"rows",
"matching",
"the",
"query",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/orm/query.go#L1111-L1121 | train |
go-pg/pg | db.go | Connect | func Connect(opt *Options) *DB {
opt.init()
return newDB(
context.TODO(),
&baseDB{
opt: opt,
pool: newConnPool(opt),
},
)
} | go | func Connect(opt *Options) *DB {
opt.init()
return newDB(
context.TODO(),
&baseDB{
opt: opt,
pool: newConnPool(opt),
},
)
} | [
"func",
"Connect",
"(",
"opt",
"*",
"Options",
")",
"*",
"DB",
"{",
"opt",
".",
"init",
"(",
")",
"\n",
"return",
"newDB",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"&",
"baseDB",
"{",
"opt",
":",
"opt",
",",
"pool",
":",
"newConnPool",
"(",
... | // Connect connects to a database using provided options.
//
// The returned DB is safe for concurrent use by multiple goroutines
// and maintains its own connection pool. | [
"Connect",
"connects",
"to",
"a",
"database",
"using",
"provided",
"options",
".",
"The",
"returned",
"DB",
"is",
"safe",
"for",
"concurrent",
"use",
"by",
"multiple",
"goroutines",
"and",
"maintains",
"its",
"own",
"connection",
"pool",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/db.go#L16-L25 | train |
go-pg/pg | db.go | Listen | func (db *DB) Listen(channels ...string) *Listener {
ln := &Listener{
db: db,
}
ln.init()
_ = ln.Listen(channels...)
return ln
} | go | func (db *DB) Listen(channels ...string) *Listener {
ln := &Listener{
db: db,
}
ln.init()
_ = ln.Listen(channels...)
return ln
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Listen",
"(",
"channels",
"...",
"string",
")",
"*",
"Listener",
"{",
"ln",
":=",
"&",
"Listener",
"{",
"db",
":",
"db",
",",
"}",
"\n",
"ln",
".",
"init",
"(",
")",
"\n",
"_",
"=",
"ln",
".",
"Listen",
"("... | // Listen listens for notifications sent with NOTIFY command. | [
"Listen",
"listens",
"for",
"notifications",
"sent",
"with",
"NOTIFY",
"command",
"."
] | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/db.go#L80-L87 | train |
go-pg/pg | db.go | Conn | func (db *DB) Conn() *Conn {
return newConn(db.ctx, db.baseDB.withPool(pool.NewSingleConnPool(db.pool)))
} | go | func (db *DB) Conn() *Conn {
return newConn(db.ctx, db.baseDB.withPool(pool.NewSingleConnPool(db.pool)))
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Conn",
"(",
")",
"*",
"Conn",
"{",
"return",
"newConn",
"(",
"db",
".",
"ctx",
",",
"db",
".",
"baseDB",
".",
"withPool",
"(",
"pool",
".",
"NewSingleConnPool",
"(",
"db",
".",
"pool",
")",
")",
")",
"\n",
"}... | // Conn returns a single connection by either opening a new connection
// or returning an existing connection from the connection pool. Conn will
// block until either a connection is returned or ctx is canceled.
// Queries run on the same Conn will be run in the same database session.
//
// Every Conn must be returned... | [
"Conn",
"returns",
"a",
"single",
"connection",
"by",
"either",
"opening",
"a",
"new",
"connection",
"or",
"returning",
"an",
"existing",
"connection",
"from",
"the",
"connection",
"pool",
".",
"Conn",
"will",
"block",
"until",
"either",
"a",
"connection",
"is... | 9ab5ba23b6047052b91007b7041d9216025219a8 | https://github.com/go-pg/pg/blob/9ab5ba23b6047052b91007b7041d9216025219a8/db.go#L111-L113 | train |
sendgrid/sendgrid-go | examples/helpers/mail/example.go | helloEmail | func helloEmail() []byte {
address := "test@example.com"
name := "Example User"
from := mail.NewEmail(name, address)
subject := "Hello World from the SendGrid Go Library"
address = "test@example.com"
name = "Example User"
to := mail.NewEmail(name, address)
content := mail.NewContent("text/plain", "some text her... | go | func helloEmail() []byte {
address := "test@example.com"
name := "Example User"
from := mail.NewEmail(name, address)
subject := "Hello World from the SendGrid Go Library"
address = "test@example.com"
name = "Example User"
to := mail.NewEmail(name, address)
content := mail.NewContent("text/plain", "some text her... | [
"func",
"helloEmail",
"(",
")",
"[",
"]",
"byte",
"{",
"address",
":=",
"\"",
"\"",
"\n",
"name",
":=",
"\"",
"\"",
"\n",
"from",
":=",
"mail",
".",
"NewEmail",
"(",
"name",
",",
"address",
")",
"\n",
"subject",
":=",
"\"",
"\"",
"\n",
"address",
... | // Minimum required to send an email | [
"Minimum",
"required",
"to",
"send",
"an",
"email"
] | df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5 | https://github.com/sendgrid/sendgrid-go/blob/df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5/examples/helpers/mail/example.go#L14-L29 | train |
sendgrid/sendgrid-go | sendgrid.go | GetRequestSubuser | func GetRequestSubuser(key, endpoint, host, subuser string) rest.Request {
return requestNew(options{key, endpoint, host, subuser})
} | go | func GetRequestSubuser(key, endpoint, host, subuser string) rest.Request {
return requestNew(options{key, endpoint, host, subuser})
} | [
"func",
"GetRequestSubuser",
"(",
"key",
",",
"endpoint",
",",
"host",
",",
"subuser",
"string",
")",
"rest",
".",
"Request",
"{",
"return",
"requestNew",
"(",
"options",
"{",
"key",
",",
"endpoint",
",",
"host",
",",
"subuser",
"}",
")",
"\n",
"}"
] | // GetRequestSubuser like GetRequest but with On-Behalf of Subuser
// @return [Request] a default request object | [
"GetRequestSubuser",
"like",
"GetRequest",
"but",
"with",
"On",
"-",
"Behalf",
"of",
"Subuser"
] | df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5 | https://github.com/sendgrid/sendgrid-go/blob/df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5/sendgrid.go#L47-L49 | train |
sendgrid/sendgrid-go | sendgrid.go | requestNew | func requestNew(options options) rest.Request {
if options.Host == "" {
options.Host = "https://api.sendgrid.com"
}
requestHeaders := map[string]string{
"Authorization": "Bearer " + options.Key,
"User-Agent": "sendgrid/" + Version + ";go",
"Accept": "application/json",
}
if len(options.Subuser)... | go | func requestNew(options options) rest.Request {
if options.Host == "" {
options.Host = "https://api.sendgrid.com"
}
requestHeaders := map[string]string{
"Authorization": "Bearer " + options.Key,
"User-Agent": "sendgrid/" + Version + ";go",
"Accept": "application/json",
}
if len(options.Subuser)... | [
"func",
"requestNew",
"(",
"options",
"options",
")",
"rest",
".",
"Request",
"{",
"if",
"options",
".",
"Host",
"==",
"\"",
"\"",
"{",
"options",
".",
"Host",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"requestHeaders",
":=",
"map",
"[",
"string",
"]",
"st... | // requestNew create Request
// @return [Request] a default request object | [
"requestNew",
"create",
"Request"
] | df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5 | https://github.com/sendgrid/sendgrid-go/blob/df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5/sendgrid.go#L53-L72 | train |
sendgrid/sendgrid-go | sendgrid.go | Send | func (cl *Client) Send(email *mail.SGMailV3) (*rest.Response, error) {
cl.Body = mail.GetRequestBody(email)
return MakeRequest(cl.Request)
} | go | func (cl *Client) Send(email *mail.SGMailV3) (*rest.Response, error) {
cl.Body = mail.GetRequestBody(email)
return MakeRequest(cl.Request)
} | [
"func",
"(",
"cl",
"*",
"Client",
")",
"Send",
"(",
"email",
"*",
"mail",
".",
"SGMailV3",
")",
"(",
"*",
"rest",
".",
"Response",
",",
"error",
")",
"{",
"cl",
".",
"Body",
"=",
"mail",
".",
"GetRequestBody",
"(",
"email",
")",
"\n",
"return",
"... | // Send sends an email through SendGrid | [
"Send",
"sends",
"an",
"email",
"through",
"SendGrid"
] | df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5 | https://github.com/sendgrid/sendgrid-go/blob/df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5/sendgrid.go#L75-L78 | train |
sendgrid/sendgrid-go | sendgrid.go | NewSendClient | func NewSendClient(key string) *Client {
request := GetRequest(key, "/v3/mail/send", "")
request.Method = "POST"
return &Client{request}
} | go | func NewSendClient(key string) *Client {
request := GetRequest(key, "/v3/mail/send", "")
request.Method = "POST"
return &Client{request}
} | [
"func",
"NewSendClient",
"(",
"key",
"string",
")",
"*",
"Client",
"{",
"request",
":=",
"GetRequest",
"(",
"key",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"request",
".",
"Method",
"=",
"\"",
"\"",
"\n",
"return",
"&",
"Client",
"{",
"request",
... | // NewSendClient constructs a new SendGrid client given an API key | [
"NewSendClient",
"constructs",
"a",
"new",
"SendGrid",
"client",
"given",
"an",
"API",
"key"
] | df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5 | https://github.com/sendgrid/sendgrid-go/blob/df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5/sendgrid.go#L81-L85 | train |
sendgrid/sendgrid-go | sendgrid.go | NewSendClientSubuser | func NewSendClientSubuser(key, subuser string) *Client {
request := GetRequestSubuser(key, "/v3/mail/send", "", subuser)
request.Method = "POST"
return &Client{request}
} | go | func NewSendClientSubuser(key, subuser string) *Client {
request := GetRequestSubuser(key, "/v3/mail/send", "", subuser)
request.Method = "POST"
return &Client{request}
} | [
"func",
"NewSendClientSubuser",
"(",
"key",
",",
"subuser",
"string",
")",
"*",
"Client",
"{",
"request",
":=",
"GetRequestSubuser",
"(",
"key",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"subuser",
")",
"\n",
"request",
".",
"Method",
"=",
"\"",
"\"",
"\n... | // GetRequestSubuser like NewSendClient but with On-Behalf of Subuser
// @return [Client] | [
"GetRequestSubuser",
"like",
"NewSendClient",
"but",
"with",
"On",
"-",
"Behalf",
"of",
"Subuser"
] | df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5 | https://github.com/sendgrid/sendgrid-go/blob/df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5/sendgrid.go#L89-L93 | train |
sendgrid/sendgrid-go | sendgrid.go | MakeRequest | func MakeRequest(request rest.Request) (*rest.Response, error) {
return DefaultClient.Send(request)
} | go | func MakeRequest(request rest.Request) (*rest.Response, error) {
return DefaultClient.Send(request)
} | [
"func",
"MakeRequest",
"(",
"request",
"rest",
".",
"Request",
")",
"(",
"*",
"rest",
".",
"Response",
",",
"error",
")",
"{",
"return",
"DefaultClient",
".",
"Send",
"(",
"request",
")",
"\n",
"}"
] | // MakeRequest attempts a SendGrid request synchronously. | [
"MakeRequest",
"attempts",
"a",
"SendGrid",
"request",
"synchronously",
"."
] | df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5 | https://github.com/sendgrid/sendgrid-go/blob/df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5/sendgrid.go#L106-L108 | train |
sendgrid/sendgrid-go | sendgrid.go | MakeRequestRetry | func MakeRequestRetry(request rest.Request) (*rest.Response, error) {
retry := 0
var response *rest.Response
var err error
for {
response, err = MakeRequest(request)
if err != nil {
return nil, err
}
if response.StatusCode != http.StatusTooManyRequests {
return response, nil
}
if retry > rateLi... | go | func MakeRequestRetry(request rest.Request) (*rest.Response, error) {
retry := 0
var response *rest.Response
var err error
for {
response, err = MakeRequest(request)
if err != nil {
return nil, err
}
if response.StatusCode != http.StatusTooManyRequests {
return response, nil
}
if retry > rateLi... | [
"func",
"MakeRequestRetry",
"(",
"request",
"rest",
".",
"Request",
")",
"(",
"*",
"rest",
".",
"Response",
",",
"error",
")",
"{",
"retry",
":=",
"0",
"\n",
"var",
"response",
"*",
"rest",
".",
"Response",
"\n",
"var",
"err",
"error",
"\n\n",
"for",
... | // MakeRequestRetry a synchronous request, but retry in the event of a rate
// limited response. | [
"MakeRequestRetry",
"a",
"synchronous",
"request",
"but",
"retry",
"in",
"the",
"event",
"of",
"a",
"rate",
"limited",
"response",
"."
] | df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5 | https://github.com/sendgrid/sendgrid-go/blob/df2105ec04e32aff6b9e9a2fd1ca8e5c16a836c5/sendgrid.go#L112-L143 | train |
golang/tour | local.go | isRoot | func isRoot(path string) bool {
_, err := os.Stat(filepath.Join(path, "content", "welcome.article"))
if err == nil {
_, err = os.Stat(filepath.Join(path, "template", "index.tmpl"))
}
return err == nil
} | go | func isRoot(path string) bool {
_, err := os.Stat(filepath.Join(path, "content", "welcome.article"))
if err == nil {
_, err = os.Stat(filepath.Join(path, "template", "index.tmpl"))
}
return err == nil
} | [
"func",
"isRoot",
"(",
"path",
"string",
")",
"bool",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"filepath",
".",
"Join",
"(",
"path",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"_",
",",
"err",
... | // isRoot reports whether path is the root directory of the tour tree.
// To be the root, it must have content and template subdirectories. | [
"isRoot",
"reports",
"whether",
"path",
"is",
"the",
"root",
"directory",
"of",
"the",
"tour",
"tree",
".",
"To",
"be",
"the",
"root",
"it",
"must",
"have",
"content",
"and",
"template",
"subdirectories",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/local.go#L50-L56 | train |
golang/tour | local.go | registerStatic | func registerStatic(root string) {
// Keep these static file handlers in sync with app.yaml.
http.Handle("/favicon.ico", http.FileServer(http.Dir(filepath.Join(root, "static", "img"))))
static := http.FileServer(http.Dir(root))
http.Handle("/content/img/", static)
http.Handle("/static/", static)
} | go | func registerStatic(root string) {
// Keep these static file handlers in sync with app.yaml.
http.Handle("/favicon.ico", http.FileServer(http.Dir(filepath.Join(root, "static", "img"))))
static := http.FileServer(http.Dir(root))
http.Handle("/content/img/", static)
http.Handle("/static/", static)
} | [
"func",
"registerStatic",
"(",
"root",
"string",
")",
"{",
"// Keep these static file handlers in sync with app.yaml.",
"http",
".",
"Handle",
"(",
"\"",
"\"",
",",
"http",
".",
"FileServer",
"(",
"http",
".",
"Dir",
"(",
"filepath",
".",
"Join",
"(",
"root",
... | // registerStatic registers handlers to serve static content
// from the directory root. | [
"registerStatic",
"registers",
"handlers",
"to",
"serve",
"static",
"content",
"from",
"the",
"directory",
"root",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/local.go#L128-L134 | train |
golang/tour | local.go | rootHandler | func rootHandler(w http.ResponseWriter, r *http.Request) {
if err := renderUI(w); err != nil {
log.Println(err)
}
} | go | func rootHandler(w http.ResponseWriter, r *http.Request) {
if err := renderUI(w); err != nil {
log.Println(err)
}
} | [
"func",
"rootHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"err",
":=",
"renderUI",
"(",
"w",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Println",
"(",
"err",
")",
"\n",
"}",
"\n",
... | // rootHandler returns a handler for all the requests except the ones for lessons. | [
"rootHandler",
"returns",
"a",
"handler",
"for",
"all",
"the",
"requests",
"except",
"the",
"ones",
"for",
"lessons",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/local.go#L137-L141 | train |
golang/tour | local.go | lessonHandler | func lessonHandler(w http.ResponseWriter, r *http.Request) {
lesson := strings.TrimPrefix(r.URL.Path, "/lesson/")
if err := writeLesson(lesson, w); err != nil {
if err == lessonNotFound {
http.NotFound(w, r)
} else {
log.Println(err)
}
}
} | go | func lessonHandler(w http.ResponseWriter, r *http.Request) {
lesson := strings.TrimPrefix(r.URL.Path, "/lesson/")
if err := writeLesson(lesson, w); err != nil {
if err == lessonNotFound {
http.NotFound(w, r)
} else {
log.Println(err)
}
}
} | [
"func",
"lessonHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"lesson",
":=",
"strings",
".",
"TrimPrefix",
"(",
"r",
".",
"URL",
".",
"Path",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"writ... | // lessonHandler handler the HTTP requests for lessons. | [
"lessonHandler",
"handler",
"the",
"HTTP",
"requests",
"for",
"lessons",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/local.go#L144-L153 | train |
golang/tour | local.go | waitServer | func waitServer(url string) bool {
tries := 20
for tries > 0 {
resp, err := http.Get(url)
if err == nil {
resp.Body.Close()
return true
}
time.Sleep(100 * time.Millisecond)
tries--
}
return false
} | go | func waitServer(url string) bool {
tries := 20
for tries > 0 {
resp, err := http.Get(url)
if err == nil {
resp.Body.Close()
return true
}
time.Sleep(100 * time.Millisecond)
tries--
}
return false
} | [
"func",
"waitServer",
"(",
"url",
"string",
")",
"bool",
"{",
"tries",
":=",
"20",
"\n",
"for",
"tries",
">",
"0",
"{",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"url",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"resp",
".",
"Body",
"."... | // waitServer waits some time for the http Server to start
// serving url. The return value reports whether it starts. | [
"waitServer",
"waits",
"some",
"time",
"for",
"the",
"http",
"Server",
"to",
"start",
"serving",
"url",
".",
"The",
"return",
"value",
"reports",
"whether",
"it",
"starts",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/local.go#L191-L203 | train |
golang/tour | local.go | startBrowser | func startBrowser(url string) bool {
// try to start the browser
var args []string
switch runtime.GOOS {
case "darwin":
args = []string{"open"}
case "windows":
args = []string{"cmd", "/c", "start"}
default:
args = []string{"xdg-open"}
}
cmd := exec.Command(args[0], append(args[1:], url)...)
return cmd.St... | go | func startBrowser(url string) bool {
// try to start the browser
var args []string
switch runtime.GOOS {
case "darwin":
args = []string{"open"}
case "windows":
args = []string{"cmd", "/c", "start"}
default:
args = []string{"xdg-open"}
}
cmd := exec.Command(args[0], append(args[1:], url)...)
return cmd.St... | [
"func",
"startBrowser",
"(",
"url",
"string",
")",
"bool",
"{",
"// try to start the browser",
"var",
"args",
"[",
"]",
"string",
"\n",
"switch",
"runtime",
".",
"GOOS",
"{",
"case",
"\"",
"\"",
":",
"args",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}... | // startBrowser tries to open the URL in a browser, and returns
// whether it succeed. | [
"startBrowser",
"tries",
"to",
"open",
"the",
"URL",
"in",
"a",
"browser",
"and",
"returns",
"whether",
"it",
"succeed",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/local.go#L207-L220 | train |
golang/tour | appengine.go | hstsHandler | func hstsHandler(fn http.HandlerFunc) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Strict-Transport-Security", "max-age=31536000; preload")
fn(w, r)
})
} | go | func hstsHandler(fn http.HandlerFunc) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Strict-Transport-Security", "max-age=31536000; preload")
fn(w, r)
})
} | [
"func",
"hstsHandler",
"(",
"fn",
"http",
".",
"HandlerFunc",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"He... | // hstsHandler wraps an http.HandlerFunc such that it sets the HSTS header. | [
"hstsHandler",
"wraps",
"an",
"http",
".",
"HandlerFunc",
"such",
"that",
"it",
"sets",
"the",
"HSTS",
"header",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/appengine.go#L83-L88 | train |
golang/tour | tree/tree.go | New | func New(k int) *Tree {
var t *Tree
for _, v := range rand.Perm(10) {
t = insert(t, (1+v)*k)
}
return t
} | go | func New(k int) *Tree {
var t *Tree
for _, v := range rand.Perm(10) {
t = insert(t, (1+v)*k)
}
return t
} | [
"func",
"New",
"(",
"k",
"int",
")",
"*",
"Tree",
"{",
"var",
"t",
"*",
"Tree",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"rand",
".",
"Perm",
"(",
"10",
")",
"{",
"t",
"=",
"insert",
"(",
"t",
",",
"(",
"1",
"+",
"v",
")",
"*",
"k",
"... | // New returns a new, random binary tree holding the values k, 2k, ..., 10k. | [
"New",
"returns",
"a",
"new",
"random",
"binary",
"tree",
"holding",
"the",
"values",
"k",
"2k",
"...",
"10k",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/tree/tree.go#L20-L26 | train |
golang/tour | solutions/fib.go | fibonacci | func fibonacci() func() int {
f, g := 1, 0
return func() int {
f, g = g, f+g
return f
}
} | go | func fibonacci() func() int {
f, g := 1, 0
return func() int {
f, g = g, f+g
return f
}
} | [
"func",
"fibonacci",
"(",
")",
"func",
"(",
")",
"int",
"{",
"f",
",",
"g",
":=",
"1",
",",
"0",
"\n",
"return",
"func",
"(",
")",
"int",
"{",
"f",
",",
"g",
"=",
"g",
",",
"f",
"+",
"g",
"\n",
"return",
"f",
"\n",
"}",
"\n",
"}"
] | // fibonacci is a function that returns
// a function that returns an int. | [
"fibonacci",
"is",
"a",
"function",
"that",
"returns",
"a",
"function",
"that",
"returns",
"an",
"int",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/solutions/fib.go#L13-L19 | train |
golang/tour | solutions/binarytrees_quit.go | Walk | func Walk(t *tree.Tree, ch, quit chan int) {
walkImpl(t, ch, quit)
close(ch)
} | go | func Walk(t *tree.Tree, ch, quit chan int) {
walkImpl(t, ch, quit)
close(ch)
} | [
"func",
"Walk",
"(",
"t",
"*",
"tree",
".",
"Tree",
",",
"ch",
",",
"quit",
"chan",
"int",
")",
"{",
"walkImpl",
"(",
"t",
",",
"ch",
",",
"quit",
")",
"\n",
"close",
"(",
"ch",
")",
"\n",
"}"
] | // Walk walks the tree t sending all values
// from the tree to the channel ch. | [
"Walk",
"walks",
"the",
"tree",
"t",
"sending",
"all",
"values",
"from",
"the",
"tree",
"to",
"the",
"channel",
"ch",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/solutions/binarytrees_quit.go#L31-L34 | train |
golang/tour | solutions/binarytrees_quit.go | Same | func Same(t1, t2 *tree.Tree) bool {
w1, w2 := make(chan int), make(chan int)
quit := make(chan int)
defer close(quit)
go Walk(t1, w1, quit)
go Walk(t2, w2, quit)
for {
v1, ok1 := <-w1
v2, ok2 := <-w2
if !ok1 || !ok2 {
return ok1 == ok2
}
if v1 != v2 {
return false
}
}
} | go | func Same(t1, t2 *tree.Tree) bool {
w1, w2 := make(chan int), make(chan int)
quit := make(chan int)
defer close(quit)
go Walk(t1, w1, quit)
go Walk(t2, w2, quit)
for {
v1, ok1 := <-w1
v2, ok2 := <-w2
if !ok1 || !ok2 {
return ok1 == ok2
}
if v1 != v2 {
return false
}
}
} | [
"func",
"Same",
"(",
"t1",
",",
"t2",
"*",
"tree",
".",
"Tree",
")",
"bool",
"{",
"w1",
",",
"w2",
":=",
"make",
"(",
"chan",
"int",
")",
",",
"make",
"(",
"chan",
"int",
")",
"\n",
"quit",
":=",
"make",
"(",
"chan",
"int",
")",
"\n",
"defer"... | // Same determines whether the trees
// t1 and t2 contain the same values. | [
"Same",
"determines",
"whether",
"the",
"trees",
"t1",
"and",
"t2",
"contain",
"the",
"same",
"values",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/solutions/binarytrees_quit.go#L38-L56 | train |
golang/tour | content/concurrency/mutex-counter.go | Inc | func (c *SafeCounter) Inc(key string) {
c.mux.Lock()
// Lock so only one goroutine at a time can access the map c.v.
c.v[key]++
c.mux.Unlock()
} | go | func (c *SafeCounter) Inc(key string) {
c.mux.Lock()
// Lock so only one goroutine at a time can access the map c.v.
c.v[key]++
c.mux.Unlock()
} | [
"func",
"(",
"c",
"*",
"SafeCounter",
")",
"Inc",
"(",
"key",
"string",
")",
"{",
"c",
".",
"mux",
".",
"Lock",
"(",
")",
"\n",
"// Lock so only one goroutine at a time can access the map c.v.",
"c",
".",
"v",
"[",
"key",
"]",
"++",
"\n",
"c",
".",
"mux"... | // Inc increments the counter for the given key. | [
"Inc",
"increments",
"the",
"counter",
"for",
"the",
"given",
"key",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/content/concurrency/mutex-counter.go#L18-L23 | train |
golang/tour | content/concurrency/mutex-counter.go | Value | func (c *SafeCounter) Value(key string) int {
c.mux.Lock()
// Lock so only one goroutine at a time can access the map c.v.
defer c.mux.Unlock()
return c.v[key]
} | go | func (c *SafeCounter) Value(key string) int {
c.mux.Lock()
// Lock so only one goroutine at a time can access the map c.v.
defer c.mux.Unlock()
return c.v[key]
} | [
"func",
"(",
"c",
"*",
"SafeCounter",
")",
"Value",
"(",
"key",
"string",
")",
"int",
"{",
"c",
".",
"mux",
".",
"Lock",
"(",
")",
"\n",
"// Lock so only one goroutine at a time can access the map c.v.",
"defer",
"c",
".",
"mux",
".",
"Unlock",
"(",
")",
"... | // Value returns the current value of the counter for the given key. | [
"Value",
"returns",
"the",
"current",
"value",
"of",
"the",
"counter",
"for",
"the",
"given",
"key",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/content/concurrency/mutex-counter.go#L26-L31 | train |
golang/tour | tour.go | initTour | func initTour(root, transport string) error {
// Make sure playground is enabled before rendering.
present.PlayEnabled = true
// Set up templates.
action := filepath.Join(root, "template", "action.tmpl")
tmpl, err := present.Template().ParseFiles(action)
if err != nil {
return fmt.Errorf("parse templates: %v",... | go | func initTour(root, transport string) error {
// Make sure playground is enabled before rendering.
present.PlayEnabled = true
// Set up templates.
action := filepath.Join(root, "template", "action.tmpl")
tmpl, err := present.Template().ParseFiles(action)
if err != nil {
return fmt.Errorf("parse templates: %v",... | [
"func",
"initTour",
"(",
"root",
",",
"transport",
"string",
")",
"error",
"{",
"// Make sure playground is enabled before rendering.",
"present",
".",
"PlayEnabled",
"=",
"true",
"\n\n",
"// Set up templates.",
"action",
":=",
"filepath",
".",
"Join",
"(",
"root",
... | // initTour loads tour.article and the relevant HTML templates from the given
// tour root, and renders the template to the tourContent global variable. | [
"initTour",
"loads",
"tour",
".",
"article",
"and",
"the",
"relevant",
"HTML",
"templates",
"from",
"the",
"given",
"tour",
"root",
"and",
"renders",
"the",
"template",
"to",
"the",
"tourContent",
"global",
"variable",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/tour.go#L34-L70 | train |
golang/tour | tour.go | initLessons | func initLessons(tmpl *template.Template, content string) error {
dir, err := os.Open(content)
if err != nil {
return err
}
files, err := dir.Readdirnames(0)
if err != nil {
return err
}
for _, f := range files {
if filepath.Ext(f) != ".article" {
continue
}
content, err := parseLesson(tmpl, filepat... | go | func initLessons(tmpl *template.Template, content string) error {
dir, err := os.Open(content)
if err != nil {
return err
}
files, err := dir.Readdirnames(0)
if err != nil {
return err
}
for _, f := range files {
if filepath.Ext(f) != ".article" {
continue
}
content, err := parseLesson(tmpl, filepat... | [
"func",
"initLessons",
"(",
"tmpl",
"*",
"template",
".",
"Template",
",",
"content",
"string",
")",
"error",
"{",
"dir",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"content",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n... | // initLessonss finds all the lessons in the passed directory, renders them,
// using the given template and saves the content in the lessons map. | [
"initLessonss",
"finds",
"all",
"the",
"lessons",
"in",
"the",
"passed",
"directory",
"renders",
"them",
"using",
"the",
"given",
"template",
"and",
"saves",
"the",
"content",
"in",
"the",
"lessons",
"map",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/tour.go#L74-L95 | train |
golang/tour | tour.go | parseLesson | func parseLesson(tmpl *template.Template, path string) ([]byte, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
doc, err := present.Parse(prepContent(f), path, 0)
if err != nil {
return nil, err
}
lesson := Lesson{
doc.Title,
doc.Subtitle,
make([]Page, len(doc.Secti... | go | func parseLesson(tmpl *template.Template, path string) ([]byte, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
doc, err := present.Parse(prepContent(f), path, 0)
if err != nil {
return nil, err
}
lesson := Lesson{
doc.Title,
doc.Subtitle,
make([]Page, len(doc.Secti... | [
"func",
"parseLesson",
"(",
"tmpl",
"*",
"template",
".",
"Template",
",",
"path",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r... | // parseLesson parses and returns a lesson content given its name and
// the template to render it. | [
"parseLesson",
"parses",
"and",
"returns",
"a",
"lesson",
"content",
"given",
"its",
"name",
"and",
"the",
"template",
"to",
"render",
"it",
"."
] | db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77 | https://github.com/golang/tour/blob/db40fe78fefcfdeefb4ac4a94c72cfb20f40ee77/tour.go#L120-L161 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.