id int32 0 167k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
147,200 | dajohi/goemail | email.go | AddBCC | func (m *Message) AddBCC(emailAddr string) {
m.bcc = append(m.bcc, emailAddr)
} | go | func (m *Message) AddBCC(emailAddr string) {
m.bcc = append(m.bcc, emailAddr)
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"AddBCC",
"(",
"emailAddr",
"string",
")",
"{",
"m",
".",
"bcc",
"=",
"append",
"(",
"m",
".",
"bcc",
",",
"emailAddr",
")",
"\n",
"}"
] | // AddBCC adds a single email address to the BCC list. | [
"AddBCC",
"adds",
"a",
"single",
"email",
"address",
"to",
"the",
"BCC",
"list",
"."
] | 2e68548ea8bb950e454918222398598a8aad0e60 | https://github.com/dajohi/goemail/blob/2e68548ea8bb950e454918222398598a8aad0e60/email.go#L121-L123 |
147,201 | dajohi/goemail | email.go | AddTo | func (m *Message) AddTo(emailAddr string) {
m.to = append(m.to, emailAddr)
} | go | func (m *Message) AddTo(emailAddr string) {
m.to = append(m.to, emailAddr)
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"AddTo",
"(",
"emailAddr",
"string",
")",
"{",
"m",
".",
"to",
"=",
"append",
"(",
"m",
".",
"to",
",",
"emailAddr",
")",
"\n",
"}"
] | // AddTo adds an email address to the To recipients. | [
"AddTo",
"adds",
"an",
"email",
"address",
"to",
"the",
"To",
"recipients",
"."
] | 2e68548ea8bb950e454918222398598a8aad0e60 | https://github.com/dajohi/goemail/blob/2e68548ea8bb950e454918222398598a8aad0e60/email.go#L126-L128 |
147,202 | dajohi/goemail | email.go | Body | func (m *Message) Body() []byte {
buf := bytes.NewBuffer(nil)
from := fmt.Sprintf("\"%s\" <%s>", m.name, m.from)
buf.WriteString("From: " + from + "\n")
buf.WriteString("Date: " + m.date + "\n")
buf.WriteString("To: " + strings.Join(m.to, ",") + "\n")
if len(m.cc) > 0 {
buf.WriteString("Cc: " + strings.Join(m.c... | go | func (m *Message) Body() []byte {
buf := bytes.NewBuffer(nil)
from := fmt.Sprintf("\"%s\" <%s>", m.name, m.from)
buf.WriteString("From: " + from + "\n")
buf.WriteString("Date: " + m.date + "\n")
buf.WriteString("To: " + strings.Join(m.to, ",") + "\n")
if len(m.cc) > 0 {
buf.WriteString("Cc: " + strings.Join(m.c... | [
"func",
"(",
"m",
"*",
"Message",
")",
"Body",
"(",
")",
"[",
"]",
"byte",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n",
"from",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"m",
".",
"name",
",",
"... | // Body returns the formatted message body. | [
"Body",
"returns",
"the",
"formatted",
"message",
"body",
"."
] | 2e68548ea8bb950e454918222398598a8aad0e60 | https://github.com/dajohi/goemail/blob/2e68548ea8bb950e454918222398598a8aad0e60/email.go#L131-L173 |
147,203 | dajohi/goemail | email.go | Recipients | func (m *Message) Recipients() []string {
rcpts := make([]string, 0, len(m.to)+len(m.cc)+len(m.bcc))
rcpts = append(rcpts, m.to...)
rcpts = append(rcpts, m.cc...)
rcpts = append(rcpts, m.bcc...)
return rcpts
} | go | func (m *Message) Recipients() []string {
rcpts := make([]string, 0, len(m.to)+len(m.cc)+len(m.bcc))
rcpts = append(rcpts, m.to...)
rcpts = append(rcpts, m.cc...)
rcpts = append(rcpts, m.bcc...)
return rcpts
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"Recipients",
"(",
")",
"[",
"]",
"string",
"{",
"rcpts",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"m",
".",
"to",
")",
"+",
"len",
"(",
"m",
".",
"cc",
")",
"+",
"len",
"(",
... | // Recipients returns an array of all the recipients, which includes
// To, CC, and BCC | [
"Recipients",
"returns",
"an",
"array",
"of",
"all",
"the",
"recipients",
"which",
"includes",
"To",
"CC",
"and",
"BCC"
] | 2e68548ea8bb950e454918222398598a8aad0e60 | https://github.com/dajohi/goemail/blob/2e68548ea8bb950e454918222398598a8aad0e60/email.go#L192-L198 |
147,204 | dajohi/goemail | email.go | Send | func (s *SMTP) Send(msg *Message) error {
var conn net.Conn
var err error
var success bool
recipients := msg.Recipients()
if len(recipients) < 1 {
return ErrNoRecipients
}
switch s.scheme {
case "smtps":
conn, err = tls.Dial("tcp", s.server, s.tlsConfig)
case "tls":
fallthrough
default:
conn, err = ... | go | func (s *SMTP) Send(msg *Message) error {
var conn net.Conn
var err error
var success bool
recipients := msg.Recipients()
if len(recipients) < 1 {
return ErrNoRecipients
}
switch s.scheme {
case "smtps":
conn, err = tls.Dial("tcp", s.server, s.tlsConfig)
case "tls":
fallthrough
default:
conn, err = ... | [
"func",
"(",
"s",
"*",
"SMTP",
")",
"Send",
"(",
"msg",
"*",
"Message",
")",
"error",
"{",
"var",
"conn",
"net",
".",
"Conn",
"\n",
"var",
"err",
"error",
"\n",
"var",
"success",
"bool",
"\n\n",
"recipients",
":=",
"msg",
".",
"Recipients",
"(",
")... | // Send connects to the server and sends the email message. | [
"Send",
"connects",
"to",
"the",
"server",
"and",
"sends",
"the",
"email",
"message",
"."
] | 2e68548ea8bb950e454918222398598a8aad0e60 | https://github.com/dajohi/goemail/blob/2e68548ea8bb950e454918222398598a8aad0e60/email.go#L243-L331 |
147,205 | kenshaw/baseconv | baseconv.go | Convert | func Convert(num, fromBase, toBase string) (string, error) {
if num == "" {
return "", ErrInvalidNumber
}
if len(fromBase) < 2 {
return "", ErrInvalidFromBase
}
if len(toBase) < 2 {
return "", ErrInvalidToBase
}
// rune counts
fromLenRunes := utf8.RuneCountInString(fromBase)
toLenRunes := utf8.RuneCou... | go | func Convert(num, fromBase, toBase string) (string, error) {
if num == "" {
return "", ErrInvalidNumber
}
if len(fromBase) < 2 {
return "", ErrInvalidFromBase
}
if len(toBase) < 2 {
return "", ErrInvalidToBase
}
// rune counts
fromLenRunes := utf8.RuneCountInString(fromBase)
toLenRunes := utf8.RuneCou... | [
"func",
"Convert",
"(",
"num",
",",
"fromBase",
",",
"toBase",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"num",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"ErrInvalidNumber",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"fromBase",
... | // Convert num from specified base to a different base. | [
"Convert",
"num",
"from",
"specified",
"base",
"to",
"a",
"different",
"base",
"."
] | 5ac6a1b7584c87afde1a974bdc313149489ec173 | https://github.com/kenshaw/baseconv/blob/5ac6a1b7584c87afde1a974bdc313149489ec173/baseconv.go#L42-L122 |
147,206 | alcortesm/tgz | tgz.go | Extract | func Extract(tgz string) (d string, err error) {
f, err := os.Open(tgz)
if err != nil {
return "", err
}
defer func() {
errClose := f.Close()
if err == nil {
err = errClose
}
}()
d, err = ioutil.TempDir(useDefaultTempDir, tmpPrefix)
if err != nil {
return "", err
}
tar, err := zipTarReader(f)
... | go | func Extract(tgz string) (d string, err error) {
f, err := os.Open(tgz)
if err != nil {
return "", err
}
defer func() {
errClose := f.Close()
if err == nil {
err = errClose
}
}()
d, err = ioutil.TempDir(useDefaultTempDir, tmpPrefix)
if err != nil {
return "", err
}
tar, err := zipTarReader(f)
... | [
"func",
"Extract",
"(",
"tgz",
"string",
")",
"(",
"d",
"string",
",",
"err",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"tgz",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\... | // Extract decompress a gziped tarball into a new temporal directory
// created just for this purpose.
//
// On success, the path of the newly created directory and a nil error
// is returned.
//
// A non-nil error is returned if the method fails to complete. The
// returned path will be an empty string if no informati... | [
"Extract",
"decompress",
"a",
"gziped",
"tarball",
"into",
"a",
"new",
"temporal",
"directory",
"created",
"just",
"for",
"this",
"purpose",
".",
"On",
"success",
"the",
"path",
"of",
"the",
"newly",
"created",
"directory",
"and",
"a",
"nil",
"error",
"is",
... | 9c5fe88206d7765837fed3732a42ef88fc51f1a1 | https://github.com/alcortesm/tgz/blob/9c5fe88206d7765837fed3732a42ef88fc51f1a1/tgz.go#L28-L56 |
147,207 | ssor/bom | bom.go | CleanBom | func CleanBom(b []byte) []byte {
if len(b) >= 3 &&
b[0] == bom0 &&
b[1] == bom1 &&
b[2] == bom2 {
return b[3:]
}
return b
} | go | func CleanBom(b []byte) []byte {
if len(b) >= 3 &&
b[0] == bom0 &&
b[1] == bom1 &&
b[2] == bom2 {
return b[3:]
}
return b
} | [
"func",
"CleanBom",
"(",
"b",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"if",
"len",
"(",
"b",
")",
">=",
"3",
"&&",
"b",
"[",
"0",
"]",
"==",
"bom0",
"&&",
"b",
"[",
"1",
"]",
"==",
"bom1",
"&&",
"b",
"[",
"2",
"]",
"==",
"bom2",
"... | // CleanBom returns b with the 3 byte BOM stripped off the front if it is present.
// If the BOM is not present, then b is returned. | [
"CleanBom",
"returns",
"b",
"with",
"the",
"3",
"byte",
"BOM",
"stripped",
"off",
"the",
"front",
"if",
"it",
"is",
"present",
".",
"If",
"the",
"BOM",
"is",
"not",
"present",
"then",
"b",
"is",
"returned",
"."
] | 6386211fdfcf24c0bfbdaceafd02849ed9a8a509 | https://github.com/ssor/bom/blob/6386211fdfcf24c0bfbdaceafd02849ed9a8a509/bom.go#L17-L25 |
147,208 | ssor/bom | bom.go | NewReaderWithoutBom | func NewReaderWithoutBom(r io.Reader) (io.Reader, error) {
bs, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
return bytes.NewReader(CleanBom(bs)), nil
} | go | func NewReaderWithoutBom(r io.Reader) (io.Reader, error) {
bs, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
return bytes.NewReader(CleanBom(bs)), nil
} | [
"func",
"NewReaderWithoutBom",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"io",
".",
"Reader",
",",
"error",
")",
"{",
"bs",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err"... | // NewReaderWithoutBom returns an io.Reader that will skip over initial UTF-8 byte order marks. | [
"NewReaderWithoutBom",
"returns",
"an",
"io",
".",
"Reader",
"that",
"will",
"skip",
"over",
"initial",
"UTF",
"-",
"8",
"byte",
"order",
"marks",
"."
] | 6386211fdfcf24c0bfbdaceafd02849ed9a8a509 | https://github.com/ssor/bom/blob/6386211fdfcf24c0bfbdaceafd02849ed9a8a509/bom.go#L28-L34 |
147,209 | dustin/gojson | indent.go | Indent | func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
origLen := dst.Len()
var scan Scanner
scan.Reset()
needIndent := false
depth := 0
for _, c := range src {
scan.bytes++
v := scan.Step(&scan, int(c))
if v == ScanSkipSpace {
continue
}
if v == ScanError {
break
}
if needI... | go | func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
origLen := dst.Len()
var scan Scanner
scan.Reset()
needIndent := false
depth := 0
for _, c := range src {
scan.bytes++
v := scan.Step(&scan, int(c))
if v == ScanSkipSpace {
continue
}
if v == ScanError {
break
}
if needI... | [
"func",
"Indent",
"(",
"dst",
"*",
"bytes",
".",
"Buffer",
",",
"src",
"[",
"]",
"byte",
",",
"prefix",
",",
"indent",
"string",
")",
"error",
"{",
"origLen",
":=",
"dst",
".",
"Len",
"(",
")",
"\n",
"var",
"scan",
"Scanner",
"\n",
"scan",
".",
"... | // Indent appends to dst an indented form of the JSON-encoded src.
// Each element in a JSON object or array begins on a new,
// indented line beginning with prefix followed by one or more
// copies of indent according to the indentation nesting.
// The data appended to dst does not begin with the prefix nor
// any ind... | [
"Indent",
"appends",
"to",
"dst",
"an",
"indented",
"form",
"of",
"the",
"JSON",
"-",
"encoded",
"src",
".",
"Each",
"element",
"in",
"a",
"JSON",
"object",
"or",
"array",
"begins",
"on",
"a",
"new",
"indented",
"line",
"beginning",
"with",
"prefix",
"fo... | 2e71ec9dd5adce3b168cd0dbde03b5cc04951c30 | https://github.com/dustin/gojson/blob/2e71ec9dd5adce3b168cd0dbde03b5cc04951c30/indent.go#L75-L137 |
147,210 | dustin/gojson | scanner.go | NextValue | func NextValue(data []byte, scan *Scanner) (value, rest []byte, err error) {
scan.Reset()
for i, c := range data {
v := scan.Step(scan, int(c))
if v >= ScanEnd {
switch v {
case ScanError:
return nil, nil, scan.Err
case ScanEnd:
return data[0:i], data[i:], nil
}
}
}
if scan.EOF() == ScanEr... | go | func NextValue(data []byte, scan *Scanner) (value, rest []byte, err error) {
scan.Reset()
for i, c := range data {
v := scan.Step(scan, int(c))
if v >= ScanEnd {
switch v {
case ScanError:
return nil, nil, scan.Err
case ScanEnd:
return data[0:i], data[i:], nil
}
}
}
if scan.EOF() == ScanEr... | [
"func",
"NextValue",
"(",
"data",
"[",
"]",
"byte",
",",
"scan",
"*",
"Scanner",
")",
"(",
"value",
",",
"rest",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"scan",
".",
"Reset",
"(",
")",
"\n",
"for",
"i",
",",
"c",
":=",
"range",
"data",... | // NextValue splits data after the next whole JSON value,
// returning that value and the bytes that follow it as separate slices.
// scan is passed in for use by NextValue to avoid an allocation. | [
"NextValue",
"splits",
"data",
"after",
"the",
"next",
"whole",
"JSON",
"value",
"returning",
"that",
"value",
"and",
"the",
"bytes",
"that",
"follow",
"it",
"as",
"separate",
"slices",
".",
"scan",
"is",
"passed",
"in",
"for",
"use",
"by",
"NextValue",
"t... | 2e71ec9dd5adce3b168cd0dbde03b5cc04951c30 | https://github.com/dustin/gojson/blob/2e71ec9dd5adce3b168cd0dbde03b5cc04951c30/scanner.go#L43-L60 |
147,211 | dustin/gojson | scanner.go | EOF | func (s *Scanner) EOF() int {
if s.Err != nil {
return ScanError
}
if s.endTop {
return ScanEnd
}
s.Step(s, ' ')
if s.endTop {
return ScanEnd
}
if s.Err == nil {
s.Err = &SyntaxError{"unexpected end of JSON input", s.bytes}
}
return ScanError
} | go | func (s *Scanner) EOF() int {
if s.Err != nil {
return ScanError
}
if s.endTop {
return ScanEnd
}
s.Step(s, ' ')
if s.endTop {
return ScanEnd
}
if s.Err == nil {
s.Err = &SyntaxError{"unexpected end of JSON input", s.bytes}
}
return ScanError
} | [
"func",
"(",
"s",
"*",
"Scanner",
")",
"EOF",
"(",
")",
"int",
"{",
"if",
"s",
".",
"Err",
"!=",
"nil",
"{",
"return",
"ScanError",
"\n",
"}",
"\n",
"if",
"s",
".",
"endTop",
"{",
"return",
"ScanEnd",
"\n",
"}",
"\n",
"s",
".",
"Step",
"(",
"... | // EOF tells the scanner that the end of input has been reached.
// It returns a scan status just as s.step does. | [
"EOF",
"tells",
"the",
"scanner",
"that",
"the",
"end",
"of",
"input",
"has",
"been",
"reached",
".",
"It",
"returns",
"a",
"scan",
"status",
"just",
"as",
"s",
".",
"step",
"does",
"."
] | 2e71ec9dd5adce3b168cd0dbde03b5cc04951c30 | https://github.com/dustin/gojson/blob/2e71ec9dd5adce3b168cd0dbde03b5cc04951c30/scanner.go#L154-L169 |
147,212 | dustin/gojson | scanner.go | stateInStringEscU12 | func stateInStringEscU12(s *Scanner, c int) int {
if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
s.Step = stateInStringEscU123
return ScanContinue
}
// numbers
return s.error(c, "in \\u hexadecimal character escape")
} | go | func stateInStringEscU12(s *Scanner, c int) int {
if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
s.Step = stateInStringEscU123
return ScanContinue
}
// numbers
return s.error(c, "in \\u hexadecimal character escape")
} | [
"func",
"stateInStringEscU12",
"(",
"s",
"*",
"Scanner",
",",
"c",
"int",
")",
"int",
"{",
"if",
"'0'",
"<=",
"c",
"&&",
"c",
"<=",
"'9'",
"||",
"'a'",
"<=",
"c",
"&&",
"c",
"<=",
"'f'",
"||",
"'A'",
"<=",
"c",
"&&",
"c",
"<=",
"'F'",
"{",
"s... | // stateInStringEscU12 is the state after reading `"\u12` during a quoted string. | [
"stateInStringEscU12",
"is",
"the",
"state",
"after",
"reading",
"\\",
"u12",
"during",
"a",
"quoted",
"string",
"."
] | 2e71ec9dd5adce3b168cd0dbde03b5cc04951c30 | https://github.com/dustin/gojson/blob/2e71ec9dd5adce3b168cd0dbde03b5cc04951c30/scanner.go#L380-L387 |
147,213 | dustin/gojson | scanner.go | stateT | func stateT(s *Scanner, c int) int {
if c == 'r' {
s.Step = stateTr
return ScanContinue
}
return s.error(c, "in literal true (expecting 'r')")
} | go | func stateT(s *Scanner, c int) int {
if c == 'r' {
s.Step = stateTr
return ScanContinue
}
return s.error(c, "in literal true (expecting 'r')")
} | [
"func",
"stateT",
"(",
"s",
"*",
"Scanner",
",",
"c",
"int",
")",
"int",
"{",
"if",
"c",
"==",
"'r'",
"{",
"s",
".",
"Step",
"=",
"stateTr",
"\n",
"return",
"ScanContinue",
"\n",
"}",
"\n",
"return",
"s",
".",
"error",
"(",
"c",
",",
"\"",
"\""... | // stateT is the state after reading `t`. | [
"stateT",
"is",
"the",
"state",
"after",
"reading",
"t",
"."
] | 2e71ec9dd5adce3b168cd0dbde03b5cc04951c30 | https://github.com/dustin/gojson/blob/2e71ec9dd5adce3b168cd0dbde03b5cc04951c30/scanner.go#L495-L501 |
147,214 | caarlos0/ctrlc | ctrlc.go | New | func New() *Ctrlc {
return &Ctrlc{
signals: make(chan os.Signal, 1),
errs: make(chan error, 1),
}
} | go | func New() *Ctrlc {
return &Ctrlc{
signals: make(chan os.Signal, 1),
errs: make(chan error, 1),
}
} | [
"func",
"New",
"(",
")",
"*",
"Ctrlc",
"{",
"return",
"&",
"Ctrlc",
"{",
"signals",
":",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"1",
")",
",",
"errs",
":",
"make",
"(",
"chan",
"error",
",",
"1",
")",
",",
"}",
"\n",
"}"
] | // New returns a new ctrlc with its internals setup. | [
"New",
"returns",
"a",
"new",
"ctrlc",
"with",
"its",
"internals",
"setup",
"."
] | 7857ca964538b12692338013672b7cdec70b4a81 | https://github.com/caarlos0/ctrlc/blob/7857ca964538b12692338013672b7cdec70b4a81/ctrlc.go#L23-L28 |
147,215 | caarlos0/ctrlc | ctrlc.go | Run | func (c *Ctrlc) Run(ctx context.Context, task Task) error {
go func() {
c.errs <- task()
}()
signal.Notify(c.signals, syscall.SIGINT, syscall.SIGTERM)
select {
case err := <-c.errs:
return err
case <-ctx.Done():
return ctx.Err()
case sig := <-c.signals:
return fmt.Errorf("received: %s", sig)
}
} | go | func (c *Ctrlc) Run(ctx context.Context, task Task) error {
go func() {
c.errs <- task()
}()
signal.Notify(c.signals, syscall.SIGINT, syscall.SIGTERM)
select {
case err := <-c.errs:
return err
case <-ctx.Done():
return ctx.Err()
case sig := <-c.signals:
return fmt.Errorf("received: %s", sig)
}
} | [
"func",
"(",
"c",
"*",
"Ctrlc",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
",",
"task",
"Task",
")",
"error",
"{",
"go",
"func",
"(",
")",
"{",
"c",
".",
"errs",
"<-",
"task",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"signal",
".",
"Notif... | // Run executes a given task with a given context, dealing with its timeouts,
// cancels and SIGTERM and SIGINT signals.
// It will return an error if the context is canceled, if deadline exceeds,
// if a SIGTERM or SIGINT is received and of course if the task itself fails. | [
"Run",
"executes",
"a",
"given",
"task",
"with",
"a",
"given",
"context",
"dealing",
"with",
"its",
"timeouts",
"cancels",
"and",
"SIGTERM",
"and",
"SIGINT",
"signals",
".",
"It",
"will",
"return",
"an",
"error",
"if",
"the",
"context",
"is",
"canceled",
"... | 7857ca964538b12692338013672b7cdec70b4a81 | https://github.com/caarlos0/ctrlc/blob/7857ca964538b12692338013672b7cdec70b4a81/ctrlc.go#L37-L50 |
147,216 | lytics/dfa | dfa.go | SetTransition | func (m *DFA) SetTransition(from State, input Letter, to State, exec interface{}) {
if exec == nil {
panic("stateful computation cannot be nil")
}
if from == State("") || to == State("") {
panic("state cannot be defined as the empty string")
}
switch exec.(type) {
case func():
if !m.f[to] {
panic(fmt.Spr... | go | func (m *DFA) SetTransition(from State, input Letter, to State, exec interface{}) {
if exec == nil {
panic("stateful computation cannot be nil")
}
if from == State("") || to == State("") {
panic("state cannot be defined as the empty string")
}
switch exec.(type) {
case func():
if !m.f[to] {
panic(fmt.Spr... | [
"func",
"(",
"m",
"*",
"DFA",
")",
"SetTransition",
"(",
"from",
"State",
",",
"input",
"Letter",
",",
"to",
"State",
",",
"exec",
"interface",
"{",
"}",
")",
"{",
"if",
"exec",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
... | // SetTransition, argument 'exec' must be a function that will supply the next letter if the
// 'to' state is non-terminal. | [
"SetTransition",
"argument",
"exec",
"must",
"be",
"a",
"function",
"that",
"will",
"supply",
"the",
"next",
"letter",
"if",
"the",
"to",
"state",
"is",
"non",
"-",
"terminal",
"."
] | 63e35f788f7fa5203fcd2dcd7e318da5a1b981e5 | https://github.com/lytics/dfa/blob/63e35f788f7fa5203fcd2dcd7e318da5a1b981e5/dfa.go#L61-L87 |
147,217 | lytics/dfa | dfa.go | SetTerminalStates | func (m *DFA) SetTerminalStates(f ...State) {
for _, q := range f {
m.f[q] = true
}
} | go | func (m *DFA) SetTerminalStates(f ...State) {
for _, q := range f {
m.f[q] = true
}
} | [
"func",
"(",
"m",
"*",
"DFA",
")",
"SetTerminalStates",
"(",
"f",
"...",
"State",
")",
"{",
"for",
"_",
",",
"q",
":=",
"range",
"f",
"{",
"m",
".",
"f",
"[",
"q",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}"
] | // SetTerminalStates, there can be more than one. Once entered the
// DFA will stop. | [
"SetTerminalStates",
"there",
"can",
"be",
"more",
"than",
"one",
".",
"Once",
"entered",
"the",
"DFA",
"will",
"stop",
"."
] | 63e35f788f7fa5203fcd2dcd7e318da5a1b981e5 | https://github.com/lytics/dfa/blob/63e35f788f7fa5203fcd2dcd7e318da5a1b981e5/dfa.go#L96-L100 |
147,218 | lytics/dfa | dfa.go | States | func (m *DFA) States() []State {
q := make([]State, 0, len(m.q))
for s, _ := range m.q {
q = append(q, s)
}
return q
} | go | func (m *DFA) States() []State {
q := make([]State, 0, len(m.q))
for s, _ := range m.q {
q = append(q, s)
}
return q
} | [
"func",
"(",
"m",
"*",
"DFA",
")",
"States",
"(",
")",
"[",
"]",
"State",
"{",
"q",
":=",
"make",
"(",
"[",
"]",
"State",
",",
"0",
",",
"len",
"(",
"m",
".",
"q",
")",
")",
"\n",
"for",
"s",
",",
"_",
":=",
"range",
"m",
".",
"q",
"{",... | // States of the DFA. | [
"States",
"of",
"the",
"DFA",
"."
] | 63e35f788f7fa5203fcd2dcd7e318da5a1b981e5 | https://github.com/lytics/dfa/blob/63e35f788f7fa5203fcd2dcd7e318da5a1b981e5/dfa.go#L107-L113 |
147,219 | lytics/dfa | dfa.go | Alphabet | func (m *DFA) Alphabet() []Letter {
e := make([]Letter, 0, len(m.e))
for l, _ := range m.e {
e = append(e, l)
}
return e
} | go | func (m *DFA) Alphabet() []Letter {
e := make([]Letter, 0, len(m.e))
for l, _ := range m.e {
e = append(e, l)
}
return e
} | [
"func",
"(",
"m",
"*",
"DFA",
")",
"Alphabet",
"(",
")",
"[",
"]",
"Letter",
"{",
"e",
":=",
"make",
"(",
"[",
"]",
"Letter",
",",
"0",
",",
"len",
"(",
"m",
".",
"e",
")",
")",
"\n",
"for",
"l",
",",
"_",
":=",
"range",
"m",
".",
"e",
... | // Alphabet of the DFA. | [
"Alphabet",
"of",
"the",
"DFA",
"."
] | 63e35f788f7fa5203fcd2dcd7e318da5a1b981e5 | https://github.com/lytics/dfa/blob/63e35f788f7fa5203fcd2dcd7e318da5a1b981e5/dfa.go#L116-L122 |
147,220 | lytics/dfa | dfa.go | Run | func (m *DFA) Run(init interface{}) (State, bool) {
// Check some pre-conditions.
if init == nil {
panic("initial stateful computation is nil")
}
if m.q0 == State("") {
panic("no start state definied")
}
if len(m.f) == 0 {
panic("no terminal states definied")
}
if _, ok := m.q[m.q0]; !ok {
panic(fmt.Spr... | go | func (m *DFA) Run(init interface{}) (State, bool) {
// Check some pre-conditions.
if init == nil {
panic("initial stateful computation is nil")
}
if m.q0 == State("") {
panic("no start state definied")
}
if len(m.f) == 0 {
panic("no terminal states definied")
}
if _, ok := m.q[m.q0]; !ok {
panic(fmt.Spr... | [
"func",
"(",
"m",
"*",
"DFA",
")",
"Run",
"(",
"init",
"interface",
"{",
"}",
")",
"(",
"State",
",",
"bool",
")",
"{",
"// Check some pre-conditions.",
"if",
"init",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"m",
".... | // Run the DFA, blocking until Stop is called or the DFA enters a terminal state.
// Returns the last state and true if the last state was a terminal state. | [
"Run",
"the",
"DFA",
"blocking",
"until",
"Stop",
"is",
"called",
"or",
"the",
"DFA",
"enters",
"a",
"terminal",
"state",
".",
"Returns",
"the",
"last",
"state",
"and",
"true",
"if",
"the",
"last",
"state",
"was",
"a",
"terminal",
"state",
"."
] | 63e35f788f7fa5203fcd2dcd7e318da5a1b981e5 | https://github.com/lytics/dfa/blob/63e35f788f7fa5203fcd2dcd7e318da5a1b981e5/dfa.go#L126-L223 |
147,221 | kr/secureheader | secureheader.go | Handler | func Handler(h http.Handler) *Config {
c := new(Config)
*c = *DefaultConfig
c.Next = h
return c
} | go | func Handler(h http.Handler) *Config {
c := new(Config)
*c = *DefaultConfig
c.Next = h
return c
} | [
"func",
"Handler",
"(",
"h",
"http",
".",
"Handler",
")",
"*",
"Config",
"{",
"c",
":=",
"new",
"(",
"Config",
")",
"\n",
"*",
"c",
"=",
"*",
"DefaultConfig",
"\n",
"c",
".",
"Next",
"=",
"h",
"\n",
"return",
"c",
"\n",
"}"
] | // Handler returns a new HTTP handler
// using the configuration in DefaultConfig,
// serving requests using h.
// If h is nil, it uses http.DefaultServeMux. | [
"Handler",
"returns",
"a",
"new",
"HTTP",
"handler",
"using",
"the",
"configuration",
"in",
"DefaultConfig",
"serving",
"requests",
"using",
"h",
".",
"If",
"h",
"is",
"nil",
"it",
"uses",
"http",
".",
"DefaultServeMux",
"."
] | 9ede93442296d5ede3632c633b3255558f4e4757 | https://github.com/kr/secureheader/blob/9ede93442296d5ede3632c633b3255558f4e4757/secureheader.go#L65-L70 |
147,222 | kr/secureheader | secureheader.go | ServeHTTP | func (c *Config) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if c.HTTPSRedirect && !c.isHTTPS(r) && !c.okloopback(r) {
url := *r.URL
url.Scheme = "https"
url.Host = r.Host
http.Redirect(w, r, url.String(), http.StatusMovedPermanently)
return
}
if c.ContentTypeOptions {
w.Header().Set("X-Content-T... | go | func (c *Config) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if c.HTTPSRedirect && !c.isHTTPS(r) && !c.okloopback(r) {
url := *r.URL
url.Scheme = "https"
url.Host = r.Host
http.Redirect(w, r, url.String(), http.StatusMovedPermanently)
return
}
if c.ContentTypeOptions {
w.Header().Set("X-Content-T... | [
"func",
"(",
"c",
"*",
"Config",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"c",
".",
"HTTPSRedirect",
"&&",
"!",
"c",
".",
"isHTTPS",
"(",
"r",
")",
"&&",
"!",
"c",
".",
"o... | // ServeHTTP sets header fields on w according to the options in
// c, then either replies directly or runs c.Next to reply.
// Typically c.Next is nil, in which case http.DefaultServeMux is
// used instead. | [
"ServeHTTP",
"sets",
"header",
"fields",
"on",
"w",
"according",
"to",
"the",
"options",
"in",
"c",
"then",
"either",
"replies",
"directly",
"or",
"runs",
"c",
".",
"Next",
"to",
"reply",
".",
"Typically",
"c",
".",
"Next",
"is",
"nil",
"in",
"which",
... | 9ede93442296d5ede3632c633b3255558f4e4757 | https://github.com/kr/secureheader/blob/9ede93442296d5ede3632c633b3255558f4e4757/secureheader.go#L136-L186 |
147,223 | toldjuuso/go-jaro-winkler-distance | algo.go | sort | func sort(s1, s2 string) (shorter, longer string) {
if utf8.RuneCountInString(s1) < utf8.RuneCountInString(s2) {
return s1, s2
}
return s2, s1
} | go | func sort(s1, s2 string) (shorter, longer string) {
if utf8.RuneCountInString(s1) < utf8.RuneCountInString(s2) {
return s1, s2
}
return s2, s1
} | [
"func",
"sort",
"(",
"s1",
",",
"s2",
"string",
")",
"(",
"shorter",
",",
"longer",
"string",
")",
"{",
"if",
"utf8",
".",
"RuneCountInString",
"(",
"s1",
")",
"<",
"utf8",
".",
"RuneCountInString",
"(",
"s2",
")",
"{",
"return",
"s1",
",",
"s2",
"... | // To avoid panicing later on, order strings according to
// their unicode length. | [
"To",
"avoid",
"panicing",
"later",
"on",
"order",
"strings",
"according",
"to",
"their",
"unicode",
"length",
"."
] | 277e4e08ce41e35b186a51f88026c018825537a8 | https://github.com/toldjuuso/go-jaro-winkler-distance/blob/277e4e08ce41e35b186a51f88026c018825537a8/algo.go#L15-L20 |
147,224 | toldjuuso/go-jaro-winkler-distance | algo.go | closestIndex | func closestIndex(s []rune, r rune, pos int) int {
desc := naiveSearchDescending(s, r, pos)
asc := naiveSearchAscending(s, r, pos)
da := math.Abs(float64(desc - pos))
aa := math.Abs(float64(asc - pos))
if da < aa {
return desc
}
return asc
} | go | func closestIndex(s []rune, r rune, pos int) int {
desc := naiveSearchDescending(s, r, pos)
asc := naiveSearchAscending(s, r, pos)
da := math.Abs(float64(desc - pos))
aa := math.Abs(float64(asc - pos))
if da < aa {
return desc
}
return asc
} | [
"func",
"closestIndex",
"(",
"s",
"[",
"]",
"rune",
",",
"r",
"rune",
",",
"pos",
"int",
")",
"int",
"{",
"desc",
":=",
"naiveSearchDescending",
"(",
"s",
",",
"r",
",",
"pos",
")",
"\n",
"asc",
":=",
"naiveSearchAscending",
"(",
"s",
",",
"r",
","... | // closestIndex returns position of the closest rune r starting
// from pos | [
"closestIndex",
"returns",
"position",
"of",
"the",
"closest",
"rune",
"r",
"starting",
"from",
"pos"
] | 277e4e08ce41e35b186a51f88026c018825537a8 | https://github.com/toldjuuso/go-jaro-winkler-distance/blob/277e4e08ce41e35b186a51f88026c018825537a8/algo.go#L50-L62 |
147,225 | toldjuuso/go-jaro-winkler-distance | algo.go | Calculate | func Calculate(s1, s2 string) float64 {
// Avoid returning NaN
if utf8.RuneCountInString(s1) == 0 || utf8.RuneCountInString(s2) == 0 {
return 0
}
s1, s2 = sort(strings.ToLower(s1), strings.ToLower(s2))
// m as `matching characters`
// t as `transposition`
// l as `the length of common prefix at the start of... | go | func Calculate(s1, s2 string) float64 {
// Avoid returning NaN
if utf8.RuneCountInString(s1) == 0 || utf8.RuneCountInString(s2) == 0 {
return 0
}
s1, s2 = sort(strings.ToLower(s1), strings.ToLower(s2))
// m as `matching characters`
// t as `transposition`
// l as `the length of common prefix at the start of... | [
"func",
"Calculate",
"(",
"s1",
",",
"s2",
"string",
")",
"float64",
"{",
"// Avoid returning NaN",
"if",
"utf8",
".",
"RuneCountInString",
"(",
"s1",
")",
"==",
"0",
"||",
"utf8",
".",
"RuneCountInString",
"(",
"s2",
")",
"==",
"0",
"{",
"return",
"0",
... | // Calculate calculates Jaro-Winkler distance of two strings.
// The function lowercases its parameters. | [
"Calculate",
"calculates",
"Jaro",
"-",
"Winkler",
"distance",
"of",
"two",
"strings",
".",
"The",
"function",
"lowercases",
"its",
"parameters",
"."
] | 277e4e08ce41e35b186a51f88026c018825537a8 | https://github.com/toldjuuso/go-jaro-winkler-distance/blob/277e4e08ce41e35b186a51f88026c018825537a8/algo.go#L66-L134 |
147,226 | kisielk/raven-go | raven/raven.go | CaptureMessage | func (client Client) CaptureMessage(message ...string) (string, error) {
ev := Event{Message: strings.Join(message, " ")}
sentryErr := client.Capture(&ev)
if sentryErr != nil {
return "", sentryErr
}
return ev.EventId, nil
} | go | func (client Client) CaptureMessage(message ...string) (string, error) {
ev := Event{Message: strings.Join(message, " ")}
sentryErr := client.Capture(&ev)
if sentryErr != nil {
return "", sentryErr
}
return ev.EventId, nil
} | [
"func",
"(",
"client",
"Client",
")",
"CaptureMessage",
"(",
"message",
"...",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"ev",
":=",
"Event",
"{",
"Message",
":",
"strings",
".",
"Join",
"(",
"message",
",",
"\"",
"\"",
")",
"}",
"\n",
... | // CaptureMessage sends a message to the Sentry server.
// It returns the Sentry event ID or an empty string and any error that occurred. | [
"CaptureMessage",
"sends",
"a",
"message",
"to",
"the",
"Sentry",
"server",
".",
"It",
"returns",
"the",
"Sentry",
"event",
"ID",
"or",
"an",
"empty",
"string",
"and",
"any",
"error",
"that",
"occurred",
"."
] | 7a3cb5bc33ce65b73a3f44eefc8fa567f18aca69 | https://github.com/kisielk/raven-go/blob/7a3cb5bc33ce65b73a3f44eefc8fa567f18aca69/raven/raven.go#L172-L180 |
147,227 | kisielk/raven-go | raven/raven.go | CaptureMessagef | func (client Client) CaptureMessagef(format string, args ...interface{}) (string, error) {
return client.CaptureMessage(fmt.Sprintf(format, args...))
} | go | func (client Client) CaptureMessagef(format string, args ...interface{}) (string, error) {
return client.CaptureMessage(fmt.Sprintf(format, args...))
} | [
"func",
"(",
"client",
"Client",
")",
"CaptureMessagef",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"client",
".",
"CaptureMessage",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",... | // CaptureMessagef is similar to CaptureMessage except it is using Printf to format the args in
// to the given format string. | [
"CaptureMessagef",
"is",
"similar",
"to",
"CaptureMessage",
"except",
"it",
"is",
"using",
"Printf",
"to",
"format",
"the",
"args",
"in",
"to",
"the",
"given",
"format",
"string",
"."
] | 7a3cb5bc33ce65b73a3f44eefc8fa567f18aca69 | https://github.com/kisielk/raven-go/blob/7a3cb5bc33ce65b73a3f44eefc8fa567f18aca69/raven/raven.go#L184-L186 |
147,228 | kisielk/raven-go | raven/raven.go | Capture | func (client Client) Capture(ev *Event) error {
// Fill in defaults
ev.Project = client.Project
if ev.EventId == "" {
eventId, err := uuid4()
if err != nil {
return err
}
ev.EventId = eventId
}
if ev.Level == "" {
ev.Level = "error"
}
if ev.Logger == "" {
ev.Logger = "root"
}
if ev.Timestamp == ... | go | func (client Client) Capture(ev *Event) error {
// Fill in defaults
ev.Project = client.Project
if ev.EventId == "" {
eventId, err := uuid4()
if err != nil {
return err
}
ev.EventId = eventId
}
if ev.Level == "" {
ev.Level = "error"
}
if ev.Logger == "" {
ev.Logger = "root"
}
if ev.Timestamp == ... | [
"func",
"(",
"client",
"Client",
")",
"Capture",
"(",
"ev",
"*",
"Event",
")",
"error",
"{",
"// Fill in defaults",
"ev",
".",
"Project",
"=",
"client",
".",
"Project",
"\n",
"if",
"ev",
".",
"EventId",
"==",
"\"",
"\"",
"{",
"eventId",
",",
"err",
"... | // Capture sends the given event to Sentry.
// Fields which are left blank are populated with default values. | [
"Capture",
"sends",
"the",
"given",
"event",
"to",
"Sentry",
".",
"Fields",
"which",
"are",
"left",
"blank",
"are",
"populated",
"with",
"default",
"values",
"."
] | 7a3cb5bc33ce65b73a3f44eefc8fa567f18aca69 | https://github.com/kisielk/raven-go/blob/7a3cb5bc33ce65b73a3f44eefc8fa567f18aca69/raven/raven.go#L190-L232 |
147,229 | kisielk/raven-go | raven/raven.go | send | func (client Client) send(packet []byte, timestamp time.Time) (err error) {
apiURL := *client.URL
apiURL.Path = path.Join(apiURL.Path, "/api/"+client.Project+"/store")
apiURL.Path += "/"
location := apiURL.String()
buf := bytes.NewBuffer(packet)
req, err := http.NewRequest("POST", location, buf)
if err != nil {... | go | func (client Client) send(packet []byte, timestamp time.Time) (err error) {
apiURL := *client.URL
apiURL.Path = path.Join(apiURL.Path, "/api/"+client.Project+"/store")
apiURL.Path += "/"
location := apiURL.String()
buf := bytes.NewBuffer(packet)
req, err := http.NewRequest("POST", location, buf)
if err != nil {... | [
"func",
"(",
"client",
"Client",
")",
"send",
"(",
"packet",
"[",
"]",
"byte",
",",
"timestamp",
"time",
".",
"Time",
")",
"(",
"err",
"error",
")",
"{",
"apiURL",
":=",
"*",
"client",
".",
"URL",
"\n",
"apiURL",
".",
"Path",
"=",
"path",
".",
"J... | // sends a packet to the sentry server with a given timestamp | [
"sends",
"a",
"packet",
"to",
"the",
"sentry",
"server",
"with",
"a",
"given",
"timestamp"
] | 7a3cb5bc33ce65b73a3f44eefc8fa567f18aca69 | https://github.com/kisielk/raven-go/blob/7a3cb5bc33ce65b73a3f44eefc8fa567f18aca69/raven/raven.go#L235-L267 |
147,230 | arschles/go-bindata-html-template | template.go | Funcs | func (t *Template) Funcs(funcMap FuncMap) *Template {
return t.replaceTmpl(t.tmpl.Funcs(template.FuncMap(funcMap)))
} | go | func (t *Template) Funcs(funcMap FuncMap) *Template {
return t.replaceTmpl(t.tmpl.Funcs(template.FuncMap(funcMap)))
} | [
"func",
"(",
"t",
"*",
"Template",
")",
"Funcs",
"(",
"funcMap",
"FuncMap",
")",
"*",
"Template",
"{",
"return",
"t",
".",
"replaceTmpl",
"(",
"t",
".",
"tmpl",
".",
"Funcs",
"(",
"template",
".",
"FuncMap",
"(",
"funcMap",
")",
")",
")",
"\n",
"}"... | // Funcs is a proxy to the underlying template's Funcs function | [
"Funcs",
"is",
"a",
"proxy",
"to",
"the",
"underlying",
"template",
"s",
"Funcs",
"function"
] | 839a6918b9ff535f95246ef0f43edfdb4ed186be | https://github.com/arschles/go-bindata-html-template/blob/839a6918b9ff535f95246ef0f43edfdb4ed186be/template.go#L56-L58 |
147,231 | arschles/go-bindata-html-template | template.go | Delims | func (t *Template) Delims(left, right string) *Template {
return t.replaceTmpl(t.tmpl.Delims(left, right))
} | go | func (t *Template) Delims(left, right string) *Template {
return t.replaceTmpl(t.tmpl.Delims(left, right))
} | [
"func",
"(",
"t",
"*",
"Template",
")",
"Delims",
"(",
"left",
",",
"right",
"string",
")",
"*",
"Template",
"{",
"return",
"t",
".",
"replaceTmpl",
"(",
"t",
".",
"tmpl",
".",
"Delims",
"(",
"left",
",",
"right",
")",
")",
"\n",
"}"
] | //Delims is a proxy to the underlying template's Delims function | [
"Delims",
"is",
"a",
"proxy",
"to",
"the",
"underlying",
"template",
"s",
"Delims",
"function"
] | 839a6918b9ff535f95246ef0f43edfdb4ed186be | https://github.com/arschles/go-bindata-html-template/blob/839a6918b9ff535f95246ef0f43edfdb4ed186be/template.go#L61-L63 |
147,232 | arschles/go-bindata-html-template | template.go | Parse | func (t *Template) Parse(filename string) (*Template, error) {
tmplBytes, err := t.file(filename)
if err != nil {
return nil, err
}
newTmpl, err := t.tmpl.Parse(string(tmplBytes))
if err != nil {
return nil, err
}
return t.replaceTmpl(newTmpl), nil
} | go | func (t *Template) Parse(filename string) (*Template, error) {
tmplBytes, err := t.file(filename)
if err != nil {
return nil, err
}
newTmpl, err := t.tmpl.Parse(string(tmplBytes))
if err != nil {
return nil, err
}
return t.replaceTmpl(newTmpl), nil
} | [
"func",
"(",
"t",
"*",
"Template",
")",
"Parse",
"(",
"filename",
"string",
")",
"(",
"*",
"Template",
",",
"error",
")",
"{",
"tmplBytes",
",",
"err",
":=",
"t",
".",
"file",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"... | // Parse looks up the filename in the underlying Asset store,
// then calls the underlying template's Parse function with the result.
// returns an error if the file wasn't found or the Parse call failed | [
"Parse",
"looks",
"up",
"the",
"filename",
"in",
"the",
"underlying",
"Asset",
"store",
"then",
"calls",
"the",
"underlying",
"template",
"s",
"Parse",
"function",
"with",
"the",
"result",
".",
"returns",
"an",
"error",
"if",
"the",
"file",
"wasn",
"t",
"f... | 839a6918b9ff535f95246ef0f43edfdb4ed186be | https://github.com/arschles/go-bindata-html-template/blob/839a6918b9ff535f95246ef0f43edfdb4ed186be/template.go#L68-L78 |
147,233 | arschles/go-bindata-html-template | template.go | ParseFiles | func (t *Template) ParseFiles(filenames ...string) (*Template, error) {
fileBytes := []byte{}
for _, filename := range filenames {
tmplBytes, err := t.file(filename)
if err != nil {
return nil, err
}
fileBytes = append(fileBytes, tmplBytes...)
}
newTmpl, err := t.tmpl.Parse(string(fileBytes))
if err != ... | go | func (t *Template) ParseFiles(filenames ...string) (*Template, error) {
fileBytes := []byte{}
for _, filename := range filenames {
tmplBytes, err := t.file(filename)
if err != nil {
return nil, err
}
fileBytes = append(fileBytes, tmplBytes...)
}
newTmpl, err := t.tmpl.Parse(string(fileBytes))
if err != ... | [
"func",
"(",
"t",
"*",
"Template",
")",
"ParseFiles",
"(",
"filenames",
"...",
"string",
")",
"(",
"*",
"Template",
",",
"error",
")",
"{",
"fileBytes",
":=",
"[",
"]",
"byte",
"{",
"}",
"\n",
"for",
"_",
",",
"filename",
":=",
"range",
"filenames",
... | // ParseFiles looks up all of the filenames in the underlying Asset store,
// concatenates the file contents together, then calls the underlying template's
// Parse function with the result. returns an error if any of the files
// don't exist or the underlying Parse call failed. | [
"ParseFiles",
"looks",
"up",
"all",
"of",
"the",
"filenames",
"in",
"the",
"underlying",
"Asset",
"store",
"concatenates",
"the",
"file",
"contents",
"together",
"then",
"calls",
"the",
"underlying",
"template",
"s",
"Parse",
"function",
"with",
"the",
"result",... | 839a6918b9ff535f95246ef0f43edfdb4ed186be | https://github.com/arschles/go-bindata-html-template/blob/839a6918b9ff535f95246ef0f43edfdb4ed186be/template.go#L84-L98 |
147,234 | arschles/go-bindata-html-template | template.go | Execute | func (t *Template) Execute(w io.Writer, data interface{}) error {
return t.tmpl.Execute(w, data)
} | go | func (t *Template) Execute(w io.Writer, data interface{}) error {
return t.tmpl.Execute(w, data)
} | [
"func",
"(",
"t",
"*",
"Template",
")",
"Execute",
"(",
"w",
"io",
".",
"Writer",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"t",
".",
"tmpl",
".",
"Execute",
"(",
"w",
",",
"data",
")",
"\n",
"}"
] | // Execute is a proxy to the underlying template's Execute function | [
"Execute",
"is",
"a",
"proxy",
"to",
"the",
"underlying",
"template",
"s",
"Execute",
"function"
] | 839a6918b9ff535f95246ef0f43edfdb4ed186be | https://github.com/arschles/go-bindata-html-template/blob/839a6918b9ff535f95246ef0f43edfdb4ed186be/template.go#L101-L103 |
147,235 | arschles/go-bindata-html-template | template.go | ExecuteTemplate | func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error {
return t.tmpl.ExecuteTemplate(wr, name, data)
} | go | func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error {
return t.tmpl.ExecuteTemplate(wr, name, data)
} | [
"func",
"(",
"t",
"*",
"Template",
")",
"ExecuteTemplate",
"(",
"wr",
"io",
".",
"Writer",
",",
"name",
"string",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"t",
".",
"tmpl",
".",
"ExecuteTemplate",
"(",
"wr",
",",
"name",
",",
... | // ExecuteTemplate is a proxy to the underlying template's ExecuteTemplate function | [
"ExecuteTemplate",
"is",
"a",
"proxy",
"to",
"the",
"underlying",
"template",
"s",
"ExecuteTemplate",
"function"
] | 839a6918b9ff535f95246ef0f43edfdb4ed186be | https://github.com/arschles/go-bindata-html-template/blob/839a6918b9ff535f95246ef0f43edfdb4ed186be/template.go#L106-L108 |
147,236 | arschles/go-bindata-html-template | template.go | replaceTmpl | func (t *Template) replaceTmpl(tmpl *template.Template) *Template {
t.tmpl = tmpl
return t
} | go | func (t *Template) replaceTmpl(tmpl *template.Template) *Template {
t.tmpl = tmpl
return t
} | [
"func",
"(",
"t",
"*",
"Template",
")",
"replaceTmpl",
"(",
"tmpl",
"*",
"template",
".",
"Template",
")",
"*",
"Template",
"{",
"t",
".",
"tmpl",
"=",
"tmpl",
"\n",
"return",
"t",
"\n",
"}"
] | // replaceTmpl is a convenience function to replace t.tmpl with the given tmpl | [
"replaceTmpl",
"is",
"a",
"convenience",
"function",
"to",
"replace",
"t",
".",
"tmpl",
"with",
"the",
"given",
"tmpl"
] | 839a6918b9ff535f95246ef0f43edfdb4ed186be | https://github.com/arschles/go-bindata-html-template/blob/839a6918b9ff535f95246ef0f43edfdb4ed186be/template.go#L111-L114 |
147,237 | arschles/go-bindata-html-template | template.go | file | func (t *Template) file(fileName string) ([]byte, error) {
tmplBytes, err := t.AssetFunc(fileName)
if err != nil {
return nil, err
}
return tmplBytes, nil
} | go | func (t *Template) file(fileName string) ([]byte, error) {
tmplBytes, err := t.AssetFunc(fileName)
if err != nil {
return nil, err
}
return tmplBytes, nil
} | [
"func",
"(",
"t",
"*",
"Template",
")",
"file",
"(",
"fileName",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"tmplBytes",
",",
"err",
":=",
"t",
".",
"AssetFunc",
"(",
"fileName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retur... | // file is a convenience function to look up fileName using t.AssetFunc, then
// return the contents or an error if the file doesn't exist | [
"file",
"is",
"a",
"convenience",
"function",
"to",
"look",
"up",
"fileName",
"using",
"t",
".",
"AssetFunc",
"then",
"return",
"the",
"contents",
"or",
"an",
"error",
"if",
"the",
"file",
"doesn",
"t",
"exist"
] | 839a6918b9ff535f95246ef0f43edfdb4ed186be | https://github.com/arschles/go-bindata-html-template/blob/839a6918b9ff535f95246ef0f43edfdb4ed186be/template.go#L118-L124 |
147,238 | rubiojr/go-vhd | vhd/vhd.go | TimestampTime | func (h *VHDHeader) TimestampTime() time.Time {
tstamp := binary.BigEndian.Uint32(h.Timestamp[:])
return time.Unix(int64(946684800+tstamp), 0)
} | go | func (h *VHDHeader) TimestampTime() time.Time {
tstamp := binary.BigEndian.Uint32(h.Timestamp[:])
return time.Unix(int64(946684800+tstamp), 0)
} | [
"func",
"(",
"h",
"*",
"VHDHeader",
")",
"TimestampTime",
"(",
")",
"time",
".",
"Time",
"{",
"tstamp",
":=",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"h",
".",
"Timestamp",
"[",
":",
"]",
")",
"\n",
"return",
"time",
".",
"Unix",
"(",
"int6... | // Return the timestamp of the header | [
"Return",
"the",
"timestamp",
"of",
"the",
"header"
] | 0bfd3b39853cdde5762efda92289f14b0ac0491b | https://github.com/rubiojr/go-vhd/blob/0bfd3b39853cdde5762efda92289f14b0ac0491b/vhd/vhd.go#L132-L135 |
147,239 | m4rw3r/uuid | uuid.go | FromString | func FromString(str string) (UUID, error) {
u := UUID{}
err := u.SetString(str)
return u, err
} | go | func FromString(str string) (UUID, error) {
u := UUID{}
err := u.SetString(str)
return u, err
} | [
"func",
"FromString",
"(",
"str",
"string",
")",
"(",
"UUID",
",",
"error",
")",
"{",
"u",
":=",
"UUID",
"{",
"}",
"\n\n",
"err",
":=",
"u",
".",
"SetString",
"(",
"str",
")",
"\n\n",
"return",
"u",
",",
"err",
"\n",
"}"
] | // FromString reads a UUID into a new UUID instance. | [
"FromString",
"reads",
"a",
"UUID",
"into",
"a",
"new",
"UUID",
"instance",
"."
] | 00c72d48d5aaaf3058e26d9641164c43ba239f33 | https://github.com/m4rw3r/uuid/blob/00c72d48d5aaaf3058e26d9641164c43ba239f33/uuid.go#L147-L153 |
147,240 | m4rw3r/uuid | uuid.go | MustFromString | func MustFromString(str string) UUID {
u, err := FromString(str)
if err != nil {
panic(err)
}
return u
} | go | func MustFromString(str string) UUID {
u, err := FromString(str)
if err != nil {
panic(err)
}
return u
} | [
"func",
"MustFromString",
"(",
"str",
"string",
")",
"UUID",
"{",
"u",
",",
"err",
":=",
"FromString",
"(",
"str",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"u",
"\n",
"}"
] | // MustFromString reads a UUID into a new UUID instance,
// panicing on failure. | [
"MustFromString",
"reads",
"a",
"UUID",
"into",
"a",
"new",
"UUID",
"instance",
"panicing",
"on",
"failure",
"."
] | 00c72d48d5aaaf3058e26d9641164c43ba239f33 | https://github.com/m4rw3r/uuid/blob/00c72d48d5aaaf3058e26d9641164c43ba239f33/uuid.go#L157-L164 |
147,241 | m4rw3r/uuid | uuid.go | MaybeFromString | func MaybeFromString(str string) UUID {
u, err := FromString(str)
if err != nil {
return zero
}
return u
} | go | func MaybeFromString(str string) UUID {
u, err := FromString(str)
if err != nil {
return zero
}
return u
} | [
"func",
"MaybeFromString",
"(",
"str",
"string",
")",
"UUID",
"{",
"u",
",",
"err",
":=",
"FromString",
"(",
"str",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"zero",
"\n",
"}",
"\n\n",
"return",
"u",
"\n",
"}"
] | // MaybeFromString reads a UUID into a new UUID instance,
// setting the instance to zero if it fails. | [
"MaybeFromString",
"reads",
"a",
"UUID",
"into",
"a",
"new",
"UUID",
"instance",
"setting",
"the",
"instance",
"to",
"zero",
"if",
"it",
"fails",
"."
] | 00c72d48d5aaaf3058e26d9641164c43ba239f33 | https://github.com/m4rw3r/uuid/blob/00c72d48d5aaaf3058e26d9641164c43ba239f33/uuid.go#L168-L175 |
147,242 | m4rw3r/uuid | uuid.go | SetString | func (u *UUID) SetString(str string) error {
/* NOTE: Duplicate of ReadBytes, with different method signature, to
prevent unnecessary copying of memory due to string <-> []byte conversion */
i := 0
x := 0
c := len(str)
for x < c {
a := hexchar2byte[str[x]]
if a == 255 {
// Invalid char, skip
x++
... | go | func (u *UUID) SetString(str string) error {
/* NOTE: Duplicate of ReadBytes, with different method signature, to
prevent unnecessary copying of memory due to string <-> []byte conversion */
i := 0
x := 0
c := len(str)
for x < c {
a := hexchar2byte[str[x]]
if a == 255 {
// Invalid char, skip
x++
... | [
"func",
"(",
"u",
"*",
"UUID",
")",
"SetString",
"(",
"str",
"string",
")",
"error",
"{",
"/* NOTE: Duplicate of ReadBytes, with different method signature, to\n\t prevent unnecessary copying of memory due to string <-> []byte conversion */",
"i",
":=",
"0",
"\n",
"x",
":=",
... | // SetString reads the supplied string-representation of the UUID into the instance.
// On invalid UUID an error is returned and the UUID state will be undetermined.
// This function will ignore all non-hexadecimal digits. | [
"SetString",
"reads",
"the",
"supplied",
"string",
"-",
"representation",
"of",
"the",
"UUID",
"into",
"the",
"instance",
".",
"On",
"invalid",
"UUID",
"an",
"error",
"is",
"returned",
"and",
"the",
"UUID",
"state",
"will",
"be",
"undetermined",
".",
"This",... | 00c72d48d5aaaf3058e26d9641164c43ba239f33 | https://github.com/m4rw3r/uuid/blob/00c72d48d5aaaf3058e26d9641164c43ba239f33/uuid.go#L180-L224 |
147,243 | m4rw3r/uuid | uuid.go | ReadBytes | func (u *UUID) ReadBytes(str []byte) error {
/* NOTE: Duplicate of SetString, with different method signature, to
prevent unnecessary copying of memory due to string <-> []byte conversion */
i := 0
x := 0
c := len(str)
for x < c {
a := hexchar2byte[str[x]]
if a == 255 {
// Invalid char, skip
x++
... | go | func (u *UUID) ReadBytes(str []byte) error {
/* NOTE: Duplicate of SetString, with different method signature, to
prevent unnecessary copying of memory due to string <-> []byte conversion */
i := 0
x := 0
c := len(str)
for x < c {
a := hexchar2byte[str[x]]
if a == 255 {
// Invalid char, skip
x++
... | [
"func",
"(",
"u",
"*",
"UUID",
")",
"ReadBytes",
"(",
"str",
"[",
"]",
"byte",
")",
"error",
"{",
"/* NOTE: Duplicate of SetString, with different method signature, to\n\t prevent unnecessary copying of memory due to string <-> []byte conversion */",
"i",
":=",
"0",
"\n",
"... | // ReadBytes reads the supplied byte array of hexadecimal characters representing
// a UUID into the instance.
// On invalid UUID an error is returned and the UUID state will be undetermined.
// This function will ignore all non-hexadecimal digits. | [
"ReadBytes",
"reads",
"the",
"supplied",
"byte",
"array",
"of",
"hexadecimal",
"characters",
"representing",
"a",
"UUID",
"into",
"the",
"instance",
".",
"On",
"invalid",
"UUID",
"an",
"error",
"is",
"returned",
"and",
"the",
"UUID",
"state",
"will",
"be",
"... | 00c72d48d5aaaf3058e26d9641164c43ba239f33 | https://github.com/m4rw3r/uuid/blob/00c72d48d5aaaf3058e26d9641164c43ba239f33/uuid.go#L230-L274 |
147,244 | m4rw3r/uuid | uuid.go | String | func (u UUID) String() string {
/* It is a lot (~10x) faster to allocate a byte slice of specific size and
then use a lookup table to write the characters to the byte-array and
finally cast to string instead of using fmt.Sprintf() */
/* Slightly faster to not use make([]byte, 36), guessing either call
ove... | go | func (u UUID) String() string {
/* It is a lot (~10x) faster to allocate a byte slice of specific size and
then use a lookup table to write the characters to the byte-array and
finally cast to string instead of using fmt.Sprintf() */
/* Slightly faster to not use make([]byte, 36), guessing either call
ove... | [
"func",
"(",
"u",
"UUID",
")",
"String",
"(",
")",
"string",
"{",
"/* It is a lot (~10x) faster to allocate a byte slice of specific size and\n\t then use a lookup table to write the characters to the byte-array and\n\t finally cast to string instead of using fmt.Sprintf() */",
"/* Slightl... | // String returns the string representation of the UUID.
// This method returns the canonical representation of
// ``xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx``. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"the",
"UUID",
".",
"This",
"method",
"returns",
"the",
"canonical",
"representation",
"of",
"xxxxxxxx",
"-",
"xxxx",
"-",
"Mxxx",
"-",
"Nxxx",
"-",
"xxxxxxxxxxxx",
"."
] | 00c72d48d5aaaf3058e26d9641164c43ba239f33 | https://github.com/m4rw3r/uuid/blob/00c72d48d5aaaf3058e26d9641164c43ba239f33/uuid.go#L289-L317 |
147,245 | Financial-Times/go-logger | exported.go | WithError | func WithError(err error) LogEntry {
return &logEntry{log.WithField(logrus.ErrorKey, err)}
} | go | func WithError(err error) LogEntry {
return &logEntry{log.WithField(logrus.ErrorKey, err)}
} | [
"func",
"WithError",
"(",
"err",
"error",
")",
"LogEntry",
"{",
"return",
"&",
"logEntry",
"{",
"log",
".",
"WithField",
"(",
"logrus",
".",
"ErrorKey",
",",
"err",
")",
"}",
"\n",
"}"
] | // WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key. | [
"WithError",
"creates",
"an",
"entry",
"from",
"the",
"standard",
"logger",
"and",
"adds",
"an",
"error",
"to",
"it",
"using",
"the",
"value",
"defined",
"in",
"ErrorKey",
"as",
"key",
"."
] | febee6537e90971bab6f6fe60b71b4a0562dcab3 | https://github.com/Financial-Times/go-logger/blob/febee6537e90971bab6f6fe60b71b4a0562dcab3/exported.go#L6-L8 |
147,246 | m4rw3r/uuid | sql.go | Scan | func (u *UUID) Scan(val interface{}) error {
if s, ok := val.(string); ok {
return u.SetString(s)
}
if b, ok := val.([]byte); ok {
return u.ReadBytes(b)
}
return &ErrInvalidType{reflect.TypeOf(val)}
} | go | func (u *UUID) Scan(val interface{}) error {
if s, ok := val.(string); ok {
return u.SetString(s)
}
if b, ok := val.([]byte); ok {
return u.ReadBytes(b)
}
return &ErrInvalidType{reflect.TypeOf(val)}
} | [
"func",
"(",
"u",
"*",
"UUID",
")",
"Scan",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"s",
",",
"ok",
":=",
"val",
".",
"(",
"string",
")",
";",
"ok",
"{",
"return",
"u",
".",
"SetString",
"(",
"s",
")",
"\n",
"}",
"\n",
"... | // Scan scans a uuid from the given interface instance.
// If scanning fails the state of the UUID is undetermined. | [
"Scan",
"scans",
"a",
"uuid",
"from",
"the",
"given",
"interface",
"instance",
".",
"If",
"scanning",
"fails",
"the",
"state",
"of",
"the",
"UUID",
"is",
"undetermined",
"."
] | 00c72d48d5aaaf3058e26d9641164c43ba239f33 | https://github.com/m4rw3r/uuid/blob/00c72d48d5aaaf3058e26d9641164c43ba239f33/sql.go#L24-L33 |
147,247 | m4rw3r/uuid | sql.go | Scan | func (nu *NullUUID) Scan(val interface{}) error {
if val == nil {
nu.UUID, nu.Valid = [16]byte{}, false
return nil
}
nu.Valid = true
return nu.UUID.Scan(val)
} | go | func (nu *NullUUID) Scan(val interface{}) error {
if val == nil {
nu.UUID, nu.Valid = [16]byte{}, false
return nil
}
nu.Valid = true
return nu.UUID.Scan(val)
} | [
"func",
"(",
"nu",
"*",
"NullUUID",
")",
"Scan",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"val",
"==",
"nil",
"{",
"nu",
".",
"UUID",
",",
"nu",
".",
"Valid",
"=",
"[",
"16",
"]",
"byte",
"{",
"}",
",",
"false",
"\n\n",
"re... | // Scan scans a uuid or null from the given value.
// If the supplied value is nil, Valid will be set to false and the
// UUID will be zeroed. | [
"Scan",
"scans",
"a",
"uuid",
"or",
"null",
"from",
"the",
"given",
"value",
".",
"If",
"the",
"supplied",
"value",
"is",
"nil",
"Valid",
"will",
"be",
"set",
"to",
"false",
"and",
"the",
"UUID",
"will",
"be",
"zeroed",
"."
] | 00c72d48d5aaaf3058e26d9641164c43ba239f33 | https://github.com/m4rw3r/uuid/blob/00c72d48d5aaaf3058e26d9641164c43ba239f33/sql.go#L44-L54 |
147,248 | m4rw3r/uuid | sql.go | Value | func (nu NullUUID) Value() (driver.Value, error) {
if !nu.Valid {
return nil, nil
}
// The return here causes a second allocation because of the driver.Value interface{} box
return nu.UUID.String(), nil
} | go | func (nu NullUUID) Value() (driver.Value, error) {
if !nu.Valid {
return nil, nil
}
// The return here causes a second allocation because of the driver.Value interface{} box
return nu.UUID.String(), nil
} | [
"func",
"(",
"nu",
"NullUUID",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"if",
"!",
"nu",
".",
"Valid",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"// The return here causes a second allocation because of the driv... | // Value gives the database driver representation of the UUID or NULL. | [
"Value",
"gives",
"the",
"database",
"driver",
"representation",
"of",
"the",
"UUID",
"or",
"NULL",
"."
] | 00c72d48d5aaaf3058e26d9641164c43ba239f33 | https://github.com/m4rw3r/uuid/blob/00c72d48d5aaaf3058e26d9641164c43ba239f33/sql.go#L57-L64 |
147,249 | m4rw3r/uuid | marshal.go | MarshalText | func (u UUID) MarshalText() ([]byte, error) {
/* Inlined UUID.String() implementation, cannot reuse the one from
UUID.String() as that cast will force an additional memory
allocation because current version the compiler (go 1.3.1) cannot
realize that the data pointer of the result of the UUID.String() call... | go | func (u UUID) MarshalText() ([]byte, error) {
/* Inlined UUID.String() implementation, cannot reuse the one from
UUID.String() as that cast will force an additional memory
allocation because current version the compiler (go 1.3.1) cannot
realize that the data pointer of the result of the UUID.String() call... | [
"func",
"(",
"u",
"UUID",
")",
"MarshalText",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"/* Inlined UUID.String() implementation, cannot reuse the one from\n\t UUID.String() as that cast will force an additional memory\n\t allocation because current version the com... | // MarshalText returns the string-representation of the UUID as a byte-array. | [
"MarshalText",
"returns",
"the",
"string",
"-",
"representation",
"of",
"the",
"UUID",
"as",
"a",
"byte",
"-",
"array",
"."
] | 00c72d48d5aaaf3058e26d9641164c43ba239f33 | https://github.com/m4rw3r/uuid/blob/00c72d48d5aaaf3058e26d9641164c43ba239f33/marshal.go#L10-L40 |
147,250 | m4rw3r/uuid | marshal.go | UnmarshalJSON | func (u *UUID) UnmarshalJSON(data []byte) error {
return u.ReadBytes(data[1 : len(data)-1])
} | go | func (u *UUID) UnmarshalJSON(data []byte) error {
return u.ReadBytes(data[1 : len(data)-1])
} | [
"func",
"(",
"u",
"*",
"UUID",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"u",
".",
"ReadBytes",
"(",
"data",
"[",
"1",
":",
"len",
"(",
"data",
")",
"-",
"1",
"]",
")",
"\n",
"}"
] | // UnmarshalJSON reads an UUID from a JSON-string into the UUID instance.
// If this fails the state of the UUID is undetermined. | [
"UnmarshalJSON",
"reads",
"an",
"UUID",
"from",
"a",
"JSON",
"-",
"string",
"into",
"the",
"UUID",
"instance",
".",
"If",
"this",
"fails",
"the",
"state",
"of",
"the",
"UUID",
"is",
"undetermined",
"."
] | 00c72d48d5aaaf3058e26d9641164c43ba239f33 | https://github.com/m4rw3r/uuid/blob/00c72d48d5aaaf3058e26d9641164c43ba239f33/marshal.go#L82-L84 |
147,251 | m4rw3r/uuid | marshal.go | MarshalJSON | func (n NullUUID) MarshalJSON() ([]byte, error) {
if n.Valid {
return n.UUID.MarshalJSON()
} else {
return nullByteString, nil
}
} | go | func (n NullUUID) MarshalJSON() ([]byte, error) {
if n.Valid {
return n.UUID.MarshalJSON()
} else {
return nullByteString, nil
}
} | [
"func",
"(",
"n",
"NullUUID",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"n",
".",
"Valid",
"{",
"return",
"n",
".",
"UUID",
".",
"MarshalJSON",
"(",
")",
"\n",
"}",
"else",
"{",
"return",
"nullByteString",
... | // MarshalJSON marshals a potentially null UUID into either a string-
// representation of the UUID or the null-constant depending on the
// Valid property. | [
"MarshalJSON",
"marshals",
"a",
"potentially",
"null",
"UUID",
"into",
"either",
"a",
"string",
"-",
"representation",
"of",
"the",
"UUID",
"or",
"the",
"null",
"-",
"constant",
"depending",
"on",
"the",
"Valid",
"property",
"."
] | 00c72d48d5aaaf3058e26d9641164c43ba239f33 | https://github.com/m4rw3r/uuid/blob/00c72d48d5aaaf3058e26d9641164c43ba239f33/marshal.go#L89-L95 |
147,252 | cloudfoundry/gosteno | syslog/syslog.go | Dial | func Dial(network, raddr string, priority Priority, prefix string) (w *Writer, err error) {
if prefix == "" {
prefix = os.Args[0]
}
var conn serverConn
if network == "" {
conn, err = unixSyslog()
} else {
var c net.Conn
c, err = net.Dial(network, raddr)
conn = netConn{c}
}
return &Writer{priority, pref... | go | func Dial(network, raddr string, priority Priority, prefix string) (w *Writer, err error) {
if prefix == "" {
prefix = os.Args[0]
}
var conn serverConn
if network == "" {
conn, err = unixSyslog()
} else {
var c net.Conn
c, err = net.Dial(network, raddr)
conn = netConn{c}
}
return &Writer{priority, pref... | [
"func",
"Dial",
"(",
"network",
",",
"raddr",
"string",
",",
"priority",
"Priority",
",",
"prefix",
"string",
")",
"(",
"w",
"*",
"Writer",
",",
"err",
"error",
")",
"{",
"if",
"prefix",
"==",
"\"",
"\"",
"{",
"prefix",
"=",
"os",
".",
"Args",
"[",... | // Dial establishes a connection to a log daemon by connecting
// to address raddr on the network net.
// Each write to the returned writer sends a log message with
// the given priority and prefix. | [
"Dial",
"establishes",
"a",
"connection",
"to",
"a",
"log",
"daemon",
"by",
"connecting",
"to",
"address",
"raddr",
"on",
"the",
"network",
"net",
".",
"Each",
"write",
"to",
"the",
"returned",
"writer",
"sends",
"a",
"log",
"message",
"with",
"the",
"give... | 0c8581caea35ac903728230e447792e2365dcc34 | https://github.com/cloudfoundry/gosteno/blob/0c8581caea35ac903728230e447792e2365dcc34/syslog/syslog.go#L64-L77 |
147,253 | cloudfoundry/gosteno | syslog/syslog.go | Crit | func (w *Writer) Crit(m string) (err error) {
_, err = w.writeString(LOG_CRIT, m)
return err
} | go | func (w *Writer) Crit(m string) (err error) {
_, err = w.writeString(LOG_CRIT, m)
return err
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"Crit",
"(",
"m",
"string",
")",
"(",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"w",
".",
"writeString",
"(",
"LOG_CRIT",
",",
"m",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Crit logs a message using the LOG_CRIT priority. | [
"Crit",
"logs",
"a",
"message",
"using",
"the",
"LOG_CRIT",
"priority",
"."
] | 0c8581caea35ac903728230e447792e2365dcc34 | https://github.com/cloudfoundry/gosteno/blob/0c8581caea35ac903728230e447792e2365dcc34/syslog/syslog.go#L106-L109 |
147,254 | sec51/convert | common.go | Round | func Round(n float64) uint64 {
if n < 0 {
return uint64(math.Ceil(n - 0.5))
}
return uint64(math.Floor(n + 0.5))
} | go | func Round(n float64) uint64 {
if n < 0 {
return uint64(math.Ceil(n - 0.5))
}
return uint64(math.Floor(n + 0.5))
} | [
"func",
"Round",
"(",
"n",
"float64",
")",
"uint64",
"{",
"if",
"n",
"<",
"0",
"{",
"return",
"uint64",
"(",
"math",
".",
"Ceil",
"(",
"n",
"-",
"0.5",
")",
")",
"\n",
"}",
"\n",
"return",
"uint64",
"(",
"math",
".",
"Floor",
"(",
"n",
"+",
"... | // Helper function which rounds the float to the nearest integet | [
"Helper",
"function",
"which",
"rounds",
"the",
"float",
"to",
"the",
"nearest",
"integet"
] | ebe586d879515e070b9e374616bdd2db2fc4b8f6 | https://github.com/sec51/convert/blob/ebe586d879515e070b9e374616bdd2db2fc4b8f6/common.go#L8-L13 |
147,255 | kayac/parallel-benchmark | benchmark/benchmark.go | RunFunc | func RunFunc(benchmarkFunc func() int, duration time.Duration, c int) *Result {
workers := make([]Worker, c)
for i := 0; i < c; i++ {
workers[i] = &funcWorker{ID: i, benchmarkFunc: benchmarkFunc}
}
return Run(workers, duration)
} | go | func RunFunc(benchmarkFunc func() int, duration time.Duration, c int) *Result {
workers := make([]Worker, c)
for i := 0; i < c; i++ {
workers[i] = &funcWorker{ID: i, benchmarkFunc: benchmarkFunc}
}
return Run(workers, duration)
} | [
"func",
"RunFunc",
"(",
"benchmarkFunc",
"func",
"(",
")",
"int",
",",
"duration",
"time",
".",
"Duration",
",",
"c",
"int",
")",
"*",
"Result",
"{",
"workers",
":=",
"make",
"(",
"[",
"]",
"Worker",
",",
"c",
")",
"\n",
"for",
"i",
":=",
"0",
";... | // RunFunc ... benchmark by function | [
"RunFunc",
"...",
"benchmark",
"by",
"function"
] | 8767c01bdc444833d8f996e2a97a0604a458c1ff | https://github.com/kayac/parallel-benchmark/blob/8767c01bdc444833d8f996e2a97a0604a458c1ff/benchmark/benchmark.go#L58-L64 |
147,256 | kayac/parallel-benchmark | benchmark/benchmark.go | Run | func Run(workers []Worker, duration time.Duration) *Result {
debug = os.Getenv("DEBUG") != ""
c := len(workers)
log.Printf("starting benchmark: concurrency: %d, time: %s, GOMAXPROCS: %d", c, duration, runtime.GOMAXPROCS(0))
startCh := make(chan bool, c)
readyCh := make(chan bool, c)
var stopFlag int32
scoreCh :=... | go | func Run(workers []Worker, duration time.Duration) *Result {
debug = os.Getenv("DEBUG") != ""
c := len(workers)
log.Printf("starting benchmark: concurrency: %d, time: %s, GOMAXPROCS: %d", c, duration, runtime.GOMAXPROCS(0))
startCh := make(chan bool, c)
readyCh := make(chan bool, c)
var stopFlag int32
scoreCh :=... | [
"func",
"Run",
"(",
"workers",
"[",
"]",
"Worker",
",",
"duration",
"time",
".",
"Duration",
")",
"*",
"Result",
"{",
"debug",
"=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"!=",
"\"",
"\"",
"\n",
"c",
":=",
"len",
"(",
"workers",
")",
"\n",
... | // Run ... benchmark by workers | [
"Run",
"...",
"benchmark",
"by",
"workers"
] | 8767c01bdc444833d8f996e2a97a0604a458c1ff | https://github.com/kayac/parallel-benchmark/blob/8767c01bdc444833d8f996e2a97a0604a458c1ff/benchmark/benchmark.go#L67-L139 |
147,257 | leonelquinteros/gorand | id.go | init | func init() {
buf, err := GetBytes(9)
if err != nil {
localID = [9]byte{'D', 'e', 'f', 'a', 'u', 'l', 't', 'I', 'D'}
} else {
_, err = io.ReadFull(bytes.NewBuffer(buf), localID[:])
if err != nil {
localID = [9]byte{'D', 'e', 'f', 'a', 'u', 'l', 't', 'I', 'D'}
}
}
} | go | func init() {
buf, err := GetBytes(9)
if err != nil {
localID = [9]byte{'D', 'e', 'f', 'a', 'u', 'l', 't', 'I', 'D'}
} else {
_, err = io.ReadFull(bytes.NewBuffer(buf), localID[:])
if err != nil {
localID = [9]byte{'D', 'e', 'f', 'a', 'u', 'l', 't', 'I', 'D'}
}
}
} | [
"func",
"init",
"(",
")",
"{",
"buf",
",",
"err",
":=",
"GetBytes",
"(",
"9",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"localID",
"=",
"[",
"9",
"]",
"byte",
"{",
"'D'",
",",
"'e'",
",",
"'f'",
",",
"'a'",
",",
"'u'",
",",
"'l'",
",",
"'t'... | // Initializes the value for the local process run identifier | [
"Initializes",
"the",
"value",
"for",
"the",
"local",
"process",
"run",
"identifier"
] | c6864945f54c4dc60dd5d399c0390e85da44a8a8 | https://github.com/leonelquinteros/gorand/blob/c6864945f54c4dc60dd5d399c0390e85da44a8a8/id.go#L12-L22 |
147,258 | gokyle/twofactor | otp.go | FromURL | func FromURL(URL string) (OTP, string, error) {
u, err := url.Parse(URL)
if err != nil {
return nil, "", err
}
if u.Scheme != "otpauth" {
return nil, "", ErrInvalidURL
}
switch {
case u.Host == "totp":
return totpFromURL(u)
case u.Host == "hotp":
return hotpFromURL(u)
default:
return nil, "", ErrIn... | go | func FromURL(URL string) (OTP, string, error) {
u, err := url.Parse(URL)
if err != nil {
return nil, "", err
}
if u.Scheme != "otpauth" {
return nil, "", ErrInvalidURL
}
switch {
case u.Host == "totp":
return totpFromURL(u)
case u.Host == "hotp":
return hotpFromURL(u)
default:
return nil, "", ErrIn... | [
"func",
"FromURL",
"(",
"URL",
"string",
")",
"(",
"OTP",
",",
"string",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"URL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"err",
"... | // FromURL constructs a new OTP token from a URL string. | [
"FromURL",
"constructs",
"a",
"new",
"OTP",
"token",
"from",
"a",
"URL",
"string",
"."
] | 9e0979e07f39c706c9406715d99b6a8f3960ef10 | https://github.com/gokyle/twofactor/blob/9e0979e07f39c706c9406715d99b6a8f3960ef10/otp.go#L68-L86 |
147,259 | gokyle/twofactor | util.go | Pad | func Pad(s string) string {
if !strings.HasSuffix(s, "=") && len(s)%8 != 0 {
for len(s)%8 != 0 {
s += "="
}
}
return s
} | go | func Pad(s string) string {
if !strings.HasSuffix(s, "=") && len(s)%8 != 0 {
for len(s)%8 != 0 {
s += "="
}
}
return s
} | [
"func",
"Pad",
"(",
"s",
"string",
")",
"string",
"{",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"s",
",",
"\"",
"\"",
")",
"&&",
"len",
"(",
"s",
")",
"%",
"8",
"!=",
"0",
"{",
"for",
"len",
"(",
"s",
")",
"%",
"8",
"!=",
"0",
"{",
"s... | // Pad calculates the number of '='s to add to our encoded string
// to make base32.StdEncoding.DecodeString happy | [
"Pad",
"calculates",
"the",
"number",
"of",
"=",
"s",
"to",
"add",
"to",
"our",
"encoded",
"string",
"to",
"make",
"base32",
".",
"StdEncoding",
".",
"DecodeString",
"happy"
] | 9e0979e07f39c706c9406715d99b6a8f3960ef10 | https://github.com/gokyle/twofactor/blob/9e0979e07f39c706c9406715d99b6a8f3960ef10/util.go#L9-L16 |
147,260 | gokyle/twofactor | totp.go | OTPCounter | func (otp *TOTP) OTPCounter() uint64 {
return otp.otpCounter(uint64(time.Now().Unix()))
} | go | func (otp *TOTP) OTPCounter() uint64 {
return otp.otpCounter(uint64(time.Now().Unix()))
} | [
"func",
"(",
"otp",
"*",
"TOTP",
")",
"OTPCounter",
"(",
")",
"uint64",
"{",
"return",
"otp",
".",
"otpCounter",
"(",
"uint64",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(",
")",
")",
")",
"\n",
"}"
] | // OTPCounter returns the current time value for the OTP. | [
"OTPCounter",
"returns",
"the",
"current",
"time",
"value",
"for",
"the",
"OTP",
"."
] | 9e0979e07f39c706c9406715d99b6a8f3960ef10 | https://github.com/gokyle/twofactor/blob/9e0979e07f39c706c9406715d99b6a8f3960ef10/totp.go#L55-L57 |
147,261 | gokyle/twofactor | totp.go | NewTOTPSHA1 | func NewTOTPSHA1(key []byte, start uint64, step uint64, digits int) *TOTP {
return NewTOTP(key, start, step, digits, crypto.SHA1)
} | go | func NewTOTPSHA1(key []byte, start uint64, step uint64, digits int) *TOTP {
return NewTOTP(key, start, step, digits, crypto.SHA1)
} | [
"func",
"NewTOTPSHA1",
"(",
"key",
"[",
"]",
"byte",
",",
"start",
"uint64",
",",
"step",
"uint64",
",",
"digits",
"int",
")",
"*",
"TOTP",
"{",
"return",
"NewTOTP",
"(",
"key",
",",
"start",
",",
"step",
",",
"digits",
",",
"crypto",
".",
"SHA1",
... | // NewTOTPSHA1 will build a new TOTP using SHA-1. | [
"NewTOTPSHA1",
"will",
"build",
"a",
"new",
"TOTP",
"using",
"SHA",
"-",
"1",
"."
] | 9e0979e07f39c706c9406715d99b6a8f3960ef10 | https://github.com/gokyle/twofactor/blob/9e0979e07f39c706c9406715d99b6a8f3960ef10/totp.go#L82-L84 |
147,262 | gokyle/twofactor | totp.go | GenerateGoogleTOTP | func GenerateGoogleTOTP() *TOTP {
key := make([]byte, sha1.Size)
if _, err := io.ReadFull(PRNG, key); err != nil {
return nil
}
return NewTOTP(key, 0, 30, 6, crypto.SHA1)
} | go | func GenerateGoogleTOTP() *TOTP {
key := make([]byte, sha1.Size)
if _, err := io.ReadFull(PRNG, key); err != nil {
return nil
}
return NewTOTP(key, 0, 30, 6, crypto.SHA1)
} | [
"func",
"GenerateGoogleTOTP",
"(",
")",
"*",
"TOTP",
"{",
"key",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"sha1",
".",
"Size",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"PRNG",
",",
"key",
")",
";",
"err",
"!=",
"nil"... | // GenerateGoogleTOTP produces a new TOTP token with the defaults expected by
// Google Authenticator. | [
"GenerateGoogleTOTP",
"produces",
"a",
"new",
"TOTP",
"token",
"with",
"the",
"defaults",
"expected",
"by",
"Google",
"Authenticator",
"."
] | 9e0979e07f39c706c9406715d99b6a8f3960ef10 | https://github.com/gokyle/twofactor/blob/9e0979e07f39c706c9406715d99b6a8f3960ef10/totp.go#L100-L106 |
147,263 | gokyle/twofactor | totp.go | NewGoogleTOTP | func NewGoogleTOTP(secret string) (*TOTP, error) {
key, err := base32.StdEncoding.DecodeString(secret)
if err != nil {
return nil, err
}
return NewTOTP(key, 0, 30, 6, crypto.SHA1), nil
} | go | func NewGoogleTOTP(secret string) (*TOTP, error) {
key, err := base32.StdEncoding.DecodeString(secret)
if err != nil {
return nil, err
}
return NewTOTP(key, 0, 30, 6, crypto.SHA1), nil
} | [
"func",
"NewGoogleTOTP",
"(",
"secret",
"string",
")",
"(",
"*",
"TOTP",
",",
"error",
")",
"{",
"key",
",",
"err",
":=",
"base32",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"secret",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
","... | // NewGoogleTOTP takes a secret as a base32-encoded string and
// returns an appropriate Google Authenticator TOTP instance. | [
"NewGoogleTOTP",
"takes",
"a",
"secret",
"as",
"a",
"base32",
"-",
"encoded",
"string",
"and",
"returns",
"an",
"appropriate",
"Google",
"Authenticator",
"TOTP",
"instance",
"."
] | 9e0979e07f39c706c9406715d99b6a8f3960ef10 | https://github.com/gokyle/twofactor/blob/9e0979e07f39c706c9406715d99b6a8f3960ef10/totp.go#L110-L116 |
147,264 | gokyle/twofactor | totp.go | QR | func (otp *TOTP) QR(label string) ([]byte, error) {
return otp.OATH.QR(otp.Type(), label)
} | go | func (otp *TOTP) QR(label string) ([]byte, error) {
return otp.OATH.QR(otp.Type(), label)
} | [
"func",
"(",
"otp",
"*",
"TOTP",
")",
"QR",
"(",
"label",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"otp",
".",
"OATH",
".",
"QR",
"(",
"otp",
".",
"Type",
"(",
")",
",",
"label",
")",
"\n",
"}"
] | // QR generates a new TOTP QR code. | [
"QR",
"generates",
"a",
"new",
"TOTP",
"QR",
"code",
"."
] | 9e0979e07f39c706c9406715d99b6a8f3960ef10 | https://github.com/gokyle/twofactor/blob/9e0979e07f39c706c9406715d99b6a8f3960ef10/totp.go#L166-L168 |
147,265 | gokyle/twofactor | hotp.go | OTP | func (otp *HOTP) OTP() string {
code := otp.OATH.OTP(otp.counter)
otp.counter++
return code
} | go | func (otp *HOTP) OTP() string {
code := otp.OATH.OTP(otp.counter)
otp.counter++
return code
} | [
"func",
"(",
"otp",
"*",
"HOTP",
")",
"OTP",
"(",
")",
"string",
"{",
"code",
":=",
"otp",
".",
"OATH",
".",
"OTP",
"(",
"otp",
".",
"counter",
")",
"\n",
"otp",
".",
"counter",
"++",
"\n",
"return",
"code",
"\n",
"}"
] | // OTP returns the next OTP and increments the counter. | [
"OTP",
"returns",
"the",
"next",
"OTP",
"and",
"increments",
"the",
"counter",
"."
] | 9e0979e07f39c706c9406715d99b6a8f3960ef10 | https://github.com/gokyle/twofactor/blob/9e0979e07f39c706c9406715d99b6a8f3960ef10/hotp.go#L38-L42 |
147,266 | gokyle/twofactor | hotp.go | GenerateGoogleHOTP | func GenerateGoogleHOTP() *HOTP {
key := make([]byte, sha1.Size)
if _, err := io.ReadFull(PRNG, key); err != nil {
return nil
}
return NewHOTP(key, 0, 6)
} | go | func GenerateGoogleHOTP() *HOTP {
key := make([]byte, sha1.Size)
if _, err := io.ReadFull(PRNG, key); err != nil {
return nil
}
return NewHOTP(key, 0, 6)
} | [
"func",
"GenerateGoogleHOTP",
"(",
")",
"*",
"HOTP",
"{",
"key",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"sha1",
".",
"Size",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"PRNG",
",",
"key",
")",
";",
"err",
"!=",
"nil"... | // GenerateGoogleHOTP generates a new HOTP instance as used by
// Google Authenticator. | [
"GenerateGoogleHOTP",
"generates",
"a",
"new",
"HOTP",
"instance",
"as",
"used",
"by",
"Google",
"Authenticator",
"."
] | 9e0979e07f39c706c9406715d99b6a8f3960ef10 | https://github.com/gokyle/twofactor/blob/9e0979e07f39c706c9406715d99b6a8f3960ef10/hotp.go#L56-L62 |
147,267 | goji/glogrus | writer_proxy.go | wrapWriter | func wrapWriter(w http.ResponseWriter) writerProxy {
bw := basicWriter{ResponseWriter: w}
return &bw
} | go | func wrapWriter(w http.ResponseWriter) writerProxy {
bw := basicWriter{ResponseWriter: w}
return &bw
} | [
"func",
"wrapWriter",
"(",
"w",
"http",
".",
"ResponseWriter",
")",
"writerProxy",
"{",
"bw",
":=",
"basicWriter",
"{",
"ResponseWriter",
":",
"w",
"}",
"\n",
"return",
"&",
"bw",
"\n",
"}"
] | // wrapWriter returns a proxy that wraps ResponseWriter | [
"wrapWriter",
"returns",
"a",
"proxy",
"that",
"wraps",
"ResponseWriter"
] | f7c99b3e8e6fa20cea91cd028f5af326688ba38b | https://github.com/goji/glogrus/blob/f7c99b3e8e6fa20cea91cd028f5af326688ba38b/writer_proxy.go#L8-L11 |
147,268 | goji/glogrus | writer_proxy.go | Write | func (b *basicWriter) Write(buf []byte) (int, error) {
b.maybeWriteHeader()
return b.ResponseWriter.Write(buf)
} | go | func (b *basicWriter) Write(buf []byte) (int, error) {
b.maybeWriteHeader()
return b.ResponseWriter.Write(buf)
} | [
"func",
"(",
"b",
"*",
"basicWriter",
")",
"Write",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"b",
".",
"maybeWriteHeader",
"(",
")",
"\n",
"return",
"b",
".",
"ResponseWriter",
".",
"Write",
"(",
"buf",
")",
"\n",
"}... | // Write writes the bytes and calls MaybeWriteHeader | [
"Write",
"writes",
"the",
"bytes",
"and",
"calls",
"MaybeWriteHeader"
] | f7c99b3e8e6fa20cea91cd028f5af326688ba38b | https://github.com/goji/glogrus/blob/f7c99b3e8e6fa20cea91cd028f5af326688ba38b/writer_proxy.go#L38-L41 |
147,269 | gokyle/twofactor | oath.go | OTP | func (o OATH) OTP(counter uint64) string {
var ctr [8]byte
binary.BigEndian.PutUint64(ctr[:], counter)
var mod int64 = 1
if len(digits) > o.size {
for i := 1; i <= o.size; i++ {
mod *= 10
}
} else {
mod = digits[o.size]
}
h := hmac.New(o.hash, o.key)
h.Write(ctr[:])
dt := truncate(h.Sum(nil)) % mod
... | go | func (o OATH) OTP(counter uint64) string {
var ctr [8]byte
binary.BigEndian.PutUint64(ctr[:], counter)
var mod int64 = 1
if len(digits) > o.size {
for i := 1; i <= o.size; i++ {
mod *= 10
}
} else {
mod = digits[o.size]
}
h := hmac.New(o.hash, o.key)
h.Write(ctr[:])
dt := truncate(h.Sum(nil)) % mod
... | [
"func",
"(",
"o",
"OATH",
")",
"OTP",
"(",
"counter",
"uint64",
")",
"string",
"{",
"var",
"ctr",
"[",
"8",
"]",
"byte",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint64",
"(",
"ctr",
"[",
":",
"]",
",",
"counter",
")",
"\n\n",
"var",
"mod",
"in... | // The top-level type should provide a counter; for example, HOTP
// will provide the counter directly while TOTP will provide the
// time-stepped counter. | [
"The",
"top",
"-",
"level",
"type",
"should",
"provide",
"a",
"counter",
";",
"for",
"example",
"HOTP",
"will",
"provide",
"the",
"counter",
"directly",
"while",
"TOTP",
"will",
"provide",
"the",
"time",
"-",
"stepped",
"counter",
"."
] | 9e0979e07f39c706c9406715d99b6a8f3960ef10 | https://github.com/gokyle/twofactor/blob/9e0979e07f39c706c9406715d99b6a8f3960ef10/oath.go#L107-L125 |
147,270 | gokyle/twofactor | oath.go | QR | func (o OATH) QR(t Type, label string) ([]byte, error) {
u := o.URL(t, label)
code, err := qr.Encode(u, qr.Q)
if err != nil {
return nil, err
}
return code.PNG(), nil
} | go | func (o OATH) QR(t Type, label string) ([]byte, error) {
u := o.URL(t, label)
code, err := qr.Encode(u, qr.Q)
if err != nil {
return nil, err
}
return code.PNG(), nil
} | [
"func",
"(",
"o",
"OATH",
")",
"QR",
"(",
"t",
"Type",
",",
"label",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"u",
":=",
"o",
".",
"URL",
"(",
"t",
",",
"label",
")",
"\n",
"code",
",",
"err",
":=",
"qr",
".",
"Encode",... | // QR generates a byte slice containing the a QR code encoded as a
// PNG with level Q error correction. | [
"QR",
"generates",
"a",
"byte",
"slice",
"containing",
"the",
"a",
"QR",
"code",
"encoded",
"as",
"a",
"PNG",
"with",
"level",
"Q",
"error",
"correction",
"."
] | 9e0979e07f39c706c9406715d99b6a8f3960ef10 | https://github.com/gokyle/twofactor/blob/9e0979e07f39c706c9406715d99b6a8f3960ef10/oath.go#L143-L150 |
147,271 | knq/ini | parser/parser.go | NameSplitFunc | func NameSplitFunc(name string) (string, string) {
idx := strings.LastIndex(name, DefaultNameKeySeparator)
// no section name
if idx < 0 {
return "", name
}
return name[:idx], name[idx+1:]
} | go | func NameSplitFunc(name string) (string, string) {
idx := strings.LastIndex(name, DefaultNameKeySeparator)
// no section name
if idx < 0 {
return "", name
}
return name[:idx], name[idx+1:]
} | [
"func",
"NameSplitFunc",
"(",
"name",
"string",
")",
"(",
"string",
",",
"string",
")",
"{",
"idx",
":=",
"strings",
".",
"LastIndex",
"(",
"name",
",",
"DefaultNameKeySeparator",
")",
"\n\n",
"// no section name",
"if",
"idx",
"<",
"0",
"{",
"return",
"\"... | // NameSplitFunc splits Section names.
//
// Splits names based on DefaultNameKeySeparator.
//
// Returns section, key.
//
// This function is used to split keys when being retrieved or set on a File.
//
// Override on a per-File basis by setting File.NameSplitFunc. | [
"NameSplitFunc",
"splits",
"Section",
"names",
".",
"Splits",
"names",
"based",
"on",
"DefaultNameKeySeparator",
".",
"Returns",
"section",
"key",
".",
"This",
"function",
"is",
"used",
"to",
"split",
"keys",
"when",
"being",
"retrieved",
"or",
"set",
"on",
"a... | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/parser.go#L83-L92 |
147,272 | knq/ini | parser/parser.go | NewLine | func NewLine(pos position, ws string, item Item, le string) *Line {
return &Line{
pos: pos,
ws: ws,
item: item,
le: le,
}
} | go | func NewLine(pos position, ws string, item Item, le string) *Line {
return &Line{
pos: pos,
ws: ws,
item: item,
le: le,
}
} | [
"func",
"NewLine",
"(",
"pos",
"position",
",",
"ws",
"string",
",",
"item",
"Item",
",",
"le",
"string",
")",
"*",
"Line",
"{",
"return",
"&",
"Line",
"{",
"pos",
":",
"pos",
",",
"ws",
":",
"ws",
",",
"item",
":",
"item",
",",
"le",
":",
"le"... | // NewLine creates a new line. | [
"NewLine",
"creates",
"a",
"new",
"line",
"."
] | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/parser.go#L121-L129 |
147,273 | knq/ini | parser/parser.go | String | func (l Line) String() string {
item := ""
if l.item != nil {
item = l.item.String()
}
return fmt.Sprintf("%s%s%s", l.ws, item, l.le)
} | go | func (l Line) String() string {
item := ""
if l.item != nil {
item = l.item.String()
}
return fmt.Sprintf("%s%s%s", l.ws, item, l.le)
} | [
"func",
"(",
"l",
"Line",
")",
"String",
"(",
")",
"string",
"{",
"item",
":=",
"\"",
"\"",
"\n",
"if",
"l",
".",
"item",
"!=",
"nil",
"{",
"item",
"=",
"l",
".",
"item",
".",
"String",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Spri... | // String returns a formatted line. | [
"String",
"returns",
"a",
"formatted",
"line",
"."
] | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/parser.go#L132-L139 |
147,274 | knq/ini | parser/parser.go | NewComment | func NewComment(pos position, cs string, comment string) *Comment {
return &Comment{
pos: pos,
cs: cs,
comment: comment,
}
} | go | func NewComment(pos position, cs string, comment string) *Comment {
return &Comment{
pos: pos,
cs: cs,
comment: comment,
}
} | [
"func",
"NewComment",
"(",
"pos",
"position",
",",
"cs",
"string",
",",
"comment",
"string",
")",
"*",
"Comment",
"{",
"return",
"&",
"Comment",
"{",
"pos",
":",
"pos",
",",
"cs",
":",
"cs",
",",
"comment",
":",
"comment",
",",
"}",
"\n",
"}"
] | // NewComment creates a new Comment. | [
"NewComment",
"creates",
"a",
"new",
"Comment",
"."
] | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/parser.go#L150-L157 |
147,275 | knq/ini | parser/parser.go | String | func (c Comment) String() string {
return fmt.Sprintf("%s%s", c.cs, c.comment)
} | go | func (c Comment) String() string {
return fmt.Sprintf("%s%s", c.cs, c.comment)
} | [
"func",
"(",
"c",
"Comment",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"cs",
",",
"c",
".",
"comment",
")",
"\n",
"}"
] | // String returns a formatted comment. | [
"String",
"returns",
"a",
"formatted",
"comment",
"."
] | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/parser.go#L160-L162 |
147,276 | knq/ini | parser/parser.go | NewKeyValuePair | func NewKeyValuePair(pos position, key, ws string, value *string, comment *Comment) *KeyValuePair {
return &KeyValuePair{
pos: pos,
key: key,
ws: ws,
value: value,
comment: comment,
}
} | go | func NewKeyValuePair(pos position, key, ws string, value *string, comment *Comment) *KeyValuePair {
return &KeyValuePair{
pos: pos,
key: key,
ws: ws,
value: value,
comment: comment,
}
} | [
"func",
"NewKeyValuePair",
"(",
"pos",
"position",
",",
"key",
",",
"ws",
"string",
",",
"value",
"*",
"string",
",",
"comment",
"*",
"Comment",
")",
"*",
"KeyValuePair",
"{",
"return",
"&",
"KeyValuePair",
"{",
"pos",
":",
"pos",
",",
"key",
":",
"key... | // NewKeyValuePair creates a new key value pair. | [
"NewKeyValuePair",
"creates",
"a",
"new",
"key",
"value",
"pair",
"."
] | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/parser.go#L176-L185 |
147,277 | knq/ini | parser/parser.go | String | func (kvp KeyValuePair) String() string {
var comment string
if kvp.comment != nil {
comment = kvp.comment.String()
}
if kvp.value == nil {
return fmt.Sprintf("%s%s%s", kvp.key, kvp.ws, comment)
}
return fmt.Sprintf("%s=%s%s%s", kvp.key, kvp.ws, *kvp.value, comment)
} | go | func (kvp KeyValuePair) String() string {
var comment string
if kvp.comment != nil {
comment = kvp.comment.String()
}
if kvp.value == nil {
return fmt.Sprintf("%s%s%s", kvp.key, kvp.ws, comment)
}
return fmt.Sprintf("%s=%s%s%s", kvp.key, kvp.ws, *kvp.value, comment)
} | [
"func",
"(",
"kvp",
"KeyValuePair",
")",
"String",
"(",
")",
"string",
"{",
"var",
"comment",
"string",
"\n",
"if",
"kvp",
".",
"comment",
"!=",
"nil",
"{",
"comment",
"=",
"kvp",
".",
"comment",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"kvp... | // String returns a formatted key value pair. | [
"String",
"returns",
"a",
"formatted",
"key",
"value",
"pair",
"."
] | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/parser.go#L188-L197 |
147,278 | knq/ini | parser/section.go | String | func (s Section) String() string {
comment := ""
if s.comment != nil {
comment = s.comment.String()
}
return fmt.Sprintf("[%s]%s%s", s.name, s.ws, comment)
} | go | func (s Section) String() string {
comment := ""
if s.comment != nil {
comment = s.comment.String()
}
return fmt.Sprintf("[%s]%s%s", s.name, s.ws, comment)
} | [
"func",
"(",
"s",
"Section",
")",
"String",
"(",
")",
"string",
"{",
"comment",
":=",
"\"",
"\"",
"\n",
"if",
"s",
".",
"comment",
"!=",
"nil",
"{",
"comment",
"=",
"s",
".",
"comment",
".",
"String",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",... | // String returns a formatted section. | [
"String",
"returns",
"a",
"formatted",
"section",
"."
] | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/section.go#L34-L41 |
147,279 | knq/ini | parser/section.go | Keys | func (s *Section) Keys() []string {
keys := make([]string, len(s.keys))
for i, k := range s.keys {
keys[i] = s.file.KeyManipFunc(k)
}
return keys
} | go | func (s *Section) Keys() []string {
keys := make([]string, len(s.keys))
for i, k := range s.keys {
keys[i] = s.file.KeyManipFunc(k)
}
return keys
} | [
"func",
"(",
"s",
"*",
"Section",
")",
"Keys",
"(",
")",
"[",
"]",
"string",
"{",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"s",
".",
"keys",
")",
")",
"\n",
"for",
"i",
",",
"k",
":=",
"range",
"s",
".",
"keys",
"{",
... | // Keys returns the keys defined in Section.
//
// Keys are passed through File's KeyManipFunc. | [
"Keys",
"returns",
"the",
"keys",
"defined",
"in",
"Section",
".",
"Keys",
"are",
"passed",
"through",
"File",
"s",
"KeyManipFunc",
"."
] | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/section.go#L63-L70 |
147,280 | knq/ini | parser/section.go | getInsertLocation | func (s *Section) getInsertLocation(idx int) int {
for i := idx; i >= 0; i-- {
if s.file.lines[i].item != nil {
return i + 1
}
}
return -1
} | go | func (s *Section) getInsertLocation(idx int) int {
for i := idx; i >= 0; i-- {
if s.file.lines[i].item != nil {
return i + 1
}
}
return -1
} | [
"func",
"(",
"s",
"*",
"Section",
")",
"getInsertLocation",
"(",
"idx",
"int",
")",
"int",
"{",
"for",
"i",
":=",
"idx",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"if",
"s",
".",
"file",
".",
"lines",
"[",
"i",
"]",
".",
"item",
"!=",
"nil",
... | // getInsertLocation determines insert location in a Section, which is the
// first blank line after a non-blank. | [
"getInsertLocation",
"determines",
"insert",
"location",
"in",
"a",
"Section",
"which",
"is",
"the",
"first",
"blank",
"line",
"after",
"a",
"non",
"-",
"blank",
"."
] | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/section.go#L74-L82 |
147,281 | knq/ini | parser/section.go | getKey | func (s *Section) getKey(key string) (*KeyValuePair, int) {
// loop over lines and find the key
lastSectionName := ""
var lastSectionPos position
for lastIdx, l := range s.file.lines {
switch l.item.(type) {
case *Section:
if lastSectionName == s.name && lastSectionPos == s.pos {
// must be entering a ne... | go | func (s *Section) getKey(key string) (*KeyValuePair, int) {
// loop over lines and find the key
lastSectionName := ""
var lastSectionPos position
for lastIdx, l := range s.file.lines {
switch l.item.(type) {
case *Section:
if lastSectionName == s.name && lastSectionPos == s.pos {
// must be entering a ne... | [
"func",
"(",
"s",
"*",
"Section",
")",
"getKey",
"(",
"key",
"string",
")",
"(",
"*",
"KeyValuePair",
",",
"int",
")",
"{",
"// loop over lines and find the key",
"lastSectionName",
":=",
"\"",
"\"",
"\n",
"var",
"lastSectionPos",
"position",
"\n",
"for",
"l... | // getKey returns the KeyValuePair and its line position, or nil and the
// position the key should be inserted at. | [
"getKey",
"returns",
"the",
"KeyValuePair",
"and",
"its",
"line",
"position",
"or",
"nil",
"and",
"the",
"position",
"the",
"key",
"should",
"be",
"inserted",
"at",
"."
] | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/section.go#L86-L113 |
147,282 | knq/ini | parser/section.go | Get | func (s *Section) Get(key string) string {
return s.file.ValueManipFunc(s.GetRaw(key))
} | go | func (s *Section) Get(key string) string {
return s.file.ValueManipFunc(s.GetRaw(key))
} | [
"func",
"(",
"s",
"*",
"Section",
")",
"Get",
"(",
"key",
"string",
")",
"string",
"{",
"return",
"s",
".",
"file",
".",
"ValueManipFunc",
"(",
"s",
".",
"GetRaw",
"(",
"key",
")",
")",
"\n",
"}"
] | // Get returns the value for a key.
//
// The value is passed through ValueManipFunc. | [
"Get",
"returns",
"the",
"value",
"for",
"a",
"key",
".",
"The",
"value",
"is",
"passed",
"through",
"ValueManipFunc",
"."
] | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/section.go#L127-L129 |
147,283 | knq/ini | parser/section.go | SetKey | func (s *Section) SetKey(key, value string) {
s.SetKeyValueRaw(s.file.KeyManipFunc(key), s.file.ValueManipFunc(value))
} | go | func (s *Section) SetKey(key, value string) {
s.SetKeyValueRaw(s.file.KeyManipFunc(key), s.file.ValueManipFunc(value))
} | [
"func",
"(",
"s",
"*",
"Section",
")",
"SetKey",
"(",
"key",
",",
"value",
"string",
")",
"{",
"s",
".",
"SetKeyValueRaw",
"(",
"s",
".",
"file",
".",
"KeyManipFunc",
"(",
"key",
")",
",",
"s",
".",
"file",
".",
"ValueManipFunc",
"(",
"value",
")",... | // SetKey sets a key to the provided value.
//
// If key already present, then it's value is overwritten. If key doesn't
// exist, then it is added to the end of the Section.
//
// Passes key through KeyManipFunc and value through ValueManipFunc. | [
"SetKey",
"sets",
"a",
"key",
"to",
"the",
"provided",
"value",
".",
"If",
"key",
"already",
"present",
"then",
"it",
"s",
"value",
"is",
"overwritten",
".",
"If",
"key",
"doesn",
"t",
"exist",
"then",
"it",
"is",
"added",
"to",
"the",
"end",
"of",
"... | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/section.go#L194-L196 |
147,284 | knq/ini | parser/section.go | RemoveKey | func (s *Section) RemoveKey(key string) {
k, pos := s.getKey(key)
if k != nil {
s.file.lines = append(s.file.lines[:pos], s.file.lines[pos+1:]...)
// find place in s.keys
idx := 0
for ; idx < len(s.keys); idx++ {
if s.file.KeyCompFunc(key, s.keys[idx]) {
break
}
}
// remove from s.keys
s.key... | go | func (s *Section) RemoveKey(key string) {
k, pos := s.getKey(key)
if k != nil {
s.file.lines = append(s.file.lines[:pos], s.file.lines[pos+1:]...)
// find place in s.keys
idx := 0
for ; idx < len(s.keys); idx++ {
if s.file.KeyCompFunc(key, s.keys[idx]) {
break
}
}
// remove from s.keys
s.key... | [
"func",
"(",
"s",
"*",
"Section",
")",
"RemoveKey",
"(",
"key",
"string",
")",
"{",
"k",
",",
"pos",
":=",
"s",
".",
"getKey",
"(",
"key",
")",
"\n",
"if",
"k",
"!=",
"nil",
"{",
"s",
".",
"file",
".",
"lines",
"=",
"append",
"(",
"s",
".",
... | // RemoveKey removes a key and its value from Section.
//
// If there is a comment on the line, it will not be removed. | [
"RemoveKey",
"removes",
"a",
"key",
"and",
"its",
"value",
"from",
"Section",
".",
"If",
"there",
"is",
"a",
"comment",
"on",
"the",
"line",
"it",
"will",
"not",
"be",
"removed",
"."
] | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/parser/section.go#L201-L217 |
147,285 | tidwall/raft-redcon | transport.go | NewRedconTransport | func NewRedconTransport(
bindAddr string,
handle func(conn redcon.Conn, cmd redcon.Command),
accept func(conn redcon.Conn) bool,
closed func(conn redcon.Conn, err error),
logOutput io.Writer,
) (*RedconTransport, error) {
t := &RedconTransport{
addr: bindAddr,
consumer: make(chan raft.RPC),
handleFn: ha... | go | func NewRedconTransport(
bindAddr string,
handle func(conn redcon.Conn, cmd redcon.Command),
accept func(conn redcon.Conn) bool,
closed func(conn redcon.Conn, err error),
logOutput io.Writer,
) (*RedconTransport, error) {
t := &RedconTransport{
addr: bindAddr,
consumer: make(chan raft.RPC),
handleFn: ha... | [
"func",
"NewRedconTransport",
"(",
"bindAddr",
"string",
",",
"handle",
"func",
"(",
"conn",
"redcon",
".",
"Conn",
",",
"cmd",
"redcon",
".",
"Command",
")",
",",
"accept",
"func",
"(",
"conn",
"redcon",
".",
"Conn",
")",
"bool",
",",
"closed",
"func",
... | // NewRedconTransport creates a new RedconTransport | [
"NewRedconTransport",
"creates",
"a",
"new",
"RedconTransport"
] | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L42-L67 |
147,286 | tidwall/raft-redcon | transport.go | newTargetPool | func newTargetPool(target string) *redis.Pool {
return &redis.Pool{
MaxIdle: 5, // figure 5 should suffice most clusters.
IdleTimeout: time.Minute, //
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", target)
if err != nil {
return nil, err
}
return c, err
},
TestOn... | go | func newTargetPool(target string) *redis.Pool {
return &redis.Pool{
MaxIdle: 5, // figure 5 should suffice most clusters.
IdleTimeout: time.Minute, //
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", target)
if err != nil {
return nil, err
}
return c, err
},
TestOn... | [
"func",
"newTargetPool",
"(",
"target",
"string",
")",
"*",
"redis",
".",
"Pool",
"{",
"return",
"&",
"redis",
".",
"Pool",
"{",
"MaxIdle",
":",
"5",
",",
"// figure 5 should suffice most clusters.",
"IdleTimeout",
":",
"time",
".",
"Minute",
",",
"//",
"Dia... | // newTargetPool returns a Redigo pool for the specified target node. | [
"newTargetPool",
"returns",
"a",
"Redigo",
"pool",
"for",
"the",
"specified",
"target",
"node",
"."
] | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L70-L89 |
147,287 | tidwall/raft-redcon | transport.go | Close | func (t *RedconTransport) Close() error {
t.mu.Lock()
defer t.mu.Unlock()
if t.closed {
return errors.New("closed")
}
t.closed = true
t.server.Close()
for _, pool := range t.pools {
pool.Close()
}
t.pools = nil
return nil
} | go | func (t *RedconTransport) Close() error {
t.mu.Lock()
defer t.mu.Unlock()
if t.closed {
return errors.New("closed")
}
t.closed = true
t.server.Close()
for _, pool := range t.pools {
pool.Close()
}
t.pools = nil
return nil
} | [
"func",
"(",
"t",
"*",
"RedconTransport",
")",
"Close",
"(",
")",
"error",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"t",
".",
"closed",
"{",
"return",
"errors",
".",
"New",
... | // Close is used to permanently disable the transport | [
"Close",
"is",
"used",
"to",
"permanently",
"disable",
"the",
"transport"
] | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L92-L105 |
147,288 | tidwall/raft-redcon | transport.go | getPool | func (t *RedconTransport) getPool(target string) (*redis.Pool, error) {
t.mu.Lock()
defer t.mu.Unlock()
if t.closed {
return nil, errors.New("closed")
}
pool, ok := t.pools[target]
if !ok {
pool = newTargetPool(target)
t.pools[target] = pool
}
return pool, nil
} | go | func (t *RedconTransport) getPool(target string) (*redis.Pool, error) {
t.mu.Lock()
defer t.mu.Unlock()
if t.closed {
return nil, errors.New("closed")
}
pool, ok := t.pools[target]
if !ok {
pool = newTargetPool(target)
t.pools[target] = pool
}
return pool, nil
} | [
"func",
"(",
"t",
"*",
"RedconTransport",
")",
"getPool",
"(",
"target",
"string",
")",
"(",
"*",
"redis",
".",
"Pool",
",",
"error",
")",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",... | // getPool returns a usable pool for obtaining a connection to the specified
// target. | [
"getPool",
"returns",
"a",
"usable",
"pool",
"for",
"obtaining",
"a",
"connection",
"to",
"the",
"specified",
"target",
"."
] | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L109-L121 |
147,289 | tidwall/raft-redcon | transport.go | getConn | func (t *RedconTransport) getConn(target string) (redis.Conn, error) {
pool, err := t.getPool(target)
if err != nil {
return nil, err
}
return pool.Get(), nil
} | go | func (t *RedconTransport) getConn(target string) (redis.Conn, error) {
pool, err := t.getPool(target)
if err != nil {
return nil, err
}
return pool.Get(), nil
} | [
"func",
"(",
"t",
"*",
"RedconTransport",
")",
"getConn",
"(",
"target",
"string",
")",
"(",
"redis",
".",
"Conn",
",",
"error",
")",
"{",
"pool",
",",
"err",
":=",
"t",
".",
"getPool",
"(",
"target",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"re... | // getConn returns a connection to the target. | [
"getConn",
"returns",
"a",
"connection",
"to",
"the",
"target",
"."
] | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L124-L130 |
147,290 | tidwall/raft-redcon | transport.go | AppendEntriesPipeline | func (t *RedconTransport) AppendEntriesPipeline(target string) (
raft.AppendPipeline, error,
) {
return nil, raft.ErrPipelineReplicationNotSupported
} | go | func (t *RedconTransport) AppendEntriesPipeline(target string) (
raft.AppendPipeline, error,
) {
return nil, raft.ErrPipelineReplicationNotSupported
} | [
"func",
"(",
"t",
"*",
"RedconTransport",
")",
"AppendEntriesPipeline",
"(",
"target",
"string",
")",
"(",
"raft",
".",
"AppendPipeline",
",",
"error",
",",
")",
"{",
"return",
"nil",
",",
"raft",
".",
"ErrPipelineReplicationNotSupported",
"\n",
"}"
] | // AppendEntriesPipeline returns an interface that can be used to pipeline
// AppendEntries requests. | [
"AppendEntriesPipeline",
"returns",
"an",
"interface",
"that",
"can",
"be",
"used",
"to",
"pipeline",
"AppendEntries",
"requests",
"."
] | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L134-L138 |
147,291 | tidwall/raft-redcon | transport.go | encodeAppendEntriesRequest | func encodeAppendEntriesRequest(args *raft.AppendEntriesRequest) []byte {
n := make([]byte, 8) // used to store uint64s
b := make([]byte, 40, 256) // encoded message goes here
binary.LittleEndian.PutUint64(b[0:8], args.Term)
binary.LittleEndian.PutUint64(b[8:16], args.PrevLogEntry)
binary.LittleEndian.PutUin... | go | func encodeAppendEntriesRequest(args *raft.AppendEntriesRequest) []byte {
n := make([]byte, 8) // used to store uint64s
b := make([]byte, 40, 256) // encoded message goes here
binary.LittleEndian.PutUint64(b[0:8], args.Term)
binary.LittleEndian.PutUint64(b[8:16], args.PrevLogEntry)
binary.LittleEndian.PutUin... | [
"func",
"encodeAppendEntriesRequest",
"(",
"args",
"*",
"raft",
".",
"AppendEntriesRequest",
")",
"[",
"]",
"byte",
"{",
"n",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"8",
")",
"// used to store uint64s",
"\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
... | // encodeAppendEntriesRequest encodes AppendEntriesRequest arguments into a
// tight binary format. | [
"encodeAppendEntriesRequest",
"encodes",
"AppendEntriesRequest",
"arguments",
"into",
"a",
"tight",
"binary",
"format",
"."
] | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L142-L164 |
147,292 | tidwall/raft-redcon | transport.go | decodeAppendEntriesRequest | func decodeAppendEntriesRequest(
b []byte,
args *raft.AppendEntriesRequest,
) bool {
if len(b) < 40 {
return false
}
args.Term = binary.LittleEndian.Uint64(b[0:8])
args.PrevLogEntry = binary.LittleEndian.Uint64(b[8:16])
args.PrevLogTerm = binary.LittleEndian.Uint64(b[16:24])
args.LeaderCommitIndex = binary.Li... | go | func decodeAppendEntriesRequest(
b []byte,
args *raft.AppendEntriesRequest,
) bool {
if len(b) < 40 {
return false
}
args.Term = binary.LittleEndian.Uint64(b[0:8])
args.PrevLogEntry = binary.LittleEndian.Uint64(b[8:16])
args.PrevLogTerm = binary.LittleEndian.Uint64(b[16:24])
args.LeaderCommitIndex = binary.Li... | [
"func",
"decodeAppendEntriesRequest",
"(",
"b",
"[",
"]",
"byte",
",",
"args",
"*",
"raft",
".",
"AppendEntriesRequest",
",",
")",
"bool",
"{",
"if",
"len",
"(",
"b",
")",
"<",
"40",
"{",
"return",
"false",
"\n",
"}",
"\n",
"args",
".",
"Term",
"=",
... | // decodeAppendEntriesRequest decodes AppendEntriesRequest data.
// Returns true when successful | [
"decodeAppendEntriesRequest",
"decodes",
"AppendEntriesRequest",
"data",
".",
"Returns",
"true",
"when",
"successful"
] | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L168-L209 |
147,293 | tidwall/raft-redcon | transport.go | AppendEntries | func (t *RedconTransport) AppendEntries(target string,
args *raft.AppendEntriesRequest, resp *raft.AppendEntriesResponse,
) error {
conn, err := t.getConn(target)
if err != nil {
return err
}
defer conn.Close()
reply, err := conn.Do("raftappendentries", encodeAppendEntriesRequest(args))
if err != nil {
retu... | go | func (t *RedconTransport) AppendEntries(target string,
args *raft.AppendEntriesRequest, resp *raft.AppendEntriesResponse,
) error {
conn, err := t.getConn(target)
if err != nil {
return err
}
defer conn.Close()
reply, err := conn.Do("raftappendentries", encodeAppendEntriesRequest(args))
if err != nil {
retu... | [
"func",
"(",
"t",
"*",
"RedconTransport",
")",
"AppendEntries",
"(",
"target",
"string",
",",
"args",
"*",
"raft",
".",
"AppendEntriesRequest",
",",
"resp",
"*",
"raft",
".",
"AppendEntriesResponse",
",",
")",
"error",
"{",
"conn",
",",
"err",
":=",
"t",
... | // AppendEntries implements the Transport interface. | [
"AppendEntries",
"implements",
"the",
"Transport",
"interface",
"."
] | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L246-L270 |
147,294 | tidwall/raft-redcon | transport.go | RequestVote | func (t *RedconTransport) RequestVote(target string,
args *raft.RequestVoteRequest, resp *raft.RequestVoteResponse,
) error {
data, _ := json.Marshal(args)
val, _, err := Do(target, nil, []byte("raftrequestvote"), data)
if err != nil {
return err
}
if err := json.Unmarshal(val, resp); err != nil {
return err
... | go | func (t *RedconTransport) RequestVote(target string,
args *raft.RequestVoteRequest, resp *raft.RequestVoteResponse,
) error {
data, _ := json.Marshal(args)
val, _, err := Do(target, nil, []byte("raftrequestvote"), data)
if err != nil {
return err
}
if err := json.Unmarshal(val, resp); err != nil {
return err
... | [
"func",
"(",
"t",
"*",
"RedconTransport",
")",
"RequestVote",
"(",
"target",
"string",
",",
"args",
"*",
"raft",
".",
"RequestVoteRequest",
",",
"resp",
"*",
"raft",
".",
"RequestVoteResponse",
",",
")",
"error",
"{",
"data",
",",
"_",
":=",
"json",
".",... | // RequestVote implements the Transport interface. | [
"RequestVote",
"implements",
"the",
"Transport",
"interface",
"."
] | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L300-L312 |
147,295 | tidwall/raft-redcon | transport.go | InstallSnapshot | func (t *RedconTransport) InstallSnapshot(
target string, args *raft.InstallSnapshotRequest,
resp *raft.InstallSnapshotResponse, data io.Reader,
) error {
// Use a dedicated connection for snapshots. This operation happens very
// infrequently, but when it does it often passes a lot of data.
conn, err := net.Dial(... | go | func (t *RedconTransport) InstallSnapshot(
target string, args *raft.InstallSnapshotRequest,
resp *raft.InstallSnapshotResponse, data io.Reader,
) error {
// Use a dedicated connection for snapshots. This operation happens very
// infrequently, but when it does it often passes a lot of data.
conn, err := net.Dial(... | [
"func",
"(",
"t",
"*",
"RedconTransport",
")",
"InstallSnapshot",
"(",
"target",
"string",
",",
"args",
"*",
"raft",
".",
"InstallSnapshotRequest",
",",
"resp",
"*",
"raft",
".",
"InstallSnapshotResponse",
",",
"data",
"io",
".",
"Reader",
",",
")",
"error",... | // InstallSnapshot implmenents the Transport interface. | [
"InstallSnapshot",
"implmenents",
"the",
"Transport",
"interface",
"."
] | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L342-L415 |
147,296 | tidwall/raft-redcon | transport.go | Do | func Do(addr string, buf []byte, args ...[]byte) (
resp []byte, nbuf []byte, err error,
) {
cmd := buildCommand(buf, args...)
conn, err := net.Dial("tcp", addr)
if err != nil {
return nil, cmd, err
}
defer conn.Close()
if _, err = conn.Write(cmd); err != nil {
return nil, cmd, err
}
resp, err = response(bu... | go | func Do(addr string, buf []byte, args ...[]byte) (
resp []byte, nbuf []byte, err error,
) {
cmd := buildCommand(buf, args...)
conn, err := net.Dial("tcp", addr)
if err != nil {
return nil, cmd, err
}
defer conn.Close()
if _, err = conn.Write(cmd); err != nil {
return nil, cmd, err
}
resp, err = response(bu... | [
"func",
"Do",
"(",
"addr",
"string",
",",
"buf",
"[",
"]",
"byte",
",",
"args",
"...",
"[",
"]",
"byte",
")",
"(",
"resp",
"[",
"]",
"byte",
",",
"nbuf",
"[",
"]",
"byte",
",",
"err",
"error",
",",
")",
"{",
"cmd",
":=",
"buildCommand",
"(",
... | // Do is a helper function that makes a very simple remote request with
// the specified command.
// The addr param is the target server address.
// The buf param is an optional reusable buffer, this can be nil.
// The args are the command arguments such as "SET", "key", "value".
// Return response is a bulk, string, o... | [
"Do",
"is",
"a",
"helper",
"function",
"that",
"makes",
"a",
"very",
"simple",
"remote",
"request",
"with",
"the",
"specified",
"command",
".",
"The",
"addr",
"param",
"is",
"the",
"target",
"server",
"address",
".",
"The",
"buf",
"param",
"is",
"an",
"o... | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L558-L572 |
147,297 | tidwall/raft-redcon | transport.go | buildCommand | func buildCommand(buf []byte, args ...[]byte) []byte {
buf = append(buf, '*')
buf = append(buf, strconv.FormatInt(int64(len(args)), 10)...)
buf = append(buf, '\r', '\n')
for _, arg := range args {
buf = append(buf, '$')
buf = append(buf, strconv.FormatInt(int64(len(arg)), 10)...)
buf = append(buf, '\r', '\n')... | go | func buildCommand(buf []byte, args ...[]byte) []byte {
buf = append(buf, '*')
buf = append(buf, strconv.FormatInt(int64(len(args)), 10)...)
buf = append(buf, '\r', '\n')
for _, arg := range args {
buf = append(buf, '$')
buf = append(buf, strconv.FormatInt(int64(len(arg)), 10)...)
buf = append(buf, '\r', '\n')... | [
"func",
"buildCommand",
"(",
"buf",
"[",
"]",
"byte",
",",
"args",
"...",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"buf",
"=",
"append",
"(",
"buf",
",",
"'*'",
")",
"\n",
"buf",
"=",
"append",
"(",
"buf",
",",
"strconv",
".",
"FormatInt",
... | // buildCommand builds a valid redis command and appends to buf.
// The return value is the newly appended buf. | [
"buildCommand",
"builds",
"a",
"valid",
"redis",
"command",
"and",
"appends",
"to",
"buf",
".",
"The",
"return",
"value",
"is",
"the",
"newly",
"appended",
"buf",
"."
] | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L632-L644 |
147,298 | tidwall/raft-redcon | transport.go | ReadRawResponse | func ReadRawResponse(rd *bufio.Reader) (raw []byte, kind byte, err error) {
kind, err = rd.ReadByte()
if err != nil {
return raw, kind, err
}
raw = append(raw, kind)
switch kind {
default:
return raw, kind, errors.New("invalid response")
case '+', '-', '$', ':', '*':
line, err := rd.ReadBytes('\n')
if er... | go | func ReadRawResponse(rd *bufio.Reader) (raw []byte, kind byte, err error) {
kind, err = rd.ReadByte()
if err != nil {
return raw, kind, err
}
raw = append(raw, kind)
switch kind {
default:
return raw, kind, errors.New("invalid response")
case '+', '-', '$', ':', '*':
line, err := rd.ReadBytes('\n')
if er... | [
"func",
"ReadRawResponse",
"(",
"rd",
"*",
"bufio",
".",
"Reader",
")",
"(",
"raw",
"[",
"]",
"byte",
",",
"kind",
"byte",
",",
"err",
"error",
")",
"{",
"kind",
",",
"err",
"=",
"rd",
".",
"ReadByte",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // ReadRawResponse reads a raw response for an input buffer reader | [
"ReadRawResponse",
"reads",
"a",
"raw",
"response",
"for",
"an",
"input",
"buffer",
"reader"
] | 178be3543d7f9bd48a955067ef084fcf06e0915b | https://github.com/tidwall/raft-redcon/blob/178be3543d7f9bd48a955067ef084fcf06e0915b/transport.go#L647-L703 |
147,299 | knq/ini | ini.go | Save | func (f *File) Save() error {
if f.Filename == "" {
return ErrNoFilenameSupplied
}
return f.Write(f.Filename)
} | go | func (f *File) Save() error {
if f.Filename == "" {
return ErrNoFilenameSupplied
}
return f.Write(f.Filename)
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Save",
"(",
")",
"error",
"{",
"if",
"f",
".",
"Filename",
"==",
"\"",
"\"",
"{",
"return",
"ErrNoFilenameSupplied",
"\n",
"}",
"\n",
"return",
"f",
".",
"Write",
"(",
"f",
".",
"Filename",
")",
"\n",
"}"
] | // Save writes the ini file data to File.Filename.
//
// Returns error if File.Filename name was not set, or if an error was
// encountered during write. Simple wrapper around parser.File.Write. | [
"Save",
"writes",
"the",
"ini",
"file",
"data",
"to",
"File",
".",
"Filename",
".",
"Returns",
"error",
"if",
"File",
".",
"Filename",
"name",
"was",
"not",
"set",
"or",
"if",
"an",
"error",
"was",
"encountered",
"during",
"write",
".",
"Simple",
"wrappe... | a301e724bd355e60a16998da1c57e916ecea6ec8 | https://github.com/knq/ini/blob/a301e724bd355e60a16998da1c57e916ecea6ec8/ini.go#L61-L66 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.