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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
144,900 | zieckey/goini | ini.go | Get | func (ini *INI) Get(key string) (string, bool) {
return ini.SectionGet(DefaultSection, key)
} | go | func (ini *INI) Get(key string) (string, bool) {
return ini.SectionGet(DefaultSection, key)
} | [
"func",
"(",
"ini",
"*",
"INI",
")",
"Get",
"(",
"key",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"return",
"ini",
".",
"SectionGet",
"(",
"DefaultSection",
",",
"key",
")",
"\n",
"}"
] | // Get looks up a value for a key in the default section
// and returns that value, along with a boolean result similar to a map lookup. | [
"Get",
"looks",
"up",
"a",
"value",
"for",
"a",
"key",
"in",
"the",
"default",
"section",
"and",
"returns",
"that",
"value",
"along",
"with",
"a",
"boolean",
"result",
"similar",
"to",
"a",
"map",
"lookup",
"."
] | 0da17d361d262d81977b926fcd55f34d2f8deed0 | https://github.com/zieckey/goini/blob/0da17d361d262d81977b926fcd55f34d2f8deed0/ini.go#L100-L102 |
144,901 | zieckey/goini | ini.go | GetInt | func (ini *INI) GetInt(key string) (int, bool) {
return ini.SectionGetInt(DefaultSection, key)
} | go | func (ini *INI) GetInt(key string) (int, bool) {
return ini.SectionGetInt(DefaultSection, key)
} | [
"func",
"(",
"ini",
"*",
"INI",
")",
"GetInt",
"(",
"key",
"string",
")",
"(",
"int",
",",
"bool",
")",
"{",
"return",
"ini",
".",
"SectionGetInt",
"(",
"DefaultSection",
",",
"key",
")",
"\n",
"}"
] | // GetInt gets value as int | [
"GetInt",
"gets",
"value",
"as",
"int"
] | 0da17d361d262d81977b926fcd55f34d2f8deed0 | https://github.com/zieckey/goini/blob/0da17d361d262d81977b926fcd55f34d2f8deed0/ini.go#L105-L107 |
144,902 | zieckey/goini | ini.go | GetFloat | func (ini *INI) GetFloat(key string) (float64, bool) {
return ini.SectionGetFloat(DefaultSection, key)
} | go | func (ini *INI) GetFloat(key string) (float64, bool) {
return ini.SectionGetFloat(DefaultSection, key)
} | [
"func",
"(",
"ini",
"*",
"INI",
")",
"GetFloat",
"(",
"key",
"string",
")",
"(",
"float64",
",",
"bool",
")",
"{",
"return",
"ini",
".",
"SectionGetFloat",
"(",
"DefaultSection",
",",
"key",
")",
"\n",
"}"
] | // GetFloat gets value as float64 | [
"GetFloat",
"gets",
"value",
"as",
"float64"
] | 0da17d361d262d81977b926fcd55f34d2f8deed0 | https://github.com/zieckey/goini/blob/0da17d361d262d81977b926fcd55f34d2f8deed0/ini.go#L110-L112 |
144,903 | zieckey/goini | ini.go | GetBool | func (ini *INI) GetBool(key string) (bool, bool) {
return ini.SectionGetBool(DefaultSection, key)
} | go | func (ini *INI) GetBool(key string) (bool, bool) {
return ini.SectionGetBool(DefaultSection, key)
} | [
"func",
"(",
"ini",
"*",
"INI",
")",
"GetBool",
"(",
"key",
"string",
")",
"(",
"bool",
",",
"bool",
")",
"{",
"return",
"ini",
".",
"SectionGetBool",
"(",
"DefaultSection",
",",
"key",
")",
"\n",
"}"
] | // GetBool returns the boolean value represented by the string.
// It accepts "1", "t", "T", "true", "TRUE", "True", "on", "ON", "On", "yes", "YES", "Yes" as true
// and "0", "f", "F", "false", "FALSE", "False", "off", "OFF", "Off", "no", "NO", "No" as false
// Any other value returns false. | [
"GetBool",
"returns",
"the",
"boolean",
"value",
"represented",
"by",
"the",
"string",
".",
"It",
"accepts",
"1",
"t",
"T",
"true",
"TRUE",
"True",
"on",
"ON",
"On",
"yes",
"YES",
"Yes",
"as",
"true",
"and",
"0",
"f",
"F",
"false",
"FALSE",
"False",
... | 0da17d361d262d81977b926fcd55f34d2f8deed0 | https://github.com/zieckey/goini/blob/0da17d361d262d81977b926fcd55f34d2f8deed0/ini.go#L118-L120 |
144,904 | zieckey/goini | ini.go | SectionGet | func (ini *INI) SectionGet(section, key string) (value string, ok bool) {
if s := ini.sections[section]; s != nil {
value, ok = s[key]
}
return
} | go | func (ini *INI) SectionGet(section, key string) (value string, ok bool) {
if s := ini.sections[section]; s != nil {
value, ok = s[key]
}
return
} | [
"func",
"(",
"ini",
"*",
"INI",
")",
"SectionGet",
"(",
"section",
",",
"key",
"string",
")",
"(",
"value",
"string",
",",
"ok",
"bool",
")",
"{",
"if",
"s",
":=",
"ini",
".",
"sections",
"[",
"section",
"]",
";",
"s",
"!=",
"nil",
"{",
"value",
... | // SectionGet looks up a value for a key in a section
// and returns that value, along with a boolean result similar to a map lookup. | [
"SectionGet",
"looks",
"up",
"a",
"value",
"for",
"a",
"key",
"in",
"a",
"section",
"and",
"returns",
"that",
"value",
"along",
"with",
"a",
"boolean",
"result",
"similar",
"to",
"a",
"map",
"lookup",
"."
] | 0da17d361d262d81977b926fcd55f34d2f8deed0 | https://github.com/zieckey/goini/blob/0da17d361d262d81977b926fcd55f34d2f8deed0/ini.go#L124-L129 |
144,905 | zieckey/goini | ini.go | SectionGetInt | func (ini *INI) SectionGetInt(section, key string) (int, bool) {
v, ok := ini.SectionGet(section, key)
if ok {
v, err := strconv.Atoi(v)
if err == nil {
return v, true
}
}
return 0, ok
} | go | func (ini *INI) SectionGetInt(section, key string) (int, bool) {
v, ok := ini.SectionGet(section, key)
if ok {
v, err := strconv.Atoi(v)
if err == nil {
return v, true
}
}
return 0, ok
} | [
"func",
"(",
"ini",
"*",
"INI",
")",
"SectionGetInt",
"(",
"section",
",",
"key",
"string",
")",
"(",
"int",
",",
"bool",
")",
"{",
"v",
",",
"ok",
":=",
"ini",
".",
"SectionGet",
"(",
"section",
",",
"key",
")",
"\n",
"if",
"ok",
"{",
"v",
","... | // SectionGetInt gets value as int | [
"SectionGetInt",
"gets",
"value",
"as",
"int"
] | 0da17d361d262d81977b926fcd55f34d2f8deed0 | https://github.com/zieckey/goini/blob/0da17d361d262d81977b926fcd55f34d2f8deed0/ini.go#L132-L142 |
144,906 | zieckey/goini | ini.go | SectionGetFloat | func (ini *INI) SectionGetFloat(section, key string) (float64, bool) {
v, ok := ini.SectionGet(section, key)
if ok {
v, err := strconv.ParseFloat(v, 64)
if err == nil {
return v, true
}
}
return 0.0, ok
} | go | func (ini *INI) SectionGetFloat(section, key string) (float64, bool) {
v, ok := ini.SectionGet(section, key)
if ok {
v, err := strconv.ParseFloat(v, 64)
if err == nil {
return v, true
}
}
return 0.0, ok
} | [
"func",
"(",
"ini",
"*",
"INI",
")",
"SectionGetFloat",
"(",
"section",
",",
"key",
"string",
")",
"(",
"float64",
",",
"bool",
")",
"{",
"v",
",",
"ok",
":=",
"ini",
".",
"SectionGet",
"(",
"section",
",",
"key",
")",
"\n",
"if",
"ok",
"{",
"v",... | // SectionGetFloat gets value as float64 | [
"SectionGetFloat",
"gets",
"value",
"as",
"float64"
] | 0da17d361d262d81977b926fcd55f34d2f8deed0 | https://github.com/zieckey/goini/blob/0da17d361d262d81977b926fcd55f34d2f8deed0/ini.go#L145-L155 |
144,907 | zieckey/goini | ini.go | SectionGetBool | func (ini *INI) SectionGetBool(section, key string) (bool, bool) {
v, ok := ini.SectionGet(section, key)
if ok {
switch v {
case "1", "t", "T", "true", "TRUE", "True", "on", "ON", "On", "yes", "YES", "Yes":
return true, true
case "0", "f", "F", "false", "FALSE", "False", "off... | go | func (ini *INI) SectionGetBool(section, key string) (bool, bool) {
v, ok := ini.SectionGet(section, key)
if ok {
switch v {
case "1", "t", "T", "true", "TRUE", "True", "on", "ON", "On", "yes", "YES", "Yes":
return true, true
case "0", "f", "F", "false", "FALSE", "False", "off... | [
"func",
"(",
"ini",
"*",
"INI",
")",
"SectionGetBool",
"(",
"section",
",",
"key",
"string",
")",
"(",
"bool",
",",
"bool",
")",
"{",
"v",
",",
"ok",
":=",
"ini",
".",
"SectionGet",
"(",
"section",
",",
"key",
")",
"\n",
"if",
"ok",
"{",
"switch"... | // SectionGetBool gets a value as bool. See GetBool for more detail | [
"SectionGetBool",
"gets",
"a",
"value",
"as",
"bool",
".",
"See",
"GetBool",
"for",
"more",
"detail"
] | 0da17d361d262d81977b926fcd55f34d2f8deed0 | https://github.com/zieckey/goini/blob/0da17d361d262d81977b926fcd55f34d2f8deed0/ini.go#L158-L170 |
144,908 | zieckey/goini | ini.go | Delete | func (ini *INI) Delete(section, key string) {
kvmap, ok := ini.GetKvmap(section)
if ok {
delete(kvmap, key)
}
} | go | func (ini *INI) Delete(section, key string) {
kvmap, ok := ini.GetKvmap(section)
if ok {
delete(kvmap, key)
}
} | [
"func",
"(",
"ini",
"*",
"INI",
")",
"Delete",
"(",
"section",
",",
"key",
"string",
")",
"{",
"kvmap",
",",
"ok",
":=",
"ini",
".",
"GetKvmap",
"(",
"section",
")",
"\n",
"if",
"ok",
"{",
"delete",
"(",
"kvmap",
",",
"key",
")",
"\n",
"}",
"\n... | // Delete deletes the key in given section. | [
"Delete",
"deletes",
"the",
"key",
"in",
"given",
"section",
"."
] | 0da17d361d262d81977b926fcd55f34d2f8deed0 | https://github.com/zieckey/goini/blob/0da17d361d262d81977b926fcd55f34d2f8deed0/ini.go#L244-L249 |
144,909 | zieckey/goini | ini.go | Write | func (ini *INI) Write(w io.Writer) error {
buf := bufio.NewWriter(w)
//write the default section first
if kv, ok := ini.GetKvmap(DefaultSection); ok {
ini.write(kv, buf)
}
for section, kv := range ini.sections {
if section == DefaultSection {
continue
}
... | go | func (ini *INI) Write(w io.Writer) error {
buf := bufio.NewWriter(w)
//write the default section first
if kv, ok := ini.GetKvmap(DefaultSection); ok {
ini.write(kv, buf)
}
for section, kv := range ini.sections {
if section == DefaultSection {
continue
}
... | [
"func",
"(",
"ini",
"*",
"INI",
")",
"Write",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"buf",
":=",
"bufio",
".",
"NewWriter",
"(",
"w",
")",
"\n\n",
"//write the default section first",
"if",
"kv",
",",
"ok",
":=",
"ini",
".",
"GetKvmap",
"... | // Write tries to write the INI data into an output. | [
"Write",
"tries",
"to",
"write",
"the",
"INI",
"data",
"into",
"an",
"output",
"."
] | 0da17d361d262d81977b926fcd55f34d2f8deed0 | https://github.com/zieckey/goini/blob/0da17d361d262d81977b926fcd55f34d2f8deed0/ini.go#L252-L268 |
144,910 | miolini/datacounter | response_writer.go | NewResponseWriterCounter | func NewResponseWriterCounter(rw http.ResponseWriter) *ResponseWriterCounter {
return &ResponseWriterCounter{
writer: rw,
started: time.Now(),
}
} | go | func NewResponseWriterCounter(rw http.ResponseWriter) *ResponseWriterCounter {
return &ResponseWriterCounter{
writer: rw,
started: time.Now(),
}
} | [
"func",
"NewResponseWriterCounter",
"(",
"rw",
"http",
".",
"ResponseWriter",
")",
"*",
"ResponseWriterCounter",
"{",
"return",
"&",
"ResponseWriterCounter",
"{",
"writer",
":",
"rw",
",",
"started",
":",
"time",
".",
"Now",
"(",
")",
",",
"}",
"\n",
"}"
] | // NewResponseWriterCounter function create new ResponseWriterCounter | [
"NewResponseWriterCounter",
"function",
"create",
"new",
"ResponseWriterCounter"
] | fd4e42a1d5e0d2714f16caf92f9c64215bf957ce | https://github.com/miolini/datacounter/blob/fd4e42a1d5e0d2714f16caf92f9c64215bf957ce/response_writer.go#L21-L26 |
144,911 | gobuffalo/x | fakesmtp/connection.go | write | func (c *Connection) write(s string) {
c.bufout.WriteString(s + "\r\n")
c.bufout.Flush()
} | go | func (c *Connection) write(s string) {
c.bufout.WriteString(s + "\r\n")
c.bufout.Flush()
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"write",
"(",
"s",
"string",
")",
"{",
"c",
".",
"bufout",
".",
"WriteString",
"(",
"s",
"+",
"\"",
"\\r",
"\\n",
"\"",
")",
"\n",
"c",
".",
"bufout",
".",
"Flush",
"(",
")",
"\n",
"}"
] | //write something to the client on the connection | [
"write",
"something",
"to",
"the",
"client",
"on",
"the",
"connection"
] | 6bb134105960cad85951ed5d28b7c127b3ebca87 | https://github.com/gobuffalo/x/blob/6bb134105960cad85951ed5d28b7c127b3ebca87/fakesmtp/connection.go#L19-L22 |
144,912 | gobuffalo/x | fakesmtp/connection.go | read | func (c *Connection) read() string {
reply, err := c.bufin.ReadString('\n')
if err != nil {
fmt.Println("e ", err)
}
return reply
} | go | func (c *Connection) read() string {
reply, err := c.bufin.ReadString('\n')
if err != nil {
fmt.Println("e ", err)
}
return reply
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"read",
"(",
")",
"string",
"{",
"reply",
",",
"err",
":=",
"c",
".",
"bufin",
".",
"ReadString",
"(",
"'\\n'",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"... | //read a string from the connected client | [
"read",
"a",
"string",
"from",
"the",
"connected",
"client"
] | 6bb134105960cad85951ed5d28b7c127b3ebca87 | https://github.com/gobuffalo/x/blob/6bb134105960cad85951ed5d28b7c127b3ebca87/fakesmtp/connection.go#L25-L32 |
144,913 | gobuffalo/x | fakesmtp/server.go | Start | func (s *Server) Start(port string) error {
for {
conn, err := s.Listener.Accept()
if err != nil {
return err
}
s.Handle(&Connection{
conn: conn,
address: conn.RemoteAddr().String(),
time: time.Now().Unix(),
bufin: bufio.NewReader(conn),
bufout: bufio.NewWriter(conn),
})
}
} | go | func (s *Server) Start(port string) error {
for {
conn, err := s.Listener.Accept()
if err != nil {
return err
}
s.Handle(&Connection{
conn: conn,
address: conn.RemoteAddr().String(),
time: time.Now().Unix(),
bufin: bufio.NewReader(conn),
bufout: bufio.NewWriter(conn),
})
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Start",
"(",
"port",
"string",
")",
"error",
"{",
"for",
"{",
"conn",
",",
"err",
":=",
"s",
".",
"Listener",
".",
"Accept",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n... | //Start listens for connections on the given port | [
"Start",
"listens",
"for",
"connections",
"on",
"the",
"given",
"port"
] | 6bb134105960cad85951ed5d28b7c127b3ebca87 | https://github.com/gobuffalo/x/blob/6bb134105960cad85951ed5d28b7c127b3ebca87/fakesmtp/server.go#L23-L38 |
144,914 | gobuffalo/x | fakesmtp/server.go | Handle | func (s *Server) Handle(c *Connection) {
s.mutex.Lock()
defer s.mutex.Unlock()
s.messages = append(s.messages, "")
s.readHello(c)
s.readSender(c)
s.readRecipients(c)
s.readData(c)
c.conn.Close()
} | go | func (s *Server) Handle(c *Connection) {
s.mutex.Lock()
defer s.mutex.Unlock()
s.messages = append(s.messages, "")
s.readHello(c)
s.readSender(c)
s.readRecipients(c)
s.readData(c)
c.conn.Close()
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Handle",
"(",
"c",
"*",
"Connection",
")",
"{",
"s",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"s",
".",
"messages",
"=",
"append",
"(",
"s",
... | //Handle a connection from a client | [
"Handle",
"a",
"connection",
"from",
"a",
"client"
] | 6bb134105960cad85951ed5d28b7c127b3ebca87 | https://github.com/gobuffalo/x/blob/6bb134105960cad85951ed5d28b7c127b3ebca87/fakesmtp/server.go#L41-L53 |
144,915 | gobuffalo/x | fakesmtp/server.go | readHello | func (s *Server) readHello(c *Connection) {
c.write("220 Welcome")
text := c.read()
s.addMessageLine(text)
c.write("250 Received")
} | go | func (s *Server) readHello(c *Connection) {
c.write("220 Welcome")
text := c.read()
s.addMessageLine(text)
c.write("250 Received")
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"readHello",
"(",
"c",
"*",
"Connection",
")",
"{",
"c",
".",
"write",
"(",
"\"",
"\"",
")",
"\n",
"text",
":=",
"c",
".",
"read",
"(",
")",
"\n",
"s",
".",
"addMessageLine",
"(",
"text",
")",
"\n\n",
"c",
... | //Requests and notifies readed the Hello | [
"Requests",
"and",
"notifies",
"readed",
"the",
"Hello"
] | 6bb134105960cad85951ed5d28b7c127b3ebca87 | https://github.com/gobuffalo/x/blob/6bb134105960cad85951ed5d28b7c127b3ebca87/fakesmtp/server.go#L56-L62 |
144,916 | gobuffalo/x | fakesmtp/server.go | readRecipients | func (s *Server) readRecipients(c *Connection) {
text := c.read()
s.addMessageLine(text)
c.write("250 Recipient")
text = c.read()
for strings.Contains(text, "RCPT") {
s.addMessageLine(text)
c.write("250 Recipient")
text = c.read()
}
} | go | func (s *Server) readRecipients(c *Connection) {
text := c.read()
s.addMessageLine(text)
c.write("250 Recipient")
text = c.read()
for strings.Contains(text, "RCPT") {
s.addMessageLine(text)
c.write("250 Recipient")
text = c.read()
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"readRecipients",
"(",
"c",
"*",
"Connection",
")",
"{",
"text",
":=",
"c",
".",
"read",
"(",
")",
"\n",
"s",
".",
"addMessageLine",
"(",
"text",
")",
"\n\n",
"c",
".",
"write",
"(",
"\"",
"\"",
")",
"\n",
... | //readRecipients reads recipients from the connection | [
"readRecipients",
"reads",
"recipients",
"from",
"the",
"connection"
] | 6bb134105960cad85951ed5d28b7c127b3ebca87 | https://github.com/gobuffalo/x/blob/6bb134105960cad85951ed5d28b7c127b3ebca87/fakesmtp/server.go#L72-L83 |
144,917 | gobuffalo/x | fakesmtp/server.go | readData | func (s *Server) readData(c *Connection) {
c.write("354 Ok Send data ending with <CRLF>.<CRLF>")
for {
text := c.read()
bytes := []byte(text)
s.addMessageLine(text)
// 46 13 10
if bytes[0] == 46 && bytes[1] == 13 && bytes[2] == 10 {
break
}
}
c.write("250 server has transmitted the message")
} | go | func (s *Server) readData(c *Connection) {
c.write("354 Ok Send data ending with <CRLF>.<CRLF>")
for {
text := c.read()
bytes := []byte(text)
s.addMessageLine(text)
// 46 13 10
if bytes[0] == 46 && bytes[1] == 13 && bytes[2] == 10 {
break
}
}
c.write("250 server has transmitted the message")
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"readData",
"(",
"c",
"*",
"Connection",
")",
"{",
"c",
".",
"write",
"(",
"\"",
"\"",
")",
"\n\n",
"for",
"{",
"text",
":=",
"c",
".",
"read",
"(",
")",
"\n",
"bytes",
":=",
"[",
"]",
"byte",
"(",
"text"... | //readData reads the message data. | [
"readData",
"reads",
"the",
"message",
"data",
"."
] | 6bb134105960cad85951ed5d28b7c127b3ebca87 | https://github.com/gobuffalo/x/blob/6bb134105960cad85951ed5d28b7c127b3ebca87/fakesmtp/server.go#L86-L99 |
144,918 | gobuffalo/x | fakesmtp/server.go | addMessageLine | func (s *Server) addMessageLine(text string) {
s.messages[len(s.Messages())-1] = s.LastMessage() + text
} | go | func (s *Server) addMessageLine(text string) {
s.messages[len(s.Messages())-1] = s.LastMessage() + text
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"addMessageLine",
"(",
"text",
"string",
")",
"{",
"s",
".",
"messages",
"[",
"len",
"(",
"s",
".",
"Messages",
"(",
")",
")",
"-",
"1",
"]",
"=",
"s",
".",
"LastMessage",
"(",
")",
"+",
"text",
"\n",
"}"
] | //addMessageLine ads a line to the last message | [
"addMessageLine",
"ads",
"a",
"line",
"to",
"the",
"last",
"message"
] | 6bb134105960cad85951ed5d28b7c127b3ebca87 | https://github.com/gobuffalo/x/blob/6bb134105960cad85951ed5d28b7c127b3ebca87/fakesmtp/server.go#L102-L104 |
144,919 | gobuffalo/x | fakesmtp/server.go | LastMessage | func (s *Server) LastMessage() string {
if len(s.Messages()) == 0 {
return ""
}
return s.Messages()[len(s.Messages())-1]
} | go | func (s *Server) LastMessage() string {
if len(s.Messages()) == 0 {
return ""
}
return s.Messages()[len(s.Messages())-1]
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"LastMessage",
"(",
")",
"string",
"{",
"if",
"len",
"(",
"s",
".",
"Messages",
"(",
")",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"Messages",
"(",
")",
"[",
"len",
... | //LastMessage returns the last message on the server | [
"LastMessage",
"returns",
"the",
"last",
"message",
"on",
"the",
"server"
] | 6bb134105960cad85951ed5d28b7c127b3ebca87 | https://github.com/gobuffalo/x/blob/6bb134105960cad85951ed5d28b7c127b3ebca87/fakesmtp/server.go#L107-L113 |
144,920 | gobuffalo/x | fakesmtp/server.go | Clear | func (s *Server) Clear() {
s.mutex.Lock()
defer s.mutex.Unlock()
s.messages = []string{}
} | go | func (s *Server) Clear() {
s.mutex.Lock()
defer s.mutex.Unlock()
s.messages = []string{}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Clear",
"(",
")",
"{",
"s",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"s",
".",
"messages",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"}"
] | //Clear the server messages | [
"Clear",
"the",
"server",
"messages"
] | 6bb134105960cad85951ed5d28b7c127b3ebca87 | https://github.com/gobuffalo/x/blob/6bb134105960cad85951ed5d28b7c127b3ebca87/fakesmtp/server.go#L121-L126 |
144,921 | gobuffalo/x | fakesmtp/server.go | New | func New(port string) (*Server, error) {
s := &Server{messages: []string{}}
listener, err := net.Listen("tcp", "0.0.0.0:"+port)
if err != nil {
return s, err
}
s.Listener = listener
return s, nil
} | go | func New(port string) (*Server, error) {
s := &Server{messages: []string{}}
listener, err := net.Listen("tcp", "0.0.0.0:"+port)
if err != nil {
return s, err
}
s.Listener = listener
return s, nil
} | [
"func",
"New",
"(",
"port",
"string",
")",
"(",
"*",
"Server",
",",
"error",
")",
"{",
"s",
":=",
"&",
"Server",
"{",
"messages",
":",
"[",
"]",
"string",
"{",
"}",
"}",
"\n\n",
"listener",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"... | //New returns a pointer to a new Server instance listening on the given port. | [
"New",
"returns",
"a",
"pointer",
"to",
"a",
"new",
"Server",
"instance",
"listening",
"on",
"the",
"given",
"port",
"."
] | 6bb134105960cad85951ed5d28b7c127b3ebca87 | https://github.com/gobuffalo/x/blob/6bb134105960cad85951ed5d28b7c127b3ebca87/fakesmtp/server.go#L129-L138 |
144,922 | imkira/go-interpol | interpol.go | New | func New(opts ...Option) *Interpolator {
opts2 := &Options{}
setOptions(opts, newOptionSetter(opts2))
return NewWithOptions(opts2)
} | go | func New(opts ...Option) *Interpolator {
opts2 := &Options{}
setOptions(opts, newOptionSetter(opts2))
return NewWithOptions(opts2)
} | [
"func",
"New",
"(",
"opts",
"...",
"Option",
")",
"*",
"Interpolator",
"{",
"opts2",
":=",
"&",
"Options",
"{",
"}",
"\n",
"setOptions",
"(",
"opts",
",",
"newOptionSetter",
"(",
"opts2",
")",
")",
"\n",
"return",
"NewWithOptions",
"(",
"opts2",
")",
"... | // New creates a new interpolator with the given list of options.
// You can use options such as the ones returned by WithTemplate, WithFormat
// and WithOutput. | [
"New",
"creates",
"a",
"new",
"interpolator",
"with",
"the",
"given",
"list",
"of",
"options",
".",
"You",
"can",
"use",
"options",
"such",
"as",
"the",
"ones",
"returned",
"by",
"WithTemplate",
"WithFormat",
"and",
"WithOutput",
"."
] | 5accad8134979a6ac504d456a6c7f1c53da237ca | https://github.com/imkira/go-interpol/blob/5accad8134979a6ac504d456a6c7f1c53da237ca/interpol.go#L30-L34 |
144,923 | imkira/go-interpol | interpol.go | NewWithOptions | func NewWithOptions(opts *Options) *Interpolator {
return &Interpolator{
template: templateReader(opts),
output: outputWriter(opts),
format: opts.Format,
rb: make([]rune, 0, 64),
start: -1,
closing: false,
}
} | go | func NewWithOptions(opts *Options) *Interpolator {
return &Interpolator{
template: templateReader(opts),
output: outputWriter(opts),
format: opts.Format,
rb: make([]rune, 0, 64),
start: -1,
closing: false,
}
} | [
"func",
"NewWithOptions",
"(",
"opts",
"*",
"Options",
")",
"*",
"Interpolator",
"{",
"return",
"&",
"Interpolator",
"{",
"template",
":",
"templateReader",
"(",
"opts",
")",
",",
"output",
":",
"outputWriter",
"(",
"opts",
")",
",",
"format",
":",
"opts",... | // NewWithOptions creates a new interpolator with the given options. | [
"NewWithOptions",
"creates",
"a",
"new",
"interpolator",
"with",
"the",
"given",
"options",
"."
] | 5accad8134979a6ac504d456a6c7f1c53da237ca | https://github.com/imkira/go-interpol/blob/5accad8134979a6ac504d456a6c7f1c53da237ca/interpol.go#L37-L46 |
144,924 | imkira/go-interpol | interpol.go | Interpolate | func (i *Interpolator) Interpolate() error {
for pos := 0; ; pos++ {
r, _, err := i.template.ReadRune()
if err != nil {
if err == io.EOF {
break
}
return err
}
if err := i.parse(r, pos); err != nil {
return err
}
}
return i.finish()
} | go | func (i *Interpolator) Interpolate() error {
for pos := 0; ; pos++ {
r, _, err := i.template.ReadRune()
if err != nil {
if err == io.EOF {
break
}
return err
}
if err := i.parse(r, pos); err != nil {
return err
}
}
return i.finish()
} | [
"func",
"(",
"i",
"*",
"Interpolator",
")",
"Interpolate",
"(",
")",
"error",
"{",
"for",
"pos",
":=",
"0",
";",
";",
"pos",
"++",
"{",
"r",
",",
"_",
",",
"err",
":=",
"i",
".",
"template",
".",
"ReadRune",
"(",
")",
"\n",
"if",
"err",
"!=",
... | // Interpolate reads runes from Template and writes them to Output, with the
// exception of placeholders which are passed to Format. | [
"Interpolate",
"reads",
"runes",
"from",
"Template",
"and",
"writes",
"them",
"to",
"Output",
"with",
"the",
"exception",
"of",
"placeholders",
"which",
"are",
"passed",
"to",
"Format",
"."
] | 5accad8134979a6ac504d456a6c7f1c53da237ca | https://github.com/imkira/go-interpol/blob/5accad8134979a6ac504d456a6c7f1c53da237ca/interpol.go#L60-L74 |
144,925 | imkira/go-interpol | interpol.go | WithFunc | func WithFunc(template string, format Func) (string, error) {
buffer := bytes.NewBuffer(make([]byte, 0, len(template)))
opts := &Options{
Template: strings.NewReader(template),
Output: buffer,
Format: format,
}
i := NewWithOptions(opts)
if err := i.Interpolate(); err != nil {
return "", err
}
return ... | go | func WithFunc(template string, format Func) (string, error) {
buffer := bytes.NewBuffer(make([]byte, 0, len(template)))
opts := &Options{
Template: strings.NewReader(template),
Output: buffer,
Format: format,
}
i := NewWithOptions(opts)
if err := i.Interpolate(); err != nil {
return "", err
}
return ... | [
"func",
"WithFunc",
"(",
"template",
"string",
",",
"format",
"Func",
")",
"(",
"string",
",",
"error",
")",
"{",
"buffer",
":=",
"bytes",
".",
"NewBuffer",
"(",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"len",
"(",
"template",
")",
")",
")",
... | // WithFunc interpolates the specified template with replacements using the
// given function. | [
"WithFunc",
"interpolates",
"the",
"specified",
"template",
"with",
"replacements",
"using",
"the",
"given",
"function",
"."
] | 5accad8134979a6ac504d456a6c7f1c53da237ca | https://github.com/imkira/go-interpol/blob/5accad8134979a6ac504d456a6c7f1c53da237ca/interpol.go#L144-L156 |
144,926 | imkira/go-interpol | interpol.go | WithMap | func WithMap(template string, m map[string]string) (string, error) {
format := func(key string, w io.Writer) error {
value, ok := m[key]
if !ok {
return ErrKeyNotFound
}
_, err := w.Write([]byte(value))
return err
}
return WithFunc(template, format)
} | go | func WithMap(template string, m map[string]string) (string, error) {
format := func(key string, w io.Writer) error {
value, ok := m[key]
if !ok {
return ErrKeyNotFound
}
_, err := w.Write([]byte(value))
return err
}
return WithFunc(template, format)
} | [
"func",
"WithMap",
"(",
"template",
"string",
",",
"m",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"format",
":=",
"func",
"(",
"key",
"string",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"value",
",",
... | // WithMap interpolates the specified template with replacements using the
// given map. If a placeholder is used for which a value is not found, an error
// is returned. | [
"WithMap",
"interpolates",
"the",
"specified",
"template",
"with",
"replacements",
"using",
"the",
"given",
"map",
".",
"If",
"a",
"placeholder",
"is",
"used",
"for",
"which",
"a",
"value",
"is",
"not",
"found",
"an",
"error",
"is",
"returned",
"."
] | 5accad8134979a6ac504d456a6c7f1c53da237ca | https://github.com/imkira/go-interpol/blob/5accad8134979a6ac504d456a6c7f1c53da237ca/interpol.go#L161-L171 |
144,927 | imkira/go-interpol | options.go | WithTemplate | func WithTemplate(template io.Reader) Option {
return func(setter OptionSetter) {
setter.SetTemplate(template)
}
} | go | func WithTemplate(template io.Reader) Option {
return func(setter OptionSetter) {
setter.SetTemplate(template)
}
} | [
"func",
"WithTemplate",
"(",
"template",
"io",
".",
"Reader",
")",
"Option",
"{",
"return",
"func",
"(",
"setter",
"OptionSetter",
")",
"{",
"setter",
".",
"SetTemplate",
"(",
"template",
")",
"\n",
"}",
"\n",
"}"
] | // WithTemplate assigns Template to Options. | [
"WithTemplate",
"assigns",
"Template",
"to",
"Options",
"."
] | 5accad8134979a6ac504d456a6c7f1c53da237ca | https://github.com/imkira/go-interpol/blob/5accad8134979a6ac504d456a6c7f1c53da237ca/options.go#L24-L28 |
144,928 | imkira/go-interpol | options.go | WithOutput | func WithOutput(output io.Writer) Option {
return func(setter OptionSetter) {
setter.SetOutput(output)
}
} | go | func WithOutput(output io.Writer) Option {
return func(setter OptionSetter) {
setter.SetOutput(output)
}
} | [
"func",
"WithOutput",
"(",
"output",
"io",
".",
"Writer",
")",
"Option",
"{",
"return",
"func",
"(",
"setter",
"OptionSetter",
")",
"{",
"setter",
".",
"SetOutput",
"(",
"output",
")",
"\n",
"}",
"\n",
"}"
] | // WithOutput assigns Output to Options. | [
"WithOutput",
"assigns",
"Output",
"to",
"Options",
"."
] | 5accad8134979a6ac504d456a6c7f1c53da237ca | https://github.com/imkira/go-interpol/blob/5accad8134979a6ac504d456a6c7f1c53da237ca/options.go#L38-L42 |
144,929 | lucas-clemente/aes12 | xor.go | xorBytes | func xorBytes(dst, a, b []byte) int {
if supportsUnaligned {
return fastXORBytes(dst, a, b)
} else {
// TODO(hanwen): if (dst, a, b) have common alignment
// we could still try fastXORBytes. It is not clear
// how often this happens, and it's only worth it if
// the block encryption itself is hardware
// ... | go | func xorBytes(dst, a, b []byte) int {
if supportsUnaligned {
return fastXORBytes(dst, a, b)
} else {
// TODO(hanwen): if (dst, a, b) have common alignment
// we could still try fastXORBytes. It is not clear
// how often this happens, and it's only worth it if
// the block encryption itself is hardware
// ... | [
"func",
"xorBytes",
"(",
"dst",
",",
"a",
",",
"b",
"[",
"]",
"byte",
")",
"int",
"{",
"if",
"supportsUnaligned",
"{",
"return",
"fastXORBytes",
"(",
"dst",
",",
"a",
",",
"b",
")",
"\n",
"}",
"else",
"{",
"// TODO(hanwen): if (dst, a, b) have common align... | // xorBytes xors the bytes in a and b. The destination is assumed to have enough
// space. Returns the number of bytes xor'd. | [
"xorBytes",
"xors",
"the",
"bytes",
"in",
"a",
"and",
"b",
".",
"The",
"destination",
"is",
"assumed",
"to",
"have",
"enough",
"space",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"xor",
"d",
"."
] | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/xor.go#L53-L64 |
144,930 | lucas-clemente/aes12 | cipher_generic.go | expandKey | func expandKey(key []byte, enc, dec []uint32) {
expandKeyGo(key, enc, dec)
} | go | func expandKey(key []byte, enc, dec []uint32) {
expandKeyGo(key, enc, dec)
} | [
"func",
"expandKey",
"(",
"key",
"[",
"]",
"byte",
",",
"enc",
",",
"dec",
"[",
"]",
"uint32",
")",
"{",
"expandKeyGo",
"(",
"key",
",",
"enc",
",",
"dec",
")",
"\n",
"}"
] | // expandKey is used by BenchmarkExpand and should
// call an assembly implementation if one is available. | [
"expandKey",
"is",
"used",
"by",
"BenchmarkExpand",
"and",
"should",
"call",
"an",
"assembly",
"implementation",
"if",
"one",
"is",
"available",
"."
] | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/cipher_generic.go#L20-L22 |
144,931 | lucas-clemente/aes12 | aes_gcm.go | Seal | func (g *gcmAsm) Seal(dst, nonce, plaintext, data []byte) []byte {
if len(nonce) != g.nonceSize {
panic("cipher: incorrect nonce length given to GCM")
}
var counter, tagMask [gcmBlockSize]byte
if len(nonce) == gcmStandardNonceSize {
// Init counter to nonce||1
copy(counter[:], nonce)
counter[gcmBlockSize-... | go | func (g *gcmAsm) Seal(dst, nonce, plaintext, data []byte) []byte {
if len(nonce) != g.nonceSize {
panic("cipher: incorrect nonce length given to GCM")
}
var counter, tagMask [gcmBlockSize]byte
if len(nonce) == gcmStandardNonceSize {
// Init counter to nonce||1
copy(counter[:], nonce)
counter[gcmBlockSize-... | [
"func",
"(",
"g",
"*",
"gcmAsm",
")",
"Seal",
"(",
"dst",
",",
"nonce",
",",
"plaintext",
",",
"data",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"if",
"len",
"(",
"nonce",
")",
"!=",
"g",
".",
"nonceSize",
"{",
"panic",
"(",
"\"",
"\"",
"... | // Seal encrypts and authenticates plaintext. See the AEAD interface for
// details. | [
"Seal",
"encrypts",
"and",
"authenticates",
"plaintext",
".",
"See",
"the",
"AEAD",
"interface",
"for",
"details",
"."
] | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/aes_gcm.go#L71-L101 |
144,932 | lucas-clemente/aes12 | aes_gcm.go | Open | func (g *gcmAsm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
if len(nonce) != g.nonceSize {
panic("cipher: incorrect nonce length given to GCM")
}
if len(ciphertext) < gcmTagSize {
return nil, errOpen
}
tag := ciphertext[len(ciphertext)-gcmTagSize:]
ciphertext = ciphertext[:len(ciphertext)-gc... | go | func (g *gcmAsm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
if len(nonce) != g.nonceSize {
panic("cipher: incorrect nonce length given to GCM")
}
if len(ciphertext) < gcmTagSize {
return nil, errOpen
}
tag := ciphertext[len(ciphertext)-gcmTagSize:]
ciphertext = ciphertext[:len(ciphertext)-gc... | [
"func",
"(",
"g",
"*",
"gcmAsm",
")",
"Open",
"(",
"dst",
",",
"nonce",
",",
"ciphertext",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"len",
"(",
"nonce",
")",
"!=",
"g",
".",
"nonceSize",
"{",
"p... | // Open authenticates and decrypts ciphertext. See the AEAD interface
// for details. | [
"Open",
"authenticates",
"and",
"decrypts",
"ciphertext",
".",
"See",
"the",
"AEAD",
"interface",
"for",
"details",
"."
] | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/aes_gcm.go#L105-L148 |
144,933 | lucas-clemente/aes12 | cipher_amd64.go | expandKey | func expandKey(key []byte, enc, dec []uint32) {
if useAsm {
rounds := 10 // rounds needed for AES128
switch len(key) {
case 192 / 8:
rounds = 12
case 256 / 8:
rounds = 14
}
expandKeyAsm(rounds, &key[0], &enc[0], &dec[0])
} else {
expandKeyGo(key, enc, dec)
}
} | go | func expandKey(key []byte, enc, dec []uint32) {
if useAsm {
rounds := 10 // rounds needed for AES128
switch len(key) {
case 192 / 8:
rounds = 12
case 256 / 8:
rounds = 14
}
expandKeyAsm(rounds, &key[0], &enc[0], &dec[0])
} else {
expandKeyGo(key, enc, dec)
}
} | [
"func",
"expandKey",
"(",
"key",
"[",
"]",
"byte",
",",
"enc",
",",
"dec",
"[",
"]",
"uint32",
")",
"{",
"if",
"useAsm",
"{",
"rounds",
":=",
"10",
"// rounds needed for AES128",
"\n",
"switch",
"len",
"(",
"key",
")",
"{",
"case",
"192",
"/",
"8",
... | // expandKey is used by BenchmarkExpand to ensure that the asm implementation
// of key expansion is used for the benchmark when it is available. | [
"expandKey",
"is",
"used",
"by",
"BenchmarkExpand",
"to",
"ensure",
"that",
"the",
"asm",
"implementation",
"of",
"key",
"expansion",
"is",
"used",
"for",
"the",
"benchmark",
"when",
"it",
"is",
"available",
"."
] | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/cipher_amd64.go#L66-L79 |
144,934 | lucas-clemente/aes12 | block.go | subw | func subw(w uint32) uint32 {
return uint32(sbox0[w>>24])<<24 |
uint32(sbox0[w>>16&0xff])<<16 |
uint32(sbox0[w>>8&0xff])<<8 |
uint32(sbox0[w&0xff])
} | go | func subw(w uint32) uint32 {
return uint32(sbox0[w>>24])<<24 |
uint32(sbox0[w>>16&0xff])<<16 |
uint32(sbox0[w>>8&0xff])<<8 |
uint32(sbox0[w&0xff])
} | [
"func",
"subw",
"(",
"w",
"uint32",
")",
"uint32",
"{",
"return",
"uint32",
"(",
"sbox0",
"[",
"w",
">>",
"24",
"]",
")",
"<<",
"24",
"|",
"uint32",
"(",
"sbox0",
"[",
"w",
">>",
"16",
"&",
"0xff",
"]",
")",
"<<",
"16",
"|",
"uint32",
"(",
"s... | // Apply sbox0 to each byte in w. | [
"Apply",
"sbox0",
"to",
"each",
"byte",
"in",
"w",
"."
] | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/block.go#L130-L135 |
144,935 | lucas-clemente/aes12 | gcm.go | NewGCMWithNonceSize | func NewGCMWithNonceSize(cipher Block, size int) (AEAD, error) {
if cipher, ok := cipher.(gcmAble); ok {
return cipher.NewGCM(size)
}
if cipher.BlockSize() != gcmBlockSize {
return nil, errors.New("cipher: NewGCM requires 128-bit block cipher")
}
var key [gcmBlockSize]byte
cipher.Encrypt(key[:], key[:])
g... | go | func NewGCMWithNonceSize(cipher Block, size int) (AEAD, error) {
if cipher, ok := cipher.(gcmAble); ok {
return cipher.NewGCM(size)
}
if cipher.BlockSize() != gcmBlockSize {
return nil, errors.New("cipher: NewGCM requires 128-bit block cipher")
}
var key [gcmBlockSize]byte
cipher.Encrypt(key[:], key[:])
g... | [
"func",
"NewGCMWithNonceSize",
"(",
"cipher",
"Block",
",",
"size",
"int",
")",
"(",
"AEAD",
",",
"error",
")",
"{",
"if",
"cipher",
",",
"ok",
":=",
"cipher",
".",
"(",
"gcmAble",
")",
";",
"ok",
"{",
"return",
"cipher",
".",
"NewGCM",
"(",
"size",
... | // NewGCMWithNonceSize returns the given 128-bit, block cipher wrapped in Galois
// Counter Mode, which accepts nonces of the given length.
//
// Only use this function if you require compatibility with an existing
// cryptosystem that uses non-standard nonce lengths. All other users should use
// NewGCM, which is fast... | [
"NewGCMWithNonceSize",
"returns",
"the",
"given",
"128",
"-",
"bit",
"block",
"cipher",
"wrapped",
"in",
"Galois",
"Counter",
"Mode",
"which",
"accepts",
"nonces",
"of",
"the",
"given",
"length",
".",
"Only",
"use",
"this",
"function",
"if",
"you",
"require",
... | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/gcm.go#L87-L118 |
144,936 | lucas-clemente/aes12 | gcm.go | reverseBits | func reverseBits(i int) int {
i = ((i << 2) & 0xc) | ((i >> 2) & 0x3)
i = ((i << 1) & 0xa) | ((i >> 1) & 0x5)
return i
} | go | func reverseBits(i int) int {
i = ((i << 2) & 0xc) | ((i >> 2) & 0x3)
i = ((i << 1) & 0xa) | ((i >> 1) & 0x5)
return i
} | [
"func",
"reverseBits",
"(",
"i",
"int",
")",
"int",
"{",
"i",
"=",
"(",
"(",
"i",
"<<",
"2",
")",
"&",
"0xc",
")",
"|",
"(",
"(",
"i",
">>",
"2",
")",
"&",
"0x3",
")",
"\n",
"i",
"=",
"(",
"(",
"i",
"<<",
"1",
")",
"&",
"0xa",
")",
"|... | // reverseBits reverses the order of the bits of 4-bit number in i. | [
"reverseBits",
"reverses",
"the",
"order",
"of",
"the",
"bits",
"of",
"4",
"-",
"bit",
"number",
"in",
"i",
"."
] | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/gcm.go#L196-L200 |
144,937 | lucas-clemente/aes12 | gcm.go | updateBlocks | func (g *gcm) updateBlocks(y *gcmFieldElement, blocks []byte) {
for len(blocks) > 0 {
y.low ^= getUint64(blocks)
y.high ^= getUint64(blocks[8:])
g.mul(y)
blocks = blocks[gcmBlockSize:]
}
} | go | func (g *gcm) updateBlocks(y *gcmFieldElement, blocks []byte) {
for len(blocks) > 0 {
y.low ^= getUint64(blocks)
y.high ^= getUint64(blocks[8:])
g.mul(y)
blocks = blocks[gcmBlockSize:]
}
} | [
"func",
"(",
"g",
"*",
"gcm",
")",
"updateBlocks",
"(",
"y",
"*",
"gcmFieldElement",
",",
"blocks",
"[",
"]",
"byte",
")",
"{",
"for",
"len",
"(",
"blocks",
")",
">",
"0",
"{",
"y",
".",
"low",
"^=",
"getUint64",
"(",
"blocks",
")",
"\n",
"y",
... | // updateBlocks extends y with more polynomial terms from blocks, based on
// Horner's rule. There must be a multiple of gcmBlockSize bytes in blocks. | [
"updateBlocks",
"extends",
"y",
"with",
"more",
"polynomial",
"terms",
"from",
"blocks",
"based",
"on",
"Horner",
"s",
"rule",
".",
"There",
"must",
"be",
"a",
"multiple",
"of",
"gcmBlockSize",
"bytes",
"in",
"blocks",
"."
] | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/gcm.go#L271-L278 |
144,938 | lucas-clemente/aes12 | gcm.go | update | func (g *gcm) update(y *gcmFieldElement, data []byte) {
fullBlocks := (len(data) >> 4) << 4
g.updateBlocks(y, data[:fullBlocks])
if len(data) != fullBlocks {
var partialBlock [gcmBlockSize]byte
copy(partialBlock[:], data[fullBlocks:])
g.updateBlocks(y, partialBlock[:])
}
} | go | func (g *gcm) update(y *gcmFieldElement, data []byte) {
fullBlocks := (len(data) >> 4) << 4
g.updateBlocks(y, data[:fullBlocks])
if len(data) != fullBlocks {
var partialBlock [gcmBlockSize]byte
copy(partialBlock[:], data[fullBlocks:])
g.updateBlocks(y, partialBlock[:])
}
} | [
"func",
"(",
"g",
"*",
"gcm",
")",
"update",
"(",
"y",
"*",
"gcmFieldElement",
",",
"data",
"[",
"]",
"byte",
")",
"{",
"fullBlocks",
":=",
"(",
"len",
"(",
"data",
")",
">>",
"4",
")",
"<<",
"4",
"\n",
"g",
".",
"updateBlocks",
"(",
"y",
",",
... | // update extends y with more polynomial terms from data. If data is not a
// multiple of gcmBlockSize bytes long then the remainder is zero padded. | [
"update",
"extends",
"y",
"with",
"more",
"polynomial",
"terms",
"from",
"data",
".",
"If",
"data",
"is",
"not",
"a",
"multiple",
"of",
"gcmBlockSize",
"bytes",
"long",
"then",
"the",
"remainder",
"is",
"zero",
"padded",
"."
] | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/gcm.go#L282-L291 |
144,939 | lucas-clemente/aes12 | gcm.go | gcmInc32 | func gcmInc32(counterBlock *[16]byte) {
for i := gcmBlockSize - 1; i >= gcmBlockSize-4; i-- {
counterBlock[i]++
if counterBlock[i] != 0 {
break
}
}
} | go | func gcmInc32(counterBlock *[16]byte) {
for i := gcmBlockSize - 1; i >= gcmBlockSize-4; i-- {
counterBlock[i]++
if counterBlock[i] != 0 {
break
}
}
} | [
"func",
"gcmInc32",
"(",
"counterBlock",
"*",
"[",
"16",
"]",
"byte",
")",
"{",
"for",
"i",
":=",
"gcmBlockSize",
"-",
"1",
";",
"i",
">=",
"gcmBlockSize",
"-",
"4",
";",
"i",
"--",
"{",
"counterBlock",
"[",
"i",
"]",
"++",
"\n",
"if",
"counterBloc... | // gcmInc32 treats the final four bytes of counterBlock as a big-endian value
// and increments it. | [
"gcmInc32",
"treats",
"the",
"final",
"four",
"bytes",
"of",
"counterBlock",
"as",
"a",
"big",
"-",
"endian",
"value",
"and",
"increments",
"it",
"."
] | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/gcm.go#L295-L302 |
144,940 | lucas-clemente/aes12 | gcm.go | counterCrypt | func (g *gcm) counterCrypt(out, in []byte, counter *[gcmBlockSize]byte) {
var mask [gcmBlockSize]byte
for len(in) >= gcmBlockSize {
g.cipher.Encrypt(mask[:], counter[:])
gcmInc32(counter)
xorWords(out, in, mask[:])
out = out[gcmBlockSize:]
in = in[gcmBlockSize:]
}
if len(in) > 0 {
g.cipher.Encrypt(ma... | go | func (g *gcm) counterCrypt(out, in []byte, counter *[gcmBlockSize]byte) {
var mask [gcmBlockSize]byte
for len(in) >= gcmBlockSize {
g.cipher.Encrypt(mask[:], counter[:])
gcmInc32(counter)
xorWords(out, in, mask[:])
out = out[gcmBlockSize:]
in = in[gcmBlockSize:]
}
if len(in) > 0 {
g.cipher.Encrypt(ma... | [
"func",
"(",
"g",
"*",
"gcm",
")",
"counterCrypt",
"(",
"out",
",",
"in",
"[",
"]",
"byte",
",",
"counter",
"*",
"[",
"gcmBlockSize",
"]",
"byte",
")",
"{",
"var",
"mask",
"[",
"gcmBlockSize",
"]",
"byte",
"\n\n",
"for",
"len",
"(",
"in",
")",
">... | // counterCrypt crypts in to out using g.cipher in counter mode. | [
"counterCrypt",
"crypts",
"in",
"to",
"out",
"using",
"g",
".",
"cipher",
"in",
"counter",
"mode",
"."
] | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/gcm.go#L320-L337 |
144,941 | lucas-clemente/aes12 | gcm.go | deriveCounter | func (g *gcm) deriveCounter(counter *[gcmBlockSize]byte, nonce []byte) {
// GCM has two modes of operation with respect to the initial counter
// state: a "fast path" for 96-bit (12-byte) nonces, and a "slow path"
// for nonces of other lengths. For a 96-bit nonce, the nonce, along
// with a four-byte big-endian co... | go | func (g *gcm) deriveCounter(counter *[gcmBlockSize]byte, nonce []byte) {
// GCM has two modes of operation with respect to the initial counter
// state: a "fast path" for 96-bit (12-byte) nonces, and a "slow path"
// for nonces of other lengths. For a 96-bit nonce, the nonce, along
// with a four-byte big-endian co... | [
"func",
"(",
"g",
"*",
"gcm",
")",
"deriveCounter",
"(",
"counter",
"*",
"[",
"gcmBlockSize",
"]",
"byte",
",",
"nonce",
"[",
"]",
"byte",
")",
"{",
"// GCM has two modes of operation with respect to the initial counter",
"// state: a \"fast path\" for 96-bit (12-byte) no... | // deriveCounter computes the initial GCM counter state from the given nonce.
// See NIST SP 800-38D, section 7.1. This assumes that counter is filled with
// zeros on entry. | [
"deriveCounter",
"computes",
"the",
"initial",
"GCM",
"counter",
"state",
"from",
"the",
"given",
"nonce",
".",
"See",
"NIST",
"SP",
"800",
"-",
"38D",
"section",
"7",
".",
"1",
".",
"This",
"assumes",
"that",
"counter",
"is",
"filled",
"with",
"zeros",
... | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/gcm.go#L342-L360 |
144,942 | lucas-clemente/aes12 | cipher.go | NewCipher | func NewCipher(key []byte) (Block, error) {
k := len(key)
switch k {
default:
return nil, KeySizeError(k)
case 16, 24, 32:
break
}
return newCipher(key)
} | go | func NewCipher(key []byte) (Block, error) {
k := len(key)
switch k {
default:
return nil, KeySizeError(k)
case 16, 24, 32:
break
}
return newCipher(key)
} | [
"func",
"NewCipher",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"Block",
",",
"error",
")",
"{",
"k",
":=",
"len",
"(",
"key",
")",
"\n",
"switch",
"k",
"{",
"default",
":",
"return",
"nil",
",",
"KeySizeError",
"(",
"k",
")",
"\n",
"case",
"16",
... | // NewCipher creates and returns a new Block.
// The key argument should be the AES key,
// either 16, 24, or 32 bytes to select
// AES-128, AES-192, or AES-256. | [
"NewCipher",
"creates",
"and",
"returns",
"a",
"new",
"Block",
".",
"The",
"key",
"argument",
"should",
"be",
"the",
"AES",
"key",
"either",
"16",
"24",
"or",
"32",
"bytes",
"to",
"select",
"AES",
"-",
"128",
"AES",
"-",
"192",
"or",
"AES",
"-",
"256... | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/cipher.go#L28-L37 |
144,943 | lucas-clemente/aes12 | cipher.go | newCipherGeneric | func newCipherGeneric(key []byte) (Block, error) {
n := len(key) + 28
c := aesCipher{make([]uint32, n), make([]uint32, n)}
expandKeyGo(key, c.enc, c.dec)
return &c, nil
} | go | func newCipherGeneric(key []byte) (Block, error) {
n := len(key) + 28
c := aesCipher{make([]uint32, n), make([]uint32, n)}
expandKeyGo(key, c.enc, c.dec)
return &c, nil
} | [
"func",
"newCipherGeneric",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"Block",
",",
"error",
")",
"{",
"n",
":=",
"len",
"(",
"key",
")",
"+",
"28",
"\n",
"c",
":=",
"aesCipher",
"{",
"make",
"(",
"[",
"]",
"uint32",
",",
"n",
")",
",",
"make",
... | // newCipherGeneric creates and returns a new Block
// implemented in pure Go. | [
"newCipherGeneric",
"creates",
"and",
"returns",
"a",
"new",
"Block",
"implemented",
"in",
"pure",
"Go",
"."
] | cd47fb39b79f867c6e4e5cd39cf7abd799f71670 | https://github.com/lucas-clemente/aes12/blob/cd47fb39b79f867c6e4e5cd39cf7abd799f71670/cipher.go#L41-L46 |
144,944 | chewxy/hm | perf.go | ReturnSubs | func ReturnSubs(sub Subs) {
switch s := sub.(type) {
case mSubs:
for k := range s {
delete(s, k)
}
mSubPool.Put(sub)
case *sSubs:
size := cap(s.s) - 2
if size > 0 && size < poolSize+1 {
// reset to empty
for i := range s.s {
s.s[i] = Substitution{}
}
s.s = s.s[:size]
sSubPool[size-1]... | go | func ReturnSubs(sub Subs) {
switch s := sub.(type) {
case mSubs:
for k := range s {
delete(s, k)
}
mSubPool.Put(sub)
case *sSubs:
size := cap(s.s) - 2
if size > 0 && size < poolSize+1 {
// reset to empty
for i := range s.s {
s.s[i] = Substitution{}
}
s.s = s.s[:size]
sSubPool[size-1]... | [
"func",
"ReturnSubs",
"(",
"sub",
"Subs",
")",
"{",
"switch",
"s",
":=",
"sub",
".",
"(",
"type",
")",
"{",
"case",
"mSubs",
":",
"for",
"k",
":=",
"range",
"s",
"{",
"delete",
"(",
"s",
",",
"k",
")",
"\n",
"}",
"\n",
"mSubPool",
".",
"Put",
... | // ReturnSubs returns substitutions to the pool. USE WITH CAUTION. | [
"ReturnSubs",
"returns",
"substitutions",
"to",
"the",
"pool",
".",
"USE",
"WITH",
"CAUTION",
"."
] | 61efb3290a086d1335e8954b3734c102126818ba | https://github.com/chewxy/hm/blob/61efb3290a086d1335e8954b3734c102126818ba/perf.go#L30-L49 |
144,945 | chewxy/hm | perf.go | BorrowSSubs | func BorrowSSubs(size int) *sSubs {
if size > 0 && size < 5 {
retVal := sSubPool[size-1].Get().(*sSubs)
return retVal
}
s := make([]Substitution, size)
return &sSubs{s: s}
} | go | func BorrowSSubs(size int) *sSubs {
if size > 0 && size < 5 {
retVal := sSubPool[size-1].Get().(*sSubs)
return retVal
}
s := make([]Substitution, size)
return &sSubs{s: s}
} | [
"func",
"BorrowSSubs",
"(",
"size",
"int",
")",
"*",
"sSubs",
"{",
"if",
"size",
">",
"0",
"&&",
"size",
"<",
"5",
"{",
"retVal",
":=",
"sSubPool",
"[",
"size",
"-",
"1",
"]",
".",
"Get",
"(",
")",
".",
"(",
"*",
"sSubs",
")",
"\n",
"return",
... | // BorrowSSubs gets a slice based substituiton from a shared pool. USE WITH CAUTION | [
"BorrowSSubs",
"gets",
"a",
"slice",
"based",
"substituiton",
"from",
"a",
"shared",
"pool",
".",
"USE",
"WITH",
"CAUTION"
] | 61efb3290a086d1335e8954b3734c102126818ba | https://github.com/chewxy/hm/blob/61efb3290a086d1335e8954b3734c102126818ba/perf.go#L57-L64 |
144,946 | chewxy/hm | perf.go | BorrowTypes | func BorrowTypes(size int) Types {
if size > 0 && size < poolSize+1 {
return typesPool[size-1].Get().(Types)
}
return make(Types, size)
} | go | func BorrowTypes(size int) Types {
if size > 0 && size < poolSize+1 {
return typesPool[size-1].Get().(Types)
}
return make(Types, size)
} | [
"func",
"BorrowTypes",
"(",
"size",
"int",
")",
"Types",
"{",
"if",
"size",
">",
"0",
"&&",
"size",
"<",
"poolSize",
"+",
"1",
"{",
"return",
"typesPool",
"[",
"size",
"-",
"1",
"]",
".",
"Get",
"(",
")",
".",
"(",
"Types",
")",
"\n",
"}",
"\n"... | // BorrowTypes gets a slice of Types with size. USE WITH CAUTION. | [
"BorrowTypes",
"gets",
"a",
"slice",
"of",
"Types",
"with",
"size",
".",
"USE",
"WITH",
"CAUTION",
"."
] | 61efb3290a086d1335e8954b3734c102126818ba | https://github.com/chewxy/hm/blob/61efb3290a086d1335e8954b3734c102126818ba/perf.go#L85-L90 |
144,947 | chewxy/hm | perf.go | ReturnTypes | func ReturnTypes(ts Types) {
if size := cap(ts); size > 0 && size < poolSize+1 {
ts = ts[:cap(ts)]
for i := range ts {
ts[i] = nil
}
typesPool[size-1].Put(ts)
}
} | go | func ReturnTypes(ts Types) {
if size := cap(ts); size > 0 && size < poolSize+1 {
ts = ts[:cap(ts)]
for i := range ts {
ts[i] = nil
}
typesPool[size-1].Put(ts)
}
} | [
"func",
"ReturnTypes",
"(",
"ts",
"Types",
")",
"{",
"if",
"size",
":=",
"cap",
"(",
"ts",
")",
";",
"size",
">",
"0",
"&&",
"size",
"<",
"poolSize",
"+",
"1",
"{",
"ts",
"=",
"ts",
"[",
":",
"cap",
"(",
"ts",
")",
"]",
"\n",
"for",
"i",
":... | // ReturnTypes returns the slice of types into the pool. USE WITH CAUTION | [
"ReturnTypes",
"returns",
"the",
"slice",
"of",
"types",
"into",
"the",
"pool",
".",
"USE",
"WITH",
"CAUTION"
] | 61efb3290a086d1335e8954b3734c102126818ba | https://github.com/chewxy/hm/blob/61efb3290a086d1335e8954b3734c102126818ba/perf.go#L93-L101 |
144,948 | chewxy/hm | perf.go | BorrowTypeVarSet | func BorrowTypeVarSet(size int) TypeVarSet {
if size > 0 && size < poolSize+1 {
return typeVarSetPool[size-1].Get().(TypeVarSet)
}
return make(TypeVarSet, size)
} | go | func BorrowTypeVarSet(size int) TypeVarSet {
if size > 0 && size < poolSize+1 {
return typeVarSetPool[size-1].Get().(TypeVarSet)
}
return make(TypeVarSet, size)
} | [
"func",
"BorrowTypeVarSet",
"(",
"size",
"int",
")",
"TypeVarSet",
"{",
"if",
"size",
">",
"0",
"&&",
"size",
"<",
"poolSize",
"+",
"1",
"{",
"return",
"typeVarSetPool",
"[",
"size",
"-",
"1",
"]",
".",
"Get",
"(",
")",
".",
"(",
"TypeVarSet",
")",
... | // BorrowTypeVarSet gets a TypeVarSet of size from pool. USE WITH CAUTION | [
"BorrowTypeVarSet",
"gets",
"a",
"TypeVarSet",
"of",
"size",
"from",
"pool",
".",
"USE",
"WITH",
"CAUTION"
] | 61efb3290a086d1335e8954b3734c102126818ba | https://github.com/chewxy/hm/blob/61efb3290a086d1335e8954b3734c102126818ba/perf.go#L122-L127 |
144,949 | chewxy/hm | perf.go | ReturnTypeVarSet | func ReturnTypeVarSet(ts TypeVarSet) {
var def TypeVariable
if size := cap(ts); size > 0 && size < poolSize+1 {
ts = ts[:cap(ts)]
for i := range ts {
ts[i] = def
}
typeVarSetPool[size-1].Put(ts)
}
} | go | func ReturnTypeVarSet(ts TypeVarSet) {
var def TypeVariable
if size := cap(ts); size > 0 && size < poolSize+1 {
ts = ts[:cap(ts)]
for i := range ts {
ts[i] = def
}
typeVarSetPool[size-1].Put(ts)
}
} | [
"func",
"ReturnTypeVarSet",
"(",
"ts",
"TypeVarSet",
")",
"{",
"var",
"def",
"TypeVariable",
"\n",
"if",
"size",
":=",
"cap",
"(",
"ts",
")",
";",
"size",
">",
"0",
"&&",
"size",
"<",
"poolSize",
"+",
"1",
"{",
"ts",
"=",
"ts",
"[",
":",
"cap",
"... | // ReturnTypeVarSet returns the TypeVarSet to pool. USE WITH CAUTION | [
"ReturnTypeVarSet",
"returns",
"the",
"TypeVarSet",
"to",
"pool",
".",
"USE",
"WITH",
"CAUTION"
] | 61efb3290a086d1335e8954b3734c102126818ba | https://github.com/chewxy/hm/blob/61efb3290a086d1335e8954b3734c102126818ba/perf.go#L130-L139 |
144,950 | chewxy/hm | type.go | NewRecordType | func NewRecordType(name string, ts ...Type) *Record {
return &Record{
ts: ts,
name: name,
}
} | go | func NewRecordType(name string, ts ...Type) *Record {
return &Record{
ts: ts,
name: name,
}
} | [
"func",
"NewRecordType",
"(",
"name",
"string",
",",
"ts",
"...",
"Type",
")",
"*",
"Record",
"{",
"return",
"&",
"Record",
"{",
"ts",
":",
"ts",
",",
"name",
":",
"name",
",",
"}",
"\n",
"}"
] | // NewRecordType creates a new Record Type | [
"NewRecordType",
"creates",
"a",
"new",
"Record",
"Type"
] | 61efb3290a086d1335e8954b3734c102126818ba | https://github.com/chewxy/hm/blob/61efb3290a086d1335e8954b3734c102126818ba/type.go#L44-L49 |
144,951 | chewxy/hm | functionType.go | Ret | func (t *FunctionType) Ret(recursive bool) Type {
if !recursive {
return t.b
}
if fnt, ok := t.b.(*FunctionType); ok {
return fnt.Ret(recursive)
}
return t.b
} | go | func (t *FunctionType) Ret(recursive bool) Type {
if !recursive {
return t.b
}
if fnt, ok := t.b.(*FunctionType); ok {
return fnt.Ret(recursive)
}
return t.b
} | [
"func",
"(",
"t",
"*",
"FunctionType",
")",
"Ret",
"(",
"recursive",
"bool",
")",
"Type",
"{",
"if",
"!",
"recursive",
"{",
"return",
"t",
".",
"b",
"\n",
"}",
"\n\n",
"if",
"fnt",
",",
"ok",
":=",
"t",
".",
"b",
".",
"(",
"*",
"FunctionType",
... | // Ret returns the return type of a function. If recursive is true, it will get the final return type | [
"Ret",
"returns",
"the",
"return",
"type",
"of",
"a",
"function",
".",
"If",
"recursive",
"is",
"true",
"it",
"will",
"get",
"the",
"final",
"return",
"type"
] | 61efb3290a086d1335e8954b3734c102126818ba | https://github.com/chewxy/hm/blob/61efb3290a086d1335e8954b3734c102126818ba/functionType.go#L73-L83 |
144,952 | chewxy/hm | functionType.go | FlatTypes | func (t *FunctionType) FlatTypes() Types {
retVal := BorrowTypes(8) // start with 8. Can always grow
retVal = retVal[:0]
if a, ok := t.a.(*FunctionType); ok {
ft := a.FlatTypes()
retVal = append(retVal, ft...)
ReturnTypes(ft)
} else {
retVal = append(retVal, t.a)
}
if b, ok := t.b.(*FunctionType); ok {
... | go | func (t *FunctionType) FlatTypes() Types {
retVal := BorrowTypes(8) // start with 8. Can always grow
retVal = retVal[:0]
if a, ok := t.a.(*FunctionType); ok {
ft := a.FlatTypes()
retVal = append(retVal, ft...)
ReturnTypes(ft)
} else {
retVal = append(retVal, t.a)
}
if b, ok := t.b.(*FunctionType); ok {
... | [
"func",
"(",
"t",
"*",
"FunctionType",
")",
"FlatTypes",
"(",
")",
"Types",
"{",
"retVal",
":=",
"BorrowTypes",
"(",
"8",
")",
"// start with 8. Can always grow",
"\n",
"retVal",
"=",
"retVal",
"[",
":",
"0",
"]",
"\n\n",
"if",
"a",
",",
"ok",
":=",
"t... | // FlatTypes returns the types in FunctionTypes as a flat slice of types. This allows for easier iteration in some applications | [
"FlatTypes",
"returns",
"the",
"types",
"in",
"FunctionTypes",
"as",
"a",
"flat",
"slice",
"of",
"types",
".",
"This",
"allows",
"for",
"easier",
"iteration",
"in",
"some",
"applications"
] | 61efb3290a086d1335e8954b3734c102126818ba | https://github.com/chewxy/hm/blob/61efb3290a086d1335e8954b3734c102126818ba/functionType.go#L86-L106 |
144,953 | chewxy/hm | scheme.go | Normalize | func (s *Scheme) Normalize() (err error) {
tfv := s.t.FreeTypeVar()
if len(tfv) == 0 {
return nil
}
defer ReturnTypeVarSet(tfv)
ord := BorrowTypeVarSet(len(tfv))
for i := range tfv {
ord[i] = TypeVariable(letters[i])
}
s.t, err = s.t.Normalize(tfv, ord)
s.tvs = ord.Set()
return
} | go | func (s *Scheme) Normalize() (err error) {
tfv := s.t.FreeTypeVar()
if len(tfv) == 0 {
return nil
}
defer ReturnTypeVarSet(tfv)
ord := BorrowTypeVarSet(len(tfv))
for i := range tfv {
ord[i] = TypeVariable(letters[i])
}
s.t, err = s.t.Normalize(tfv, ord)
s.tvs = ord.Set()
return
} | [
"func",
"(",
"s",
"*",
"Scheme",
")",
"Normalize",
"(",
")",
"(",
"err",
"error",
")",
"{",
"tfv",
":=",
"s",
".",
"t",
".",
"FreeTypeVar",
"(",
")",
"\n\n",
"if",
"len",
"(",
"tfv",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"d... | // Normalize normalizes the type variables in a scheme, so all the names will be in alphabetical order | [
"Normalize",
"normalizes",
"the",
"type",
"variables",
"in",
"a",
"scheme",
"so",
"all",
"the",
"names",
"will",
"be",
"in",
"alphabetical",
"order"
] | 61efb3290a086d1335e8954b3734c102126818ba | https://github.com/chewxy/hm/blob/61efb3290a086d1335e8954b3734c102126818ba/scheme.go#L75-L91 |
144,954 | coreos/go-log | log/logger.go | New | func New(prefix string, verbose bool, sinks ...Sink) *Logger {
return &Logger{
sinks: sinks,
verbose: verbose,
prefix: prefix,
created: time.Now(),
seq: 0,
executable: getExecutableName(),
}
} | go | func New(prefix string, verbose bool, sinks ...Sink) *Logger {
return &Logger{
sinks: sinks,
verbose: verbose,
prefix: prefix,
created: time.Now(),
seq: 0,
executable: getExecutableName(),
}
} | [
"func",
"New",
"(",
"prefix",
"string",
",",
"verbose",
"bool",
",",
"sinks",
"...",
"Sink",
")",
"*",
"Logger",
"{",
"return",
"&",
"Logger",
"{",
"sinks",
":",
"sinks",
",",
"verbose",
":",
"verbose",
",",
"prefix",
":",
"prefix",
",",
"created",
"... | // New creates a new Logger which logs to all the supplied sinks. The prefix
// argument is passed to all loggers under the field "prefix" with every log
// message. If verbose is true, more expensive runtime fields will be computed
// and passed to loggers. These fields are funcname, lineno, pathname, and
// filena... | [
"New",
"creates",
"a",
"new",
"Logger",
"which",
"logs",
"to",
"all",
"the",
"supplied",
"sinks",
".",
"The",
"prefix",
"argument",
"is",
"passed",
"to",
"all",
"loggers",
"under",
"the",
"field",
"prefix",
"with",
"every",
"log",
"message",
".",
"If",
"... | b22fd89e1882702b3ba97bc792ca6b45e7e6b635 | https://github.com/coreos/go-log/blob/b22fd89e1882702b3ba97bc792ca6b45e7e6b635/log/logger.go#L42-L52 |
144,955 | coreos/go-log | log/commands.go | Log | func (logger *Logger) Log(priority Priority, v ...interface{}) {
fields := logger.fieldValues()
fields["priority"] = priority
fields["message"] = fmt.Sprint(v...)
for _, sink := range logger.sinks {
sink.Log(fields)
}
} | go | func (logger *Logger) Log(priority Priority, v ...interface{}) {
fields := logger.fieldValues()
fields["priority"] = priority
fields["message"] = fmt.Sprint(v...)
for _, sink := range logger.sinks {
sink.Log(fields)
}
} | [
"func",
"(",
"logger",
"*",
"Logger",
")",
"Log",
"(",
"priority",
"Priority",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"fields",
":=",
"logger",
".",
"fieldValues",
"(",
")",
"\n",
"fields",
"[",
"\"",
"\"",
"]",
"=",
"priority",
"\n",
"f... | // This function has an unusual name to aid in finding it while walking the
// stack. We need to do some dead reckoning from this function to access the
// caller's stack, so there is a consistent call depth above this function. | [
"This",
"function",
"has",
"an",
"unusual",
"name",
"to",
"aid",
"in",
"finding",
"it",
"while",
"walking",
"the",
"stack",
".",
"We",
"need",
"to",
"do",
"some",
"dead",
"reckoning",
"from",
"this",
"function",
"to",
"access",
"the",
"caller",
"s",
"sta... | b22fd89e1882702b3ba97bc792ca6b45e7e6b635 | https://github.com/coreos/go-log/blob/b22fd89e1882702b3ba97bc792ca6b45e7e6b635/log/commands.go#L32-L39 |
144,956 | coreos/go-log | log/commands.go | Fatalln | func (logger *Logger)Fatalln (v ...interface{}) {
logger.Log(PriCrit, v...)
os.Exit(1)
} | go | func (logger *Logger)Fatalln (v ...interface{}) {
logger.Log(PriCrit, v...)
os.Exit(1)
} | [
"func",
"(",
"logger",
"*",
"Logger",
")",
"Fatalln",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"logger",
".",
"Log",
"(",
"PriCrit",
",",
"v",
"...",
")",
"\n",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"}"
] | // Standard library log functions | [
"Standard",
"library",
"log",
"functions"
] | b22fd89e1882702b3ba97bc792ca6b45e7e6b635 | https://github.com/coreos/go-log/blob/b22fd89e1882702b3ba97bc792ca6b45e7e6b635/log/commands.go#L161-L164 |
144,957 | mackerelio/go-mackerel-plugin-helper | mackerel-plugin.go | SetTempfileByBasename | func (h *MackerelPlugin) SetTempfileByBasename(base string) {
h.Tempfile = filepath.Join(pluginutil.PluginWorkDir(), base)
} | go | func (h *MackerelPlugin) SetTempfileByBasename(base string) {
h.Tempfile = filepath.Join(pluginutil.PluginWorkDir(), base)
} | [
"func",
"(",
"h",
"*",
"MackerelPlugin",
")",
"SetTempfileByBasename",
"(",
"base",
"string",
")",
"{",
"h",
".",
"Tempfile",
"=",
"filepath",
".",
"Join",
"(",
"pluginutil",
".",
"PluginWorkDir",
"(",
")",
",",
"base",
")",
"\n",
"}"
] | // SetTempfileByBasename sets Tempfile under proper directory with specified basename. | [
"SetTempfileByBasename",
"sets",
"Tempfile",
"under",
"proper",
"directory",
"with",
"specified",
"basename",
"."
] | f151d2503465e4983c9e28115dc5f58266a9dfd6 | https://github.com/mackerelio/go-mackerel-plugin-helper/blob/f151d2503465e4983c9e28115dc5f58266a9dfd6/mackerel-plugin.go#L205-L207 |
144,958 | jasonwinn/geocoder | geocoding.go | Geocode | func Geocode(address string) (float64, float64, error) {
// Query Provider
resp, err := http.Get(geocodeURL + url.QueryEscape(address) + "&key=" + apiKey)
if err != nil {
return 0, 0, fmt.Errorf("Error geocoding address: <%v>", err)
}
defer resp.Body.Close()
// Decode our JSON results
var result geocodingRe... | go | func Geocode(address string) (float64, float64, error) {
// Query Provider
resp, err := http.Get(geocodeURL + url.QueryEscape(address) + "&key=" + apiKey)
if err != nil {
return 0, 0, fmt.Errorf("Error geocoding address: <%v>", err)
}
defer resp.Body.Close()
// Decode our JSON results
var result geocodingRe... | [
"func",
"Geocode",
"(",
"address",
"string",
")",
"(",
"float64",
",",
"float64",
",",
"error",
")",
"{",
"// Query Provider",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"geocodeURL",
"+",
"url",
".",
"QueryEscape",
"(",
"address",
")",
"+",
"\... | // Returns the latitude and longitude of the best location match
// for the specified query. | [
"Returns",
"the",
"latitude",
"and",
"longitude",
"of",
"the",
"best",
"location",
"match",
"for",
"the",
"specified",
"query",
"."
] | 0a8a678400b8abdf29dd60b9dac3fd5268fad101 | https://github.com/jasonwinn/geocoder/blob/0a8a678400b8abdf29dd60b9dac3fd5268fad101/geocoding.go#L30-L56 |
144,959 | jasonwinn/geocoder | geocoding.go | FullGeocode | func FullGeocode(address string) (*GeocodingResult, error) {
// Query Provider
resp, err := http.Get(geocodeURL + url.QueryEscape(address) + "&key=" + apiKey)
if err != nil {
return nil, fmt.Errorf("Error geocoding address: <%v>", err)
}
defer resp.Body.Close()
// Decode our JSON results
var result Geocodin... | go | func FullGeocode(address string) (*GeocodingResult, error) {
// Query Provider
resp, err := http.Get(geocodeURL + url.QueryEscape(address) + "&key=" + apiKey)
if err != nil {
return nil, fmt.Errorf("Error geocoding address: <%v>", err)
}
defer resp.Body.Close()
// Decode our JSON results
var result Geocodin... | [
"func",
"FullGeocode",
"(",
"address",
"string",
")",
"(",
"*",
"GeocodingResult",
",",
"error",
")",
"{",
"// Query Provider",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"geocodeURL",
"+",
"url",
".",
"QueryEscape",
"(",
"address",
")",
"+",
"\"... | // Returns the full geocoding response including all of the matches
// as well as reverse-geocoded for each match location. | [
"Returns",
"the",
"full",
"geocoding",
"response",
"including",
"all",
"of",
"the",
"matches",
"as",
"well",
"as",
"reverse",
"-",
"geocoded",
"for",
"each",
"match",
"location",
"."
] | 0a8a678400b8abdf29dd60b9dac3fd5268fad101 | https://github.com/jasonwinn/geocoder/blob/0a8a678400b8abdf29dd60b9dac3fd5268fad101/geocoding.go#L60-L79 |
144,960 | jasonwinn/geocoder | geocoding.go | ReverseGeocode | func ReverseGeocode(lat float64, lng float64) (*Location, error) {
// Query Provider
resp, err := http.Get(reverseGeocodeURL +
fmt.Sprintf("%f,%f&key=%s", lat, lng, apiKey))
if err != nil {
return nil, fmt.Errorf("Error reverse geocoding lat, long pair: <%v>", err)
}
defer resp.Body.Close()
// Decode our J... | go | func ReverseGeocode(lat float64, lng float64) (*Location, error) {
// Query Provider
resp, err := http.Get(reverseGeocodeURL +
fmt.Sprintf("%f,%f&key=%s", lat, lng, apiKey))
if err != nil {
return nil, fmt.Errorf("Error reverse geocoding lat, long pair: <%v>", err)
}
defer resp.Body.Close()
// Decode our J... | [
"func",
"ReverseGeocode",
"(",
"lat",
"float64",
",",
"lng",
"float64",
")",
"(",
"*",
"Location",
",",
"error",
")",
"{",
"// Query Provider",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"reverseGeocodeURL",
"+",
"fmt",
".",
"Sprintf",
"(",
"\"",... | // Returns the address for a latitude and longitude. | [
"Returns",
"the",
"address",
"for",
"a",
"latitude",
"and",
"longitude",
"."
] | 0a8a678400b8abdf29dd60b9dac3fd5268fad101 | https://github.com/jasonwinn/geocoder/blob/0a8a678400b8abdf29dd60b9dac3fd5268fad101/geocoding.go#L82-L109 |
144,961 | jasonwinn/geocoder | geocoding.go | BatchGeocode | func BatchGeocode(addresses []string) ([]LatLng, error) {
var next, start, end int
n := len(addresses)
latLngs := make([]LatLng, n)
batches := n/100 + 1
next = 0
for batch := 0; batch < batches; batch++ {
start = next
next = (batch + 1) * 100
if n < next {
end = n
} else {
end = next
}
bgb := ba... | go | func BatchGeocode(addresses []string) ([]LatLng, error) {
var next, start, end int
n := len(addresses)
latLngs := make([]LatLng, n)
batches := n/100 + 1
next = 0
for batch := 0; batch < batches; batch++ {
start = next
next = (batch + 1) * 100
if n < next {
end = n
} else {
end = next
}
bgb := ba... | [
"func",
"BatchGeocode",
"(",
"addresses",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"LatLng",
",",
"error",
")",
"{",
"var",
"next",
",",
"start",
",",
"end",
"int",
"\n",
"n",
":=",
"len",
"(",
"addresses",
")",
"\n",
"latLngs",
":=",
"make",
"(",
... | // Geocodes multiple locations with a single API request.
// Up to 100 locations per call may be provided. | [
"Geocodes",
"multiple",
"locations",
"with",
"a",
"single",
"API",
"request",
".",
"Up",
"to",
"100",
"locations",
"per",
"call",
"may",
"be",
"provided",
"."
] | 0a8a678400b8abdf29dd60b9dac3fd5268fad101 | https://github.com/jasonwinn/geocoder/blob/0a8a678400b8abdf29dd60b9dac3fd5268fad101/geocoding.go#L113-L156 |
144,962 | jasonwinn/geocoder | geocoder.go | decoder | func decoder(resp *http.Response) *json.Decoder {
return json.NewDecoder(resp.Body)
} | go | func decoder(resp *http.Response) *json.Decoder {
return json.NewDecoder(resp.Body)
} | [
"func",
"decoder",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"*",
"json",
".",
"Decoder",
"{",
"return",
"json",
".",
"NewDecoder",
"(",
"resp",
".",
"Body",
")",
"\n",
"}"
] | // Shortcut for creating a json decoder out of a response | [
"Shortcut",
"for",
"creating",
"a",
"json",
"decoder",
"out",
"of",
"a",
"response"
] | 0a8a678400b8abdf29dd60b9dac3fd5268fad101 | https://github.com/jasonwinn/geocoder/blob/0a8a678400b8abdf29dd60b9dac3fd5268fad101/geocoder.go#L20-L22 |
144,963 | jasonwinn/geocoder | directions.go | NewDirections | func NewDirections(from string, to []string) *Directions {
return &Directions{
From: from,
To: to,
Unit: "m",
RouteType: "fastest",
DoReverseGeocode: true,
NarrativeType: "text",
EnhancedNarrative:... | go | func NewDirections(from string, to []string) *Directions {
return &Directions{
From: from,
To: to,
Unit: "m",
RouteType: "fastest",
DoReverseGeocode: true,
NarrativeType: "text",
EnhancedNarrative:... | [
"func",
"NewDirections",
"(",
"from",
"string",
",",
"to",
"[",
"]",
"string",
")",
"*",
"Directions",
"{",
"return",
"&",
"Directions",
"{",
"From",
":",
"from",
",",
"To",
":",
"to",
",",
"Unit",
":",
"\"",
"\"",
",",
"RouteType",
":",
"\"",
"\""... | // NewDirections is a constructor to initialize a Directions struct
// with mapquest defaults. | [
"NewDirections",
"is",
"a",
"constructor",
"to",
"initialize",
"a",
"Directions",
"struct",
"with",
"mapquest",
"defaults",
"."
] | 0a8a678400b8abdf29dd60b9dac3fd5268fad101 | https://github.com/jasonwinn/geocoder/blob/0a8a678400b8abdf29dd60b9dac3fd5268fad101/directions.go#L88-L111 |
144,964 | jasonwinn/geocoder | directions.go | Dump | func (directions Directions) Dump(format string) (data []byte, err error) {
resp, err := http.Get(directions.URL(format))
if err != nil {
return
}
defer resp.Body.Close()
data, err = ioutil.ReadAll(resp.Body)
return
} | go | func (directions Directions) Dump(format string) (data []byte, err error) {
resp, err := http.Get(directions.URL(format))
if err != nil {
return
}
defer resp.Body.Close()
data, err = ioutil.ReadAll(resp.Body)
return
} | [
"func",
"(",
"directions",
"Directions",
")",
"Dump",
"(",
"format",
"string",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"directions",
".",
"URL",
"(",
"format",
")",
")",
... | // Dump directions as undecoded json or xml bytes | [
"Dump",
"directions",
"as",
"undecoded",
"json",
"or",
"xml",
"bytes"
] | 0a8a678400b8abdf29dd60b9dac3fd5268fad101 | https://github.com/jasonwinn/geocoder/blob/0a8a678400b8abdf29dd60b9dac3fd5268fad101/directions.go#L167-L175 |
144,965 | ararog/timeago | timeago.go | TimeAgoFromNowWithTime | func TimeAgoFromNowWithTime(end time.Time) (string, error) {
return TimeAgoWithTime(time.Now(), end)
} | go | func TimeAgoFromNowWithTime(end time.Time) (string, error) {
return TimeAgoWithTime(time.Now(), end)
} | [
"func",
"TimeAgoFromNowWithTime",
"(",
"end",
"time",
".",
"Time",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"TimeAgoWithTime",
"(",
"time",
".",
"Now",
"(",
")",
",",
"end",
")",
"\n",
"}"
] | // TimeAgoFromNowWithTime takes a specific end Time value
// and the current Time to return how much has been passed
// between them. | [
"TimeAgoFromNowWithTime",
"takes",
"a",
"specific",
"end",
"Time",
"value",
"and",
"the",
"current",
"Time",
"to",
"return",
"how",
"much",
"has",
"been",
"passed",
"between",
"them",
"."
] | e9969cf18b8d5f04cc42f050e8b9968e152cd294 | https://github.com/ararog/timeago/blob/e9969cf18b8d5f04cc42f050e8b9968e152cd294/timeago.go#L27-L30 |
144,966 | ararog/timeago | timeago.go | TimeAgoFromNowWithString | func TimeAgoFromNowWithString(layout, end string) (string, error) {
t, e := time.Parse(layout, end)
if e == nil {
return TimeAgoWithTime(time.Now(), t)
} else {
err := errors.New("Invalid format")
return "", err
}
} | go | func TimeAgoFromNowWithString(layout, end string) (string, error) {
t, e := time.Parse(layout, end)
if e == nil {
return TimeAgoWithTime(time.Now(), t)
} else {
err := errors.New("Invalid format")
return "", err
}
} | [
"func",
"TimeAgoFromNowWithString",
"(",
"layout",
",",
"end",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"t",
",",
"e",
":=",
"time",
".",
"Parse",
"(",
"layout",
",",
"end",
")",
"\n",
"if",
"e",
"==",
"nil",
"{",
"return",
"TimeAgoWithT... | // TimeAgoFromNowWithTime takes a specific layout as time
// format to parse the time string on end paramter to return
// how much time has been passed between the current time and
// the string representation of the time provided by user. | [
"TimeAgoFromNowWithTime",
"takes",
"a",
"specific",
"layout",
"as",
"time",
"format",
"to",
"parse",
"the",
"time",
"string",
"on",
"end",
"paramter",
"to",
"return",
"how",
"much",
"time",
"has",
"been",
"passed",
"between",
"the",
"current",
"time",
"and",
... | e9969cf18b8d5f04cc42f050e8b9968e152cd294 | https://github.com/ararog/timeago/blob/e9969cf18b8d5f04cc42f050e8b9968e152cd294/timeago.go#L36-L45 |
144,967 | zentures/encoding | fastpfor/fastpfor.go | getBestBFromData | func (this *FastPFOR) getBestBFromData(in []int32) (bestb int32, bestc int32, maxb int32) {
copy(this.freqs, zeroFreqs)
// Get the count of all the leading bit positionsfor the slice
// Mainly to figure out what's the best (most popular) bit position
//for _, v := range in[k:kEnd] {
for _, v := range in {
this.f... | go | func (this *FastPFOR) getBestBFromData(in []int32) (bestb int32, bestc int32, maxb int32) {
copy(this.freqs, zeroFreqs)
// Get the count of all the leading bit positionsfor the slice
// Mainly to figure out what's the best (most popular) bit position
//for _, v := range in[k:kEnd] {
for _, v := range in {
this.f... | [
"func",
"(",
"this",
"*",
"FastPFOR",
")",
"getBestBFromData",
"(",
"in",
"[",
"]",
"int32",
")",
"(",
"bestb",
"int32",
",",
"bestc",
"int32",
",",
"maxb",
"int32",
")",
"{",
"copy",
"(",
"this",
".",
"freqs",
",",
"zeroFreqs",
")",
"\n",
"// Get th... | // getBestBFromData determins the best bit position with the best cost of exceptions,
// and the max bit position of the array of int32s | [
"getBestBFromData",
"determins",
"the",
"best",
"bit",
"position",
"with",
"the",
"best",
"cost",
"of",
"exceptions",
"and",
"the",
"max",
"bit",
"position",
"of",
"the",
"array",
"of",
"int32s"
] | b90e310a0325f9b765b4be7220df3642ad93ad8d | https://github.com/zentures/encoding/blob/b90e310a0325f9b765b4be7220df3642ad93ad8d/fastpfor/fastpfor.go#L118-L149 |
144,968 | cisco/senml | senml.go | Decode | func Decode(msg []byte, format Format) (SenML, error) {
var s SenML
var err error
s.XMLName = nil
s.Xmlns = "urn:ietf:params:xml:ns:senml"
switch {
case format == JSON:
// parse the input JSON stream
err = json.Unmarshal(msg, &s.Records)
if err != nil {
//fmt.Println("error parsing JSON SenML Stream: "... | go | func Decode(msg []byte, format Format) (SenML, error) {
var s SenML
var err error
s.XMLName = nil
s.Xmlns = "urn:ietf:params:xml:ns:senml"
switch {
case format == JSON:
// parse the input JSON stream
err = json.Unmarshal(msg, &s.Records)
if err != nil {
//fmt.Println("error parsing JSON SenML Stream: "... | [
"func",
"Decode",
"(",
"msg",
"[",
"]",
"byte",
",",
"format",
"Format",
")",
"(",
"SenML",
",",
"error",
")",
"{",
"var",
"s",
"SenML",
"\n",
"var",
"err",
"error",
"\n\n",
"s",
".",
"XMLName",
"=",
"nil",
"\n",
"s",
".",
"Xmlns",
"=",
"\"",
"... | // Decode takes a SenML message in the given format and parses it and decodes it
// into the returned SenML record. | [
"Decode",
"takes",
"a",
"SenML",
"message",
"in",
"the",
"given",
"format",
"and",
"parses",
"it",
"and",
"decodes",
"it",
"into",
"the",
"returned",
"SenML",
"record",
"."
] | 910a55054e168c1122b905e3f8acdc5ff97cbec1 | https://github.com/cisco/senml/blob/910a55054e168c1122b905e3f8acdc5ff97cbec1/senml.go#L66-L134 |
144,969 | cisco/senml | senml.go | Encode | func Encode(s SenML, format Format, options OutputOptions) ([]byte, error) {
var data []byte
var err error
if options.Topic == "" {
options.Topic = "senml"
}
s.Xmlns = "urn:ietf:params:xml:ns:senml"
switch {
case format == JSON:
// ouput JSON version
if options.PrettyPrint {
// data, err = json.Mars... | go | func Encode(s SenML, format Format, options OutputOptions) ([]byte, error) {
var data []byte
var err error
if options.Topic == "" {
options.Topic = "senml"
}
s.Xmlns = "urn:ietf:params:xml:ns:senml"
switch {
case format == JSON:
// ouput JSON version
if options.PrettyPrint {
// data, err = json.Mars... | [
"func",
"Encode",
"(",
"s",
"SenML",
",",
"format",
"Format",
",",
"options",
"OutputOptions",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"data",
"[",
"]",
"byte",
"\n",
"var",
"err",
"error",
"\n\n",
"if",
"options",
".",
"Topic",
... | // Encode takes a SenML record, and encodes it using the given format. | [
"Encode",
"takes",
"a",
"SenML",
"record",
"and",
"encodes",
"it",
"using",
"the",
"given",
"format",
"."
] | 910a55054e168c1122b905e3f8acdc5ff97cbec1 | https://github.com/cisco/senml/blob/910a55054e168c1122b905e3f8acdc5ff97cbec1/senml.go#L137-L268 |
144,970 | cisco/senml | senml.go | Normalize | func Normalize(senml SenML) SenML {
var bname string = ""
var btime float64 = 0
var bunit string = ""
var ver = 5
var ret SenML
var totalRecords int = 0
for _, r := range senml.Records {
if (r.Value != nil) || (len(r.StringValue) > 0) || (len(r.DataValue) > 0) || (r.BoolValue != nil) {
totalRecords += 1
... | go | func Normalize(senml SenML) SenML {
var bname string = ""
var btime float64 = 0
var bunit string = ""
var ver = 5
var ret SenML
var totalRecords int = 0
for _, r := range senml.Records {
if (r.Value != nil) || (len(r.StringValue) > 0) || (len(r.DataValue) > 0) || (r.BoolValue != nil) {
totalRecords += 1
... | [
"func",
"Normalize",
"(",
"senml",
"SenML",
")",
"SenML",
"{",
"var",
"bname",
"string",
"=",
"\"",
"\"",
"\n",
"var",
"btime",
"float64",
"=",
"0",
"\n",
"var",
"bunit",
"string",
"=",
"\"",
"\"",
"\n",
"var",
"ver",
"=",
"5",
"\n",
"var",
"ret",
... | // Removes all the base items and expands records to have items that include
// what previosly in base iterms. Convets relative times to absoltue times. | [
"Removes",
"all",
"the",
"base",
"items",
"and",
"expands",
"records",
"to",
"have",
"items",
"that",
"include",
"what",
"previosly",
"in",
"base",
"iterms",
".",
"Convets",
"relative",
"times",
"to",
"absoltue",
"times",
"."
] | 910a55054e168c1122b905e3f8acdc5ff97cbec1 | https://github.com/cisco/senml/blob/910a55054e168c1122b905e3f8acdc5ff97cbec1/senml.go#L272-L328 |
144,971 | cisco/senml | senml.go | IsValid | func IsValid(senml SenML) bool {
var bname string = ""
var bver = -1
//fmt.Println("In Validate")
for _, r := range senml.Records {
// Check version is same for all records
if bver == -1 {
// set the bver the first time it is seen
if r.BaseVersion != 0 {
bver = r.BaseVersion
}
} else {
if r... | go | func IsValid(senml SenML) bool {
var bname string = ""
var bver = -1
//fmt.Println("In Validate")
for _, r := range senml.Records {
// Check version is same for all records
if bver == -1 {
// set the bver the first time it is seen
if r.BaseVersion != 0 {
bver = r.BaseVersion
}
} else {
if r... | [
"func",
"IsValid",
"(",
"senml",
"SenML",
")",
"bool",
"{",
"var",
"bname",
"string",
"=",
"\"",
"\"",
"\n",
"var",
"bver",
"=",
"-",
"1",
"\n\n",
"//fmt.Println(\"In Validate\")",
"for",
"_",
",",
"r",
":=",
"range",
"senml",
".",
"Records",
"{",
"// ... | // Test if SenML is valid | [
"Test",
"if",
"SenML",
"is",
"valid"
] | 910a55054e168c1122b905e3f8acdc5ff97cbec1 | https://github.com/cisco/senml/blob/910a55054e168c1122b905e3f8acdc5ff97cbec1/senml.go#L331-L412 |
144,972 | abursavich/nett | dial.go | deadline | func (d *Dialer) deadline() time.Time {
if d.Timeout == 0 {
return d.Deadline
}
timeout := time.Now().Add(d.Timeout)
if d.Deadline.IsZero() || timeout.Before(d.Deadline) {
return timeout
}
return d.Deadline
} | go | func (d *Dialer) deadline() time.Time {
if d.Timeout == 0 {
return d.Deadline
}
timeout := time.Now().Add(d.Timeout)
if d.Deadline.IsZero() || timeout.Before(d.Deadline) {
return timeout
}
return d.Deadline
} | [
"func",
"(",
"d",
"*",
"Dialer",
")",
"deadline",
"(",
")",
"time",
".",
"Time",
"{",
"if",
"d",
".",
"Timeout",
"==",
"0",
"{",
"return",
"d",
".",
"Deadline",
"\n",
"}",
"\n",
"timeout",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
... | // Return either now+Timeout or Deadline, whichever comes first.
// Or zero, if neither is set. | [
"Return",
"either",
"now",
"+",
"Timeout",
"or",
"Deadline",
"whichever",
"comes",
"first",
".",
"Or",
"zero",
"if",
"neither",
"is",
"set",
"."
] | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/dial.go#L70-L79 |
144,973 | abursavich/nett | dial.go | dialMulti | func dialMulti(dialer net.Dialer, network string, addrs addrList) (net.Conn, error) {
type racer struct {
net.Conn
error
}
addrsLen := addrs.Len()
// Sig controls the flow of dial results on lane. It passes a
// token to the next racer and also indicates the end of flow
// by using closed channel.
sig := mak... | go | func dialMulti(dialer net.Dialer, network string, addrs addrList) (net.Conn, error) {
type racer struct {
net.Conn
error
}
addrsLen := addrs.Len()
// Sig controls the flow of dial results on lane. It passes a
// token to the next racer and also indicates the end of flow
// by using closed channel.
sig := mak... | [
"func",
"dialMulti",
"(",
"dialer",
"net",
".",
"Dialer",
",",
"network",
"string",
",",
"addrs",
"addrList",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"type",
"racer",
"struct",
"{",
"net",
".",
"Conn",
"\n",
"error",
"\n",
"}",
"\n",
... | // dialMulti attempts to establish connections to each destination of
// the list of addresses. It will return the first established
// connection and close the other connections. Otherwise it returns
// error on the last attempt. | [
"dialMulti",
"attempts",
"to",
"establish",
"connections",
"to",
"each",
"destination",
"of",
"the",
"list",
"of",
"addresses",
".",
"It",
"will",
"return",
"the",
"first",
"established",
"connection",
"and",
"close",
"the",
"other",
"connections",
".",
"Otherwi... | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/dial.go#L158-L194 |
144,974 | abursavich/nett | dial.go | defaultIP | func defaultIP(ips []net.IP) []net.IP {
if len(ips) <= 1 {
return ips
}
v6 := -1
for i, ip := range ips {
if ipLen := len(ip); ipLen == net.IPv4len {
return ips[i : i+1]
} else if v6 == -1 && ipLen == net.IPv6len {
v6 = i
}
}
if v6 == -1 {
return nil // shouldn't ever happen
}
return ips[v6 : v6... | go | func defaultIP(ips []net.IP) []net.IP {
if len(ips) <= 1 {
return ips
}
v6 := -1
for i, ip := range ips {
if ipLen := len(ip); ipLen == net.IPv4len {
return ips[i : i+1]
} else if v6 == -1 && ipLen == net.IPv6len {
v6 = i
}
}
if v6 == -1 {
return nil // shouldn't ever happen
}
return ips[v6 : v6... | [
"func",
"defaultIP",
"(",
"ips",
"[",
"]",
"net",
".",
"IP",
")",
"[",
"]",
"net",
".",
"IP",
"{",
"if",
"len",
"(",
"ips",
")",
"<=",
"1",
"{",
"return",
"ips",
"\n",
"}",
"\n",
"v6",
":=",
"-",
"1",
"\n",
"for",
"i",
",",
"ip",
":=",
"r... | // defaultIP gives priority to IPv4 addresses and selects the first address. | [
"defaultIP",
"gives",
"priority",
"to",
"IPv4",
"addresses",
"and",
"selects",
"the",
"first",
"address",
"."
] | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/dial.go#L197-L213 |
144,975 | abursavich/nett | dial.go | DualStack | func DualStack(ips []net.IP) []net.IP {
if len(ips) <= 1 {
return ips
}
var (
ipv4, ipv6 bool
a []net.IP
)
for _, ip := range ips {
if ipLen := len(ip); !ipv4 && ipLen == net.IPv4len {
a = append(a, ip)
ipv4 = true
} else if !ipv6 && ipLen == net.IPv6len {
a = append(a, ip)
ipv6 = tr... | go | func DualStack(ips []net.IP) []net.IP {
if len(ips) <= 1 {
return ips
}
var (
ipv4, ipv6 bool
a []net.IP
)
for _, ip := range ips {
if ipLen := len(ip); !ipv4 && ipLen == net.IPv4len {
a = append(a, ip)
ipv4 = true
} else if !ipv6 && ipLen == net.IPv6len {
a = append(a, ip)
ipv6 = tr... | [
"func",
"DualStack",
"(",
"ips",
"[",
"]",
"net",
".",
"IP",
")",
"[",
"]",
"net",
".",
"IP",
"{",
"if",
"len",
"(",
"ips",
")",
"<=",
"1",
"{",
"return",
"ips",
"\n",
"}",
"\n",
"var",
"(",
"ipv4",
",",
"ipv6",
"bool",
"\n",
"a",
"[",
"]",... | // DualStack selects the first IPv4 address
// and IPv6 address in ips. | [
"DualStack",
"selects",
"the",
"first",
"IPv4",
"address",
"and",
"IPv6",
"address",
"in",
"ips",
"."
] | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/dial.go#L217-L238 |
144,976 | abursavich/nett | ipsock_plan9.go | probeIPv6Stack | func probeIPv6Stack() (supportsIPv6, supportsIPv4map bool) {
// Plan 9 uses IPv6 natively, see ip(3).
r := probe("/net/iproute", "6i")
v := false
if r {
v = probe("/net/iproute", "4i")
}
return r, v
} | go | func probeIPv6Stack() (supportsIPv6, supportsIPv4map bool) {
// Plan 9 uses IPv6 natively, see ip(3).
r := probe("/net/iproute", "6i")
v := false
if r {
v = probe("/net/iproute", "4i")
}
return r, v
} | [
"func",
"probeIPv6Stack",
"(",
")",
"(",
"supportsIPv6",
",",
"supportsIPv4map",
"bool",
")",
"{",
"// Plan 9 uses IPv6 natively, see ip(3).",
"r",
":=",
"probe",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"v",
":=",
"false",
"\n",
"if",
"r",
"{",
"v",
... | // probeIPv6Stack returns two boolean values. If the first boolean
// value is true, kernel supports basic IPv6 functionality. If the
// second boolean value is true, kernel supports IPv6 IPv4-mapping. | [
"probeIPv6Stack",
"returns",
"two",
"boolean",
"values",
".",
"If",
"the",
"first",
"boolean",
"value",
"is",
"true",
"kernel",
"supports",
"basic",
"IPv6",
"functionality",
".",
"If",
"the",
"second",
"boolean",
"value",
"is",
"true",
"kernel",
"supports",
"I... | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/ipsock_plan9.go#L40-L48 |
144,977 | abursavich/nett | resolve.go | Resolve | func (r *CacheResolver) Resolve(host string) ([]net.IP, error) {
r.mu.RLock()
if item, ok := r.cache[host]; ok {
if item.ttl.IsZero() || timeNow().Before(item.ttl) {
r.mu.RUnlock()
ips := make([]net.IP, len(item.ips))
copy(ips, item.ips)
return ips, nil
}
}
r.mu.RUnlock()
resolver := r.Resolver
i... | go | func (r *CacheResolver) Resolve(host string) ([]net.IP, error) {
r.mu.RLock()
if item, ok := r.cache[host]; ok {
if item.ttl.IsZero() || timeNow().Before(item.ttl) {
r.mu.RUnlock()
ips := make([]net.IP, len(item.ips))
copy(ips, item.ips)
return ips, nil
}
}
r.mu.RUnlock()
resolver := r.Resolver
i... | [
"func",
"(",
"r",
"*",
"CacheResolver",
")",
"Resolve",
"(",
"host",
"string",
")",
"(",
"[",
"]",
"net",
".",
"IP",
",",
"error",
")",
"{",
"r",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"if",
"item",
",",
"ok",
":=",
"r",
".",
"cache",
"[",
... | // Resolve returns a host's IP addresses. | [
"Resolve",
"returns",
"a",
"host",
"s",
"IP",
"addresses",
"."
] | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/resolve.go#L64-L100 |
144,978 | abursavich/nett | resolve.go | parsePort | func parsePort(network, port string) (int, error) {
p, i, ok := dtoi(port, 0)
if !ok || i != len(port) {
var err error
p, err = net.LookupPort(network, port)
if err != nil {
return 0, err
}
}
if p < 0 || p > 0xFFFF {
return 0, &net.AddrError{"invalid port", port}
}
return p, nil
} | go | func parsePort(network, port string) (int, error) {
p, i, ok := dtoi(port, 0)
if !ok || i != len(port) {
var err error
p, err = net.LookupPort(network, port)
if err != nil {
return 0, err
}
}
if p < 0 || p > 0xFFFF {
return 0, &net.AddrError{"invalid port", port}
}
return p, nil
} | [
"func",
"parsePort",
"(",
"network",
",",
"port",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"p",
",",
"i",
",",
"ok",
":=",
"dtoi",
"(",
"port",
",",
"0",
")",
"\n",
"if",
"!",
"ok",
"||",
"i",
"!=",
"len",
"(",
"port",
")",
"{",
"... | // parsePort parses port as a network service port number for both
// TCP and UDP. | [
"parsePort",
"parses",
"port",
"as",
"a",
"network",
"service",
"port",
"number",
"for",
"both",
"TCP",
"and",
"UDP",
"."
] | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/resolve.go#L237-L250 |
144,979 | abursavich/nett | resolve.go | parseIPv6 | func parseIPv6(s string, zoneAllowed bool) (ip net.IP, zone string) {
ip = make(net.IP, net.IPv6len)
ellipsis := -1 // position of ellipsis in p
i := 0 // index in string s
if zoneAllowed {
s, zone = splitHostZone(s)
}
// Might have leading ellipsis
if len(s) >= 2 && s[0] == ':' && s[1] == ':' {
el... | go | func parseIPv6(s string, zoneAllowed bool) (ip net.IP, zone string) {
ip = make(net.IP, net.IPv6len)
ellipsis := -1 // position of ellipsis in p
i := 0 // index in string s
if zoneAllowed {
s, zone = splitHostZone(s)
}
// Might have leading ellipsis
if len(s) >= 2 && s[0] == ':' && s[1] == ':' {
el... | [
"func",
"parseIPv6",
"(",
"s",
"string",
",",
"zoneAllowed",
"bool",
")",
"(",
"ip",
"net",
".",
"IP",
",",
"zone",
"string",
")",
"{",
"ip",
"=",
"make",
"(",
"net",
".",
"IP",
",",
"net",
".",
"IPv6len",
")",
"\n",
"ellipsis",
":=",
"-",
"1",
... | // parseIPv6 parses s as a literal IPv6 address described in RFC 4291
// and RFC 5952. It can also parse a literal scoped IPv6 address with
// zone identifier which is described in RFC 4007 when zoneAllowed is
// true. | [
"parseIPv6",
"parses",
"s",
"as",
"a",
"literal",
"IPv6",
"address",
"described",
"in",
"RFC",
"4291",
"and",
"RFC",
"5952",
".",
"It",
"can",
"also",
"parse",
"a",
"literal",
"scoped",
"IPv6",
"address",
"with",
"zone",
"identifier",
"which",
"is",
"descr... | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/resolve.go#L287-L389 |
144,980 | abursavich/nett | resolve.go | ipv4only | func ipv4only(ip net.IP) net.IP {
if supportsIPv4 {
return ip.To4()
}
return nil
} | go | func ipv4only(ip net.IP) net.IP {
if supportsIPv4 {
return ip.To4()
}
return nil
} | [
"func",
"ipv4only",
"(",
"ip",
"net",
".",
"IP",
")",
"net",
".",
"IP",
"{",
"if",
"supportsIPv4",
"{",
"return",
"ip",
".",
"To4",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ipv4only returns IPv4 addresses that we can use with the kernel's
// IPv4 addressing modes. If ip is an IPv4 address, ipv4only returns ip.
// Otherwise it returns nil. | [
"ipv4only",
"returns",
"IPv4",
"addresses",
"that",
"we",
"can",
"use",
"with",
"the",
"kernel",
"s",
"IPv4",
"addressing",
"modes",
".",
"If",
"ip",
"is",
"an",
"IPv4",
"address",
"ipv4only",
"returns",
"ip",
".",
"Otherwise",
"it",
"returns",
"nil",
"."
... | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/resolve.go#L467-L472 |
144,981 | abursavich/nett | resolve.go | ipv6only | func ipv6only(ip net.IP) net.IP {
if supportsIPv6 && len(ip) == net.IPv6len && ip.To4() == nil {
return ip
}
return nil
} | go | func ipv6only(ip net.IP) net.IP {
if supportsIPv6 && len(ip) == net.IPv6len && ip.To4() == nil {
return ip
}
return nil
} | [
"func",
"ipv6only",
"(",
"ip",
"net",
".",
"IP",
")",
"net",
".",
"IP",
"{",
"if",
"supportsIPv6",
"&&",
"len",
"(",
"ip",
")",
"==",
"net",
".",
"IPv6len",
"&&",
"ip",
".",
"To4",
"(",
")",
"==",
"nil",
"{",
"return",
"ip",
"\n",
"}",
"\n",
... | // ipv6only returns IPv6 addresses that we can use with the kernel's
// IPv6 addressing modes. It returns IPv4-mapped IPv6 addresses as
// nils and returns other IPv6 address types as IPv6 addresses. | [
"ipv6only",
"returns",
"IPv6",
"addresses",
"that",
"we",
"can",
"use",
"with",
"the",
"kernel",
"s",
"IPv6",
"addressing",
"modes",
".",
"It",
"returns",
"IPv4",
"-",
"mapped",
"IPv6",
"addresses",
"as",
"nils",
"and",
"returns",
"other",
"IPv6",
"address",... | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/resolve.go#L477-L482 |
144,982 | abursavich/nett | parse.go | countAnyByte | func countAnyByte(s string, t string) int {
n := 0
for i := 0; i < len(s); i++ {
if byteIndex(t, s[i]) >= 0 {
n++
}
}
return n
} | go | func countAnyByte(s string, t string) int {
n := 0
for i := 0; i < len(s); i++ {
if byteIndex(t, s[i]) >= 0 {
n++
}
}
return n
} | [
"func",
"countAnyByte",
"(",
"s",
"string",
",",
"t",
"string",
")",
"int",
"{",
"n",
":=",
"0",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"s",
")",
";",
"i",
"++",
"{",
"if",
"byteIndex",
"(",
"t",
",",
"s",
"[",
"i",
"]",
... | // Count occurrences in s of any bytes in t. | [
"Count",
"occurrences",
"in",
"s",
"of",
"any",
"bytes",
"in",
"t",
"."
] | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/parse.go#L83-L91 |
144,983 | abursavich/nett | parse.go | splitAtBytes | func splitAtBytes(s string, t string) []string {
a := make([]string, 1+countAnyByte(s, t))
n := 0
last := 0
for i := 0; i < len(s); i++ {
if byteIndex(t, s[i]) >= 0 {
if last < i {
a[n] = string(s[last:i])
n++
}
last = i + 1
}
}
if last < len(s) {
a[n] = string(s[last:])
n++
}
return a[... | go | func splitAtBytes(s string, t string) []string {
a := make([]string, 1+countAnyByte(s, t))
n := 0
last := 0
for i := 0; i < len(s); i++ {
if byteIndex(t, s[i]) >= 0 {
if last < i {
a[n] = string(s[last:i])
n++
}
last = i + 1
}
}
if last < len(s) {
a[n] = string(s[last:])
n++
}
return a[... | [
"func",
"splitAtBytes",
"(",
"s",
"string",
",",
"t",
"string",
")",
"[",
"]",
"string",
"{",
"a",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"1",
"+",
"countAnyByte",
"(",
"s",
",",
"t",
")",
")",
"\n",
"n",
":=",
"0",
"\n",
"last",
":=",
"... | // Split s at any bytes in t. | [
"Split",
"s",
"at",
"any",
"bytes",
"in",
"t",
"."
] | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/parse.go#L94-L112 |
144,984 | abursavich/nett | parse.go | last | func last(s string, b byte) int {
i := len(s)
for i--; i >= 0; i-- {
if s[i] == b {
break
}
}
return i
} | go | func last(s string, b byte) int {
i := len(s)
for i--; i >= 0; i-- {
if s[i] == b {
break
}
}
return i
} | [
"func",
"last",
"(",
"s",
"string",
",",
"b",
"byte",
")",
"int",
"{",
"i",
":=",
"len",
"(",
"s",
")",
"\n",
"for",
"i",
"--",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"if",
"s",
"[",
"i",
"]",
"==",
"b",
"{",
"break",
"\n",
"}",
"\n"... | // Index of rightmost occurrence of b in s. | [
"Index",
"of",
"rightmost",
"occurrence",
"of",
"b",
"in",
"s",
"."
] | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/parse.go#L163-L171 |
144,985 | abursavich/nett | ipsock.go | supportedIP | func supportedIP(ip net.IP) net.IP {
if supportsIPv4 {
if v4 := ip.To4(); v4 != nil {
return v4
}
}
if supportsIPv6 && len(ip) == net.IPv6len {
return ip
}
return nil
} | go | func supportedIP(ip net.IP) net.IP {
if supportsIPv4 {
if v4 := ip.To4(); v4 != nil {
return v4
}
}
if supportsIPv6 && len(ip) == net.IPv6len {
return ip
}
return nil
} | [
"func",
"supportedIP",
"(",
"ip",
"net",
".",
"IP",
")",
"net",
".",
"IP",
"{",
"if",
"supportsIPv4",
"{",
"if",
"v4",
":=",
"ip",
".",
"To4",
"(",
")",
";",
"v4",
"!=",
"nil",
"{",
"return",
"v4",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"supportsIPv... | // supportedIP returns a version of the IP that the platform
// supports. If it is not supported it returns nil. | [
"supportedIP",
"returns",
"a",
"version",
"of",
"the",
"IP",
"that",
"the",
"platform",
"supports",
".",
"If",
"it",
"is",
"not",
"supported",
"it",
"returns",
"nil",
"."
] | f31118c7aeb99f781b38483679bef7bece9f78db | https://github.com/abursavich/nett/blob/f31118c7aeb99f781b38483679bef7bece9f78db/ipsock.go#L33-L43 |
144,986 | go-macaron/inject | inject.go | callInvoke | func (inj *injector) callInvoke(f interface{}, t reflect.Type, numIn int) ([]reflect.Value, error) {
var in []reflect.Value
if numIn > 0 {
in = make([]reflect.Value, numIn)
var argType reflect.Type
var val reflect.Value
for i := 0; i < numIn; i++ {
argType = t.In(i)
val = inj.GetVal(argType)
if !val.... | go | func (inj *injector) callInvoke(f interface{}, t reflect.Type, numIn int) ([]reflect.Value, error) {
var in []reflect.Value
if numIn > 0 {
in = make([]reflect.Value, numIn)
var argType reflect.Type
var val reflect.Value
for i := 0; i < numIn; i++ {
argType = t.In(i)
val = inj.GetVal(argType)
if !val.... | [
"func",
"(",
"inj",
"*",
"injector",
")",
"callInvoke",
"(",
"f",
"interface",
"{",
"}",
",",
"t",
"reflect",
".",
"Type",
",",
"numIn",
"int",
")",
"(",
"[",
"]",
"reflect",
".",
"Value",
",",
"error",
")",
"{",
"var",
"in",
"[",
"]",
"reflect",... | // callInvoke reflect.Value.Call | [
"callInvoke",
"reflect",
".",
"Value",
".",
"Call"
] | d8a0b8677191f4380287cfebd08e462217bac7ad | https://github.com/go-macaron/inject/blob/d8a0b8677191f4380287cfebd08e462217bac7ad/inject.go#L161-L178 |
144,987 | go-macaron/inject | inject.go | Apply | func (inj *injector) Apply(val interface{}) error {
v := reflect.ValueOf(val)
for v.Kind() == reflect.Ptr {
v = v.Elem()
}
if v.Kind() != reflect.Struct {
return nil // Should not panic here ?
}
t := v.Type()
for i := 0; i < v.NumField(); i++ {
f := v.Field(i)
structField := t.Field(i)
if f.CanSet(... | go | func (inj *injector) Apply(val interface{}) error {
v := reflect.ValueOf(val)
for v.Kind() == reflect.Ptr {
v = v.Elem()
}
if v.Kind() != reflect.Struct {
return nil // Should not panic here ?
}
t := v.Type()
for i := 0; i < v.NumField(); i++ {
f := v.Field(i)
structField := t.Field(i)
if f.CanSet(... | [
"func",
"(",
"inj",
"*",
"injector",
")",
"Apply",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"val",
")",
"\n\n",
"for",
"v",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"v",
"=... | // Maps dependencies in the Type map to each field in the struct
// that is tagged with 'inject'.
// Returns an error if the injection fails. | [
"Maps",
"dependencies",
"in",
"the",
"Type",
"map",
"to",
"each",
"field",
"in",
"the",
"struct",
"that",
"is",
"tagged",
"with",
"inject",
".",
"Returns",
"an",
"error",
"if",
"the",
"injection",
"fails",
"."
] | d8a0b8677191f4380287cfebd08e462217bac7ad | https://github.com/go-macaron/inject/blob/d8a0b8677191f4380287cfebd08e462217bac7ad/inject.go#L183-L212 |
144,988 | kataras/go-serializer | json/json.go | New | func New(cfg ...Config) *Serializer {
c := DefaultConfig().Merge(cfg)
return &Serializer{config: c}
} | go | func New(cfg ...Config) *Serializer {
c := DefaultConfig().Merge(cfg)
return &Serializer{config: c}
} | [
"func",
"New",
"(",
"cfg",
"...",
"Config",
")",
"*",
"Serializer",
"{",
"c",
":=",
"DefaultConfig",
"(",
")",
".",
"Merge",
"(",
"cfg",
")",
"\n",
"return",
"&",
"Serializer",
"{",
"config",
":",
"c",
"}",
"\n",
"}"
] | // New returns a new json response engine | [
"New",
"returns",
"a",
"new",
"json",
"response",
"engine"
] | b61f2e8acda9377f80b5bf183a79ea32b9838f9d | https://github.com/kataras/go-serializer/blob/b61f2e8acda9377f80b5bf183a79ea32b9838f9d/json/json.go#L23-L26 |
144,989 | kataras/go-serializer | serializer.go | Serialize | func (s SerializeFunc) Serialize(obj interface{}, options ...map[string]interface{}) ([]byte, error) {
return s(obj, options...)
} | go | func (s SerializeFunc) Serialize(obj interface{}, options ...map[string]interface{}) ([]byte, error) {
return s(obj, options...)
} | [
"func",
"(",
"s",
"SerializeFunc",
")",
"Serialize",
"(",
"obj",
"interface",
"{",
"}",
",",
"options",
"...",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"s",
"(",
"obj",
",",
"... | // Serialize accepts an object with serialization options and returns its bytes representation | [
"Serialize",
"accepts",
"an",
"object",
"with",
"serialization",
"options",
"and",
"returns",
"its",
"bytes",
"representation"
] | b61f2e8acda9377f80b5bf183a79ea32b9838f9d | https://github.com/kataras/go-serializer/blob/b61f2e8acda9377f80b5bf183a79ea32b9838f9d/serializer.go#L36-L38 |
144,990 | kataras/go-serializer | json/config.go | DefaultConfig | func DefaultConfig() Config {
return Config{
Indent: false,
UnEscapeHTML: false,
Prefix: []byte(""),
StreamingJSON: false,
}
} | go | func DefaultConfig() Config {
return Config{
Indent: false,
UnEscapeHTML: false,
Prefix: []byte(""),
StreamingJSON: false,
}
} | [
"func",
"DefaultConfig",
"(",
")",
"Config",
"{",
"return",
"Config",
"{",
"Indent",
":",
"false",
",",
"UnEscapeHTML",
":",
"false",
",",
"Prefix",
":",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
",",
"StreamingJSON",
":",
"false",
",",
"}",
"\n",
"}"
... | // DefaultConfig returns the default configuration for this serializer | [
"DefaultConfig",
"returns",
"the",
"default",
"configuration",
"for",
"this",
"serializer"
] | b61f2e8acda9377f80b5bf183a79ea32b9838f9d | https://github.com/kataras/go-serializer/blob/b61f2e8acda9377f80b5bf183a79ea32b9838f9d/json/config.go#L16-L23 |
144,991 | kataras/go-serializer | json/config.go | Merge | func (c Config) Merge(cfg []Config) (config Config) {
if len(cfg) > 0 {
config = cfg[0]
mergo.Merge(&config, c)
} else {
_default := c
config = _default
}
return
} | go | func (c Config) Merge(cfg []Config) (config Config) {
if len(cfg) > 0 {
config = cfg[0]
mergo.Merge(&config, c)
} else {
_default := c
config = _default
}
return
} | [
"func",
"(",
"c",
"Config",
")",
"Merge",
"(",
"cfg",
"[",
"]",
"Config",
")",
"(",
"config",
"Config",
")",
"{",
"if",
"len",
"(",
"cfg",
")",
">",
"0",
"{",
"config",
"=",
"cfg",
"[",
"0",
"]",
"\n",
"mergo",
".",
"Merge",
"(",
"&",
"config... | // Merge merges the default with the given config and returns the result | [
"Merge",
"merges",
"the",
"default",
"with",
"the",
"given",
"config",
"and",
"returns",
"the",
"result"
] | b61f2e8acda9377f80b5bf183a79ea32b9838f9d | https://github.com/kataras/go-serializer/blob/b61f2e8acda9377f80b5bf183a79ea32b9838f9d/json/config.go#L26-L37 |
144,992 | kataras/go-serializer | json/config.go | MergeSingle | func (c Config) MergeSingle(cfg Config) (config Config) {
config = cfg
mergo.Merge(&config, c)
return
} | go | func (c Config) MergeSingle(cfg Config) (config Config) {
config = cfg
mergo.Merge(&config, c)
return
} | [
"func",
"(",
"c",
"Config",
")",
"MergeSingle",
"(",
"cfg",
"Config",
")",
"(",
"config",
"Config",
")",
"{",
"config",
"=",
"cfg",
"\n",
"mergo",
".",
"Merge",
"(",
"&",
"config",
",",
"c",
")",
"\n\n",
"return",
"\n",
"}"
] | // MergeSingle merges the default with the given config and returns the result | [
"MergeSingle",
"merges",
"the",
"default",
"with",
"the",
"given",
"config",
"and",
"returns",
"the",
"result"
] | b61f2e8acda9377f80b5bf183a79ea32b9838f9d | https://github.com/kataras/go-serializer/blob/b61f2e8acda9377f80b5bf183a79ea32b9838f9d/json/config.go#L40-L46 |
144,993 | jagregory/halgo | links.go | Href | func (l Links) Href(rel string) (string, error) {
return l.HrefParams(rel, nil)
} | go | func (l Links) Href(rel string) (string, error) {
return l.HrefParams(rel, nil)
} | [
"func",
"(",
"l",
"Links",
")",
"Href",
"(",
"rel",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"l",
".",
"HrefParams",
"(",
"rel",
",",
"nil",
")",
"\n",
"}"
] | // Href tries to find the href of a link with the supplied relation.
// Returns LinkNotFoundError if a link doesn't exist. | [
"Href",
"tries",
"to",
"find",
"the",
"href",
"of",
"a",
"link",
"with",
"the",
"supplied",
"relation",
".",
"Returns",
"LinkNotFoundError",
"if",
"a",
"link",
"doesn",
"t",
"exist",
"."
] | d1d6fd6cbc6ff4df35f82b03bf93fdade591985d | https://github.com/jagregory/halgo/blob/d1d6fd6cbc6ff4df35f82b03bf93fdade591985d/links.go#L98-L100 |
144,994 | jagregory/halgo | links.go | HrefParams | func (l Links) HrefParams(rel string, params P) (string, error) {
if rel == "" {
return "", errors.New("Empty string not valid relation")
}
links := l.Items[rel]
if len(links) > 0 {
link := links[0] // TODO: handle multiple here
return link.Expand(params)
}
return "", LinkNotFoundError{rel, l.Items}
} | go | func (l Links) HrefParams(rel string, params P) (string, error) {
if rel == "" {
return "", errors.New("Empty string not valid relation")
}
links := l.Items[rel]
if len(links) > 0 {
link := links[0] // TODO: handle multiple here
return link.Expand(params)
}
return "", LinkNotFoundError{rel, l.Items}
} | [
"func",
"(",
"l",
"Links",
")",
"HrefParams",
"(",
"rel",
"string",
",",
"params",
"P",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"rel",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",... | // HrefParams tries to find the href of a link with the supplied relation,
// then expands any URI template parameters. Returns LinkNotFoundError if
// a link doesn't exist. | [
"HrefParams",
"tries",
"to",
"find",
"the",
"href",
"of",
"a",
"link",
"with",
"the",
"supplied",
"relation",
"then",
"expands",
"any",
"URI",
"template",
"parameters",
".",
"Returns",
"LinkNotFoundError",
"if",
"a",
"link",
"doesn",
"t",
"exist",
"."
] | d1d6fd6cbc6ff4df35f82b03bf93fdade591985d | https://github.com/jagregory/halgo/blob/d1d6fd6cbc6ff4df35f82b03bf93fdade591985d/links.go#L105-L117 |
144,995 | jagregory/halgo | links.go | Expand | func (l Link) Expand(params P) (string, error) {
template, err := uritemplates.Parse(l.Href)
if err != nil {
return "", err
}
return template.Expand(map[string]interface{}(params))
} | go | func (l Link) Expand(params P) (string, error) {
template, err := uritemplates.Parse(l.Href)
if err != nil {
return "", err
}
return template.Expand(map[string]interface{}(params))
} | [
"func",
"(",
"l",
"Link",
")",
"Expand",
"(",
"params",
"P",
")",
"(",
"string",
",",
"error",
")",
"{",
"template",
",",
"err",
":=",
"uritemplates",
".",
"Parse",
"(",
"l",
".",
"Href",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
... | // Expand will expand the URL template of the link with the given params. | [
"Expand",
"will",
"expand",
"the",
"URL",
"template",
"of",
"the",
"link",
"with",
"the",
"given",
"params",
"."
] | d1d6fd6cbc6ff4df35f82b03bf93fdade591985d | https://github.com/jagregory/halgo/blob/d1d6fd6cbc6ff4df35f82b03bf93fdade591985d/links.go#L172-L179 |
144,996 | c4milo/unpackit | unpackit.go | magicNumber | func magicNumber(reader *bufio.Reader, offset int) (string, error) {
headerBytes, err := reader.Peek(offset + 6)
if err != nil {
return "", err
}
magic := headerBytes[offset : offset+6]
if bytes.Equal(magicTAR, magic[0:5]) {
return "tar", nil
}
if bytes.Equal(magicZIP, magic[0:4]) {
return "zip", nil
}... | go | func magicNumber(reader *bufio.Reader, offset int) (string, error) {
headerBytes, err := reader.Peek(offset + 6)
if err != nil {
return "", err
}
magic := headerBytes[offset : offset+6]
if bytes.Equal(magicTAR, magic[0:5]) {
return "tar", nil
}
if bytes.Equal(magicZIP, magic[0:4]) {
return "zip", nil
}... | [
"func",
"magicNumber",
"(",
"reader",
"*",
"bufio",
".",
"Reader",
",",
"offset",
"int",
")",
"(",
"string",
",",
"error",
")",
"{",
"headerBytes",
",",
"err",
":=",
"reader",
".",
"Peek",
"(",
"offset",
"+",
"6",
")",
"\n",
"if",
"err",
"!=",
"nil... | // Check whether a file has the magic number for tar, gzip, bzip2 or zip files
//
// Note that this function does not advance the Reader.
//
// 50 4b 03 04 for pkzip format
// 1f 8b for .gz format
// 42 5a for .bzip format
// 75 73 74 61 72 at offset 257 for tar files
// fd 37 7a 58 5a 00 for .xz format | [
"Check",
"whether",
"a",
"file",
"has",
"the",
"magic",
"number",
"for",
"tar",
"gzip",
"bzip2",
"or",
"zip",
"files",
"Note",
"that",
"this",
"function",
"does",
"not",
"advance",
"the",
"Reader",
".",
"50",
"4b",
"03",
"04",
"for",
"pkzip",
"format",
... | 4ed373e9ef1c895fe04468d813cb628902d89a0a | https://github.com/c4milo/unpackit/blob/4ed373e9ef1c895fe04468d813cb628902d89a0a/unpackit.go#L48-L75 |
144,997 | c4milo/unpackit | unpackit.go | Unzip | func Unzip(r io.Reader, destPath string) (string, error) {
var (
zr *zip.Reader
err error
)
if f, ok := r.(*os.File); ok {
fstat, err := f.Stat()
if err != nil {
return "", err
}
zr, err = zip.NewReader(f, fstat.Size())
} else {
data, err := ioutil.ReadAll(r)
if err != nil {
return "", err
... | go | func Unzip(r io.Reader, destPath string) (string, error) {
var (
zr *zip.Reader
err error
)
if f, ok := r.(*os.File); ok {
fstat, err := f.Stat()
if err != nil {
return "", err
}
zr, err = zip.NewReader(f, fstat.Size())
} else {
data, err := ioutil.ReadAll(r)
if err != nil {
return "", err
... | [
"func",
"Unzip",
"(",
"r",
"io",
".",
"Reader",
",",
"destPath",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"(",
"zr",
"*",
"zip",
".",
"Reader",
"\n",
"err",
"error",
"\n",
")",
"\n\n",
"if",
"f",
",",
"ok",
":=",
"r",
".",
... | // Unzip unpacks a ZIP stream. When given a os.File reader it will get its size without
// reading the entire zip file in memory. | [
"Unzip",
"unpacks",
"a",
"ZIP",
"stream",
".",
"When",
"given",
"a",
"os",
".",
"File",
"reader",
"it",
"will",
"get",
"its",
"size",
"without",
"reading",
"the",
"entire",
"zip",
"file",
"in",
"memory",
"."
] | 4ed373e9ef1c895fe04468d813cb628902d89a0a | https://github.com/c4milo/unpackit/blob/4ed373e9ef1c895fe04468d813cb628902d89a0a/unpackit.go#L178-L204 |
144,998 | c4milo/unpackit | unpackit.go | Untar | func Untar(data io.Reader, destPath string) (string, error) {
// Makes sure destPath exists
if err := os.MkdirAll(destPath, 0740); err != nil {
return "", err
}
tr := tar.NewReader(data)
// Iterate through the files in the archive.
rootdir := destPath
for {
hdr, err := tr.Next()
if err == io.EOF {
// ... | go | func Untar(data io.Reader, destPath string) (string, error) {
// Makes sure destPath exists
if err := os.MkdirAll(destPath, 0740); err != nil {
return "", err
}
tr := tar.NewReader(data)
// Iterate through the files in the archive.
rootdir := destPath
for {
hdr, err := tr.Next()
if err == io.EOF {
// ... | [
"func",
"Untar",
"(",
"data",
"io",
".",
"Reader",
",",
"destPath",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Makes sure destPath exists",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"destPath",
",",
"0740",
")",
";",
"err",
"!=",
"n... | // Untar unarchives a TAR archive and returns the final destination path or an error | [
"Untar",
"unarchives",
"a",
"TAR",
"archive",
"and",
"returns",
"the",
"final",
"destination",
"path",
"or",
"an",
"error"
] | 4ed373e9ef1c895fe04468d813cb628902d89a0a | https://github.com/c4milo/unpackit/blob/4ed373e9ef1c895fe04468d813cb628902d89a0a/unpackit.go#L274-L319 |
144,999 | c4milo/unpackit | unpackit.go | sanitize | func sanitize(name string) string {
// Gets rid of volume drive label in Windows
if len(name) > 1 && name[1] == ':' && runtime.GOOS == "windows" {
name = name[2:]
}
name = filepath.Clean(name)
name = filepath.ToSlash(name)
for strings.HasPrefix(name, "../") {
name = name[3:]
}
return name
} | go | func sanitize(name string) string {
// Gets rid of volume drive label in Windows
if len(name) > 1 && name[1] == ':' && runtime.GOOS == "windows" {
name = name[2:]
}
name = filepath.Clean(name)
name = filepath.ToSlash(name)
for strings.HasPrefix(name, "../") {
name = name[3:]
}
return name
} | [
"func",
"sanitize",
"(",
"name",
"string",
")",
"string",
"{",
"// Gets rid of volume drive label in Windows",
"if",
"len",
"(",
"name",
")",
">",
"1",
"&&",
"name",
"[",
"1",
"]",
"==",
"':'",
"&&",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"name",... | // Sanitizes name to avoid overwriting sensitive system files when unarchiving | [
"Sanitizes",
"name",
"to",
"avoid",
"overwriting",
"sensitive",
"system",
"files",
"when",
"unarchiving"
] | 4ed373e9ef1c895fe04468d813cb628902d89a0a | https://github.com/c4milo/unpackit/blob/4ed373e9ef1c895fe04468d813cb628902d89a0a/unpackit.go#L355-L368 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.