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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
oklog/ulid | ulid.go | MustParse | func MustParse(ulid string) ULID {
id, err := Parse(ulid)
if err != nil {
panic(err)
}
return id
} | go | func MustParse(ulid string) ULID {
id, err := Parse(ulid)
if err != nil {
panic(err)
}
return id
} | [
"func",
"MustParse",
"(",
"ulid",
"string",
")",
"ULID",
"{",
"id",
",",
"err",
":=",
"Parse",
"(",
"ulid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"id",
"\n",
"}"
] | // MustParse is a convenience function equivalent to Parse that panics on failure
// instead of returning an error. | [
"MustParse",
"is",
"a",
"convenience",
"function",
"equivalent",
"to",
"Parse",
"that",
"panics",
"on",
"failure",
"instead",
"of",
"returning",
"an",
"error",
"."
] | bacfb41fdd06edf5294635d18ec387dee671a964 | https://github.com/oklog/ulid/blob/bacfb41fdd06edf5294635d18ec387dee671a964/ulid.go#L219-L225 | train |
oklog/ulid | ulid.go | MustParseStrict | func MustParseStrict(ulid string) ULID {
id, err := ParseStrict(ulid)
if err != nil {
panic(err)
}
return id
} | go | func MustParseStrict(ulid string) ULID {
id, err := ParseStrict(ulid)
if err != nil {
panic(err)
}
return id
} | [
"func",
"MustParseStrict",
"(",
"ulid",
"string",
")",
"ULID",
"{",
"id",
",",
"err",
":=",
"ParseStrict",
"(",
"ulid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"id",
"\n",
"}"
] | // MustParseStrict is a convenience function equivalent to ParseStrict that
// panics on failure instead of returning an error. | [
"MustParseStrict",
"is",
"a",
"convenience",
"function",
"equivalent",
"to",
"ParseStrict",
"that",
"panics",
"on",
"failure",
"instead",
"of",
"returning",
"an",
"error",
"."
] | bacfb41fdd06edf5294635d18ec387dee671a964 | https://github.com/oklog/ulid/blob/bacfb41fdd06edf5294635d18ec387dee671a964/ulid.go#L229-L235 | train |
oklog/ulid | ulid.go | MarshalBinary | func (id ULID) MarshalBinary() ([]byte, error) {
ulid := make([]byte, len(id))
return ulid, id.MarshalBinaryTo(ulid)
} | go | func (id ULID) MarshalBinary() ([]byte, error) {
ulid := make([]byte, len(id))
return ulid, id.MarshalBinaryTo(ulid)
} | [
"func",
"(",
"id",
"ULID",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"ulid",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"id",
")",
")",
"\n",
"return",
"ulid",
",",
"id",
".",
"MarshalBinaryTo",
"... | // MarshalBinary implements the encoding.BinaryMarshaler interface by
// returning the ULID as a byte slice. | [
"MarshalBinary",
"implements",
"the",
"encoding",
".",
"BinaryMarshaler",
"interface",
"by",
"returning",
"the",
"ULID",
"as",
"a",
"byte",
"slice",
"."
] | bacfb41fdd06edf5294635d18ec387dee671a964 | https://github.com/oklog/ulid/blob/bacfb41fdd06edf5294635d18ec387dee671a964/ulid.go#L248-L251 | train |
oklog/ulid | ulid.go | UnmarshalBinary | func (id *ULID) UnmarshalBinary(data []byte) error {
if len(data) != len(*id) {
return ErrDataSize
}
copy((*id)[:], data)
return nil
} | go | func (id *ULID) UnmarshalBinary(data []byte) error {
if len(data) != len(*id) {
return ErrDataSize
}
copy((*id)[:], data)
return nil
} | [
"func",
"(",
"id",
"*",
"ULID",
")",
"UnmarshalBinary",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"data",
")",
"!=",
"len",
"(",
"*",
"id",
")",
"{",
"return",
"ErrDataSize",
"\n",
"}",
"\n\n",
"copy",
"(",
"(",
"*",
"... | // UnmarshalBinary implements the encoding.BinaryUnmarshaler interface by
// copying the passed data and converting it to an ULID. ErrDataSize is
// returned if the data length is different from ULID length. | [
"UnmarshalBinary",
"implements",
"the",
"encoding",
".",
"BinaryUnmarshaler",
"interface",
"by",
"copying",
"the",
"passed",
"data",
"and",
"converting",
"it",
"to",
"an",
"ULID",
".",
"ErrDataSize",
"is",
"returned",
"if",
"the",
"data",
"length",
"is",
"differ... | bacfb41fdd06edf5294635d18ec387dee671a964 | https://github.com/oklog/ulid/blob/bacfb41fdd06edf5294635d18ec387dee671a964/ulid.go#L267-L274 | train |
oklog/ulid | ulid.go | MarshalText | func (id ULID) MarshalText() ([]byte, error) {
ulid := make([]byte, EncodedSize)
return ulid, id.MarshalTextTo(ulid)
} | go | func (id ULID) MarshalText() ([]byte, error) {
ulid := make([]byte, EncodedSize)
return ulid, id.MarshalTextTo(ulid)
} | [
"func",
"(",
"id",
"ULID",
")",
"MarshalText",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"ulid",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"EncodedSize",
")",
"\n",
"return",
"ulid",
",",
"id",
".",
"MarshalTextTo",
"(",
"ulid",
")... | // MarshalText implements the encoding.TextMarshaler interface by
// returning the string encoded ULID. | [
"MarshalText",
"implements",
"the",
"encoding",
".",
"TextMarshaler",
"interface",
"by",
"returning",
"the",
"string",
"encoded",
"ULID",
"."
] | bacfb41fdd06edf5294635d18ec387dee671a964 | https://github.com/oklog/ulid/blob/bacfb41fdd06edf5294635d18ec387dee671a964/ulid.go#L281-L284 | train |
oklog/ulid | ulid.go | Time | func (id ULID) Time() uint64 {
return uint64(id[5]) | uint64(id[4])<<8 |
uint64(id[3])<<16 | uint64(id[2])<<24 |
uint64(id[1])<<32 | uint64(id[0])<<40
} | go | func (id ULID) Time() uint64 {
return uint64(id[5]) | uint64(id[4])<<8 |
uint64(id[3])<<16 | uint64(id[2])<<24 |
uint64(id[1])<<32 | uint64(id[0])<<40
} | [
"func",
"(",
"id",
"ULID",
")",
"Time",
"(",
")",
"uint64",
"{",
"return",
"uint64",
"(",
"id",
"[",
"5",
"]",
")",
"|",
"uint64",
"(",
"id",
"[",
"4",
"]",
")",
"<<",
"8",
"|",
"uint64",
"(",
"id",
"[",
"3",
"]",
")",
"<<",
"16",
"|",
"u... | // Time returns the Unix time in milliseconds encoded in the ULID.
// Use the top level Time function to convert the returned value to
// a time.Time. | [
"Time",
"returns",
"the",
"Unix",
"time",
"in",
"milliseconds",
"encoded",
"in",
"the",
"ULID",
".",
"Use",
"the",
"top",
"level",
"Time",
"function",
"to",
"convert",
"the",
"returned",
"value",
"to",
"a",
"time",
".",
"Time",
"."
] | bacfb41fdd06edf5294635d18ec387dee671a964 | https://github.com/oklog/ulid/blob/bacfb41fdd06edf5294635d18ec387dee671a964/ulid.go#L375-L379 | train |
oklog/ulid | ulid.go | Timestamp | func Timestamp(t time.Time) uint64 {
return uint64(t.Unix())*1000 +
uint64(t.Nanosecond()/int(time.Millisecond))
} | go | func Timestamp(t time.Time) uint64 {
return uint64(t.Unix())*1000 +
uint64(t.Nanosecond()/int(time.Millisecond))
} | [
"func",
"Timestamp",
"(",
"t",
"time",
".",
"Time",
")",
"uint64",
"{",
"return",
"uint64",
"(",
"t",
".",
"Unix",
"(",
")",
")",
"*",
"1000",
"+",
"uint64",
"(",
"t",
".",
"Nanosecond",
"(",
")",
"/",
"int",
"(",
"time",
".",
"Millisecond",
")",... | // Timestamp converts a time.Time to Unix milliseconds.
//
// Because of the way ULID stores time, times from the year
// 10889 produces undefined results. | [
"Timestamp",
"converts",
"a",
"time",
".",
"Time",
"to",
"Unix",
"milliseconds",
".",
"Because",
"of",
"the",
"way",
"ULID",
"stores",
"time",
"times",
"from",
"the",
"year",
"10889",
"produces",
"undefined",
"results",
"."
] | bacfb41fdd06edf5294635d18ec387dee671a964 | https://github.com/oklog/ulid/blob/bacfb41fdd06edf5294635d18ec387dee671a964/ulid.go#L398-L401 | train |
oklog/ulid | ulid.go | Time | func Time(ms uint64) time.Time {
s := int64(ms / 1e3)
ns := int64((ms % 1e3) * 1e6)
return time.Unix(s, ns)
} | go | func Time(ms uint64) time.Time {
s := int64(ms / 1e3)
ns := int64((ms % 1e3) * 1e6)
return time.Unix(s, ns)
} | [
"func",
"Time",
"(",
"ms",
"uint64",
")",
"time",
".",
"Time",
"{",
"s",
":=",
"int64",
"(",
"ms",
"/",
"1e3",
")",
"\n",
"ns",
":=",
"int64",
"(",
"(",
"ms",
"%",
"1e3",
")",
"*",
"1e6",
")",
"\n",
"return",
"time",
".",
"Unix",
"(",
"s",
... | // Time converts Unix milliseconds in the format
// returned by the Timestamp function to a time.Time. | [
"Time",
"converts",
"Unix",
"milliseconds",
"in",
"the",
"format",
"returned",
"by",
"the",
"Timestamp",
"function",
"to",
"a",
"time",
".",
"Time",
"."
] | bacfb41fdd06edf5294635d18ec387dee671a964 | https://github.com/oklog/ulid/blob/bacfb41fdd06edf5294635d18ec387dee671a964/ulid.go#L405-L409 | train |
oklog/ulid | ulid.go | SetTime | func (id *ULID) SetTime(ms uint64) error {
if ms > maxTime {
return ErrBigTime
}
(*id)[0] = byte(ms >> 40)
(*id)[1] = byte(ms >> 32)
(*id)[2] = byte(ms >> 24)
(*id)[3] = byte(ms >> 16)
(*id)[4] = byte(ms >> 8)
(*id)[5] = byte(ms)
return nil
} | go | func (id *ULID) SetTime(ms uint64) error {
if ms > maxTime {
return ErrBigTime
}
(*id)[0] = byte(ms >> 40)
(*id)[1] = byte(ms >> 32)
(*id)[2] = byte(ms >> 24)
(*id)[3] = byte(ms >> 16)
(*id)[4] = byte(ms >> 8)
(*id)[5] = byte(ms)
return nil
} | [
"func",
"(",
"id",
"*",
"ULID",
")",
"SetTime",
"(",
"ms",
"uint64",
")",
"error",
"{",
"if",
"ms",
">",
"maxTime",
"{",
"return",
"ErrBigTime",
"\n",
"}",
"\n\n",
"(",
"*",
"id",
")",
"[",
"0",
"]",
"=",
"byte",
"(",
"ms",
">>",
"40",
")",
"... | // SetTime sets the time component of the ULID to the given Unix time
// in milliseconds. | [
"SetTime",
"sets",
"the",
"time",
"component",
"of",
"the",
"ULID",
"to",
"the",
"given",
"Unix",
"time",
"in",
"milliseconds",
"."
] | bacfb41fdd06edf5294635d18ec387dee671a964 | https://github.com/oklog/ulid/blob/bacfb41fdd06edf5294635d18ec387dee671a964/ulid.go#L413-L426 | train |
oklog/ulid | ulid.go | Entropy | func (id ULID) Entropy() []byte {
e := make([]byte, 10)
copy(e, id[6:])
return e
} | go | func (id ULID) Entropy() []byte {
e := make([]byte, 10)
copy(e, id[6:])
return e
} | [
"func",
"(",
"id",
"ULID",
")",
"Entropy",
"(",
")",
"[",
"]",
"byte",
"{",
"e",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"10",
")",
"\n",
"copy",
"(",
"e",
",",
"id",
"[",
"6",
":",
"]",
")",
"\n",
"return",
"e",
"\n",
"}"
] | // Entropy returns the entropy from the ULID. | [
"Entropy",
"returns",
"the",
"entropy",
"from",
"the",
"ULID",
"."
] | bacfb41fdd06edf5294635d18ec387dee671a964 | https://github.com/oklog/ulid/blob/bacfb41fdd06edf5294635d18ec387dee671a964/ulid.go#L429-L433 | train |
oklog/ulid | ulid.go | Scan | func (id *ULID) Scan(src interface{}) error {
switch x := src.(type) {
case nil:
return nil
case string:
return id.UnmarshalText([]byte(x))
case []byte:
return id.UnmarshalBinary(x)
}
return ErrScanValue
} | go | func (id *ULID) Scan(src interface{}) error {
switch x := src.(type) {
case nil:
return nil
case string:
return id.UnmarshalText([]byte(x))
case []byte:
return id.UnmarshalBinary(x)
}
return ErrScanValue
} | [
"func",
"(",
"id",
"*",
"ULID",
")",
"Scan",
"(",
"src",
"interface",
"{",
"}",
")",
"error",
"{",
"switch",
"x",
":=",
"src",
".",
"(",
"type",
")",
"{",
"case",
"nil",
":",
"return",
"nil",
"\n",
"case",
"string",
":",
"return",
"id",
".",
"U... | // Scan implements the sql.Scanner interface. It supports scanning
// a string or byte slice. | [
"Scan",
"implements",
"the",
"sql",
".",
"Scanner",
"interface",
".",
"It",
"supports",
"scanning",
"a",
"string",
"or",
"byte",
"slice",
"."
] | bacfb41fdd06edf5294635d18ec387dee671a964 | https://github.com/oklog/ulid/blob/bacfb41fdd06edf5294635d18ec387dee671a964/ulid.go#L454-L465 | train |
oklog/ulid | ulid.go | MonotonicRead | func (m *MonotonicEntropy) MonotonicRead(ms uint64, entropy []byte) (err error) {
if !m.entropy.IsZero() && m.ms == ms {
err = m.increment()
m.entropy.AppendTo(entropy)
} else if _, err = io.ReadFull(m.Reader, entropy); err == nil {
m.ms = ms
m.entropy.SetBytes(entropy)
}
return err
} | go | func (m *MonotonicEntropy) MonotonicRead(ms uint64, entropy []byte) (err error) {
if !m.entropy.IsZero() && m.ms == ms {
err = m.increment()
m.entropy.AppendTo(entropy)
} else if _, err = io.ReadFull(m.Reader, entropy); err == nil {
m.ms = ms
m.entropy.SetBytes(entropy)
}
return err
} | [
"func",
"(",
"m",
"*",
"MonotonicEntropy",
")",
"MonotonicRead",
"(",
"ms",
"uint64",
",",
"entropy",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"if",
"!",
"m",
".",
"entropy",
".",
"IsZero",
"(",
")",
"&&",
"m",
".",
"ms",
"==",
"ms",... | // MonotonicRead implements the MonotonicReader interface. | [
"MonotonicRead",
"implements",
"the",
"MonotonicReader",
"interface",
"."
] | bacfb41fdd06edf5294635d18ec387dee671a964 | https://github.com/oklog/ulid/blob/bacfb41fdd06edf5294635d18ec387dee671a964/ulid.go#L528-L537 | train |
olekukonko/tablewriter | table.go | NewWriter | func NewWriter(writer io.Writer) *Table {
t := &Table{
out: writer,
rows: [][]string{},
lines: [][][]string{},
cs: make(map[int]int),
rs: make(map[int]int),
headers: [][]string{},
footers: [][]string{},
caption: false,
captionText: ... | go | func NewWriter(writer io.Writer) *Table {
t := &Table{
out: writer,
rows: [][]string{},
lines: [][][]string{},
cs: make(map[int]int),
rs: make(map[int]int),
headers: [][]string{},
footers: [][]string{},
caption: false,
captionText: ... | [
"func",
"NewWriter",
"(",
"writer",
"io",
".",
"Writer",
")",
"*",
"Table",
"{",
"t",
":=",
"&",
"Table",
"{",
"out",
":",
"writer",
",",
"rows",
":",
"[",
"]",
"[",
"]",
"string",
"{",
"}",
",",
"lines",
":",
"[",
"]",
"[",
"]",
"[",
"]",
... | // Start New Table
// Take io.Writer Directly | [
"Start",
"New",
"Table",
"Take",
"io",
".",
"Writer",
"Directly"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L86-L119 | train |
olekukonko/tablewriter | table.go | Render | func (t *Table) Render() {
if t.borders.Top {
t.printLine(true)
}
t.printHeading()
if t.autoMergeCells {
t.printRowsMergeCells()
} else {
t.printRows()
}
if !t.rowLine && t.borders.Bottom {
t.printLine(true)
}
t.printFooter()
if t.caption {
t.printCaption()
}
} | go | func (t *Table) Render() {
if t.borders.Top {
t.printLine(true)
}
t.printHeading()
if t.autoMergeCells {
t.printRowsMergeCells()
} else {
t.printRows()
}
if !t.rowLine && t.borders.Bottom {
t.printLine(true)
}
t.printFooter()
if t.caption {
t.printCaption()
}
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Render",
"(",
")",
"{",
"if",
"t",
".",
"borders",
".",
"Top",
"{",
"t",
".",
"printLine",
"(",
"true",
")",
"\n",
"}",
"\n",
"t",
".",
"printHeading",
"(",
")",
"\n",
"if",
"t",
".",
"autoMergeCells",
"{",... | // Render table output | [
"Render",
"table",
"output"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L122-L140 | train |
olekukonko/tablewriter | table.go | SetHeader | func (t *Table) SetHeader(keys []string) {
t.colSize = len(keys)
for i, v := range keys {
lines := t.parseDimension(v, i, headerRowIdx)
t.headers = append(t.headers, lines)
}
} | go | func (t *Table) SetHeader(keys []string) {
t.colSize = len(keys)
for i, v := range keys {
lines := t.parseDimension(v, i, headerRowIdx)
t.headers = append(t.headers, lines)
}
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"SetHeader",
"(",
"keys",
"[",
"]",
"string",
")",
"{",
"t",
".",
"colSize",
"=",
"len",
"(",
"keys",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"keys",
"{",
"lines",
":=",
"t",
".",
"parseDimension",
"... | // Set table header | [
"Set",
"table",
"header"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L148-L154 | train |
olekukonko/tablewriter | table.go | SetFooter | func (t *Table) SetFooter(keys []string) {
//t.colSize = len(keys)
for i, v := range keys {
lines := t.parseDimension(v, i, footerRowIdx)
t.footers = append(t.footers, lines)
}
} | go | func (t *Table) SetFooter(keys []string) {
//t.colSize = len(keys)
for i, v := range keys {
lines := t.parseDimension(v, i, footerRowIdx)
t.footers = append(t.footers, lines)
}
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"SetFooter",
"(",
"keys",
"[",
"]",
"string",
")",
"{",
"//t.colSize = len(keys)",
"for",
"i",
",",
"v",
":=",
"range",
"keys",
"{",
"lines",
":=",
"t",
".",
"parseDimension",
"(",
"v",
",",
"i",
",",
"footerRowId... | // Set table Footer | [
"Set",
"table",
"Footer"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L157-L163 | train |
olekukonko/tablewriter | table.go | SetCaption | func (t *Table) SetCaption(caption bool, captionText ...string) {
t.caption = caption
if len(captionText) == 1 {
t.captionText = captionText[0]
}
} | go | func (t *Table) SetCaption(caption bool, captionText ...string) {
t.caption = caption
if len(captionText) == 1 {
t.captionText = captionText[0]
}
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"SetCaption",
"(",
"caption",
"bool",
",",
"captionText",
"...",
"string",
")",
"{",
"t",
".",
"caption",
"=",
"caption",
"\n",
"if",
"len",
"(",
"captionText",
")",
"==",
"1",
"{",
"t",
".",
"captionText",
"=",
... | // Set table Caption | [
"Set",
"table",
"Caption"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L166-L171 | train |
olekukonko/tablewriter | table.go | SetColMinWidth | func (t *Table) SetColMinWidth(column int, width int) {
t.cs[column] = width
} | go | func (t *Table) SetColMinWidth(column int, width int) {
t.cs[column] = width
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"SetColMinWidth",
"(",
"column",
"int",
",",
"width",
"int",
")",
"{",
"t",
".",
"cs",
"[",
"column",
"]",
"=",
"width",
"\n",
"}"
] | // Set the minimal width for a column | [
"Set",
"the",
"minimal",
"width",
"for",
"a",
"column"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L194-L196 | train |
olekukonko/tablewriter | table.go | Append | func (t *Table) Append(row []string) {
rowSize := len(t.headers)
if rowSize > t.colSize {
t.colSize = rowSize
}
n := len(t.lines)
line := [][]string{}
for i, v := range row {
// Detect string width
// Detect String height
// Break strings into words
out := t.parseDimension(v, i, n)
// Append broke... | go | func (t *Table) Append(row []string) {
rowSize := len(t.headers)
if rowSize > t.colSize {
t.colSize = rowSize
}
n := len(t.lines)
line := [][]string{}
for i, v := range row {
// Detect string width
// Detect String height
// Break strings into words
out := t.parseDimension(v, i, n)
// Append broke... | [
"func",
"(",
"t",
"*",
"Table",
")",
"Append",
"(",
"row",
"[",
"]",
"string",
")",
"{",
"rowSize",
":=",
"len",
"(",
"t",
".",
"headers",
")",
"\n",
"if",
"rowSize",
">",
"t",
".",
"colSize",
"{",
"t",
".",
"colSize",
"=",
"rowSize",
"\n",
"}"... | // Append row to table | [
"Append",
"row",
"to",
"table"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L278-L297 | train |
olekukonko/tablewriter | table.go | AppendBulk | func (t *Table) AppendBulk(rows [][]string) {
for _, row := range rows {
t.Append(row)
}
} | go | func (t *Table) AppendBulk(rows [][]string) {
for _, row := range rows {
t.Append(row)
}
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"AppendBulk",
"(",
"rows",
"[",
"]",
"[",
"]",
"string",
")",
"{",
"for",
"_",
",",
"row",
":=",
"range",
"rows",
"{",
"t",
".",
"Append",
"(",
"row",
")",
"\n",
"}",
"\n",
"}"
] | // Allow Support for Bulk Append
// Eliminates repeated for loops | [
"Allow",
"Support",
"for",
"Bulk",
"Append",
"Eliminates",
"repeated",
"for",
"loops"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L301-L305 | train |
olekukonko/tablewriter | table.go | center | func (t *Table) center(i int) string {
if i == -1 && !t.borders.Left {
return t.pRow
}
if i == len(t.cs)-1 && !t.borders.Right {
return t.pRow
}
return t.pCenter
} | go | func (t *Table) center(i int) string {
if i == -1 && !t.borders.Left {
return t.pRow
}
if i == len(t.cs)-1 && !t.borders.Right {
return t.pRow
}
return t.pCenter
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"center",
"(",
"i",
"int",
")",
"string",
"{",
"if",
"i",
"==",
"-",
"1",
"&&",
"!",
"t",
".",
"borders",
".",
"Left",
"{",
"return",
"t",
".",
"pRow",
"\n",
"}",
"\n\n",
"if",
"i",
"==",
"len",
"(",
"t"... | // Center based on position and border. | [
"Center",
"based",
"on",
"position",
"and",
"border",
"."
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L323-L333 | train |
olekukonko/tablewriter | table.go | printLine | func (t *Table) printLine(nl bool) {
fmt.Fprint(t.out, t.center(-1))
for i := 0; i < len(t.cs); i++ {
v := t.cs[i]
fmt.Fprintf(t.out, "%s%s%s%s",
t.pRow,
strings.Repeat(string(t.pRow), v),
t.pRow,
t.center(i))
}
if nl {
fmt.Fprint(t.out, t.newLine)
}
} | go | func (t *Table) printLine(nl bool) {
fmt.Fprint(t.out, t.center(-1))
for i := 0; i < len(t.cs); i++ {
v := t.cs[i]
fmt.Fprintf(t.out, "%s%s%s%s",
t.pRow,
strings.Repeat(string(t.pRow), v),
t.pRow,
t.center(i))
}
if nl {
fmt.Fprint(t.out, t.newLine)
}
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"printLine",
"(",
"nl",
"bool",
")",
"{",
"fmt",
".",
"Fprint",
"(",
"t",
".",
"out",
",",
"t",
".",
"center",
"(",
"-",
"1",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"t",
".",... | // Print line based on row width | [
"Print",
"line",
"based",
"on",
"row",
"width"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L336-L349 | train |
olekukonko/tablewriter | table.go | printLineOptionalCellSeparators | func (t *Table) printLineOptionalCellSeparators(nl bool, displayCellSeparator []bool) {
fmt.Fprint(t.out, t.pCenter)
for i := 0; i < len(t.cs); i++ {
v := t.cs[i]
if i > len(displayCellSeparator) || displayCellSeparator[i] {
// Display the cell separator
fmt.Fprintf(t.out, "%s%s%s%s",
t.pRow,
string... | go | func (t *Table) printLineOptionalCellSeparators(nl bool, displayCellSeparator []bool) {
fmt.Fprint(t.out, t.pCenter)
for i := 0; i < len(t.cs); i++ {
v := t.cs[i]
if i > len(displayCellSeparator) || displayCellSeparator[i] {
// Display the cell separator
fmt.Fprintf(t.out, "%s%s%s%s",
t.pRow,
string... | [
"func",
"(",
"t",
"*",
"Table",
")",
"printLineOptionalCellSeparators",
"(",
"nl",
"bool",
",",
"displayCellSeparator",
"[",
"]",
"bool",
")",
"{",
"fmt",
".",
"Fprint",
"(",
"t",
".",
"out",
",",
"t",
".",
"pCenter",
")",
"\n",
"for",
"i",
":=",
"0"... | // Print line based on row width with our without cell separator | [
"Print",
"line",
"based",
"on",
"row",
"width",
"with",
"our",
"without",
"cell",
"separator"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L352-L373 | train |
olekukonko/tablewriter | table.go | pad | func pad(align int) func(string, string, int) string {
padFunc := Pad
switch align {
case ALIGN_LEFT:
padFunc = PadRight
case ALIGN_RIGHT:
padFunc = PadLeft
}
return padFunc
} | go | func pad(align int) func(string, string, int) string {
padFunc := Pad
switch align {
case ALIGN_LEFT:
padFunc = PadRight
case ALIGN_RIGHT:
padFunc = PadLeft
}
return padFunc
} | [
"func",
"pad",
"(",
"align",
"int",
")",
"func",
"(",
"string",
",",
"string",
",",
"int",
")",
"string",
"{",
"padFunc",
":=",
"Pad",
"\n",
"switch",
"align",
"{",
"case",
"ALIGN_LEFT",
":",
"padFunc",
"=",
"PadRight",
"\n",
"case",
"ALIGN_RIGHT",
":"... | // Return the PadRight function if align is left, PadLeft if align is right,
// and Pad by default | [
"Return",
"the",
"PadRight",
"function",
"if",
"align",
"is",
"left",
"PadLeft",
"if",
"align",
"is",
"right",
"and",
"Pad",
"by",
"default"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L377-L386 | train |
olekukonko/tablewriter | table.go | printCaption | func (t Table) printCaption() {
width := t.getTableWidth()
paragraph, _ := WrapString(t.captionText, width)
for linecount := 0; linecount < len(paragraph); linecount++ {
fmt.Fprintln(t.out, paragraph[linecount])
}
} | go | func (t Table) printCaption() {
width := t.getTableWidth()
paragraph, _ := WrapString(t.captionText, width)
for linecount := 0; linecount < len(paragraph); linecount++ {
fmt.Fprintln(t.out, paragraph[linecount])
}
} | [
"func",
"(",
"t",
"Table",
")",
"printCaption",
"(",
")",
"{",
"width",
":=",
"t",
".",
"getTableWidth",
"(",
")",
"\n",
"paragraph",
",",
"_",
":=",
"WrapString",
"(",
"t",
".",
"captionText",
",",
"width",
")",
"\n",
"for",
"linecount",
":=",
"0",
... | // Print caption text | [
"Print",
"caption",
"text"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L580-L586 | train |
olekukonko/tablewriter | table.go | getTableWidth | func (t Table) getTableWidth() int {
var chars int
for _, v := range t.cs {
chars += v
}
// Add chars, spaces, seperators to calculate the total width of the table.
// ncols := t.colSize
// spaces := ncols * 2
// seps := ncols + 1
return (chars + (3 * t.colSize) + 2)
} | go | func (t Table) getTableWidth() int {
var chars int
for _, v := range t.cs {
chars += v
}
// Add chars, spaces, seperators to calculate the total width of the table.
// ncols := t.colSize
// spaces := ncols * 2
// seps := ncols + 1
return (chars + (3 * t.colSize) + 2)
} | [
"func",
"(",
"t",
"Table",
")",
"getTableWidth",
"(",
")",
"int",
"{",
"var",
"chars",
"int",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"t",
".",
"cs",
"{",
"chars",
"+=",
"v",
"\n",
"}",
"\n\n",
"// Add chars, spaces, seperators to calculate the total wi... | // Calculate the total number of characters in a row | [
"Calculate",
"the",
"total",
"number",
"of",
"characters",
"in",
"a",
"row"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L589-L601 | train |
olekukonko/tablewriter | table.go | printRow | func (t *Table) printRow(columns [][]string, rowIdx int) {
// Get Maximum Height
max := t.rs[rowIdx]
total := len(columns)
// TODO Fix uneven col size
// if total < t.colSize {
// for n := t.colSize - total; n < t.colSize ; n++ {
// columns = append(columns, []string{SPACE})
// t.cs[n] = t.mW
// }
//}
//... | go | func (t *Table) printRow(columns [][]string, rowIdx int) {
// Get Maximum Height
max := t.rs[rowIdx]
total := len(columns)
// TODO Fix uneven col size
// if total < t.colSize {
// for n := t.colSize - total; n < t.colSize ; n++ {
// columns = append(columns, []string{SPACE})
// t.cs[n] = t.mW
// }
//}
//... | [
"func",
"(",
"t",
"*",
"Table",
")",
"printRow",
"(",
"columns",
"[",
"]",
"[",
"]",
"string",
",",
"rowIdx",
"int",
")",
"{",
"// Get Maximum Height",
"max",
":=",
"t",
".",
"rs",
"[",
"rowIdx",
"]",
"\n",
"total",
":=",
"len",
"(",
"columns",
")"... | // Print Row Information
// Adjust column alignment based on type | [
"Print",
"Row",
"Information",
"Adjust",
"column",
"alignment",
"based",
"on",
"type"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L621-L702 | train |
olekukonko/tablewriter | table.go | printRowsMergeCells | func (t *Table) printRowsMergeCells() {
var previousLine []string
var displayCellBorder []bool
var tmpWriter bytes.Buffer
for i, lines := range t.lines {
// We store the display of the current line in a tmp writer, as we need to know which border needs to be print above
previousLine, displayCellBorder = t.print... | go | func (t *Table) printRowsMergeCells() {
var previousLine []string
var displayCellBorder []bool
var tmpWriter bytes.Buffer
for i, lines := range t.lines {
// We store the display of the current line in a tmp writer, as we need to know which border needs to be print above
previousLine, displayCellBorder = t.print... | [
"func",
"(",
"t",
"*",
"Table",
")",
"printRowsMergeCells",
"(",
")",
"{",
"var",
"previousLine",
"[",
"]",
"string",
"\n",
"var",
"displayCellBorder",
"[",
"]",
"bool",
"\n",
"var",
"tmpWriter",
"bytes",
".",
"Buffer",
"\n",
"for",
"i",
",",
"lines",
... | // Print the rows of the table and merge the cells that are identical | [
"Print",
"the",
"rows",
"of",
"the",
"table",
"and",
"merge",
"the",
"cells",
"that",
"are",
"identical"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table.go#L705-L723 | train |
olekukonko/tablewriter | csv.go | NewCSV | func NewCSV(writer io.Writer, fileName string, hasHeader bool) (*Table, error) {
file, err := os.Open(fileName)
if err != nil {
return &Table{}, err
}
defer file.Close()
csvReader := csv.NewReader(file)
t, err := NewCSVReader(writer, csvReader, hasHeader)
return t, err
} | go | func NewCSV(writer io.Writer, fileName string, hasHeader bool) (*Table, error) {
file, err := os.Open(fileName)
if err != nil {
return &Table{}, err
}
defer file.Close()
csvReader := csv.NewReader(file)
t, err := NewCSVReader(writer, csvReader, hasHeader)
return t, err
} | [
"func",
"NewCSV",
"(",
"writer",
"io",
".",
"Writer",
",",
"fileName",
"string",
",",
"hasHeader",
"bool",
")",
"(",
"*",
"Table",
",",
"error",
")",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"fileName",
")",
"\n",
"if",
"err",
"!=",
... | // Start A new table by importing from a CSV file
// Takes io.Writer and csv File name | [
"Start",
"A",
"new",
"table",
"by",
"importing",
"from",
"a",
"CSV",
"file",
"Takes",
"io",
".",
"Writer",
"and",
"csv",
"File",
"name"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/csv.go#L18-L27 | train |
olekukonko/tablewriter | table_with_color.go | format | func format(s string, codes interface{}) string {
var seq string
switch v := codes.(type) {
case string:
seq = v
case []int:
seq = makeSequence(v)
default:
return s
}
if len(seq) == 0 {
return s
}
return startFormat(seq) + s + stopFormat()
} | go | func format(s string, codes interface{}) string {
var seq string
switch v := codes.(type) {
case string:
seq = v
case []int:
seq = makeSequence(v)
default:
return s
}
if len(seq) == 0 {
return s
}
return startFormat(seq) + s + stopFormat()
} | [
"func",
"format",
"(",
"s",
"string",
",",
"codes",
"interface",
"{",
"}",
")",
"string",
"{",
"var",
"seq",
"string",
"\n\n",
"switch",
"v",
":=",
"codes",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"seq",
"=",
"v",
"\n",
"case",
"[",
"]... | // Adding ANSI escape sequences before and after string | [
"Adding",
"ANSI",
"escape",
"sequences",
"before",
"and",
"after",
"string"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/table_with_color.go#L83-L100 | train |
olekukonko/tablewriter | util.go | ConditionString | func ConditionString(cond bool, valid, inValid string) string {
if cond {
return valid
}
return inValid
} | go | func ConditionString(cond bool, valid, inValid string) string {
if cond {
return valid
}
return inValid
} | [
"func",
"ConditionString",
"(",
"cond",
"bool",
",",
"valid",
",",
"inValid",
"string",
")",
"string",
"{",
"if",
"cond",
"{",
"return",
"valid",
"\n",
"}",
"\n",
"return",
"inValid",
"\n",
"}"
] | // Simple Condition for string
// Returns value based on condition | [
"Simple",
"Condition",
"for",
"string",
"Returns",
"value",
"based",
"on",
"condition"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/util.go#L26-L31 | train |
olekukonko/tablewriter | util.go | Title | func Title(name string) string {
origLen := len(name)
rs := []rune(name)
for i, r := range rs {
switch r {
case '_':
rs[i] = ' '
case '.':
// ignore floating number 0.0
if (i != 0 && !isNumOrSpace(rs[i-1])) || (i != len(rs)-1 && !isNumOrSpace(rs[i+1])) {
rs[i] = ' '
}
}
}
name = string(rs)
... | go | func Title(name string) string {
origLen := len(name)
rs := []rune(name)
for i, r := range rs {
switch r {
case '_':
rs[i] = ' '
case '.':
// ignore floating number 0.0
if (i != 0 && !isNumOrSpace(rs[i-1])) || (i != len(rs)-1 && !isNumOrSpace(rs[i+1])) {
rs[i] = ' '
}
}
}
name = string(rs)
... | [
"func",
"Title",
"(",
"name",
"string",
")",
"string",
"{",
"origLen",
":=",
"len",
"(",
"name",
")",
"\n",
"rs",
":=",
"[",
"]",
"rune",
"(",
"name",
")",
"\n",
"for",
"i",
",",
"r",
":=",
"range",
"rs",
"{",
"switch",
"r",
"{",
"case",
"'_'",... | // Format Table Header
// Replace _ , . and spaces | [
"Format",
"Table",
"Header",
"Replace",
"_",
".",
"and",
"spaces"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/util.go#L39-L61 | train |
olekukonko/tablewriter | util.go | Pad | func Pad(s, pad string, width int) string {
gap := width - DisplayWidth(s)
if gap > 0 {
gapLeft := int(math.Ceil(float64(gap / 2)))
gapRight := gap - gapLeft
return strings.Repeat(string(pad), gapLeft) + s + strings.Repeat(string(pad), gapRight)
}
return s
} | go | func Pad(s, pad string, width int) string {
gap := width - DisplayWidth(s)
if gap > 0 {
gapLeft := int(math.Ceil(float64(gap / 2)))
gapRight := gap - gapLeft
return strings.Repeat(string(pad), gapLeft) + s + strings.Repeat(string(pad), gapRight)
}
return s
} | [
"func",
"Pad",
"(",
"s",
",",
"pad",
"string",
",",
"width",
"int",
")",
"string",
"{",
"gap",
":=",
"width",
"-",
"DisplayWidth",
"(",
"s",
")",
"\n",
"if",
"gap",
">",
"0",
"{",
"gapLeft",
":=",
"int",
"(",
"math",
".",
"Ceil",
"(",
"float64",
... | // Pad String
// Attempts to place string in the center | [
"Pad",
"String",
"Attempts",
"to",
"place",
"string",
"in",
"the",
"center"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/util.go#L65-L73 | train |
olekukonko/tablewriter | util.go | PadRight | func PadRight(s, pad string, width int) string {
gap := width - DisplayWidth(s)
if gap > 0 {
return s + strings.Repeat(string(pad), gap)
}
return s
} | go | func PadRight(s, pad string, width int) string {
gap := width - DisplayWidth(s)
if gap > 0 {
return s + strings.Repeat(string(pad), gap)
}
return s
} | [
"func",
"PadRight",
"(",
"s",
",",
"pad",
"string",
",",
"width",
"int",
")",
"string",
"{",
"gap",
":=",
"width",
"-",
"DisplayWidth",
"(",
"s",
")",
"\n",
"if",
"gap",
">",
"0",
"{",
"return",
"s",
"+",
"strings",
".",
"Repeat",
"(",
"string",
... | // Pad String Right position
// This would place string at the left side of the screen | [
"Pad",
"String",
"Right",
"position",
"This",
"would",
"place",
"string",
"at",
"the",
"left",
"side",
"of",
"the",
"screen"
] | 7e037d187b0c13d81ccf0dd1c6b990c2759e6597 | https://github.com/olekukonko/tablewriter/blob/7e037d187b0c13d81ccf0dd1c6b990c2759e6597/util.go#L77-L83 | train |
openzipkin/zipkin-go | propagation/b3/grpc.go | ExtractGRPC | func ExtractGRPC(md *metadata.MD) propagation.Extractor {
return func() (*model.SpanContext, error) {
var (
traceIDHeader = GetGRPCHeader(md, TraceID)
spanIDHeader = GetGRPCHeader(md, SpanID)
parentSpanIDHeader = GetGRPCHeader(md, ParentSpanID)
sampledHeader = GetGRPCHeader(md, Sampled)
... | go | func ExtractGRPC(md *metadata.MD) propagation.Extractor {
return func() (*model.SpanContext, error) {
var (
traceIDHeader = GetGRPCHeader(md, TraceID)
spanIDHeader = GetGRPCHeader(md, SpanID)
parentSpanIDHeader = GetGRPCHeader(md, ParentSpanID)
sampledHeader = GetGRPCHeader(md, Sampled)
... | [
"func",
"ExtractGRPC",
"(",
"md",
"*",
"metadata",
".",
"MD",
")",
"propagation",
".",
"Extractor",
"{",
"return",
"func",
"(",
")",
"(",
"*",
"model",
".",
"SpanContext",
",",
"error",
")",
"{",
"var",
"(",
"traceIDHeader",
"=",
"GetGRPCHeader",
"(",
... | // ExtractGRPC will extract a span.Context from the gRPC Request metadata if
// found in B3 header format. | [
"ExtractGRPC",
"will",
"extract",
"a",
"span",
".",
"Context",
"from",
"the",
"gRPC",
"Request",
"metadata",
"if",
"found",
"in",
"B3",
"header",
"format",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/propagation/b3/grpc.go#L26-L41 | train |
openzipkin/zipkin-go | propagation/b3/grpc.go | InjectGRPC | func InjectGRPC(md *metadata.MD) propagation.Injector {
return func(sc model.SpanContext) error {
if (model.SpanContext{}) == sc {
return ErrEmptyContext
}
if sc.Debug {
setGRPCHeader(md, Flags, "1")
} else if sc.Sampled != nil {
// Debug is encoded as X-B3-Flags: 1. Since Debug implies Sampled,
/... | go | func InjectGRPC(md *metadata.MD) propagation.Injector {
return func(sc model.SpanContext) error {
if (model.SpanContext{}) == sc {
return ErrEmptyContext
}
if sc.Debug {
setGRPCHeader(md, Flags, "1")
} else if sc.Sampled != nil {
// Debug is encoded as X-B3-Flags: 1. Since Debug implies Sampled,
/... | [
"func",
"InjectGRPC",
"(",
"md",
"*",
"metadata",
".",
"MD",
")",
"propagation",
".",
"Injector",
"{",
"return",
"func",
"(",
"sc",
"model",
".",
"SpanContext",
")",
"error",
"{",
"if",
"(",
"model",
".",
"SpanContext",
"{",
"}",
")",
"==",
"sc",
"{"... | // InjectGRPC will inject a span.Context into gRPC metadata. | [
"InjectGRPC",
"will",
"inject",
"a",
"span",
".",
"Context",
"into",
"gRPC",
"metadata",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/propagation/b3/grpc.go#L44-L73 | train |
openzipkin/zipkin-go | propagation/b3/grpc.go | GetGRPCHeader | func GetGRPCHeader(md *metadata.MD, key string) string {
v := (*md)[key]
if len(v) < 1 {
return ""
}
return v[len(v)-1]
} | go | func GetGRPCHeader(md *metadata.MD, key string) string {
v := (*md)[key]
if len(v) < 1 {
return ""
}
return v[len(v)-1]
} | [
"func",
"GetGRPCHeader",
"(",
"md",
"*",
"metadata",
".",
"MD",
",",
"key",
"string",
")",
"string",
"{",
"v",
":=",
"(",
"*",
"md",
")",
"[",
"key",
"]",
"\n",
"if",
"len",
"(",
"v",
")",
"<",
"1",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",... | // GetGRPCHeader retrieves the last value found for a particular key. If key is
// not found it returns an empty string. | [
"GetGRPCHeader",
"retrieves",
"the",
"last",
"value",
"found",
"for",
"a",
"particular",
"key",
".",
"If",
"key",
"is",
"not",
"found",
"it",
"returns",
"an",
"empty",
"string",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/propagation/b3/grpc.go#L77-L83 | train |
openzipkin/zipkin-go | reporter/recorder/recorder.go | Send | func (r *ReporterRecorder) Send(span model.SpanModel) {
r.mtx.Lock()
r.spans = append(r.spans, span)
r.mtx.Unlock()
} | go | func (r *ReporterRecorder) Send(span model.SpanModel) {
r.mtx.Lock()
r.spans = append(r.spans, span)
r.mtx.Unlock()
} | [
"func",
"(",
"r",
"*",
"ReporterRecorder",
")",
"Send",
"(",
"span",
"model",
".",
"SpanModel",
")",
"{",
"r",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"r",
".",
"spans",
"=",
"append",
"(",
"r",
".",
"spans",
",",
"span",
")",
"\n",
"r",
".",
... | // Send adds the provided span to the span list held by the recorder. | [
"Send",
"adds",
"the",
"provided",
"span",
"to",
"the",
"span",
"list",
"held",
"by",
"the",
"recorder",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/reporter/recorder/recorder.go#L38-L42 | train |
openzipkin/zipkin-go | reporter/recorder/recorder.go | Flush | func (r *ReporterRecorder) Flush() []model.SpanModel {
r.mtx.Lock()
spans := r.spans
r.spans = nil
r.mtx.Unlock()
return spans
} | go | func (r *ReporterRecorder) Flush() []model.SpanModel {
r.mtx.Lock()
spans := r.spans
r.spans = nil
r.mtx.Unlock()
return spans
} | [
"func",
"(",
"r",
"*",
"ReporterRecorder",
")",
"Flush",
"(",
")",
"[",
"]",
"model",
".",
"SpanModel",
"{",
"r",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"spans",
":=",
"r",
".",
"spans",
"\n",
"r",
".",
"spans",
"=",
"nil",
"\n",
"r",
".",
... | // Flush returns all recorded spans and clears its internal span storage | [
"Flush",
"returns",
"all",
"recorded",
"spans",
"and",
"clears",
"its",
"internal",
"span",
"storage"
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/reporter/recorder/recorder.go#L45-L51 | train |
openzipkin/zipkin-go | tracer_options.go | WithLocalEndpoint | func WithLocalEndpoint(e *model.Endpoint) TracerOption {
return func(o *Tracer) error {
if e == nil {
o.localEndpoint = nil
return nil
}
ep := *e
o.localEndpoint = &ep
return nil
}
} | go | func WithLocalEndpoint(e *model.Endpoint) TracerOption {
return func(o *Tracer) error {
if e == nil {
o.localEndpoint = nil
return nil
}
ep := *e
o.localEndpoint = &ep
return nil
}
} | [
"func",
"WithLocalEndpoint",
"(",
"e",
"*",
"model",
".",
"Endpoint",
")",
"TracerOption",
"{",
"return",
"func",
"(",
"o",
"*",
"Tracer",
")",
"error",
"{",
"if",
"e",
"==",
"nil",
"{",
"o",
".",
"localEndpoint",
"=",
"nil",
"\n",
"return",
"nil",
"... | // WithLocalEndpoint sets the local endpoint of the tracer. | [
"WithLocalEndpoint",
"sets",
"the",
"local",
"endpoint",
"of",
"the",
"tracer",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer_options.go#L45-L55 | train |
openzipkin/zipkin-go | tracer_options.go | WithExtractFailurePolicy | func WithExtractFailurePolicy(p ExtractFailurePolicy) TracerOption {
return func(o *Tracer) error {
if p < 0 || p > ExtractFailurePolicyTagAndRestart {
return ErrInvalidExtractFailurePolicy
}
o.extractFailurePolicy = p
return nil
}
} | go | func WithExtractFailurePolicy(p ExtractFailurePolicy) TracerOption {
return func(o *Tracer) error {
if p < 0 || p > ExtractFailurePolicyTagAndRestart {
return ErrInvalidExtractFailurePolicy
}
o.extractFailurePolicy = p
return nil
}
} | [
"func",
"WithExtractFailurePolicy",
"(",
"p",
"ExtractFailurePolicy",
")",
"TracerOption",
"{",
"return",
"func",
"(",
"o",
"*",
"Tracer",
")",
"error",
"{",
"if",
"p",
"<",
"0",
"||",
"p",
">",
"ExtractFailurePolicyTagAndRestart",
"{",
"return",
"ErrInvalidExtr... | // WithExtractFailurePolicy allows one to set the ExtractFailurePolicy. | [
"WithExtractFailurePolicy",
"allows",
"one",
"to",
"set",
"the",
"ExtractFailurePolicy",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer_options.go#L58-L66 | train |
openzipkin/zipkin-go | tracer_options.go | WithNoopSpan | func WithNoopSpan(unsampledNoop bool) TracerOption {
return func(o *Tracer) error {
o.unsampledNoop = unsampledNoop
return nil
}
} | go | func WithNoopSpan(unsampledNoop bool) TracerOption {
return func(o *Tracer) error {
o.unsampledNoop = unsampledNoop
return nil
}
} | [
"func",
"WithNoopSpan",
"(",
"unsampledNoop",
"bool",
")",
"TracerOption",
"{",
"return",
"func",
"(",
"o",
"*",
"Tracer",
")",
"error",
"{",
"o",
".",
"unsampledNoop",
"=",
"unsampledNoop",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithNoopSpan if set to true will switch to a NoopSpan implementation
// if the trace is not sampled. | [
"WithNoopSpan",
"if",
"set",
"to",
"true",
"will",
"switch",
"to",
"a",
"NoopSpan",
"implementation",
"if",
"the",
"trace",
"is",
"not",
"sampled",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer_options.go#L70-L75 | train |
openzipkin/zipkin-go | tracer_options.go | WithSampler | func WithSampler(sampler Sampler) TracerOption {
return func(o *Tracer) error {
o.sampler = sampler
return nil
}
} | go | func WithSampler(sampler Sampler) TracerOption {
return func(o *Tracer) error {
o.sampler = sampler
return nil
}
} | [
"func",
"WithSampler",
"(",
"sampler",
"Sampler",
")",
"TracerOption",
"{",
"return",
"func",
"(",
"o",
"*",
"Tracer",
")",
"error",
"{",
"o",
".",
"sampler",
"=",
"sampler",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithSampler allows one to set a Sampler function | [
"WithSampler",
"allows",
"one",
"to",
"set",
"a",
"Sampler",
"function"
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer_options.go#L89-L94 | train |
openzipkin/zipkin-go | tracer_options.go | WithTraceID128Bit | func WithTraceID128Bit(val bool) TracerOption {
return func(o *Tracer) error {
if val {
o.generate = idgenerator.NewRandom128()
} else {
o.generate = idgenerator.NewRandom64()
}
return nil
}
} | go | func WithTraceID128Bit(val bool) TracerOption {
return func(o *Tracer) error {
if val {
o.generate = idgenerator.NewRandom128()
} else {
o.generate = idgenerator.NewRandom64()
}
return nil
}
} | [
"func",
"WithTraceID128Bit",
"(",
"val",
"bool",
")",
"TracerOption",
"{",
"return",
"func",
"(",
"o",
"*",
"Tracer",
")",
"error",
"{",
"if",
"val",
"{",
"o",
".",
"generate",
"=",
"idgenerator",
".",
"NewRandom128",
"(",
")",
"\n",
"}",
"else",
"{",
... | // WithTraceID128Bit if set to true will instruct the Tracer to start traces
// with 128 bit TraceID's. If set to false the Tracer will start traces with
// 64 bits. | [
"WithTraceID128Bit",
"if",
"set",
"to",
"true",
"will",
"instruct",
"the",
"Tracer",
"to",
"start",
"traces",
"with",
"128",
"bit",
"TraceID",
"s",
".",
"If",
"set",
"to",
"false",
"the",
"Tracer",
"will",
"start",
"traces",
"with",
"64",
"bits",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer_options.go#L99-L108 | train |
openzipkin/zipkin-go | tracer_options.go | WithIDGenerator | func WithIDGenerator(generator idgenerator.IDGenerator) TracerOption {
return func(o *Tracer) error {
o.generate = generator
return nil
}
} | go | func WithIDGenerator(generator idgenerator.IDGenerator) TracerOption {
return func(o *Tracer) error {
o.generate = generator
return nil
}
} | [
"func",
"WithIDGenerator",
"(",
"generator",
"idgenerator",
".",
"IDGenerator",
")",
"TracerOption",
"{",
"return",
"func",
"(",
"o",
"*",
"Tracer",
")",
"error",
"{",
"o",
".",
"generate",
"=",
"generator",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithIDGenerator allows one to set a custom ID Generator | [
"WithIDGenerator",
"allows",
"one",
"to",
"set",
"a",
"custom",
"ID",
"Generator"
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer_options.go#L111-L116 | train |
openzipkin/zipkin-go | tracer_options.go | WithTags | func WithTags(tags map[string]string) TracerOption {
return func(o *Tracer) error {
for k, v := range tags {
o.defaultTags[k] = v
}
return nil
}
} | go | func WithTags(tags map[string]string) TracerOption {
return func(o *Tracer) error {
for k, v := range tags {
o.defaultTags[k] = v
}
return nil
}
} | [
"func",
"WithTags",
"(",
"tags",
"map",
"[",
"string",
"]",
"string",
")",
"TracerOption",
"{",
"return",
"func",
"(",
"o",
"*",
"Tracer",
")",
"error",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"tags",
"{",
"o",
".",
"defaultTags",
"[",
"k",
"]",
... | // WithTags allows one to set default tags to be added to each created span | [
"WithTags",
"allows",
"one",
"to",
"set",
"default",
"tags",
"to",
"be",
"added",
"to",
"each",
"created",
"span"
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer_options.go#L119-L126 | train |
openzipkin/zipkin-go | tracer_options.go | WithNoopTracer | func WithNoopTracer(tracerNoop bool) TracerOption {
return func(o *Tracer) error {
if tracerNoop {
o.noop = 1
} else {
o.noop = 0
}
return nil
}
} | go | func WithNoopTracer(tracerNoop bool) TracerOption {
return func(o *Tracer) error {
if tracerNoop {
o.noop = 1
} else {
o.noop = 0
}
return nil
}
} | [
"func",
"WithNoopTracer",
"(",
"tracerNoop",
"bool",
")",
"TracerOption",
"{",
"return",
"func",
"(",
"o",
"*",
"Tracer",
")",
"error",
"{",
"if",
"tracerNoop",
"{",
"o",
".",
"noop",
"=",
"1",
"\n",
"}",
"else",
"{",
"o",
".",
"noop",
"=",
"0",
"\... | // WithNoopTracer allows one to start the Tracer as Noop implementation. | [
"WithNoopTracer",
"allows",
"one",
"to",
"start",
"the",
"Tracer",
"as",
"Noop",
"implementation",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer_options.go#L129-L138 | train |
openzipkin/zipkin-go | middleware/grpc/client.go | NewClientHandler | func NewClientHandler(tracer *zipkin.Tracer, options ...ClientOption) stats.Handler {
c := &clientHandler{
tracer: tracer,
}
for _, option := range options {
option(c)
}
return c
} | go | func NewClientHandler(tracer *zipkin.Tracer, options ...ClientOption) stats.Handler {
c := &clientHandler{
tracer: tracer,
}
for _, option := range options {
option(c)
}
return c
} | [
"func",
"NewClientHandler",
"(",
"tracer",
"*",
"zipkin",
".",
"Tracer",
",",
"options",
"...",
"ClientOption",
")",
"stats",
".",
"Handler",
"{",
"c",
":=",
"&",
"clientHandler",
"{",
"tracer",
":",
"tracer",
",",
"}",
"\n",
"for",
"_",
",",
"option",
... | // NewClientHandler returns a stats.Handler which can be used with grpc.WithStatsHandler to add
// tracing to a gRPC client. The gRPC method name is used as the span name and by default the only
// tags are the gRPC status code if the call fails. | [
"NewClientHandler",
"returns",
"a",
"stats",
".",
"Handler",
"which",
"can",
"be",
"used",
"with",
"grpc",
".",
"WithStatsHandler",
"to",
"add",
"tracing",
"to",
"a",
"gRPC",
"client",
".",
"The",
"gRPC",
"method",
"name",
"is",
"used",
"as",
"the",
"span"... | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/middleware/grpc/client.go#L47-L55 | train |
openzipkin/zipkin-go | reporter/log/log.go | NewReporter | func NewReporter(l *log.Logger) reporter.Reporter {
if l == nil {
// use standard type of log setup
l = log.New(os.Stderr, "", log.LstdFlags)
}
return &logReporter{
logger: l,
}
} | go | func NewReporter(l *log.Logger) reporter.Reporter {
if l == nil {
// use standard type of log setup
l = log.New(os.Stderr, "", log.LstdFlags)
}
return &logReporter{
logger: l,
}
} | [
"func",
"NewReporter",
"(",
"l",
"*",
"log",
".",
"Logger",
")",
"reporter",
".",
"Reporter",
"{",
"if",
"l",
"==",
"nil",
"{",
"// use standard type of log setup",
"l",
"=",
"log",
".",
"New",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
",",
"log",
"... | // NewReporter returns a new log reporter. | [
"NewReporter",
"returns",
"a",
"new",
"log",
"reporter",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/reporter/log/log.go#L37-L45 | train |
openzipkin/zipkin-go | reporter/log/log.go | Send | func (r *logReporter) Send(s model.SpanModel) {
if b, err := json.MarshalIndent(s, "", " "); err == nil {
r.logger.Printf("%s:\n%s\n\n", time.Now(), string(b))
}
} | go | func (r *logReporter) Send(s model.SpanModel) {
if b, err := json.MarshalIndent(s, "", " "); err == nil {
r.logger.Printf("%s:\n%s\n\n", time.Now(), string(b))
}
} | [
"func",
"(",
"r",
"*",
"logReporter",
")",
"Send",
"(",
"s",
"model",
".",
"SpanModel",
")",
"{",
"if",
"b",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"s",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"err",
"==",
"nil",
"{",
"r",
"... | // Send outputs a span to the Go logger. | [
"Send",
"outputs",
"a",
"span",
"to",
"the",
"Go",
"logger",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/reporter/log/log.go#L48-L52 | train |
openzipkin/zipkin-go | context.go | NewContext | func NewContext(ctx context.Context, s Span) context.Context {
return context.WithValue(ctx, spanKey, s)
} | go | func NewContext(ctx context.Context, s Span) context.Context {
return context.WithValue(ctx, spanKey, s)
} | [
"func",
"NewContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"s",
"Span",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"spanKey",
",",
"s",
")",
"\n",
"}"
] | // NewContext stores a Zipkin Span into Go's context propagation mechanism. | [
"NewContext",
"stores",
"a",
"Zipkin",
"Span",
"into",
"Go",
"s",
"context",
"propagation",
"mechanism",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/context.go#L46-L48 | train |
openzipkin/zipkin-go | reporter/http/http.go | Timeout | func Timeout(duration time.Duration) ReporterOption {
return func(r *httpReporter) { r.client.Timeout = duration }
} | go | func Timeout(duration time.Duration) ReporterOption {
return func(r *httpReporter) { r.client.Timeout = duration }
} | [
"func",
"Timeout",
"(",
"duration",
"time",
".",
"Duration",
")",
"ReporterOption",
"{",
"return",
"func",
"(",
"r",
"*",
"httpReporter",
")",
"{",
"r",
".",
"client",
".",
"Timeout",
"=",
"duration",
"}",
"\n",
"}"
] | // Timeout sets maximum timeout for http request. | [
"Timeout",
"sets",
"maximum",
"timeout",
"for",
"http",
"request",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/reporter/http/http.go#L173-L175 | train |
openzipkin/zipkin-go | reporter/http/http.go | BatchInterval | func BatchInterval(d time.Duration) ReporterOption {
return func(r *httpReporter) { r.batchInterval = d }
} | go | func BatchInterval(d time.Duration) ReporterOption {
return func(r *httpReporter) { r.batchInterval = d }
} | [
"func",
"BatchInterval",
"(",
"d",
"time",
".",
"Duration",
")",
"ReporterOption",
"{",
"return",
"func",
"(",
"r",
"*",
"httpReporter",
")",
"{",
"r",
".",
"batchInterval",
"=",
"d",
"}",
"\n",
"}"
] | // BatchInterval sets the maximum duration we will buffer traces before
// emitting them to the collector. The default batch interval is 1 second. | [
"BatchInterval",
"sets",
"the",
"maximum",
"duration",
"we",
"will",
"buffer",
"traces",
"before",
"emitting",
"them",
"to",
"the",
"collector",
".",
"The",
"default",
"batch",
"interval",
"is",
"1",
"second",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/reporter/http/http.go#L191-L193 | train |
openzipkin/zipkin-go | reporter/http/http.go | Client | func Client(client *http.Client) ReporterOption {
return func(r *httpReporter) { r.client = client }
} | go | func Client(client *http.Client) ReporterOption {
return func(r *httpReporter) { r.client = client }
} | [
"func",
"Client",
"(",
"client",
"*",
"http",
".",
"Client",
")",
"ReporterOption",
"{",
"return",
"func",
"(",
"r",
"*",
"httpReporter",
")",
"{",
"r",
".",
"client",
"=",
"client",
"}",
"\n",
"}"
] | // Client sets a custom http client to use. | [
"Client",
"sets",
"a",
"custom",
"http",
"client",
"to",
"use",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/reporter/http/http.go#L196-L198 | train |
openzipkin/zipkin-go | middleware/http/server.go | NewServerMiddleware | func NewServerMiddleware(t *zipkin.Tracer, options ...ServerOption) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
h := &handler{
tracer: t,
next: next,
}
for _, option := range options {
option(h)
}
return h
}
} | go | func NewServerMiddleware(t *zipkin.Tracer, options ...ServerOption) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
h := &handler{
tracer: t,
next: next,
}
for _, option := range options {
option(h)
}
return h
}
} | [
"func",
"NewServerMiddleware",
"(",
"t",
"*",
"zipkin",
".",
"Tracer",
",",
"options",
"...",
"ServerOption",
")",
"func",
"(",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"func",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
... | // NewServerMiddleware returns a http.Handler middleware with Zipkin tracing. | [
"NewServerMiddleware",
"returns",
"a",
"http",
".",
"Handler",
"middleware",
"with",
"Zipkin",
"tracing",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/middleware/http/server.go#L74-L85 | train |
openzipkin/zipkin-go | proto/v2/decode_proto.go | ParseSpans | func ParseSpans(protoBlob []byte, debugWasSet bool) (zss []*zipkinmodel.SpanModel, err error) {
var listOfSpans ListOfSpans
if err := proto.Unmarshal(protoBlob, &listOfSpans); err != nil {
return nil, err
}
for _, zps := range listOfSpans.Spans {
zms, err := protoSpanToModelSpan(zps, debugWasSet)
if err != ni... | go | func ParseSpans(protoBlob []byte, debugWasSet bool) (zss []*zipkinmodel.SpanModel, err error) {
var listOfSpans ListOfSpans
if err := proto.Unmarshal(protoBlob, &listOfSpans); err != nil {
return nil, err
}
for _, zps := range listOfSpans.Spans {
zms, err := protoSpanToModelSpan(zps, debugWasSet)
if err != ni... | [
"func",
"ParseSpans",
"(",
"protoBlob",
"[",
"]",
"byte",
",",
"debugWasSet",
"bool",
")",
"(",
"zss",
"[",
"]",
"*",
"zipkinmodel",
".",
"SpanModel",
",",
"err",
"error",
")",
"{",
"var",
"listOfSpans",
"ListOfSpans",
"\n",
"if",
"err",
":=",
"proto",
... | // ParseSpans parses zipkinmodel.SpanModel values from data serialized by Protobuf3.
// debugWasSet is a boolean that toggles the Debug field of each Span. Its value
// is usually retrieved from the transport headers when the "X-B3-Flags" header has a value of 1. | [
"ParseSpans",
"parses",
"zipkinmodel",
".",
"SpanModel",
"values",
"from",
"data",
"serialized",
"by",
"Protobuf3",
".",
"debugWasSet",
"is",
"a",
"boolean",
"that",
"toggles",
"the",
"Debug",
"field",
"of",
"each",
"Span",
".",
"Its",
"value",
"is",
"usually"... | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/proto/v2/decode_proto.go#L35-L48 | train |
openzipkin/zipkin-go | proto/v2/encode_proto.go | Serialize | func (SpanSerializer) Serialize(sms []*zipkinmodel.SpanModel) (protoBlob []byte, err error) {
var listOfSpans ListOfSpans
for _, sm := range sms {
sp, err := modelSpanToProtoSpan(sm)
if err != nil {
return nil, err
}
listOfSpans.Spans = append(listOfSpans.Spans, sp)
}
return proto.Marshal(&listOfSpans)... | go | func (SpanSerializer) Serialize(sms []*zipkinmodel.SpanModel) (protoBlob []byte, err error) {
var listOfSpans ListOfSpans
for _, sm := range sms {
sp, err := modelSpanToProtoSpan(sm)
if err != nil {
return nil, err
}
listOfSpans.Spans = append(listOfSpans.Spans, sp)
}
return proto.Marshal(&listOfSpans)... | [
"func",
"(",
"SpanSerializer",
")",
"Serialize",
"(",
"sms",
"[",
"]",
"*",
"zipkinmodel",
".",
"SpanModel",
")",
"(",
"protoBlob",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"var",
"listOfSpans",
"ListOfSpans",
"\n\n",
"for",
"_",
",",
"sm",
":=... | // Serialize takes an array of zipkin SpanModel objects and serializes it to a protobuf blob. | [
"Serialize",
"takes",
"an",
"array",
"of",
"zipkin",
"SpanModel",
"objects",
"and",
"serializes",
"it",
"to",
"a",
"protobuf",
"blob",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/proto/v2/encode_proto.go#L32-L44 | train |
openzipkin/zipkin-go | model/span.go | MarshalJSON | func (s SpanModel) MarshalJSON() ([]byte, error) {
type Alias SpanModel
var timestamp int64
if !s.Timestamp.IsZero() {
if s.Timestamp.Unix() < 1 {
// Zipkin does not allow Timestamps before Unix epoch
return nil, ErrValidTimestampRequired
}
timestamp = s.Timestamp.Round(time.Microsecond).UnixNano() / 1e... | go | func (s SpanModel) MarshalJSON() ([]byte, error) {
type Alias SpanModel
var timestamp int64
if !s.Timestamp.IsZero() {
if s.Timestamp.Unix() < 1 {
// Zipkin does not allow Timestamps before Unix epoch
return nil, ErrValidTimestampRequired
}
timestamp = s.Timestamp.Round(time.Microsecond).UnixNano() / 1e... | [
"func",
"(",
"s",
"SpanModel",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"type",
"Alias",
"SpanModel",
"\n\n",
"var",
"timestamp",
"int64",
"\n",
"if",
"!",
"s",
".",
"Timestamp",
".",
"IsZero",
"(",
")",
"{",
"if... | // MarshalJSON exports our Model into the correct format for the Zipkin V2 API. | [
"MarshalJSON",
"exports",
"our",
"Model",
"into",
"the",
"correct",
"format",
"for",
"the",
"Zipkin",
"V2",
"API",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/model/span.go#L60-L107 | train |
openzipkin/zipkin-go | model/span.go | UnmarshalJSON | func (s *SpanModel) UnmarshalJSON(b []byte) error {
type Alias SpanModel
span := &struct {
T uint64 `json:"timestamp,omitempty"`
D uint64 `json:"duration,omitempty"`
*Alias
}{
Alias: (*Alias)(s),
}
if err := json.Unmarshal(b, &span); err != nil {
return err
}
if s.ID < 1 {
return ErrValidIDRequired
... | go | func (s *SpanModel) UnmarshalJSON(b []byte) error {
type Alias SpanModel
span := &struct {
T uint64 `json:"timestamp,omitempty"`
D uint64 `json:"duration,omitempty"`
*Alias
}{
Alias: (*Alias)(s),
}
if err := json.Unmarshal(b, &span); err != nil {
return err
}
if s.ID < 1 {
return ErrValidIDRequired
... | [
"func",
"(",
"s",
"*",
"SpanModel",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"type",
"Alias",
"SpanModel",
"\n",
"span",
":=",
"&",
"struct",
"{",
"T",
"uint64",
"`json:\"timestamp,omitempty\"`",
"\n",
"D",
"uint64",
"`json:\"du... | // UnmarshalJSON imports our Model from a Zipkin V2 API compatible span
// representation. | [
"UnmarshalJSON",
"imports",
"our",
"Model",
"from",
"a",
"Zipkin",
"V2",
"API",
"compatible",
"span",
"representation",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/model/span.go#L111-L138 | train |
openzipkin/zipkin-go | tags.go | Set | func (t Tag) Set(s Span, value string) {
s.Tag(string(t), value)
} | go | func (t Tag) Set(s Span, value string) {
s.Tag(string(t), value)
} | [
"func",
"(",
"t",
"Tag",
")",
"Set",
"(",
"s",
"Span",
",",
"value",
"string",
")",
"{",
"s",
".",
"Tag",
"(",
"string",
"(",
"t",
")",
",",
"value",
")",
"\n",
"}"
] | // Set a standard Tag with a payload on provided Span. | [
"Set",
"a",
"standard",
"Tag",
"with",
"a",
"payload",
"on",
"provided",
"Span",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tags.go#L35-L37 | train |
openzipkin/zipkin-go | sample.go | NewModuloSampler | func NewModuloSampler(mod uint64) Sampler {
if mod < 2 {
return AlwaysSample
}
return func(id uint64) bool {
return (id % mod) == 0
}
} | go | func NewModuloSampler(mod uint64) Sampler {
if mod < 2 {
return AlwaysSample
}
return func(id uint64) bool {
return (id % mod) == 0
}
} | [
"func",
"NewModuloSampler",
"(",
"mod",
"uint64",
")",
"Sampler",
"{",
"if",
"mod",
"<",
"2",
"{",
"return",
"AlwaysSample",
"\n",
"}",
"\n",
"return",
"func",
"(",
"id",
"uint64",
")",
"bool",
"{",
"return",
"(",
"id",
"%",
"mod",
")",
"==",
"0",
... | // NewModuloSampler provides a generic type Sampler. | [
"NewModuloSampler",
"provides",
"a",
"generic",
"type",
"Sampler",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/sample.go#L40-L47 | train |
openzipkin/zipkin-go | tracer.go | NewTracer | func NewTracer(rep reporter.Reporter, opts ...TracerOption) (*Tracer, error) {
// set default tracer options
t := &Tracer{
defaultTags: make(map[string]string),
extractFailurePolicy: ExtractFailurePolicyRestart,
sampler: AlwaysSample,
generate: idgenerator.NewRandom64(),
re... | go | func NewTracer(rep reporter.Reporter, opts ...TracerOption) (*Tracer, error) {
// set default tracer options
t := &Tracer{
defaultTags: make(map[string]string),
extractFailurePolicy: ExtractFailurePolicyRestart,
sampler: AlwaysSample,
generate: idgenerator.NewRandom64(),
re... | [
"func",
"NewTracer",
"(",
"rep",
"reporter",
".",
"Reporter",
",",
"opts",
"...",
"TracerOption",
")",
"(",
"*",
"Tracer",
",",
"error",
")",
"{",
"// set default tracer options",
"t",
":=",
"&",
"Tracer",
"{",
"defaultTags",
":",
"make",
"(",
"map",
"[",
... | // NewTracer returns a new Zipkin Tracer. | [
"NewTracer",
"returns",
"a",
"new",
"Zipkin",
"Tracer",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer.go#L43-L71 | train |
openzipkin/zipkin-go | tracer.go | StartSpanFromContext | func (t *Tracer) StartSpanFromContext(ctx context.Context, name string, options ...SpanOption) (Span, context.Context) {
if parentSpan := SpanFromContext(ctx); parentSpan != nil {
options = append(options, Parent(parentSpan.Context()))
}
span := t.StartSpan(name, options...)
return span, NewContext(ctx, span)
} | go | func (t *Tracer) StartSpanFromContext(ctx context.Context, name string, options ...SpanOption) (Span, context.Context) {
if parentSpan := SpanFromContext(ctx); parentSpan != nil {
options = append(options, Parent(parentSpan.Context()))
}
span := t.StartSpan(name, options...)
return span, NewContext(ctx, span)
} | [
"func",
"(",
"t",
"*",
"Tracer",
")",
"StartSpanFromContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"options",
"...",
"SpanOption",
")",
"(",
"Span",
",",
"context",
".",
"Context",
")",
"{",
"if",
"parentSpan",
":=",
"SpanFr... | // StartSpanFromContext creates and starts a span using the span found in
// context as parent. If no parent span is found a root span is created. | [
"StartSpanFromContext",
"creates",
"and",
"starts",
"a",
"span",
"using",
"the",
"span",
"found",
"in",
"context",
"as",
"parent",
".",
"If",
"no",
"parent",
"span",
"is",
"found",
"a",
"root",
"span",
"is",
"created",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer.go#L75-L81 | train |
openzipkin/zipkin-go | tracer.go | StartSpan | func (t *Tracer) StartSpan(name string, options ...SpanOption) Span {
if atomic.LoadInt32(&t.noop) == 1 {
return &noopSpan{}
}
s := &spanImpl{
SpanModel: model.SpanModel{
Kind: model.Undetermined,
Name: name,
LocalEndpoint: t.localEndpoint,
Annotations: make([]model.Annotation, 0)... | go | func (t *Tracer) StartSpan(name string, options ...SpanOption) Span {
if atomic.LoadInt32(&t.noop) == 1 {
return &noopSpan{}
}
s := &spanImpl{
SpanModel: model.SpanModel{
Kind: model.Undetermined,
Name: name,
LocalEndpoint: t.localEndpoint,
Annotations: make([]model.Annotation, 0)... | [
"func",
"(",
"t",
"*",
"Tracer",
")",
"StartSpan",
"(",
"name",
"string",
",",
"options",
"...",
"SpanOption",
")",
"Span",
"{",
"if",
"atomic",
".",
"LoadInt32",
"(",
"&",
"t",
".",
"noop",
")",
"==",
"1",
"{",
"return",
"&",
"noopSpan",
"{",
"}",... | // StartSpan creates and starts a span. | [
"StartSpan",
"creates",
"and",
"starts",
"a",
"span",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer.go#L84-L153 | train |
openzipkin/zipkin-go | tracer.go | Extract | func (t *Tracer) Extract(extractor propagation.Extractor) (sc model.SpanContext) {
if atomic.LoadInt32(&t.noop) == 1 {
return
}
psc, err := extractor()
if psc != nil {
sc = *psc
}
sc.Err = err
return
} | go | func (t *Tracer) Extract(extractor propagation.Extractor) (sc model.SpanContext) {
if atomic.LoadInt32(&t.noop) == 1 {
return
}
psc, err := extractor()
if psc != nil {
sc = *psc
}
sc.Err = err
return
} | [
"func",
"(",
"t",
"*",
"Tracer",
")",
"Extract",
"(",
"extractor",
"propagation",
".",
"Extractor",
")",
"(",
"sc",
"model",
".",
"SpanContext",
")",
"{",
"if",
"atomic",
".",
"LoadInt32",
"(",
"&",
"t",
".",
"noop",
")",
"==",
"1",
"{",
"return",
... | // Extract extracts a SpanContext using the provided Extractor function. | [
"Extract",
"extracts",
"a",
"SpanContext",
"using",
"the",
"provided",
"Extractor",
"function",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer.go#L156-L166 | train |
openzipkin/zipkin-go | tracer.go | SetNoop | func (t *Tracer) SetNoop(noop bool) {
if noop {
atomic.CompareAndSwapInt32(&t.noop, 0, 1)
} else {
atomic.CompareAndSwapInt32(&t.noop, 1, 0)
}
} | go | func (t *Tracer) SetNoop(noop bool) {
if noop {
atomic.CompareAndSwapInt32(&t.noop, 0, 1)
} else {
atomic.CompareAndSwapInt32(&t.noop, 1, 0)
}
} | [
"func",
"(",
"t",
"*",
"Tracer",
")",
"SetNoop",
"(",
"noop",
"bool",
")",
"{",
"if",
"noop",
"{",
"atomic",
".",
"CompareAndSwapInt32",
"(",
"&",
"t",
".",
"noop",
",",
"0",
",",
"1",
")",
"\n",
"}",
"else",
"{",
"atomic",
".",
"CompareAndSwapInt3... | // SetNoop allows for killswitch behavior. If set to true the tracer will return
// noopSpans and all data is dropped. This allows operators to stop tracing in
// risk scenarios. Set back to false to resume tracing. | [
"SetNoop",
"allows",
"for",
"killswitch",
"behavior",
".",
"If",
"set",
"to",
"true",
"the",
"tracer",
"will",
"return",
"noopSpans",
"and",
"all",
"data",
"is",
"dropped",
".",
"This",
"allows",
"operators",
"to",
"stop",
"tracing",
"in",
"risk",
"scenarios... | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer.go#L171-L177 | train |
openzipkin/zipkin-go | tracer.go | LocalEndpoint | func (t *Tracer) LocalEndpoint() *model.Endpoint {
if t.localEndpoint == nil {
return nil
}
ep := *t.localEndpoint
return &ep
} | go | func (t *Tracer) LocalEndpoint() *model.Endpoint {
if t.localEndpoint == nil {
return nil
}
ep := *t.localEndpoint
return &ep
} | [
"func",
"(",
"t",
"*",
"Tracer",
")",
"LocalEndpoint",
"(",
")",
"*",
"model",
".",
"Endpoint",
"{",
"if",
"t",
".",
"localEndpoint",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"ep",
":=",
"*",
"t",
".",
"localEndpoint",
"\n",
"return",
"&... | // LocalEndpoint returns a copy of the currently set local endpoint of the
// tracer instance. | [
"LocalEndpoint",
"returns",
"a",
"copy",
"of",
"the",
"currently",
"set",
"local",
"endpoint",
"of",
"the",
"tracer",
"instance",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/tracer.go#L181-L187 | train |
openzipkin/zipkin-go | endpoint.go | NewEndpoint | func NewEndpoint(serviceName string, hostPort string) (*model.Endpoint, error) {
e := &model.Endpoint{
ServiceName: serviceName,
}
if hostPort == "" || hostPort == ":0" {
if serviceName == "" {
// if all properties are empty we should not have an Endpoint object.
return nil, nil
}
return e, nil
}
i... | go | func NewEndpoint(serviceName string, hostPort string) (*model.Endpoint, error) {
e := &model.Endpoint{
ServiceName: serviceName,
}
if hostPort == "" || hostPort == ":0" {
if serviceName == "" {
// if all properties are empty we should not have an Endpoint object.
return nil, nil
}
return e, nil
}
i... | [
"func",
"NewEndpoint",
"(",
"serviceName",
"string",
",",
"hostPort",
"string",
")",
"(",
"*",
"model",
".",
"Endpoint",
",",
"error",
")",
"{",
"e",
":=",
"&",
"model",
".",
"Endpoint",
"{",
"ServiceName",
":",
"serviceName",
",",
"}",
"\n\n",
"if",
"... | // NewEndpoint creates a new endpoint given the provided serviceName and
// hostPort. | [
"NewEndpoint",
"creates",
"a",
"new",
"endpoint",
"given",
"the",
"provided",
"serviceName",
"and",
"hostPort",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/endpoint.go#L27-L80 | train |
openzipkin/zipkin-go | reporter/kafka/kafka.go | Producer | func Producer(p sarama.AsyncProducer) ReporterOption {
return func(c *kafkaReporter) {
c.producer = p
}
} | go | func Producer(p sarama.AsyncProducer) ReporterOption {
return func(c *kafkaReporter) {
c.producer = p
}
} | [
"func",
"Producer",
"(",
"p",
"sarama",
".",
"AsyncProducer",
")",
"ReporterOption",
"{",
"return",
"func",
"(",
"c",
"*",
"kafkaReporter",
")",
"{",
"c",
".",
"producer",
"=",
"p",
"\n",
"}",
"\n",
"}"
] | // Producer sets the producer used to produce to Kafka. | [
"Producer",
"sets",
"the",
"producer",
"used",
"to",
"produce",
"to",
"Kafka",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/reporter/kafka/kafka.go#L56-L60 | train |
openzipkin/zipkin-go | middleware/grpc/server.go | NewServerHandler | func NewServerHandler(tracer *zipkin.Tracer, options ...ServerOption) stats.Handler {
c := &serverHandler{
tracer: tracer,
}
for _, option := range options {
option(c)
}
return c
} | go | func NewServerHandler(tracer *zipkin.Tracer, options ...ServerOption) stats.Handler {
c := &serverHandler{
tracer: tracer,
}
for _, option := range options {
option(c)
}
return c
} | [
"func",
"NewServerHandler",
"(",
"tracer",
"*",
"zipkin",
".",
"Tracer",
",",
"options",
"...",
"ServerOption",
")",
"stats",
".",
"Handler",
"{",
"c",
":=",
"&",
"serverHandler",
"{",
"tracer",
":",
"tracer",
",",
"}",
"\n",
"for",
"_",
",",
"option",
... | // NewServerHandler returns a stats.Handler which can be used with grpc.WithStatsHandler to add
// tracing to a gRPC server. The gRPC method name is used as the span name and by default the only
// tags are the gRPC status code if the call fails. Use ServerTags to add additional tags that
// should be applied to all sp... | [
"NewServerHandler",
"returns",
"a",
"stats",
".",
"Handler",
"which",
"can",
"be",
"used",
"with",
"grpc",
".",
"WithStatsHandler",
"to",
"add",
"tracing",
"to",
"a",
"gRPC",
"server",
".",
"The",
"gRPC",
"method",
"name",
"is",
"used",
"as",
"the",
"span"... | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/middleware/grpc/server.go#L46-L54 | train |
openzipkin/zipkin-go | span_options.go | Kind | func Kind(kind model.Kind) SpanOption {
return func(t *Tracer, s *spanImpl) {
s.Kind = kind
}
} | go | func Kind(kind model.Kind) SpanOption {
return func(t *Tracer, s *spanImpl) {
s.Kind = kind
}
} | [
"func",
"Kind",
"(",
"kind",
"model",
".",
"Kind",
")",
"SpanOption",
"{",
"return",
"func",
"(",
"t",
"*",
"Tracer",
",",
"s",
"*",
"spanImpl",
")",
"{",
"s",
".",
"Kind",
"=",
"kind",
"\n",
"}",
"\n",
"}"
] | // Kind sets the kind of the span being created.. | [
"Kind",
"sets",
"the",
"kind",
"of",
"the",
"span",
"being",
"created",
".."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/span_options.go#L28-L32 | train |
openzipkin/zipkin-go | span_options.go | Parent | func Parent(sc model.SpanContext) SpanOption {
return func(t *Tracer, s *spanImpl) {
if sc.Err != nil {
// encountered an extraction error
switch t.extractFailurePolicy {
case ExtractFailurePolicyRestart:
case ExtractFailurePolicyError:
panic(s.SpanContext.Err)
case ExtractFailurePolicyTagAndResta... | go | func Parent(sc model.SpanContext) SpanOption {
return func(t *Tracer, s *spanImpl) {
if sc.Err != nil {
// encountered an extraction error
switch t.extractFailurePolicy {
case ExtractFailurePolicyRestart:
case ExtractFailurePolicyError:
panic(s.SpanContext.Err)
case ExtractFailurePolicyTagAndResta... | [
"func",
"Parent",
"(",
"sc",
"model",
".",
"SpanContext",
")",
"SpanOption",
"{",
"return",
"func",
"(",
"t",
"*",
"Tracer",
",",
"s",
"*",
"spanImpl",
")",
"{",
"if",
"sc",
".",
"Err",
"!=",
"nil",
"{",
"// encountered an extraction error",
"switch",
"t... | // Parent will use provided SpanContext as parent to the span being created. | [
"Parent",
"will",
"use",
"provided",
"SpanContext",
"as",
"parent",
"to",
"the",
"span",
"being",
"created",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/span_options.go#L35-L53 | train |
openzipkin/zipkin-go | span_options.go | StartTime | func StartTime(start time.Time) SpanOption {
return func(t *Tracer, s *spanImpl) {
s.Timestamp = start
}
} | go | func StartTime(start time.Time) SpanOption {
return func(t *Tracer, s *spanImpl) {
s.Timestamp = start
}
} | [
"func",
"StartTime",
"(",
"start",
"time",
".",
"Time",
")",
"SpanOption",
"{",
"return",
"func",
"(",
"t",
"*",
"Tracer",
",",
"s",
"*",
"spanImpl",
")",
"{",
"s",
".",
"Timestamp",
"=",
"start",
"\n",
"}",
"\n",
"}"
] | // StartTime uses a given start time for the span being created. | [
"StartTime",
"uses",
"a",
"given",
"start",
"time",
"for",
"the",
"span",
"being",
"created",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/span_options.go#L56-L60 | train |
openzipkin/zipkin-go | span_options.go | RemoteEndpoint | func RemoteEndpoint(e *model.Endpoint) SpanOption {
return func(t *Tracer, s *spanImpl) {
s.RemoteEndpoint = e
}
} | go | func RemoteEndpoint(e *model.Endpoint) SpanOption {
return func(t *Tracer, s *spanImpl) {
s.RemoteEndpoint = e
}
} | [
"func",
"RemoteEndpoint",
"(",
"e",
"*",
"model",
".",
"Endpoint",
")",
"SpanOption",
"{",
"return",
"func",
"(",
"t",
"*",
"Tracer",
",",
"s",
"*",
"spanImpl",
")",
"{",
"s",
".",
"RemoteEndpoint",
"=",
"e",
"\n",
"}",
"\n",
"}"
] | // RemoteEndpoint sets the remote endpoint of the span being created. | [
"RemoteEndpoint",
"sets",
"the",
"remote",
"endpoint",
"of",
"the",
"span",
"being",
"created",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/span_options.go#L63-L67 | train |
openzipkin/zipkin-go | span_options.go | Tags | func Tags(tags map[string]string) SpanOption {
return func(t *Tracer, s *spanImpl) {
for k, v := range tags {
s.Tags[k] = v
}
}
} | go | func Tags(tags map[string]string) SpanOption {
return func(t *Tracer, s *spanImpl) {
for k, v := range tags {
s.Tags[k] = v
}
}
} | [
"func",
"Tags",
"(",
"tags",
"map",
"[",
"string",
"]",
"string",
")",
"SpanOption",
"{",
"return",
"func",
"(",
"t",
"*",
"Tracer",
",",
"s",
"*",
"spanImpl",
")",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"tags",
"{",
"s",
".",
"Tags",
"[",
"... | // Tags sets initial tags for the span being created. If default tracer tags
// are present they will be overwritten on key collisions. | [
"Tags",
"sets",
"initial",
"tags",
"for",
"the",
"span",
"being",
"created",
".",
"If",
"default",
"tracer",
"tags",
"are",
"present",
"they",
"will",
"be",
"overwritten",
"on",
"key",
"collisions",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/span_options.go#L71-L77 | train |
openzipkin/zipkin-go | model/traceid.go | String | func (t TraceID) String() string {
if t.High == 0 {
return fmt.Sprintf("%016x", t.Low)
}
return fmt.Sprintf("%016x%016x", t.High, t.Low)
} | go | func (t TraceID) String() string {
if t.High == 0 {
return fmt.Sprintf("%016x", t.Low)
}
return fmt.Sprintf("%016x%016x", t.High, t.Low)
} | [
"func",
"(",
"t",
"TraceID",
")",
"String",
"(",
")",
"string",
"{",
"if",
"t",
".",
"High",
"==",
"0",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Low",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"... | // String outputs the 128-bit traceID as hex string. | [
"String",
"outputs",
"the",
"128",
"-",
"bit",
"traceID",
"as",
"hex",
"string",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/model/traceid.go#L35-L40 | train |
openzipkin/zipkin-go | model/traceid.go | TraceIDFromHex | func TraceIDFromHex(h string) (t TraceID, err error) {
if len(h) > 16 {
if t.High, err = strconv.ParseUint(h[0:len(h)-16], 16, 64); err != nil {
return
}
t.Low, err = strconv.ParseUint(h[len(h)-16:], 16, 64)
return
}
t.Low, err = strconv.ParseUint(h, 16, 64)
return
} | go | func TraceIDFromHex(h string) (t TraceID, err error) {
if len(h) > 16 {
if t.High, err = strconv.ParseUint(h[0:len(h)-16], 16, 64); err != nil {
return
}
t.Low, err = strconv.ParseUint(h[len(h)-16:], 16, 64)
return
}
t.Low, err = strconv.ParseUint(h, 16, 64)
return
} | [
"func",
"TraceIDFromHex",
"(",
"h",
"string",
")",
"(",
"t",
"TraceID",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"h",
")",
">",
"16",
"{",
"if",
"t",
".",
"High",
",",
"err",
"=",
"strconv",
".",
"ParseUint",
"(",
"h",
"[",
"0",
":",
... | // TraceIDFromHex returns the TraceID from a hex string. | [
"TraceIDFromHex",
"returns",
"the",
"TraceID",
"from",
"a",
"hex",
"string",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/model/traceid.go#L43-L53 | train |
openzipkin/zipkin-go | model/traceid.go | MarshalJSON | func (t TraceID) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("%q", t.String())), nil
} | go | func (t TraceID) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("%q", t.String())), nil
} | [
"func",
"(",
"t",
"TraceID",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"String",
"(",
")",
")",
")",
",",
"nil",
"\n",
... | // MarshalJSON custom JSON serializer to export the TraceID in the required
// zero padded hex representation. | [
"MarshalJSON",
"custom",
"JSON",
"serializer",
"to",
"export",
"the",
"TraceID",
"in",
"the",
"required",
"zero",
"padded",
"hex",
"representation",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/model/traceid.go#L57-L59 | train |
openzipkin/zipkin-go | model/traceid.go | UnmarshalJSON | func (t *TraceID) UnmarshalJSON(traceID []byte) error {
if len(traceID) < 3 {
return ErrValidTraceIDRequired
}
// A valid JSON string is encoded wrapped in double quotes. We need to trim
// these before converting the hex payload.
tID, err := TraceIDFromHex(string(traceID[1 : len(traceID)-1]))
if err != nil {
... | go | func (t *TraceID) UnmarshalJSON(traceID []byte) error {
if len(traceID) < 3 {
return ErrValidTraceIDRequired
}
// A valid JSON string is encoded wrapped in double quotes. We need to trim
// these before converting the hex payload.
tID, err := TraceIDFromHex(string(traceID[1 : len(traceID)-1]))
if err != nil {
... | [
"func",
"(",
"t",
"*",
"TraceID",
")",
"UnmarshalJSON",
"(",
"traceID",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"traceID",
")",
"<",
"3",
"{",
"return",
"ErrValidTraceIDRequired",
"\n",
"}",
"\n",
"// A valid JSON string is encoded wrapped in do... | // UnmarshalJSON custom JSON deserializer to retrieve the traceID from the hex
// encoded representation. | [
"UnmarshalJSON",
"custom",
"JSON",
"deserializer",
"to",
"retrieve",
"the",
"traceID",
"from",
"the",
"hex",
"encoded",
"representation",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/model/traceid.go#L63-L75 | train |
openzipkin/zipkin-go | middleware/http/transport.go | RoundTripper | func RoundTripper(rt http.RoundTripper) TransportOption {
return func(t *transport) {
if rt != nil {
t.rt = rt
}
}
} | go | func RoundTripper(rt http.RoundTripper) TransportOption {
return func(t *transport) {
if rt != nil {
t.rt = rt
}
}
} | [
"func",
"RoundTripper",
"(",
"rt",
"http",
".",
"RoundTripper",
")",
"TransportOption",
"{",
"return",
"func",
"(",
"t",
"*",
"transport",
")",
"{",
"if",
"rt",
"!=",
"nil",
"{",
"t",
".",
"rt",
"=",
"rt",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // RoundTripper adds the Transport RoundTripper to wrap. | [
"RoundTripper",
"adds",
"the",
"Transport",
"RoundTripper",
"to",
"wrap",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/middleware/http/transport.go#L54-L60 | train |
openzipkin/zipkin-go | middleware/http/transport.go | TransportTags | func TransportTags(tags map[string]string) TransportOption {
return func(t *transport) {
t.defaultTags = tags
}
} | go | func TransportTags(tags map[string]string) TransportOption {
return func(t *transport) {
t.defaultTags = tags
}
} | [
"func",
"TransportTags",
"(",
"tags",
"map",
"[",
"string",
"]",
"string",
")",
"TransportOption",
"{",
"return",
"func",
"(",
"t",
"*",
"transport",
")",
"{",
"t",
".",
"defaultTags",
"=",
"tags",
"\n",
"}",
"\n",
"}"
] | // TransportTags adds default Tags to inject into transport spans. | [
"TransportTags",
"adds",
"default",
"Tags",
"to",
"inject",
"into",
"transport",
"spans",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/middleware/http/transport.go#L63-L67 | train |
openzipkin/zipkin-go | middleware/http/transport.go | NewTransport | func NewTransport(tracer *zipkin.Tracer, options ...TransportOption) (http.RoundTripper, error) {
if tracer == nil {
return nil, ErrValidTracerRequired
}
t := &transport{
tracer: tracer,
rt: http.DefaultTransport,
httpTrace: false,
errHandler: defaultErrHandler,
}
for _, option := range op... | go | func NewTransport(tracer *zipkin.Tracer, options ...TransportOption) (http.RoundTripper, error) {
if tracer == nil {
return nil, ErrValidTracerRequired
}
t := &transport{
tracer: tracer,
rt: http.DefaultTransport,
httpTrace: false,
errHandler: defaultErrHandler,
}
for _, option := range op... | [
"func",
"NewTransport",
"(",
"tracer",
"*",
"zipkin",
".",
"Tracer",
",",
"options",
"...",
"TransportOption",
")",
"(",
"http",
".",
"RoundTripper",
",",
"error",
")",
"{",
"if",
"tracer",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrValidTracerRequired",
... | // NewTransport returns a new Zipkin instrumented http RoundTripper which can be
// used with a standard library http Client. | [
"NewTransport",
"returns",
"a",
"new",
"Zipkin",
"instrumented",
"http",
"RoundTripper",
"which",
"can",
"be",
"used",
"with",
"a",
"standard",
"library",
"http",
"Client",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/middleware/http/transport.go#L85-L102 | train |
openzipkin/zipkin-go | middleware/http/transport.go | RoundTrip | func (t *transport) RoundTrip(req *http.Request) (res *http.Response, err error) {
sp, _ := t.tracer.StartSpanFromContext(
req.Context(), req.URL.Scheme+"/"+req.Method, zipkin.Kind(model.Client),
)
for k, v := range t.defaultTags {
sp.Tag(k, v)
}
if t.httpTrace {
sptr := spanTrace{
Span: sp,
}
sptr.... | go | func (t *transport) RoundTrip(req *http.Request) (res *http.Response, err error) {
sp, _ := t.tracer.StartSpanFromContext(
req.Context(), req.URL.Scheme+"/"+req.Method, zipkin.Kind(model.Client),
)
for k, v := range t.defaultTags {
sp.Tag(k, v)
}
if t.httpTrace {
sptr := spanTrace{
Span: sp,
}
sptr.... | [
"func",
"(",
"t",
"*",
"transport",
")",
"RoundTrip",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"res",
"*",
"http",
".",
"Response",
",",
"err",
"error",
")",
"{",
"sp",
",",
"_",
":=",
"t",
".",
"tracer",
".",
"StartSpanFromContext",
"(",... | // RoundTrip satisfies the RoundTripper interface. | [
"RoundTrip",
"satisfies",
"the",
"RoundTripper",
"interface",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/middleware/http/transport.go#L105-L164 | train |
openzipkin/zipkin-go | propagation/b3/spancontext.go | ParseHeaders | func ParseHeaders(
hdrTraceID, hdrSpanID, hdrParentSpanID, hdrSampled, hdrFlags string,
) (*model.SpanContext, error) {
var (
err error
spanID uint64
requiredCount int
sc = &model.SpanContext{}
)
// correct values for an existing sampled header are "0" and "1".
// For legacy su... | go | func ParseHeaders(
hdrTraceID, hdrSpanID, hdrParentSpanID, hdrSampled, hdrFlags string,
) (*model.SpanContext, error) {
var (
err error
spanID uint64
requiredCount int
sc = &model.SpanContext{}
)
// correct values for an existing sampled header are "0" and "1".
// For legacy su... | [
"func",
"ParseHeaders",
"(",
"hdrTraceID",
",",
"hdrSpanID",
",",
"hdrParentSpanID",
",",
"hdrSampled",
",",
"hdrFlags",
"string",
",",
")",
"(",
"*",
"model",
".",
"SpanContext",
",",
"error",
")",
"{",
"var",
"(",
"err",
"error",
"\n",
"spanID",
"uint64"... | // ParseHeaders takes values found from B3 Headers and tries to reconstruct a
// SpanContext. | [
"ParseHeaders",
"takes",
"values",
"found",
"from",
"B3",
"Headers",
"and",
"tries",
"to",
"reconstruct",
"a",
"SpanContext",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/propagation/b3/spancontext.go#L26-L90 | train |
openzipkin/zipkin-go | reporter/serializer.go | Serialize | func (JSONSerializer) Serialize(spans []*model.SpanModel) ([]byte, error) {
return json.Marshal(spans)
} | go | func (JSONSerializer) Serialize(spans []*model.SpanModel) ([]byte, error) {
return json.Marshal(spans)
} | [
"func",
"(",
"JSONSerializer",
")",
"Serialize",
"(",
"spans",
"[",
"]",
"*",
"model",
".",
"SpanModel",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"spans",
")",
"\n",
"}"
] | // Serialize takes an array of Zipkin SpanModel objects and returns a JSON
// encoding of it. | [
"Serialize",
"takes",
"an",
"array",
"of",
"Zipkin",
"SpanModel",
"objects",
"and",
"returns",
"a",
"JSON",
"encoding",
"of",
"it",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/reporter/serializer.go#L35-L37 | train |
openzipkin/zipkin-go | middleware/http/client.go | WithClient | func WithClient(client *http.Client) ClientOption {
return func(c *Client) {
if client == nil {
client = &http.Client{}
}
c.Client = client
}
} | go | func WithClient(client *http.Client) ClientOption {
return func(c *Client) {
if client == nil {
client = &http.Client{}
}
c.Client = client
}
} | [
"func",
"WithClient",
"(",
"client",
"*",
"http",
".",
"Client",
")",
"ClientOption",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"{",
"if",
"client",
"==",
"nil",
"{",
"client",
"=",
"&",
"http",
".",
"Client",
"{",
"}",
"\n",
"}",
"\n",
... | // WithClient allows one to add a custom configured http.Client to use. | [
"WithClient",
"allows",
"one",
"to",
"add",
"a",
"custom",
"configured",
"http",
".",
"Client",
"to",
"use",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/middleware/http/client.go#L43-L50 | train |
openzipkin/zipkin-go | middleware/http/client.go | ClientTags | func ClientTags(tags map[string]string) ClientOption {
return func(c *Client) {
c.defaultTags = tags
}
} | go | func ClientTags(tags map[string]string) ClientOption {
return func(c *Client) {
c.defaultTags = tags
}
} | [
"func",
"ClientTags",
"(",
"tags",
"map",
"[",
"string",
"]",
"string",
")",
"ClientOption",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"{",
"c",
".",
"defaultTags",
"=",
"tags",
"\n",
"}",
"\n",
"}"
] | // ClientTags adds default Tags to inject into client application spans. | [
"ClientTags",
"adds",
"default",
"Tags",
"to",
"inject",
"into",
"client",
"application",
"spans",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/middleware/http/client.go#L60-L64 | train |
openzipkin/zipkin-go | middleware/http/client.go | NewClient | func NewClient(tracer *zipkin.Tracer, options ...ClientOption) (*Client, error) {
if tracer == nil {
return nil, ErrValidTracerRequired
}
c := &Client{tracer: tracer, Client: &http.Client{}}
for _, option := range options {
option(c)
}
c.transportOptions = append(
c.transportOptions,
// the following Cl... | go | func NewClient(tracer *zipkin.Tracer, options ...ClientOption) (*Client, error) {
if tracer == nil {
return nil, ErrValidTracerRequired
}
c := &Client{tracer: tracer, Client: &http.Client{}}
for _, option := range options {
option(c)
}
c.transportOptions = append(
c.transportOptions,
// the following Cl... | [
"func",
"NewClient",
"(",
"tracer",
"*",
"zipkin",
".",
"Tracer",
",",
"options",
"...",
"ClientOption",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"if",
"tracer",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrValidTracerRequired",
"\n",
"}",
"\n\n",... | // NewClient returns an HTTP Client adding Zipkin instrumentation around an
// embedded standard Go http.Client. | [
"NewClient",
"returns",
"an",
"HTTP",
"Client",
"adding",
"Zipkin",
"instrumentation",
"around",
"an",
"embedded",
"standard",
"Go",
"http",
".",
"Client",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/middleware/http/client.go#L76-L99 | train |
openzipkin/zipkin-go | middleware/http/client.go | DoWithAppSpan | func (c *Client) DoWithAppSpan(req *http.Request, name string) (res *http.Response, err error) {
var parentContext model.SpanContext
if span := zipkin.SpanFromContext(req.Context()); span != nil {
parentContext = span.Context()
}
appSpan := c.tracer.StartSpan(name, zipkin.Parent(parentContext))
zipkin.TagHTTP... | go | func (c *Client) DoWithAppSpan(req *http.Request, name string) (res *http.Response, err error) {
var parentContext model.SpanContext
if span := zipkin.SpanFromContext(req.Context()); span != nil {
parentContext = span.Context()
}
appSpan := c.tracer.StartSpan(name, zipkin.Parent(parentContext))
zipkin.TagHTTP... | [
"func",
"(",
"c",
"*",
"Client",
")",
"DoWithAppSpan",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"name",
"string",
")",
"(",
"res",
"*",
"http",
".",
"Response",
",",
"err",
"error",
")",
"{",
"var",
"parentContext",
"model",
".",
"SpanContext",
... | // DoWithAppSpan wraps http.Client's Do with tracing using an application span. | [
"DoWithAppSpan",
"wraps",
"http",
".",
"Client",
"s",
"Do",
"with",
"tracing",
"using",
"an",
"application",
"span",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/middleware/http/client.go#L102-L144 | train |
openzipkin/zipkin-go | model/annotation.go | MarshalJSON | func (a *Annotation) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Timestamp int64 `json:"timestamp"`
Value string `json:"value"`
}{
Timestamp: a.Timestamp.Round(time.Microsecond).UnixNano() / 1e3,
Value: a.Value,
})
} | go | func (a *Annotation) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Timestamp int64 `json:"timestamp"`
Value string `json:"value"`
}{
Timestamp: a.Timestamp.Round(time.Microsecond).UnixNano() / 1e3,
Value: a.Value,
})
} | [
"func",
"(",
"a",
"*",
"Annotation",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Timestamp",
"int64",
"`json:\"timestamp\"`",
"\n",
"Value",
"string",
"`json:\"v... | // MarshalJSON implements custom JSON encoding | [
"MarshalJSON",
"implements",
"custom",
"JSON",
"encoding"
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/model/annotation.go#L33-L41 | train |
openzipkin/zipkin-go | model/annotation.go | UnmarshalJSON | func (a *Annotation) UnmarshalJSON(b []byte) error {
type Alias Annotation
annotation := &struct {
TimeStamp uint64 `json:"timestamp"`
*Alias
}{
Alias: (*Alias)(a),
}
if err := json.Unmarshal(b, &annotation); err != nil {
return err
}
if annotation.TimeStamp < 1 {
return ErrValidTimestampRequired
}
a... | go | func (a *Annotation) UnmarshalJSON(b []byte) error {
type Alias Annotation
annotation := &struct {
TimeStamp uint64 `json:"timestamp"`
*Alias
}{
Alias: (*Alias)(a),
}
if err := json.Unmarshal(b, &annotation); err != nil {
return err
}
if annotation.TimeStamp < 1 {
return ErrValidTimestampRequired
}
a... | [
"func",
"(",
"a",
"*",
"Annotation",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"type",
"Alias",
"Annotation",
"\n",
"annotation",
":=",
"&",
"struct",
"{",
"TimeStamp",
"uint64",
"`json:\"timestamp\"`",
"\n",
"*",
"Alias",
"\n",
... | // UnmarshalJSON implements custom JSON decoding | [
"UnmarshalJSON",
"implements",
"custom",
"JSON",
"decoding"
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/model/annotation.go#L44-L60 | train |
openzipkin/zipkin-go | propagation/b3/http.go | ExtractHTTP | func ExtractHTTP(r *http.Request) propagation.Extractor {
return func() (*model.SpanContext, error) {
var (
traceIDHeader = r.Header.Get(TraceID)
spanIDHeader = r.Header.Get(SpanID)
parentSpanIDHeader = r.Header.Get(ParentSpanID)
sampledHeader = r.Header.Get(Sampled)
flagsHeader ... | go | func ExtractHTTP(r *http.Request) propagation.Extractor {
return func() (*model.SpanContext, error) {
var (
traceIDHeader = r.Header.Get(TraceID)
spanIDHeader = r.Header.Get(SpanID)
parentSpanIDHeader = r.Header.Get(ParentSpanID)
sampledHeader = r.Header.Get(Sampled)
flagsHeader ... | [
"func",
"ExtractHTTP",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"propagation",
".",
"Extractor",
"{",
"return",
"func",
"(",
")",
"(",
"*",
"model",
".",
"SpanContext",
",",
"error",
")",
"{",
"var",
"(",
"traceIDHeader",
"=",
"r",
".",
"Header",
... | // ExtractHTTP will extract a span.Context from the HTTP Request if found in
// B3 header format. | [
"ExtractHTTP",
"will",
"extract",
"a",
"span",
".",
"Context",
"from",
"the",
"HTTP",
"Request",
"if",
"found",
"in",
"B3",
"header",
"format",
"."
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/propagation/b3/http.go#L26-L41 | train |
openzipkin/zipkin-go | propagation/b3/http.go | InjectHTTP | func InjectHTTP(r *http.Request) propagation.Injector {
return func(sc model.SpanContext) error {
if (model.SpanContext{}) == sc {
return ErrEmptyContext
}
if sc.Debug {
r.Header.Set(Flags, "1")
} else if sc.Sampled != nil {
// Debug is encoded as X-B3-Flags: 1. Since Debug implies Sampled,
// so ... | go | func InjectHTTP(r *http.Request) propagation.Injector {
return func(sc model.SpanContext) error {
if (model.SpanContext{}) == sc {
return ErrEmptyContext
}
if sc.Debug {
r.Header.Set(Flags, "1")
} else if sc.Sampled != nil {
// Debug is encoded as X-B3-Flags: 1. Since Debug implies Sampled,
// so ... | [
"func",
"InjectHTTP",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"propagation",
".",
"Injector",
"{",
"return",
"func",
"(",
"sc",
"model",
".",
"SpanContext",
")",
"error",
"{",
"if",
"(",
"model",
".",
"SpanContext",
"{",
"}",
")",
"==",
"sc",
"{"... | // InjectHTTP will inject a span.Context into a HTTP Request | [
"InjectHTTP",
"will",
"inject",
"a",
"span",
".",
"Context",
"into",
"a",
"HTTP",
"Request"
] | a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962 | https://github.com/openzipkin/zipkin-go/blob/a9beb3b3ee82f8d9336022a1c2ed7c1f4f5d6962/propagation/b3/http.go#L44-L72 | train |
mholt/archiver | rar.go | Unarchive | func (r *Rar) Unarchive(source, destination string) error {
if !fileExists(destination) && r.MkdirAll {
err := mkdir(destination, 0755)
if err != nil {
return fmt.Errorf("preparing destination: %v", err)
}
}
// if the files in the archive do not all share a common
// root, then make sure we extract to a s... | go | func (r *Rar) Unarchive(source, destination string) error {
if !fileExists(destination) && r.MkdirAll {
err := mkdir(destination, 0755)
if err != nil {
return fmt.Errorf("preparing destination: %v", err)
}
}
// if the files in the archive do not all share a common
// root, then make sure we extract to a s... | [
"func",
"(",
"r",
"*",
"Rar",
")",
"Unarchive",
"(",
"source",
",",
"destination",
"string",
")",
"error",
"{",
"if",
"!",
"fileExists",
"(",
"destination",
")",
"&&",
"r",
".",
"MkdirAll",
"{",
"err",
":=",
"mkdir",
"(",
"destination",
",",
"0755",
... | // Unarchive unpacks the .rar file at source to destination.
// Destination will be treated as a folder name. It supports
// multi-volume archives. | [
"Unarchive",
"unpacks",
"the",
".",
"rar",
"file",
"at",
"source",
"to",
"destination",
".",
"Destination",
"will",
"be",
"treated",
"as",
"a",
"folder",
"name",
".",
"It",
"supports",
"multi",
"-",
"volume",
"archives",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/rar.go#L66-L106 | train |
mholt/archiver | rar.go | Extract | func (r *Rar) Extract(source, target, destination string) error {
// target refers to a path inside the archive, which should be clean also
target = path.Clean(target)
// if the target ends up being a directory, then
// we will continue walking and extracting files
// until we are no longer within that directory
... | go | func (r *Rar) Extract(source, target, destination string) error {
// target refers to a path inside the archive, which should be clean also
target = path.Clean(target)
// if the target ends up being a directory, then
// we will continue walking and extracting files
// until we are no longer within that directory
... | [
"func",
"(",
"r",
"*",
"Rar",
")",
"Extract",
"(",
"source",
",",
"target",
",",
"destination",
"string",
")",
"error",
"{",
"// target refers to a path inside the archive, which should be clean also",
"target",
"=",
"path",
".",
"Clean",
"(",
"target",
")",
"\n\n... | // Extract extracts a single file from the rar archive.
// If the target is a directory, the entire folder will
// be extracted into destination. | [
"Extract",
"extracts",
"a",
"single",
"file",
"from",
"the",
"rar",
"archive",
".",
"If",
"the",
"target",
"is",
"a",
"directory",
"the",
"entire",
"folder",
"will",
"be",
"extracted",
"into",
"destination",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/rar.go#L304-L353 | train |
mholt/archiver | tarxz.go | Archive | func (txz *TarXz) Archive(sources []string, destination string) error {
err := txz.CheckExt(destination)
if err != nil {
return fmt.Errorf("output %s", err.Error())
}
txz.wrapWriter()
return txz.Tar.Archive(sources, destination)
} | go | func (txz *TarXz) Archive(sources []string, destination string) error {
err := txz.CheckExt(destination)
if err != nil {
return fmt.Errorf("output %s", err.Error())
}
txz.wrapWriter()
return txz.Tar.Archive(sources, destination)
} | [
"func",
"(",
"txz",
"*",
"TarXz",
")",
"Archive",
"(",
"sources",
"[",
"]",
"string",
",",
"destination",
"string",
")",
"error",
"{",
"err",
":=",
"txz",
".",
"CheckExt",
"(",
"destination",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",... | // Archive creates a compressed tar file at destination
// containing the files listed in sources. The destination
// must end with ".tar.xz" or ".txz". File paths can be
// those of regular files or directories; directories will
// be recursively added. | [
"Archive",
"creates",
"a",
"compressed",
"tar",
"file",
"at",
"destination",
"containing",
"the",
"files",
"listed",
"in",
"sources",
".",
"The",
"destination",
"must",
"end",
"with",
".",
"tar",
".",
"xz",
"or",
".",
"txz",
".",
"File",
"paths",
"can",
... | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/tarxz.go#L33-L40 | train |
mholt/archiver | tar.go | Archive | func (t *Tar) Archive(sources []string, destination string) error {
err := t.CheckExt(destination)
if t.writerWrapFn == nil && err != nil {
return fmt.Errorf("checking extension: %v", err)
}
if !t.OverwriteExisting && fileExists(destination) {
return fmt.Errorf("file already exists: %s", destination)
}
// ma... | go | func (t *Tar) Archive(sources []string, destination string) error {
err := t.CheckExt(destination)
if t.writerWrapFn == nil && err != nil {
return fmt.Errorf("checking extension: %v", err)
}
if !t.OverwriteExisting && fileExists(destination) {
return fmt.Errorf("file already exists: %s", destination)
}
// ma... | [
"func",
"(",
"t",
"*",
"Tar",
")",
"Archive",
"(",
"sources",
"[",
"]",
"string",
",",
"destination",
"string",
")",
"error",
"{",
"err",
":=",
"t",
".",
"CheckExt",
"(",
"destination",
")",
"\n",
"if",
"t",
".",
"writerWrapFn",
"==",
"nil",
"&&",
... | // Archive creates a tarball file at destination containing
// the files listed in sources. The destination must end with
// ".tar". File paths can be those of regular files or
// directories; directories will be recursively added. | [
"Archive",
"creates",
"a",
"tarball",
"file",
"at",
"destination",
"containing",
"the",
"files",
"listed",
"in",
"sources",
".",
"The",
"destination",
"must",
"end",
"with",
".",
"tar",
".",
"File",
"paths",
"can",
"be",
"those",
"of",
"regular",
"files",
... | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/tar.go#L68-L112 | train |
mholt/archiver | tar.go | Unarchive | func (t *Tar) Unarchive(source, destination string) error {
if !fileExists(destination) && t.MkdirAll {
err := mkdir(destination, 0755)
if err != nil {
return fmt.Errorf("preparing destination: %v", err)
}
}
// if the files in the archive do not all share a common
// root, then make sure we extract to a s... | go | func (t *Tar) Unarchive(source, destination string) error {
if !fileExists(destination) && t.MkdirAll {
err := mkdir(destination, 0755)
if err != nil {
return fmt.Errorf("preparing destination: %v", err)
}
}
// if the files in the archive do not all share a common
// root, then make sure we extract to a s... | [
"func",
"(",
"t",
"*",
"Tar",
")",
"Unarchive",
"(",
"source",
",",
"destination",
"string",
")",
"error",
"{",
"if",
"!",
"fileExists",
"(",
"destination",
")",
"&&",
"t",
".",
"MkdirAll",
"{",
"err",
":=",
"mkdir",
"(",
"destination",
",",
"0755",
... | // Unarchive unpacks the .tar file at source to destination.
// Destination will be treated as a folder name. | [
"Unarchive",
"unpacks",
"the",
".",
"tar",
"file",
"at",
"source",
"to",
"destination",
".",
"Destination",
"will",
"be",
"treated",
"as",
"a",
"folder",
"name",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/tar.go#L116-L162 | train |
mholt/archiver | tar.go | Create | func (t *Tar) Create(out io.Writer) error {
if t.tw != nil {
return fmt.Errorf("tar archive is already created for writing")
}
// wrapping writers allows us to output
// compressed tarballs, for example
if t.writerWrapFn != nil {
var err error
out, err = t.writerWrapFn(out)
if err != nil {
return fmt.E... | go | func (t *Tar) Create(out io.Writer) error {
if t.tw != nil {
return fmt.Errorf("tar archive is already created for writing")
}
// wrapping writers allows us to output
// compressed tarballs, for example
if t.writerWrapFn != nil {
var err error
out, err = t.writerWrapFn(out)
if err != nil {
return fmt.E... | [
"func",
"(",
"t",
"*",
"Tar",
")",
"Create",
"(",
"out",
"io",
".",
"Writer",
")",
"error",
"{",
"if",
"t",
".",
"tw",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// wrapping writers allows us to output... | // Create opens t for writing a tar archive to out. | [
"Create",
"opens",
"t",
"for",
"writing",
"a",
"tar",
"archive",
"to",
"out",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/tar.go#L312-L329 | train |
mholt/archiver | tar.go | Write | func (t *Tar) Write(f File) error {
if t.tw == nil {
return fmt.Errorf("tar archive was not created for writing first")
}
if f.FileInfo == nil {
return fmt.Errorf("no file info")
}
if f.FileInfo.Name() == "" {
return fmt.Errorf("missing file name")
}
var linkTarget string
if isSymlink(f) {
var err erro... | go | func (t *Tar) Write(f File) error {
if t.tw == nil {
return fmt.Errorf("tar archive was not created for writing first")
}
if f.FileInfo == nil {
return fmt.Errorf("no file info")
}
if f.FileInfo.Name() == "" {
return fmt.Errorf("missing file name")
}
var linkTarget string
if isSymlink(f) {
var err erro... | [
"func",
"(",
"t",
"*",
"Tar",
")",
"Write",
"(",
"f",
"File",
")",
"error",
"{",
"if",
"t",
".",
"tw",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"f",
".",
"FileInfo",
"==",
"nil",
"{",
"r... | // Write writes f to t, which must have been opened for writing first. | [
"Write",
"writes",
"f",
"to",
"t",
"which",
"must",
"have",
"been",
"opened",
"for",
"writing",
"first",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/tar.go#L332-L377 | 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.