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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
153,700 | bearded-web/bearded | pkg/manager/files.go | Create | func (m *FileManager) Create(r io.Reader, metaInfo *file.Meta) (*file.Meta, error) {
f, err := m.grid.Create("")
// according to gridfs code, the error here is impossible
if err != nil {
return nil, stackerr.Wrap(err)
}
size, err := io.Copy(f, r)
if err != nil {
return nil, stackerr.Wrap(err)
}
meta := &file.Meta{
Id: file.UniqueFileId(),
Size: int(size),
ContentType: metaInfo.ContentType,
Name: metaInfo.Name,
}
f.SetId(meta.Id)
f.SetMeta(meta)
if meta.ContentType != "" {
f.SetContentType(meta.ContentType)
}
if err = f.Close(); err != nil {
return nil, stackerr.Wrap(err)
}
meta.MD5 = f.MD5()
return meta, nil
} | go | func (m *FileManager) Create(r io.Reader, metaInfo *file.Meta) (*file.Meta, error) {
f, err := m.grid.Create("")
// according to gridfs code, the error here is impossible
if err != nil {
return nil, stackerr.Wrap(err)
}
size, err := io.Copy(f, r)
if err != nil {
return nil, stackerr.Wrap(err)
}
meta := &file.Meta{
Id: file.UniqueFileId(),
Size: int(size),
ContentType: metaInfo.ContentType,
Name: metaInfo.Name,
}
f.SetId(meta.Id)
f.SetMeta(meta)
if meta.ContentType != "" {
f.SetContentType(meta.ContentType)
}
if err = f.Close(); err != nil {
return nil, stackerr.Wrap(err)
}
meta.MD5 = f.MD5()
return meta, nil
} | [
"func",
"(",
"m",
"*",
"FileManager",
")",
"Create",
"(",
"r",
"io",
".",
"Reader",
",",
"metaInfo",
"*",
"file",
".",
"Meta",
")",
"(",
"*",
"file",
".",
"Meta",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"m",
".",
"grid",
".",
"Create",
... | // create file with data | [
"create",
"file",
"with",
"data"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/pkg/manager/files.go#L36-L62 |
153,701 | bearded-web/bearded | pkg/filters/session.go | GetSession | func GetSession(req *restful.Request) *Session {
m := req.Attribute(AttrSessionKey)
if m == nil {
panic("GetSession attribute is nil")
}
session, ok := m.(*Session)
if !ok {
panic(fmt.Sprintf("GetSession attribute isn't a session type, but %#v", m))
}
return session
} | go | func GetSession(req *restful.Request) *Session {
m := req.Attribute(AttrSessionKey)
if m == nil {
panic("GetSession attribute is nil")
}
session, ok := m.(*Session)
if !ok {
panic(fmt.Sprintf("GetSession attribute isn't a session type, but %#v", m))
}
return session
} | [
"func",
"GetSession",
"(",
"req",
"*",
"restful",
".",
"Request",
")",
"*",
"Session",
"{",
"m",
":=",
"req",
".",
"Attribute",
"(",
"AttrSessionKey",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"session"... | // Get session from restful.Request attribute or panic | [
"Get",
"session",
"from",
"restful",
".",
"Request",
"attribute",
"or",
"panic"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/pkg/filters/session.go#L118-L128 |
153,702 | thecodeteam/gorackhd | client/get/get_nodes_identifier_catalogs_parameters.go | WithIdentifier | func (o *GetNodesIdentifierCatalogsParams) WithIdentifier(identifier string) *GetNodesIdentifierCatalogsParams {
o.Identifier = identifier
return o
} | go | func (o *GetNodesIdentifierCatalogsParams) WithIdentifier(identifier string) *GetNodesIdentifierCatalogsParams {
o.Identifier = identifier
return o
} | [
"func",
"(",
"o",
"*",
"GetNodesIdentifierCatalogsParams",
")",
"WithIdentifier",
"(",
"identifier",
"string",
")",
"*",
"GetNodesIdentifierCatalogsParams",
"{",
"o",
".",
"Identifier",
"=",
"identifier",
"\n",
"return",
"o",
"\n",
"}"
] | // WithIdentifier adds the identifier to the get nodes identifier catalogs params | [
"WithIdentifier",
"adds",
"the",
"identifier",
"to",
"the",
"get",
"nodes",
"identifier",
"catalogs",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/get/get_nodes_identifier_catalogs_parameters.go#L53-L56 |
153,703 | bearded-web/bearded | pkg/pagination/paginator.go | ParseSkip | func (p *Paginator) ParseSkip(req *restful.Request) int {
skip := 0
if p := req.QueryParameter(p.SkipName); p != "" {
if val, err := strconv.Atoi(p); err == nil {
skip = val
}
}
if skip < 0 {
skip = 0
}
return skip
} | go | func (p *Paginator) ParseSkip(req *restful.Request) int {
skip := 0
if p := req.QueryParameter(p.SkipName); p != "" {
if val, err := strconv.Atoi(p); err == nil {
skip = val
}
}
if skip < 0 {
skip = 0
}
return skip
} | [
"func",
"(",
"p",
"*",
"Paginator",
")",
"ParseSkip",
"(",
"req",
"*",
"restful",
".",
"Request",
")",
"int",
"{",
"skip",
":=",
"0",
"\n",
"if",
"p",
":=",
"req",
".",
"QueryParameter",
"(",
"p",
".",
"SkipName",
")",
";",
"p",
"!=",
"\"",
"\"",... | // parse request and return skip | [
"parse",
"request",
"and",
"return",
"skip"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/pkg/pagination/paginator.go#L79-L91 |
153,704 | bearded-web/bearded | pkg/pagination/paginator.go | ParseLimit | func (p *Paginator) ParseLimit(req *restful.Request) int {
limit := p.LimitDefault
if p := req.QueryParameter(p.LimitName); p != "" {
if val, err := strconv.Atoi(p); err == nil {
limit = val
}
}
if limit < 0 {
limit = p.LimitDefault
}
if limit > p.LimitMax {
limit = p.LimitMax
}
return limit
} | go | func (p *Paginator) ParseLimit(req *restful.Request) int {
limit := p.LimitDefault
if p := req.QueryParameter(p.LimitName); p != "" {
if val, err := strconv.Atoi(p); err == nil {
limit = val
}
}
if limit < 0 {
limit = p.LimitDefault
}
if limit > p.LimitMax {
limit = p.LimitMax
}
return limit
} | [
"func",
"(",
"p",
"*",
"Paginator",
")",
"ParseLimit",
"(",
"req",
"*",
"restful",
".",
"Request",
")",
"int",
"{",
"limit",
":=",
"p",
".",
"LimitDefault",
"\n",
"if",
"p",
":=",
"req",
".",
"QueryParameter",
"(",
"p",
".",
"LimitName",
")",
";",
... | // parse request and return limit | [
"parse",
"request",
"and",
"return",
"limit"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/pkg/pagination/paginator.go#L94-L108 |
153,705 | veer66/mapkha | prefixtree.go | MakePrefixTree | func MakePrefixTree(wordsWithPayload []WordWithPayload) *PrefixTree {
sort.Sort(byWord(wordsWithPayload))
tab := make(map[PrefixTreeNode]*PrefixTreePointer)
for i, wordWithPayload := range wordsWithPayload {
word := wordWithPayload.Word
payload := wordWithPayload.Payload
rowNo := 0
runes := []rune(word)
for j, ch := range runes {
isFinal := ((j + 1) == len(runes))
node := PrefixTreeNode{rowNo, j, ch}
child, found := tab[node]
if !found {
var thisPayload interface{}
if isFinal {
thisPayload = payload
} else {
thisPayload = nil
}
tab[node] = &PrefixTreePointer{i, isFinal, thisPayload}
rowNo = i
} else {
rowNo = child.ChildID
}
}
}
return &PrefixTree{tab}
} | go | func MakePrefixTree(wordsWithPayload []WordWithPayload) *PrefixTree {
sort.Sort(byWord(wordsWithPayload))
tab := make(map[PrefixTreeNode]*PrefixTreePointer)
for i, wordWithPayload := range wordsWithPayload {
word := wordWithPayload.Word
payload := wordWithPayload.Payload
rowNo := 0
runes := []rune(word)
for j, ch := range runes {
isFinal := ((j + 1) == len(runes))
node := PrefixTreeNode{rowNo, j, ch}
child, found := tab[node]
if !found {
var thisPayload interface{}
if isFinal {
thisPayload = payload
} else {
thisPayload = nil
}
tab[node] = &PrefixTreePointer{i, isFinal, thisPayload}
rowNo = i
} else {
rowNo = child.ChildID
}
}
}
return &PrefixTree{tab}
} | [
"func",
"MakePrefixTree",
"(",
"wordsWithPayload",
"[",
"]",
"WordWithPayload",
")",
"*",
"PrefixTree",
"{",
"sort",
".",
"Sort",
"(",
"byWord",
"(",
"wordsWithPayload",
")",
")",
"\n",
"tab",
":=",
"make",
"(",
"map",
"[",
"PrefixTreeNode",
"]",
"*",
"Pre... | // MakePrefixTree is for constructing prefix tree for word with payload list | [
"MakePrefixTree",
"is",
"for",
"constructing",
"prefix",
"tree",
"for",
"word",
"with",
"payload",
"list"
] | 4c22c721f2c6c6414a04849669688556d882f526 | https://github.com/veer66/mapkha/blob/4c22c721f2c6c6414a04849669688556d882f526/prefixtree.go#L46-L76 |
153,706 | veer66/mapkha | prefixtree.go | Lookup | func (tree *PrefixTree) Lookup(nodeID int, offset int, ch rune) (*PrefixTreePointer, bool) {
pointer, found := tree.tab[PrefixTreeNode{nodeID, offset, ch}]
return pointer, found
} | go | func (tree *PrefixTree) Lookup(nodeID int, offset int, ch rune) (*PrefixTreePointer, bool) {
pointer, found := tree.tab[PrefixTreeNode{nodeID, offset, ch}]
return pointer, found
} | [
"func",
"(",
"tree",
"*",
"PrefixTree",
")",
"Lookup",
"(",
"nodeID",
"int",
",",
"offset",
"int",
",",
"ch",
"rune",
")",
"(",
"*",
"PrefixTreePointer",
",",
"bool",
")",
"{",
"pointer",
",",
"found",
":=",
"tree",
".",
"tab",
"[",
"PrefixTreeNode",
... | // Lookup - look up prefix tree from node-id, offset and a character | [
"Lookup",
"-",
"look",
"up",
"prefix",
"tree",
"from",
"node",
"-",
"id",
"offset",
"and",
"a",
"character"
] | 4c22c721f2c6c6414a04849669688556d882f526 | https://github.com/veer66/mapkha/blob/4c22c721f2c6c6414a04849669688556d882f526/prefixtree.go#L79-L82 |
153,707 | mcclymont/tcp2ws-go | tcp2ws.go | Proxy | func Proxy(forever bool, listenHost string, remoteHost string) error {
// Listen for incoming connections.
l, err := net.Listen(CONN_TYPE, listenHost)
if err != nil {
return fmt.Errorf("Error listening:", err.Error())
}
// Close the listener when the application closes.
defer l.Close()
fmt.Println("Listening on " + listenHost)
for {
// Listen for an incoming connection.
conn, err := l.Accept()
if err != nil {
return fmt.Errorf("Error accepting: ", err.Error())
}
if forever {
go handleRequest(conn, remoteHost)
} else {
return handleRequest(conn, remoteHost)
}
}
} | go | func Proxy(forever bool, listenHost string, remoteHost string) error {
// Listen for incoming connections.
l, err := net.Listen(CONN_TYPE, listenHost)
if err != nil {
return fmt.Errorf("Error listening:", err.Error())
}
// Close the listener when the application closes.
defer l.Close()
fmt.Println("Listening on " + listenHost)
for {
// Listen for an incoming connection.
conn, err := l.Accept()
if err != nil {
return fmt.Errorf("Error accepting: ", err.Error())
}
if forever {
go handleRequest(conn, remoteHost)
} else {
return handleRequest(conn, remoteHost)
}
}
} | [
"func",
"Proxy",
"(",
"forever",
"bool",
",",
"listenHost",
"string",
",",
"remoteHost",
"string",
")",
"error",
"{",
"// Listen for incoming connections.",
"l",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"CONN_TYPE",
",",
"listenHost",
")",
"\n",
"if",
"e... | // If forever is true, it will run in an infinite loop accepting new
// connections and proxying them to rhost.
// If it is false, it will stop listening on listenHost after
// the first connection is established. | [
"If",
"forever",
"is",
"true",
"it",
"will",
"run",
"in",
"an",
"infinite",
"loop",
"accepting",
"new",
"connections",
"and",
"proxying",
"them",
"to",
"rhost",
".",
"If",
"it",
"is",
"false",
"it",
"will",
"stop",
"listening",
"on",
"listenHost",
"after",... | b61862d004fce8f09c522de3441b5c164febf7c6 | https://github.com/mcclymont/tcp2ws-go/blob/b61862d004fce8f09c522de3441b5c164febf7c6/tcp2ws.go#L20-L41 |
153,708 | thecodeteam/gorackhd | client/pollers/delete_pollers_identifier_parameters.go | WithIdentifier | func (o *DeletePollersIdentifierParams) WithIdentifier(identifier string) *DeletePollersIdentifierParams {
o.Identifier = identifier
return o
} | go | func (o *DeletePollersIdentifierParams) WithIdentifier(identifier string) *DeletePollersIdentifierParams {
o.Identifier = identifier
return o
} | [
"func",
"(",
"o",
"*",
"DeletePollersIdentifierParams",
")",
"WithIdentifier",
"(",
"identifier",
"string",
")",
"*",
"DeletePollersIdentifierParams",
"{",
"o",
".",
"Identifier",
"=",
"identifier",
"\n",
"return",
"o",
"\n",
"}"
] | // WithIdentifier adds the identifier to the delete pollers identifier params | [
"WithIdentifier",
"adds",
"the",
"identifier",
"to",
"the",
"delete",
"pollers",
"identifier",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/pollers/delete_pollers_identifier_parameters.go#L52-L55 |
153,709 | paypal/ionet | ionet.go | Read | func (c *Conn) Read(b []byte) (int, error) {
if c.R == nil {
return 0, c.readErr(false, io.EOF)
}
c.initClosing()
// stop now if we're already closed
select {
case <-c.closing:
return 0, c.readErr(false, connClosed)
default:
}
// stop now if we're already timed out
c.rdeadmu.RLock()
defer c.rdeadmu.RUnlock()
if !c.rdead.IsZero() && c.rdead.Before(time.Now()) {
return 0, c.readErr(true, timedOut)
}
// start read
readc := make(chan nerr, 1)
go func() {
c.rmu.Lock()
n, err := c.R.Read(b)
c.rmu.Unlock()
readc <- nerr{n, err}
}()
// set up deadline timeout
var timeout <-chan time.Time
timer := deadlineTimer(c.rdead) // c.rdeadmu read lock already held above
if timer != nil {
timeout = timer.C
defer timer.Stop()
}
// wait for read success, timeout, or closing
select {
case <-c.closing:
return 0, c.readErr(false, connClosed)
case <-timeout:
return 0, c.readErr(true, timedOut)
case nerr := <-readc:
if nerr.err != nil {
// wrap the error
return nerr.n, c.readErr(false, nerr.err)
}
return nerr.n, nil
}
} | go | func (c *Conn) Read(b []byte) (int, error) {
if c.R == nil {
return 0, c.readErr(false, io.EOF)
}
c.initClosing()
// stop now if we're already closed
select {
case <-c.closing:
return 0, c.readErr(false, connClosed)
default:
}
// stop now if we're already timed out
c.rdeadmu.RLock()
defer c.rdeadmu.RUnlock()
if !c.rdead.IsZero() && c.rdead.Before(time.Now()) {
return 0, c.readErr(true, timedOut)
}
// start read
readc := make(chan nerr, 1)
go func() {
c.rmu.Lock()
n, err := c.R.Read(b)
c.rmu.Unlock()
readc <- nerr{n, err}
}()
// set up deadline timeout
var timeout <-chan time.Time
timer := deadlineTimer(c.rdead) // c.rdeadmu read lock already held above
if timer != nil {
timeout = timer.C
defer timer.Stop()
}
// wait for read success, timeout, or closing
select {
case <-c.closing:
return 0, c.readErr(false, connClosed)
case <-timeout:
return 0, c.readErr(true, timedOut)
case nerr := <-readc:
if nerr.err != nil {
// wrap the error
return nerr.n, c.readErr(false, nerr.err)
}
return nerr.n, nil
}
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Read",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"c",
".",
"R",
"==",
"nil",
"{",
"return",
"0",
",",
"c",
".",
"readErr",
"(",
"false",
",",
"io",
".",
"EOF",
")",
"\n... | // Read implements the net.Conn interface.
// Read returns net.OpError errors. | [
"Read",
"implements",
"the",
"net",
".",
"Conn",
"interface",
".",
"Read",
"returns",
"net",
".",
"OpError",
"errors",
"."
] | ed0aaebc541736bab972353125af442dcf829af2 | https://github.com/paypal/ionet/blob/ed0aaebc541736bab972353125af442dcf829af2/ionet.go#L63-L114 |
153,710 | paypal/ionet | ionet.go | Write | func (c *Conn) Write(b []byte) (int, error) {
if c.W == nil {
// all writes to Discard succeed, so there's no need to wrap errors
return ioutil.Discard.Write(b)
}
c.initClosing()
// stop now if we're already closed
select {
case <-c.closing:
return 0, c.writeErr(false, connClosed)
default:
}
// stop now if we're already timed out
c.wdeadmu.RLock()
defer c.wdeadmu.RUnlock()
if !c.wdead.IsZero() && c.wdead.Before(time.Now()) {
return 0, c.writeErr(true, timedOut)
}
// start write
writec := make(chan nerr, 1)
go func() {
c.wmu.Lock()
n, err := c.W.Write(b)
c.wmu.Unlock()
writec <- nerr{n, err}
}()
// set up deadline timeout
var timeout <-chan time.Time
c.wdeadmu.RLock()
timer := deadlineTimer(c.wdead) // c.wdeadmu read lock already held above
if timer != nil {
timeout = timer.C
defer timer.Stop()
}
// wait for write success, timeout, or closing
select {
case <-c.closing:
return 0, c.writeErr(false, connClosed)
case <-timeout:
return 0, c.writeErr(true, timedOut)
case nerr := <-writec:
if nerr.err != nil {
return nerr.n, c.writeErr(false, nerr.err) // wrap the error
}
return nerr.n, nil
}
} | go | func (c *Conn) Write(b []byte) (int, error) {
if c.W == nil {
// all writes to Discard succeed, so there's no need to wrap errors
return ioutil.Discard.Write(b)
}
c.initClosing()
// stop now if we're already closed
select {
case <-c.closing:
return 0, c.writeErr(false, connClosed)
default:
}
// stop now if we're already timed out
c.wdeadmu.RLock()
defer c.wdeadmu.RUnlock()
if !c.wdead.IsZero() && c.wdead.Before(time.Now()) {
return 0, c.writeErr(true, timedOut)
}
// start write
writec := make(chan nerr, 1)
go func() {
c.wmu.Lock()
n, err := c.W.Write(b)
c.wmu.Unlock()
writec <- nerr{n, err}
}()
// set up deadline timeout
var timeout <-chan time.Time
c.wdeadmu.RLock()
timer := deadlineTimer(c.wdead) // c.wdeadmu read lock already held above
if timer != nil {
timeout = timer.C
defer timer.Stop()
}
// wait for write success, timeout, or closing
select {
case <-c.closing:
return 0, c.writeErr(false, connClosed)
case <-timeout:
return 0, c.writeErr(true, timedOut)
case nerr := <-writec:
if nerr.err != nil {
return nerr.n, c.writeErr(false, nerr.err) // wrap the error
}
return nerr.n, nil
}
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Write",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"c",
".",
"W",
"==",
"nil",
"{",
"// all writes to Discard succeed, so there's no need to wrap errors",
"return",
"ioutil",
".",
"Discar... | // Write implements the net.Conn interface.
// Write returns net.OpError errors. | [
"Write",
"implements",
"the",
"net",
".",
"Conn",
"interface",
".",
"Write",
"returns",
"net",
".",
"OpError",
"errors",
"."
] | ed0aaebc541736bab972353125af442dcf829af2 | https://github.com/paypal/ionet/blob/ed0aaebc541736bab972353125af442dcf829af2/ionet.go#L118-L170 |
153,711 | paypal/ionet | ionet.go | SetDeadline | func (c *Conn) SetDeadline(t time.Time) error {
c.SetReadDeadline(t)
c.SetWriteDeadline(t)
return nil
} | go | func (c *Conn) SetDeadline(t time.Time) error {
c.SetReadDeadline(t)
c.SetWriteDeadline(t)
return nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SetDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"c",
".",
"SetReadDeadline",
"(",
"t",
")",
"\n",
"c",
".",
"SetWriteDeadline",
"(",
"t",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetDeadline implements the net.Conn interface. | [
"SetDeadline",
"implements",
"the",
"net",
".",
"Conn",
"interface",
"."
] | ed0aaebc541736bab972353125af442dcf829af2 | https://github.com/paypal/ionet/blob/ed0aaebc541736bab972353125af442dcf829af2/ionet.go#L204-L208 |
153,712 | paypal/ionet | ionet.go | SetReadDeadline | func (c *Conn) SetReadDeadline(t time.Time) error {
c.rdeadmu.Lock()
c.rdead = t
c.rdeadmu.Unlock()
return nil
} | go | func (c *Conn) SetReadDeadline(t time.Time) error {
c.rdeadmu.Lock()
c.rdead = t
c.rdeadmu.Unlock()
return nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SetReadDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"c",
".",
"rdeadmu",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"rdead",
"=",
"t",
"\n",
"c",
".",
"rdeadmu",
".",
"Unlock",
"(",
")",
"\n",
... | // SetReadDeadline implements the net.Conn interface. | [
"SetReadDeadline",
"implements",
"the",
"net",
".",
"Conn",
"interface",
"."
] | ed0aaebc541736bab972353125af442dcf829af2 | https://github.com/paypal/ionet/blob/ed0aaebc541736bab972353125af442dcf829af2/ionet.go#L211-L216 |
153,713 | paypal/ionet | ionet.go | SetWriteDeadline | func (c *Conn) SetWriteDeadline(t time.Time) error {
c.wdeadmu.Lock()
c.wdead = t
c.wdeadmu.Unlock()
return nil
} | go | func (c *Conn) SetWriteDeadline(t time.Time) error {
c.wdeadmu.Lock()
c.wdead = t
c.wdeadmu.Unlock()
return nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SetWriteDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"c",
".",
"wdeadmu",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"wdead",
"=",
"t",
"\n",
"c",
".",
"wdeadmu",
".",
"Unlock",
"(",
")",
"\n",
... | // SetWriteDeadline implements the net.Conn interface. | [
"SetWriteDeadline",
"implements",
"the",
"net",
".",
"Conn",
"interface",
"."
] | ed0aaebc541736bab972353125af442dcf829af2 | https://github.com/paypal/ionet/blob/ed0aaebc541736bab972353125af442dcf829af2/ionet.go#L219-L224 |
153,714 | paypal/ionet | ionet.go | deadlineTimer | func deadlineTimer(t time.Time) *time.Timer {
if t.IsZero() {
return nil
}
return time.NewTimer(t.Sub(time.Now()))
} | go | func deadlineTimer(t time.Time) *time.Timer {
if t.IsZero() {
return nil
}
return time.NewTimer(t.Sub(time.Now()))
} | [
"func",
"deadlineTimer",
"(",
"t",
"time",
".",
"Time",
")",
"*",
"time",
".",
"Timer",
"{",
"if",
"t",
".",
"IsZero",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"time",
".",
"NewTimer",
"(",
"t",
".",
"Sub",
"(",
"time",
".",
"... | // deadlineTimer returns a time.Timer that fires at the
// provided deadline. If the deadline is 0, it returns nil. | [
"deadlineTimer",
"returns",
"a",
"time",
".",
"Timer",
"that",
"fires",
"at",
"the",
"provided",
"deadline",
".",
"If",
"the",
"deadline",
"is",
"0",
"it",
"returns",
"nil",
"."
] | ed0aaebc541736bab972353125af442dcf829af2 | https://github.com/paypal/ionet/blob/ed0aaebc541736bab972353125af442dcf829af2/ionet.go#L234-L239 |
153,715 | paypal/ionet | ionet.go | initClosing | func (c *Conn) initClosing() {
c.closingmu.Lock()
if c.closing == nil {
c.closing = make(chan struct{})
}
c.closingmu.Unlock()
} | go | func (c *Conn) initClosing() {
c.closingmu.Lock()
if c.closing == nil {
c.closing = make(chan struct{})
}
c.closingmu.Unlock()
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"initClosing",
"(",
")",
"{",
"c",
".",
"closingmu",
".",
"Lock",
"(",
")",
"\n",
"if",
"c",
".",
"closing",
"==",
"nil",
"{",
"c",
".",
"closing",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"... | // initClosing lazily initializes c.closing.
// This helps with the bookkeeping needed
// to make the zero value of Conn usable. | [
"initClosing",
"lazily",
"initializes",
"c",
".",
"closing",
".",
"This",
"helps",
"with",
"the",
"bookkeeping",
"needed",
"to",
"make",
"the",
"zero",
"value",
"of",
"Conn",
"usable",
"."
] | ed0aaebc541736bab972353125af442dcf829af2 | https://github.com/paypal/ionet/blob/ed0aaebc541736bab972353125af442dcf829af2/ionet.go#L244-L250 |
153,716 | paypal/ionet | ionet.go | readErr | func (c *Conn) readErr(timeout bool, e error) *net.OpError {
return &net.OpError{
Op: "read",
Net: network,
Addr: c.RemoteAddr(),
Err: neterr{timeout: timeout, err: e},
}
} | go | func (c *Conn) readErr(timeout bool, e error) *net.OpError {
return &net.OpError{
Op: "read",
Net: network,
Addr: c.RemoteAddr(),
Err: neterr{timeout: timeout, err: e},
}
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"readErr",
"(",
"timeout",
"bool",
",",
"e",
"error",
")",
"*",
"net",
".",
"OpError",
"{",
"return",
"&",
"net",
".",
"OpError",
"{",
"Op",
":",
"\"",
"\"",
",",
"Net",
":",
"network",
",",
"Addr",
":",
"c",... | // readErr wraps a read error in a net.OpError. | [
"readErr",
"wraps",
"a",
"read",
"error",
"in",
"a",
"net",
".",
"OpError",
"."
] | ed0aaebc541736bab972353125af442dcf829af2 | https://github.com/paypal/ionet/blob/ed0aaebc541736bab972353125af442dcf829af2/ionet.go#L253-L260 |
153,717 | paypal/ionet | ionet.go | init | func (l *Listener) init() {
l.Lock()
defer l.Unlock()
if l.closing == nil {
l.closing = make(chan struct{})
}
// Initialize l.connc only if the listener is not yet closed.
select {
case <-l.closing:
default:
if l.connc == nil {
l.connc = make(chan *Conn)
}
}
} | go | func (l *Listener) init() {
l.Lock()
defer l.Unlock()
if l.closing == nil {
l.closing = make(chan struct{})
}
// Initialize l.connc only if the listener is not yet closed.
select {
case <-l.closing:
default:
if l.connc == nil {
l.connc = make(chan *Conn)
}
}
} | [
"func",
"(",
"l",
"*",
"Listener",
")",
"init",
"(",
")",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"Unlock",
"(",
")",
"\n",
"if",
"l",
".",
"closing",
"==",
"nil",
"{",
"l",
".",
"closing",
"=",
"make",
"(",
"chan",
"struct"... | // init lazily initializes a Listener. | [
"init",
"lazily",
"initializes",
"a",
"Listener",
"."
] | ed0aaebc541736bab972353125af442dcf829af2 | https://github.com/paypal/ionet/blob/ed0aaebc541736bab972353125af442dcf829af2/ionet.go#L280-L295 |
153,718 | paypal/ionet | ionet.go | Accept | func (l *Listener) Accept() (net.Conn, error) {
l.init()
select {
case conn := <-l.connc:
return conn, nil
case <-l.closing:
operr := &net.OpError{
Op: "accept",
Net: network,
Addr: l.Addr(),
Err: neterr{timeout: false, err: listenerClosed},
}
return nil, operr
}
} | go | func (l *Listener) Accept() (net.Conn, error) {
l.init()
select {
case conn := <-l.connc:
return conn, nil
case <-l.closing:
operr := &net.OpError{
Op: "accept",
Net: network,
Addr: l.Addr(),
Err: neterr{timeout: false, err: listenerClosed},
}
return nil, operr
}
} | [
"func",
"(",
"l",
"*",
"Listener",
")",
"Accept",
"(",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"l",
".",
"init",
"(",
")",
"\n",
"select",
"{",
"case",
"conn",
":=",
"<-",
"l",
".",
"connc",
":",
"return",
"conn",
",",
"nil",
"\... | // Accept implements the net.Listener interface.
// Accept returns net.OpError errors. | [
"Accept",
"implements",
"the",
"net",
".",
"Listener",
"interface",
".",
"Accept",
"returns",
"net",
".",
"OpError",
"errors",
"."
] | ed0aaebc541736bab972353125af442dcf829af2 | https://github.com/paypal/ionet/blob/ed0aaebc541736bab972353125af442dcf829af2/ionet.go#L299-L313 |
153,719 | paypal/ionet | ionet.go | Dial | func (l *Listener) Dial(r io.Reader, w io.Writer) (*Conn, error) {
l.init()
c := &Conn{R: r, W: w}
select {
case <-l.closing:
operr := &net.OpError{
Op: "dial",
Net: network,
Addr: l.Addr(),
Err: neterr{timeout: false, err: listenerClosed},
}
return nil, operr
case l.connc <- c:
return c, nil
}
} | go | func (l *Listener) Dial(r io.Reader, w io.Writer) (*Conn, error) {
l.init()
c := &Conn{R: r, W: w}
select {
case <-l.closing:
operr := &net.OpError{
Op: "dial",
Net: network,
Addr: l.Addr(),
Err: neterr{timeout: false, err: listenerClosed},
}
return nil, operr
case l.connc <- c:
return c, nil
}
} | [
"func",
"(",
"l",
"*",
"Listener",
")",
"Dial",
"(",
"r",
"io",
".",
"Reader",
",",
"w",
"io",
".",
"Writer",
")",
"(",
"*",
"Conn",
",",
"error",
")",
"{",
"l",
".",
"init",
"(",
")",
"\n",
"c",
":=",
"&",
"Conn",
"{",
"R",
":",
"r",
","... | // Dial connects to a Listener. r and w may be nil; see Conn.
// Note that r and w here are named from the server's perspective,
// so data that you are sending across the connection will be read
// from r, and responses from the connection will be written to w.
// See the documentation in Conn. | [
"Dial",
"connects",
"to",
"a",
"Listener",
".",
"r",
"and",
"w",
"may",
"be",
"nil",
";",
"see",
"Conn",
".",
"Note",
"that",
"r",
"and",
"w",
"here",
"are",
"named",
"from",
"the",
"server",
"s",
"perspective",
"so",
"data",
"that",
"you",
"are",
... | ed0aaebc541736bab972353125af442dcf829af2 | https://github.com/paypal/ionet/blob/ed0aaebc541736bab972353125af442dcf829af2/ionet.go#L346-L361 |
153,720 | bearded-web/bearded | Godeps/_workspace/src/gopkg.in/alexcesaro/quotedprintable.v1/header.go | NewHeaderEncoder | func (enc Encoding) NewHeaderEncoder(charset string) *HeaderEncoder {
// We automatically split encoded-words only when the charset is UTF-8
// because since multi-octet character must not be split across adjacent
// encoded-words (see RFC 2047, section 5) there is no way to split words
// without knowing how the charset works.
splitWords := strings.ToUpper(charset) == "UTF-8"
return &HeaderEncoder{charset, enc, splitWords}
} | go | func (enc Encoding) NewHeaderEncoder(charset string) *HeaderEncoder {
// We automatically split encoded-words only when the charset is UTF-8
// because since multi-octet character must not be split across adjacent
// encoded-words (see RFC 2047, section 5) there is no way to split words
// without knowing how the charset works.
splitWords := strings.ToUpper(charset) == "UTF-8"
return &HeaderEncoder{charset, enc, splitWords}
} | [
"func",
"(",
"enc",
"Encoding",
")",
"NewHeaderEncoder",
"(",
"charset",
"string",
")",
"*",
"HeaderEncoder",
"{",
"// We automatically split encoded-words only when the charset is UTF-8",
"// because since multi-octet character must not be split across adjacent",
"// encoded-words (se... | // NewHeaderEncoder returns a new HeaderEncoder to encode strings in the
// specified charset. | [
"NewHeaderEncoder",
"returns",
"a",
"new",
"HeaderEncoder",
"to",
"encode",
"strings",
"in",
"the",
"specified",
"charset",
"."
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/Godeps/_workspace/src/gopkg.in/alexcesaro/quotedprintable.v1/header.go#L44-L52 |
153,721 | bearded-web/bearded | Godeps/_workspace/src/gopkg.in/alexcesaro/quotedprintable.v1/header.go | Encode | func (e *HeaderEncoder) Encode(s string) string {
if !needsEncoding(s) {
return s
}
return e.encodeWord(s)
} | go | func (e *HeaderEncoder) Encode(s string) string {
if !needsEncoding(s) {
return s
}
return e.encodeWord(s)
} | [
"func",
"(",
"e",
"*",
"HeaderEncoder",
")",
"Encode",
"(",
"s",
"string",
")",
"string",
"{",
"if",
"!",
"needsEncoding",
"(",
"s",
")",
"{",
"return",
"s",
"\n",
"}",
"\n\n",
"return",
"e",
".",
"encodeWord",
"(",
"s",
")",
"\n",
"}"
] | // Encode encodes a string to be used as a MIME header value. It encodes
// the input only if it contains non-ASCII characters. | [
"Encode",
"encodes",
"a",
"string",
"to",
"be",
"used",
"as",
"a",
"MIME",
"header",
"value",
".",
"It",
"encodes",
"the",
"input",
"only",
"if",
"it",
"contains",
"non",
"-",
"ASCII",
"characters",
"."
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/Godeps/_workspace/src/gopkg.in/alexcesaro/quotedprintable.v1/header.go#L56-L62 |
153,722 | bearded-web/bearded | Godeps/_workspace/src/gopkg.in/alexcesaro/quotedprintable.v1/header.go | DecodeHeader | func DecodeHeader(header string) (text, charset string, err error) {
buf := bufFree.GetBuffer()
defer bufFree.PutBuffer(buf)
for {
i := strings.IndexByte(header, '=')
if i == -1 {
break
}
if i > 0 {
buf.WriteString(header[:i])
header = header[i:]
}
word := getEncodedWord(header)
if word == "" {
buf.WriteByte('=')
header = header[1:]
continue
}
for {
dec, wordCharset, err := decodeWord(word)
if err != nil {
buf.WriteString(word)
header = header[len(word):]
break
}
if charset == "" {
charset = wordCharset
} else if charset != wordCharset {
return "", "", fmt.Errorf("quotedprintable: multiple charsets in header are not supported: %q and %q used", charset, wordCharset)
}
buf.Write(dec)
header = header[len(word):]
// White-space and newline characters separating two encoded-words
// must be deleted.
var j int
for j = 0; j < len(header); j++ {
b := header[j]
if b != ' ' && b != '\t' && b != '\n' && b != '\r' {
break
}
}
if j == 0 {
// If there are no white-space characters following the current
// encoded-word there is nothing special to do.
break
}
word = getEncodedWord(header[j:])
if word == "" {
break
}
header = header[j:]
}
}
buf.WriteString(header)
return buf.String(), charset, nil
} | go | func DecodeHeader(header string) (text, charset string, err error) {
buf := bufFree.GetBuffer()
defer bufFree.PutBuffer(buf)
for {
i := strings.IndexByte(header, '=')
if i == -1 {
break
}
if i > 0 {
buf.WriteString(header[:i])
header = header[i:]
}
word := getEncodedWord(header)
if word == "" {
buf.WriteByte('=')
header = header[1:]
continue
}
for {
dec, wordCharset, err := decodeWord(word)
if err != nil {
buf.WriteString(word)
header = header[len(word):]
break
}
if charset == "" {
charset = wordCharset
} else if charset != wordCharset {
return "", "", fmt.Errorf("quotedprintable: multiple charsets in header are not supported: %q and %q used", charset, wordCharset)
}
buf.Write(dec)
header = header[len(word):]
// White-space and newline characters separating two encoded-words
// must be deleted.
var j int
for j = 0; j < len(header); j++ {
b := header[j]
if b != ' ' && b != '\t' && b != '\n' && b != '\r' {
break
}
}
if j == 0 {
// If there are no white-space characters following the current
// encoded-word there is nothing special to do.
break
}
word = getEncodedWord(header[j:])
if word == "" {
break
}
header = header[j:]
}
}
buf.WriteString(header)
return buf.String(), charset, nil
} | [
"func",
"DecodeHeader",
"(",
"header",
"string",
")",
"(",
"text",
",",
"charset",
"string",
",",
"err",
"error",
")",
"{",
"buf",
":=",
"bufFree",
".",
"GetBuffer",
"(",
")",
"\n",
"defer",
"bufFree",
".",
"PutBuffer",
"(",
"buf",
")",
"\n\n",
"for",
... | // DecodeHeader decodes a MIME header by decoding all encoded-words of the
// header. The returned text is encoded in the returned charset. Text is not
// necessarily encoded in UTF-8. Returned charset is always upper case. This
// function does not support decoding headers with multiple encoded-words
// using different charsets. | [
"DecodeHeader",
"decodes",
"a",
"MIME",
"header",
"by",
"decoding",
"all",
"encoded",
"-",
"words",
"of",
"the",
"header",
".",
"The",
"returned",
"text",
"is",
"encoded",
"in",
"the",
"returned",
"charset",
".",
"Text",
"is",
"not",
"necessarily",
"encoded"... | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/Godeps/_workspace/src/gopkg.in/alexcesaro/quotedprintable.v1/header.go#L224-L284 |
153,723 | thecodeteam/gorackhd | client/nodes/post_nodes_macaddress_dhcp_whitelist_parameters.go | WithMacaddress | func (o *PostNodesMacaddressDhcpWhitelistParams) WithMacaddress(macaddress string) *PostNodesMacaddressDhcpWhitelistParams {
o.Macaddress = macaddress
return o
} | go | func (o *PostNodesMacaddressDhcpWhitelistParams) WithMacaddress(macaddress string) *PostNodesMacaddressDhcpWhitelistParams {
o.Macaddress = macaddress
return o
} | [
"func",
"(",
"o",
"*",
"PostNodesMacaddressDhcpWhitelistParams",
")",
"WithMacaddress",
"(",
"macaddress",
"string",
")",
"*",
"PostNodesMacaddressDhcpWhitelistParams",
"{",
"o",
".",
"Macaddress",
"=",
"macaddress",
"\n",
"return",
"o",
"\n",
"}"
] | // WithMacaddress adds the macaddress to the post nodes macaddress dhcp whitelist params | [
"WithMacaddress",
"adds",
"the",
"macaddress",
"to",
"the",
"post",
"nodes",
"macaddress",
"dhcp",
"whitelist",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/nodes/post_nodes_macaddress_dhcp_whitelist_parameters.go#L61-L64 |
153,724 | bearded-web/bearded | Godeps/_workspace/src/gopkg.in/mgo.v2/session.go | DialWithTimeout | func DialWithTimeout(url string, timeout time.Duration) (*Session, error) {
uinfo, err := parseURL(url)
if err != nil {
return nil, err
}
direct := false
mechanism := ""
service := ""
source := ""
setName := ""
poolLimit := 0
for k, v := range uinfo.options {
switch k {
case "authSource":
source = v
case "authMechanism":
mechanism = v
case "gssapiServiceName":
service = v
case "replicaSet":
setName = v
case "maxPoolSize":
poolLimit, err = strconv.Atoi(v)
if err != nil {
return nil, errors.New("bad value for maxPoolSize: " + v)
}
case "connect":
if v == "direct" {
direct = true
break
}
if v == "replicaSet" {
break
}
fallthrough
default:
return nil, errors.New("unsupported connection URL option: " + k + "=" + v)
}
}
info := DialInfo{
Addrs: uinfo.addrs,
Direct: direct,
Timeout: timeout,
Database: uinfo.db,
Username: uinfo.user,
Password: uinfo.pass,
Mechanism: mechanism,
Service: service,
Source: source,
PoolLimit: poolLimit,
ReplicaSetName: setName,
}
return DialWithInfo(&info)
} | go | func DialWithTimeout(url string, timeout time.Duration) (*Session, error) {
uinfo, err := parseURL(url)
if err != nil {
return nil, err
}
direct := false
mechanism := ""
service := ""
source := ""
setName := ""
poolLimit := 0
for k, v := range uinfo.options {
switch k {
case "authSource":
source = v
case "authMechanism":
mechanism = v
case "gssapiServiceName":
service = v
case "replicaSet":
setName = v
case "maxPoolSize":
poolLimit, err = strconv.Atoi(v)
if err != nil {
return nil, errors.New("bad value for maxPoolSize: " + v)
}
case "connect":
if v == "direct" {
direct = true
break
}
if v == "replicaSet" {
break
}
fallthrough
default:
return nil, errors.New("unsupported connection URL option: " + k + "=" + v)
}
}
info := DialInfo{
Addrs: uinfo.addrs,
Direct: direct,
Timeout: timeout,
Database: uinfo.db,
Username: uinfo.user,
Password: uinfo.pass,
Mechanism: mechanism,
Service: service,
Source: source,
PoolLimit: poolLimit,
ReplicaSetName: setName,
}
return DialWithInfo(&info)
} | [
"func",
"DialWithTimeout",
"(",
"url",
"string",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"*",
"Session",
",",
"error",
")",
"{",
"uinfo",
",",
"err",
":=",
"parseURL",
"(",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // DialWithTimeout works like Dial, but uses timeout as the amount of time to
// wait for a server to respond when first connecting and also on follow up
// operations in the session. If timeout is zero, the call may block
// forever waiting for a connection to be made.
//
// See SetSyncTimeout for customizing the timeout for the session. | [
"DialWithTimeout",
"works",
"like",
"Dial",
"but",
"uses",
"timeout",
"as",
"the",
"amount",
"of",
"time",
"to",
"wait",
"for",
"a",
"server",
"to",
"respond",
"when",
"first",
"connecting",
"and",
"also",
"on",
"follow",
"up",
"operations",
"in",
"the",
"... | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/Godeps/_workspace/src/gopkg.in/mgo.v2/session.go#L220-L273 |
153,725 | bearded-web/bearded | Godeps/_workspace/src/gopkg.in/mgo.v2/session.go | writeQuery | func (c *Collection) writeQuery(op interface{}) (lerr *LastError, err error) {
s := c.Database.Session
dbname := c.Database.Name
socket, err := s.acquireSocket(dbname == "local")
if err != nil {
return nil, err
}
defer socket.Release()
s.m.RLock()
safeOp := s.safeOp
s.m.RUnlock()
if safeOp == nil {
return nil, socket.Query(op)
} else {
var mutex sync.Mutex
var replyData []byte
var replyErr error
mutex.Lock()
query := *safeOp // Copy the data.
query.collection = dbname + ".$cmd"
query.replyFunc = func(err error, reply *replyOp, docNum int, docData []byte) {
replyData = docData
replyErr = err
mutex.Unlock()
}
err = socket.Query(op, &query)
if err != nil {
return nil, err
}
mutex.Lock() // Wait.
if replyErr != nil {
return nil, replyErr // XXX TESTME
}
if hasErrMsg(replyData) {
// Looks like getLastError itself failed.
err = checkQueryError(query.collection, replyData)
if err != nil {
return nil, err
}
}
result := &LastError{}
bson.Unmarshal(replyData, &result)
debugf("Result from writing query: %#v", result)
if result.Err != "" {
return result, result
}
return result, nil
}
panic("unreachable")
} | go | func (c *Collection) writeQuery(op interface{}) (lerr *LastError, err error) {
s := c.Database.Session
dbname := c.Database.Name
socket, err := s.acquireSocket(dbname == "local")
if err != nil {
return nil, err
}
defer socket.Release()
s.m.RLock()
safeOp := s.safeOp
s.m.RUnlock()
if safeOp == nil {
return nil, socket.Query(op)
} else {
var mutex sync.Mutex
var replyData []byte
var replyErr error
mutex.Lock()
query := *safeOp // Copy the data.
query.collection = dbname + ".$cmd"
query.replyFunc = func(err error, reply *replyOp, docNum int, docData []byte) {
replyData = docData
replyErr = err
mutex.Unlock()
}
err = socket.Query(op, &query)
if err != nil {
return nil, err
}
mutex.Lock() // Wait.
if replyErr != nil {
return nil, replyErr // XXX TESTME
}
if hasErrMsg(replyData) {
// Looks like getLastError itself failed.
err = checkQueryError(query.collection, replyData)
if err != nil {
return nil, err
}
}
result := &LastError{}
bson.Unmarshal(replyData, &result)
debugf("Result from writing query: %#v", result)
if result.Err != "" {
return result, result
}
return result, nil
}
panic("unreachable")
} | [
"func",
"(",
"c",
"*",
"Collection",
")",
"writeQuery",
"(",
"op",
"interface",
"{",
"}",
")",
"(",
"lerr",
"*",
"LastError",
",",
"err",
"error",
")",
"{",
"s",
":=",
"c",
".",
"Database",
".",
"Session",
"\n",
"dbname",
":=",
"c",
".",
"Database"... | // writeQuery runs the given modifying operation, potentially followed up
// by a getLastError command in case the session is in safe mode. The
// LastError result is made available in lerr, and if lerr.Err is set it
// will also be returned as err. | [
"writeQuery",
"runs",
"the",
"given",
"modifying",
"operation",
"potentially",
"followed",
"up",
"by",
"a",
"getLastError",
"command",
"in",
"case",
"the",
"session",
"is",
"in",
"safe",
"mode",
".",
"The",
"LastError",
"result",
"is",
"made",
"available",
"in... | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/Godeps/_workspace/src/gopkg.in/mgo.v2/session.go#L3923-L3974 |
153,726 | tallstoat/pbparser | parse_context.go | permitsField | func (pc parseCtx) permitsField() bool {
return pc.ctxType == msgCtx || pc.ctxType == oneOfCtx || pc.ctxType == extendCtx
} | go | func (pc parseCtx) permitsField() bool {
return pc.ctxType == msgCtx || pc.ctxType == oneOfCtx || pc.ctxType == extendCtx
} | [
"func",
"(",
"pc",
"parseCtx",
")",
"permitsField",
"(",
")",
"bool",
"{",
"return",
"pc",
".",
"ctxType",
"==",
"msgCtx",
"||",
"pc",
".",
"ctxType",
"==",
"oneOfCtx",
"||",
"pc",
".",
"ctxType",
"==",
"extendCtx",
"\n",
"}"
] | // does this ctx permit field support? | [
"does",
"this",
"ctx",
"permit",
"field",
"support?"
] | 1e04894cea0468f041dbb96476d81b3d49b4a0f1 | https://github.com/tallstoat/pbparser/blob/1e04894cea0468f041dbb96476d81b3d49b4a0f1/parse_context.go#L56-L58 |
153,727 | tallstoat/pbparser | parse_context.go | permitsOption | func (pc parseCtx) permitsOption() bool {
return pc.ctxType == fileCtx ||
pc.ctxType == msgCtx ||
pc.ctxType == oneOfCtx ||
pc.ctxType == enumCtx ||
pc.ctxType == serviceCtx ||
pc.ctxType == rpcCtx
} | go | func (pc parseCtx) permitsOption() bool {
return pc.ctxType == fileCtx ||
pc.ctxType == msgCtx ||
pc.ctxType == oneOfCtx ||
pc.ctxType == enumCtx ||
pc.ctxType == serviceCtx ||
pc.ctxType == rpcCtx
} | [
"func",
"(",
"pc",
"parseCtx",
")",
"permitsOption",
"(",
")",
"bool",
"{",
"return",
"pc",
".",
"ctxType",
"==",
"fileCtx",
"||",
"pc",
".",
"ctxType",
"==",
"msgCtx",
"||",
"pc",
".",
"ctxType",
"==",
"oneOfCtx",
"||",
"pc",
".",
"ctxType",
"==",
"... | // does this ctx permit option? | [
"does",
"this",
"ctx",
"permit",
"option?"
] | 1e04894cea0468f041dbb96476d81b3d49b4a0f1 | https://github.com/tallstoat/pbparser/blob/1e04894cea0468f041dbb96476d81b3d49b4a0f1/parse_context.go#L61-L68 |
153,728 | tallstoat/pbparser | parse_context.go | permitsExtend | func (pc parseCtx) permitsExtend() bool {
return pc.ctxType == fileCtx || pc.ctxType == msgCtx
} | go | func (pc parseCtx) permitsExtend() bool {
return pc.ctxType == fileCtx || pc.ctxType == msgCtx
} | [
"func",
"(",
"pc",
"parseCtx",
")",
"permitsExtend",
"(",
")",
"bool",
"{",
"return",
"pc",
".",
"ctxType",
"==",
"fileCtx",
"||",
"pc",
".",
"ctxType",
"==",
"msgCtx",
"\n",
"}"
] | // does this ctx permit extend declarations? | [
"does",
"this",
"ctx",
"permit",
"extend",
"declarations?"
] | 1e04894cea0468f041dbb96476d81b3d49b4a0f1 | https://github.com/tallstoat/pbparser/blob/1e04894cea0468f041dbb96476d81b3d49b4a0f1/parse_context.go#L76-L78 |
153,729 | tallstoat/pbparser | parse_context.go | permitsEnum | func (pc parseCtx) permitsEnum() bool {
return pc.ctxType == fileCtx || pc.ctxType == msgCtx
} | go | func (pc parseCtx) permitsEnum() bool {
return pc.ctxType == fileCtx || pc.ctxType == msgCtx
} | [
"func",
"(",
"pc",
"parseCtx",
")",
"permitsEnum",
"(",
")",
"bool",
"{",
"return",
"pc",
".",
"ctxType",
"==",
"fileCtx",
"||",
"pc",
".",
"ctxType",
"==",
"msgCtx",
"\n",
"}"
] | // does this ctx permit enum support? | [
"does",
"this",
"ctx",
"permit",
"enum",
"support?"
] | 1e04894cea0468f041dbb96476d81b3d49b4a0f1 | https://github.com/tallstoat/pbparser/blob/1e04894cea0468f041dbb96476d81b3d49b4a0f1/parse_context.go#L96-L98 |
153,730 | tallstoat/pbparser | parse_context.go | permitsMsg | func (pc parseCtx) permitsMsg() bool {
return pc.ctxType == fileCtx || pc.ctxType == msgCtx
} | go | func (pc parseCtx) permitsMsg() bool {
return pc.ctxType == fileCtx || pc.ctxType == msgCtx
} | [
"func",
"(",
"pc",
"parseCtx",
")",
"permitsMsg",
"(",
")",
"bool",
"{",
"return",
"pc",
".",
"ctxType",
"==",
"fileCtx",
"||",
"pc",
".",
"ctxType",
"==",
"msgCtx",
"\n",
"}"
] | // does this ctx permit msg support? | [
"does",
"this",
"ctx",
"permit",
"msg",
"support?"
] | 1e04894cea0468f041dbb96476d81b3d49b4a0f1 | https://github.com/tallstoat/pbparser/blob/1e04894cea0468f041dbb96476d81b3d49b4a0f1/parse_context.go#L101-L103 |
153,731 | thecodeteam/gorackhd | client/get/get_pollers_identifier_data_parameters.go | WithIdentifier | func (o *GetPollersIdentifierDataParams) WithIdentifier(identifier string) *GetPollersIdentifierDataParams {
o.Identifier = identifier
return o
} | go | func (o *GetPollersIdentifierDataParams) WithIdentifier(identifier string) *GetPollersIdentifierDataParams {
o.Identifier = identifier
return o
} | [
"func",
"(",
"o",
"*",
"GetPollersIdentifierDataParams",
")",
"WithIdentifier",
"(",
"identifier",
"string",
")",
"*",
"GetPollersIdentifierDataParams",
"{",
"o",
".",
"Identifier",
"=",
"identifier",
"\n",
"return",
"o",
"\n",
"}"
] | // WithIdentifier adds the identifier to the get pollers identifier data params | [
"WithIdentifier",
"adds",
"the",
"identifier",
"to",
"the",
"get",
"pollers",
"identifier",
"data",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/get/get_pollers_identifier_data_parameters.go#L52-L55 |
153,732 | thecodeteam/gorackhd | client/patch/patch_nodes_identifier_tags_parameters.go | WithIdentifier | func (o *PatchNodesIdentifierTagsParams) WithIdentifier(identifier string) *PatchNodesIdentifierTagsParams {
o.Identifier = identifier
return o
} | go | func (o *PatchNodesIdentifierTagsParams) WithIdentifier(identifier string) *PatchNodesIdentifierTagsParams {
o.Identifier = identifier
return o
} | [
"func",
"(",
"o",
"*",
"PatchNodesIdentifierTagsParams",
")",
"WithIdentifier",
"(",
"identifier",
"string",
")",
"*",
"PatchNodesIdentifierTagsParams",
"{",
"o",
".",
"Identifier",
"=",
"identifier",
"\n",
"return",
"o",
"\n",
"}"
] | // WithIdentifier adds the identifier to the patch nodes identifier tags params | [
"WithIdentifier",
"adds",
"the",
"identifier",
"to",
"the",
"patch",
"nodes",
"identifier",
"tags",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/patch/patch_nodes_identifier_tags_parameters.go#L64-L67 |
153,733 | thecodeteam/gorackhd | client/workflow/post_workflows_parameters.go | WithName | func (o *PostWorkflowsParams) WithName(name string) *PostWorkflowsParams {
o.Name = name
return o
} | go | func (o *PostWorkflowsParams) WithName(name string) *PostWorkflowsParams {
o.Name = name
return o
} | [
"func",
"(",
"o",
"*",
"PostWorkflowsParams",
")",
"WithName",
"(",
"name",
"string",
")",
"*",
"PostWorkflowsParams",
"{",
"o",
".",
"Name",
"=",
"name",
"\n",
"return",
"o",
"\n",
"}"
] | // WithName adds the name to the post workflows params | [
"WithName",
"adds",
"the",
"name",
"to",
"the",
"post",
"workflows",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/workflow/post_workflows_parameters.go#L60-L63 |
153,734 | bearded-web/bearded | Godeps/_workspace/src/gopkg.in/gomail.v1/mailer.go | SetTLSConfig | func SetTLSConfig(c *tls.Config) MailerSetting {
return func(m *Mailer) {
m.config = c
}
} | go | func SetTLSConfig(c *tls.Config) MailerSetting {
return func(m *Mailer) {
m.config = c
}
} | [
"func",
"SetTLSConfig",
"(",
"c",
"*",
"tls",
".",
"Config",
")",
"MailerSetting",
"{",
"return",
"func",
"(",
"m",
"*",
"Mailer",
")",
"{",
"m",
".",
"config",
"=",
"c",
"\n",
"}",
"\n",
"}"
] | // SetTLSConfig allows to set the TLS configuration used to connect the SMTP
// server. | [
"SetTLSConfig",
"allows",
"to",
"set",
"the",
"TLS",
"configuration",
"used",
"to",
"connect",
"the",
"SMTP",
"server",
"."
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/Godeps/_workspace/src/gopkg.in/gomail.v1/mailer.go#L43-L47 |
153,735 | bearded-web/bearded | Godeps/_workspace/src/gopkg.in/gomail.v1/mailer.go | NewMailer | func NewMailer(host string, username string, password string, port int, settings ...MailerSetting) *Mailer {
return NewCustomMailer(
fmt.Sprintf("%s:%d", host, port),
smtp.PlainAuth("", username, password, host),
settings...,
)
} | go | func NewMailer(host string, username string, password string, port int, settings ...MailerSetting) *Mailer {
return NewCustomMailer(
fmt.Sprintf("%s:%d", host, port),
smtp.PlainAuth("", username, password, host),
settings...,
)
} | [
"func",
"NewMailer",
"(",
"host",
"string",
",",
"username",
"string",
",",
"password",
"string",
",",
"port",
"int",
",",
"settings",
"...",
"MailerSetting",
")",
"*",
"Mailer",
"{",
"return",
"NewCustomMailer",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\""... | // NewMailer returns a mailer. The given parameters are used to connect to the
// SMTP server via a PLAIN authentication mechanism. | [
"NewMailer",
"returns",
"a",
"mailer",
".",
"The",
"given",
"parameters",
"are",
"used",
"to",
"connect",
"to",
"the",
"SMTP",
"server",
"via",
"a",
"PLAIN",
"authentication",
"mechanism",
"."
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/Godeps/_workspace/src/gopkg.in/gomail.v1/mailer.go#L55-L61 |
153,736 | bearded-web/bearded | Godeps/_workspace/src/gopkg.in/gomail.v1/mailer.go | Send | func (m *Mailer) Send(msg *Message) error {
message := msg.Export()
from, err := getFrom(message)
if err != nil {
return err
}
recipients, bcc, err := getRecipients(message)
if err != nil {
return err
}
h := flattenHeader(message, "")
body, err := ioutil.ReadAll(message.Body)
if err != nil {
return err
}
mail := append(h, body...)
if err := m.send(m.addr, m.auth, from, recipients, mail); err != nil {
return err
}
for _, to := range bcc {
h = flattenHeader(message, to)
mail = append(h, body...)
if err := m.send(m.addr, m.auth, from, []string{to}, mail); err != nil {
return err
}
}
return nil
} | go | func (m *Mailer) Send(msg *Message) error {
message := msg.Export()
from, err := getFrom(message)
if err != nil {
return err
}
recipients, bcc, err := getRecipients(message)
if err != nil {
return err
}
h := flattenHeader(message, "")
body, err := ioutil.ReadAll(message.Body)
if err != nil {
return err
}
mail := append(h, body...)
if err := m.send(m.addr, m.auth, from, recipients, mail); err != nil {
return err
}
for _, to := range bcc {
h = flattenHeader(message, to)
mail = append(h, body...)
if err := m.send(m.addr, m.auth, from, []string{to}, mail); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"m",
"*",
"Mailer",
")",
"Send",
"(",
"msg",
"*",
"Message",
")",
"error",
"{",
"message",
":=",
"msg",
".",
"Export",
"(",
")",
"\n\n",
"from",
",",
"err",
":=",
"getFrom",
"(",
"message",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
... | // Send sends the emails to all the recipients of the message. | [
"Send",
"sends",
"the",
"emails",
"to",
"all",
"the",
"recipients",
"of",
"the",
"message",
"."
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/Godeps/_workspace/src/gopkg.in/gomail.v1/mailer.go#L93-L125 |
153,737 | veer66/mapkha | acceptor.go | Reset | func (a *DictAcceptor) Reset(p int) {
a.p = p
a.final = false
a.offset = 0
a.valid = true
} | go | func (a *DictAcceptor) Reset(p int) {
a.p = p
a.final = false
a.offset = 0
a.valid = true
} | [
"func",
"(",
"a",
"*",
"DictAcceptor",
")",
"Reset",
"(",
"p",
"int",
")",
"{",
"a",
".",
"p",
"=",
"p",
"\n",
"a",
".",
"final",
"=",
"false",
"\n",
"a",
".",
"offset",
"=",
"0",
"\n",
"a",
".",
"valid",
"=",
"true",
"\n",
"}"
] | // Reset - reset internal state | [
"Reset",
"-",
"reset",
"internal",
"state"
] | 4c22c721f2c6c6414a04849669688556d882f526 | https://github.com/veer66/mapkha/blob/4c22c721f2c6c6414a04849669688556d882f526/acceptor.go#L11-L16 |
153,738 | veer66/mapkha | acceptor.go | Transit | func (a *DictAcceptor) Transit(ch rune, dict *Dict) {
pointer, found := dict.Lookup(a.p, a.offset, ch)
if !found {
a.valid = false
return
}
a.p = pointer.ChildID
a.offset++
a.final = pointer.IsFinal
} | go | func (a *DictAcceptor) Transit(ch rune, dict *Dict) {
pointer, found := dict.Lookup(a.p, a.offset, ch)
if !found {
a.valid = false
return
}
a.p = pointer.ChildID
a.offset++
a.final = pointer.IsFinal
} | [
"func",
"(",
"a",
"*",
"DictAcceptor",
")",
"Transit",
"(",
"ch",
"rune",
",",
"dict",
"*",
"Dict",
")",
"{",
"pointer",
",",
"found",
":=",
"dict",
".",
"Lookup",
"(",
"a",
".",
"p",
",",
"a",
".",
"offset",
",",
"ch",
")",
"\n\n",
"if",
"!",
... | // Transit - walk on prefix tree by new rune | [
"Transit",
"-",
"walk",
"on",
"prefix",
"tree",
"by",
"new",
"rune"
] | 4c22c721f2c6c6414a04849669688556d882f526 | https://github.com/veer66/mapkha/blob/4c22c721f2c6c6414a04849669688556d882f526/acceptor.go#L19-L30 |
153,739 | veer66/mapkha | acceptor.go | Obtain | func (pool *AccPool) Obtain(p int) *DictAcceptor {
if pool.i >= len(pool.acc) {
pool.acc = append(pool.acc, DictAcceptor{})
}
a := &pool.acc[pool.i]
a.Reset(p)
pool.i++
return a
} | go | func (pool *AccPool) Obtain(p int) *DictAcceptor {
if pool.i >= len(pool.acc) {
pool.acc = append(pool.acc, DictAcceptor{})
}
a := &pool.acc[pool.i]
a.Reset(p)
pool.i++
return a
} | [
"func",
"(",
"pool",
"*",
"AccPool",
")",
"Obtain",
"(",
"p",
"int",
")",
"*",
"DictAcceptor",
"{",
"if",
"pool",
".",
"i",
">=",
"len",
"(",
"pool",
".",
"acc",
")",
"{",
"pool",
".",
"acc",
"=",
"append",
"(",
"pool",
".",
"acc",
",",
"DictAc... | // Obtain - obtain dict acceptor at p | [
"Obtain",
"-",
"obtain",
"dict",
"acceptor",
"at",
"p"
] | 4c22c721f2c6c6414a04849669688556d882f526 | https://github.com/veer66/mapkha/blob/4c22c721f2c6c6414a04849669688556d882f526/acceptor.go#L49-L58 |
153,740 | bearded-web/bearded | services/base.go | IsId | func (s *BaseService) IsId(id string) bool {
return s.manager.IsId(id)
} | go | func (s *BaseService) IsId(id string) bool {
return s.manager.IsId(id)
} | [
"func",
"(",
"s",
"*",
"BaseService",
")",
"IsId",
"(",
"id",
"string",
")",
"bool",
"{",
"return",
"s",
".",
"manager",
".",
"IsId",
"(",
"id",
")",
"\n",
"}"
] | // Check if id is in right format without making a copy of manager | [
"Check",
"if",
"id",
"is",
"in",
"right",
"format",
"without",
"making",
"a",
"copy",
"of",
"manager"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/services/base.go#L72-L74 |
153,741 | bearded-web/bearded | services/base.go | SetParams | func (s *BaseService) SetParams(r *restful.RouteBuilder, params []*restful.Parameter) {
for _, p := range params {
r.Param(p)
}
} | go | func (s *BaseService) SetParams(r *restful.RouteBuilder, params []*restful.Parameter) {
for _, p := range params {
r.Param(p)
}
} | [
"func",
"(",
"s",
"*",
"BaseService",
")",
"SetParams",
"(",
"r",
"*",
"restful",
".",
"RouteBuilder",
",",
"params",
"[",
"]",
"*",
"restful",
".",
"Parameter",
")",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"params",
"{",
"r",
".",
"Param",
"(",
... | // set multiple params to route | [
"set",
"multiple",
"params",
"to",
"route"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/services/base.go#L77-L81 |
153,742 | thecodeteam/gorackhd | client/obm/post_nodes_identifier_obm_identify_parameters.go | WithBody | func (o *PostNodesIdentifierObmIdentifyParams) WithBody(body *bool) *PostNodesIdentifierObmIdentifyParams {
o.Body = body
return o
} | go | func (o *PostNodesIdentifierObmIdentifyParams) WithBody(body *bool) *PostNodesIdentifierObmIdentifyParams {
o.Body = body
return o
} | [
"func",
"(",
"o",
"*",
"PostNodesIdentifierObmIdentifyParams",
")",
"WithBody",
"(",
"body",
"*",
"bool",
")",
"*",
"PostNodesIdentifierObmIdentifyParams",
"{",
"o",
".",
"Body",
"=",
"body",
"\n",
"return",
"o",
"\n",
"}"
] | // WithBody adds the body to the post nodes identifier obm identify params | [
"WithBody",
"adds",
"the",
"body",
"to",
"the",
"post",
"nodes",
"identifier",
"obm",
"identify",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/obm/post_nodes_identifier_obm_identify_parameters.go#L59-L62 |
153,743 | thecodeteam/gorackhd | client/obm/post_nodes_identifier_obm_identify_parameters.go | WithIdentifier | func (o *PostNodesIdentifierObmIdentifyParams) WithIdentifier(identifier string) *PostNodesIdentifierObmIdentifyParams {
o.Identifier = identifier
return o
} | go | func (o *PostNodesIdentifierObmIdentifyParams) WithIdentifier(identifier string) *PostNodesIdentifierObmIdentifyParams {
o.Identifier = identifier
return o
} | [
"func",
"(",
"o",
"*",
"PostNodesIdentifierObmIdentifyParams",
")",
"WithIdentifier",
"(",
"identifier",
"string",
")",
"*",
"PostNodesIdentifierObmIdentifyParams",
"{",
"o",
".",
"Identifier",
"=",
"identifier",
"\n",
"return",
"o",
"\n",
"}"
] | // WithIdentifier adds the identifier to the post nodes identifier obm identify params | [
"WithIdentifier",
"adds",
"the",
"identifier",
"to",
"the",
"post",
"nodes",
"identifier",
"obm",
"identify",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/obm/post_nodes_identifier_obm_identify_parameters.go#L65-L68 |
153,744 | thecodeteam/gorackhd | client/get/get_pollers_identifier_parameters.go | WithIdentifier | func (o *GetPollersIdentifierParams) WithIdentifier(identifier string) *GetPollersIdentifierParams {
o.Identifier = identifier
return o
} | go | func (o *GetPollersIdentifierParams) WithIdentifier(identifier string) *GetPollersIdentifierParams {
o.Identifier = identifier
return o
} | [
"func",
"(",
"o",
"*",
"GetPollersIdentifierParams",
")",
"WithIdentifier",
"(",
"identifier",
"string",
")",
"*",
"GetPollersIdentifierParams",
"{",
"o",
".",
"Identifier",
"=",
"identifier",
"\n",
"return",
"o",
"\n",
"}"
] | // WithIdentifier adds the identifier to the get pollers identifier params | [
"WithIdentifier",
"adds",
"the",
"identifier",
"to",
"the",
"get",
"pollers",
"identifier",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/get/get_pollers_identifier_parameters.go#L52-L55 |
153,745 | thecodeteam/gorackhd | client/nodes/delete_nodes_identifier_tags_tagname_parameters.go | WithIdentifier | func (o *DeleteNodesIdentifierTagsTagnameParams) WithIdentifier(identifier string) *DeleteNodesIdentifierTagsTagnameParams {
o.Identifier = identifier
return o
} | go | func (o *DeleteNodesIdentifierTagsTagnameParams) WithIdentifier(identifier string) *DeleteNodesIdentifierTagsTagnameParams {
o.Identifier = identifier
return o
} | [
"func",
"(",
"o",
"*",
"DeleteNodesIdentifierTagsTagnameParams",
")",
"WithIdentifier",
"(",
"identifier",
"string",
")",
"*",
"DeleteNodesIdentifierTagsTagnameParams",
"{",
"o",
".",
"Identifier",
"=",
"identifier",
"\n",
"return",
"o",
"\n",
"}"
] | // WithIdentifier adds the identifier to the delete nodes identifier tags tagname params | [
"WithIdentifier",
"adds",
"the",
"identifier",
"to",
"the",
"delete",
"nodes",
"identifier",
"tags",
"tagname",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/nodes/delete_nodes_identifier_tags_tagname_parameters.go#L58-L61 |
153,746 | thecodeteam/gorackhd | client/nodes/delete_nodes_identifier_tags_tagname_parameters.go | WithTagname | func (o *DeleteNodesIdentifierTagsTagnameParams) WithTagname(tagname string) *DeleteNodesIdentifierTagsTagnameParams {
o.Tagname = tagname
return o
} | go | func (o *DeleteNodesIdentifierTagsTagnameParams) WithTagname(tagname string) *DeleteNodesIdentifierTagsTagnameParams {
o.Tagname = tagname
return o
} | [
"func",
"(",
"o",
"*",
"DeleteNodesIdentifierTagsTagnameParams",
")",
"WithTagname",
"(",
"tagname",
"string",
")",
"*",
"DeleteNodesIdentifierTagsTagnameParams",
"{",
"o",
".",
"Tagname",
"=",
"tagname",
"\n",
"return",
"o",
"\n",
"}"
] | // WithTagname adds the tagname to the delete nodes identifier tags tagname params | [
"WithTagname",
"adds",
"the",
"tagname",
"to",
"the",
"delete",
"nodes",
"identifier",
"tags",
"tagname",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/nodes/delete_nodes_identifier_tags_tagname_parameters.go#L64-L67 |
153,747 | tallstoat/pbparser | datatype.go | NewScalarDataType | func NewScalarDataType(s string) (ScalarDataType, error) {
key := strings.ToLower(s)
st := scalarLookupMap[key]
if st == 0 {
msg := fmt.Sprintf("'%v' is not a valid ScalarDataType", s)
return ScalarDataType{}, errors.New(msg)
}
return ScalarDataType{name: key, scalarType: st}, nil
} | go | func NewScalarDataType(s string) (ScalarDataType, error) {
key := strings.ToLower(s)
st := scalarLookupMap[key]
if st == 0 {
msg := fmt.Sprintf("'%v' is not a valid ScalarDataType", s)
return ScalarDataType{}, errors.New(msg)
}
return ScalarDataType{name: key, scalarType: st}, nil
} | [
"func",
"NewScalarDataType",
"(",
"s",
"string",
")",
"(",
"ScalarDataType",
",",
"error",
")",
"{",
"key",
":=",
"strings",
".",
"ToLower",
"(",
"s",
")",
"\n",
"st",
":=",
"scalarLookupMap",
"[",
"key",
"]",
"\n",
"if",
"st",
"==",
"0",
"{",
"msg",... | // NewScalarDataType creates and returns a new ScalarDataType for the given string.
// If a scalar data type mapping does not exist for the given string, an Error is returned. | [
"NewScalarDataType",
"creates",
"and",
"returns",
"a",
"new",
"ScalarDataType",
"for",
"the",
"given",
"string",
".",
"If",
"a",
"scalar",
"data",
"type",
"mapping",
"does",
"not",
"exist",
"for",
"the",
"given",
"string",
"an",
"Error",
"is",
"returned",
".... | 1e04894cea0468f041dbb96476d81b3d49b4a0f1 | https://github.com/tallstoat/pbparser/blob/1e04894cea0468f041dbb96476d81b3d49b4a0f1/datatype.go#L88-L96 |
153,748 | tallstoat/pbparser | datatype.go | Name | func (mdt MapDataType) Name() string {
return "map<" + mdt.keyType.Name() + ", " + mdt.valueType.Name() + ">"
} | go | func (mdt MapDataType) Name() string {
return "map<" + mdt.keyType.Name() + ", " + mdt.valueType.Name() + ">"
} | [
"func",
"(",
"mdt",
"MapDataType",
")",
"Name",
"(",
")",
"string",
"{",
"return",
"\"",
"\"",
"+",
"mdt",
".",
"keyType",
".",
"Name",
"(",
")",
"+",
"\"",
"\"",
"+",
"mdt",
".",
"valueType",
".",
"Name",
"(",
")",
"+",
"\"",
"\"",
"\n",
"}"
] | // Name function implementation of interface DataType for MapDataType | [
"Name",
"function",
"implementation",
"of",
"interface",
"DataType",
"for",
"MapDataType"
] | 1e04894cea0468f041dbb96476d81b3d49b4a0f1 | https://github.com/tallstoat/pbparser/blob/1e04894cea0468f041dbb96476d81b3d49b4a0f1/datatype.go#L105-L107 |
153,749 | veer66/mapkha | dict_edge_builder.go | Build | func (builder *DictEdgeBuilder) Build(context *EdgeBuildingContext) *Edge {
builder.pointers = append(builder.pointers, &dictBuilderPointer{S: context.I})
newIndex := 0
for i, _ := range builder.pointers {
newPointer := builder.updatePointer(builder.pointers[i], context.Ch)
if newPointer != nil {
builder.pointers[newIndex] = newPointer
newIndex++
}
}
builder.pointers = builder.pointers[:newIndex]
var bestEdge *Edge
for _, pointer := range builder.pointers {
if pointer.IsFinal {
s := 1 + context.I - pointer.Offset
source := context.Path[s]
edge := &Edge{
S: s,
EdgeType: DICT,
WordCount: source.WordCount + 1,
UnkCount: source.UnkCount}
if !bestEdge.IsBetterThan(edge) {
bestEdge = edge
}
}
}
return bestEdge
} | go | func (builder *DictEdgeBuilder) Build(context *EdgeBuildingContext) *Edge {
builder.pointers = append(builder.pointers, &dictBuilderPointer{S: context.I})
newIndex := 0
for i, _ := range builder.pointers {
newPointer := builder.updatePointer(builder.pointers[i], context.Ch)
if newPointer != nil {
builder.pointers[newIndex] = newPointer
newIndex++
}
}
builder.pointers = builder.pointers[:newIndex]
var bestEdge *Edge
for _, pointer := range builder.pointers {
if pointer.IsFinal {
s := 1 + context.I - pointer.Offset
source := context.Path[s]
edge := &Edge{
S: s,
EdgeType: DICT,
WordCount: source.WordCount + 1,
UnkCount: source.UnkCount}
if !bestEdge.IsBetterThan(edge) {
bestEdge = edge
}
}
}
return bestEdge
} | [
"func",
"(",
"builder",
"*",
"DictEdgeBuilder",
")",
"Build",
"(",
"context",
"*",
"EdgeBuildingContext",
")",
"*",
"Edge",
"{",
"builder",
".",
"pointers",
"=",
"append",
"(",
"builder",
".",
"pointers",
",",
"&",
"dictBuilderPointer",
"{",
"S",
":",
"con... | // Build - build new edge from dictionary | [
"Build",
"-",
"build",
"new",
"edge",
"from",
"dictionary"
] | 4c22c721f2c6c6414a04849669688556d882f526 | https://github.com/veer66/mapkha/blob/4c22c721f2c6c6414a04849669688556d882f526/dict_edge_builder.go#L32-L63 |
153,750 | bearded-web/bearded | pkg/dispatcher/internal_agent.go | RunInternalAgent | func RunInternalAgent(ctx context.Context, app http.Handler, token string, cfg *config.Agent) <-chan error {
ts := httptest.NewServer(app)
api := client.NewClient(fmt.Sprintf("%s/api/", ts.URL), nil)
api.Token = token
if cfg.Name == "" {
cfg.Name = "internal"
}
return async.Promise(func() error {
return agent.ServeAgent(ctx, cfg, api)
})
} | go | func RunInternalAgent(ctx context.Context, app http.Handler, token string, cfg *config.Agent) <-chan error {
ts := httptest.NewServer(app)
api := client.NewClient(fmt.Sprintf("%s/api/", ts.URL), nil)
api.Token = token
if cfg.Name == "" {
cfg.Name = "internal"
}
return async.Promise(func() error {
return agent.ServeAgent(ctx, cfg, api)
})
} | [
"func",
"RunInternalAgent",
"(",
"ctx",
"context",
".",
"Context",
",",
"app",
"http",
".",
"Handler",
",",
"token",
"string",
",",
"cfg",
"*",
"config",
".",
"Agent",
")",
"<-",
"chan",
"error",
"{",
"ts",
":=",
"httptest",
".",
"NewServer",
"(",
"app... | // Run agent inside current process
// Start httptest local server | [
"Run",
"agent",
"inside",
"current",
"process",
"Start",
"httptest",
"local",
"server"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/pkg/dispatcher/internal_agent.go#L18-L28 |
153,751 | bearded-web/bearded | pkg/client/plugins.go | List | func (s *PluginsService) List(ctx context.Context, opt *PluginsListOpts) (*plugin.PluginList, error) {
pluginList := &plugin.PluginList{}
return pluginList, s.client.List(ctx, pluginsUrl, opt, pluginList)
} | go | func (s *PluginsService) List(ctx context.Context, opt *PluginsListOpts) (*plugin.PluginList, error) {
pluginList := &plugin.PluginList{}
return pluginList, s.client.List(ctx, pluginsUrl, opt, pluginList)
} | [
"func",
"(",
"s",
"*",
"PluginsService",
")",
"List",
"(",
"ctx",
"context",
".",
"Context",
",",
"opt",
"*",
"PluginsListOpts",
")",
"(",
"*",
"plugin",
".",
"PluginList",
",",
"error",
")",
"{",
"pluginList",
":=",
"&",
"plugin",
".",
"PluginList",
"... | // List plugins.
//
// | [
"List",
"plugins",
"."
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/pkg/client/plugins.go#L27-L30 |
153,752 | thecodeteam/gorackhd | client/obm/post_nodes_identifier_obm_parameters.go | WithIdentifier | func (o *PostNodesIdentifierObmParams) WithIdentifier(identifier string) *PostNodesIdentifierObmParams {
o.Identifier = identifier
return o
} | go | func (o *PostNodesIdentifierObmParams) WithIdentifier(identifier string) *PostNodesIdentifierObmParams {
o.Identifier = identifier
return o
} | [
"func",
"(",
"o",
"*",
"PostNodesIdentifierObmParams",
")",
"WithIdentifier",
"(",
"identifier",
"string",
")",
"*",
"PostNodesIdentifierObmParams",
"{",
"o",
".",
"Identifier",
"=",
"identifier",
"\n",
"return",
"o",
"\n",
"}"
] | // WithIdentifier adds the identifier to the post nodes identifier obm params | [
"WithIdentifier",
"adds",
"the",
"identifier",
"to",
"the",
"post",
"nodes",
"identifier",
"obm",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/obm/post_nodes_identifier_obm_parameters.go#L65-L68 |
153,753 | bearded-web/bearded | pkg/dispatcher/helpers.go | getAgentToken | func getAgentToken(mgr *manager.Manager) (string, error) {
u, err := mgr.Users.GetByEmail(manager.AgentEmail)
if err != nil {
return "", err
}
token, err := mgr.Tokens.GetOrCreate(u.Id)
if err != nil {
return "", err
}
return token.Hash, nil
} | go | func getAgentToken(mgr *manager.Manager) (string, error) {
u, err := mgr.Users.GetByEmail(manager.AgentEmail)
if err != nil {
return "", err
}
token, err := mgr.Tokens.GetOrCreate(u.Id)
if err != nil {
return "", err
}
return token.Hash, nil
} | [
"func",
"getAgentToken",
"(",
"mgr",
"*",
"manager",
".",
"Manager",
")",
"(",
"string",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"mgr",
".",
"Users",
".",
"GetByEmail",
"(",
"manager",
".",
"AgentEmail",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // Get or create token by default agent email. The token is used only by internal agent. | [
"Get",
"or",
"create",
"token",
"by",
"default",
"agent",
"email",
".",
"The",
"token",
"is",
"used",
"only",
"by",
"internal",
"agent",
"."
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/pkg/dispatcher/helpers.go#L6-L16 |
153,754 | thecodeteam/gorackhd | client/nodes/post_nodes_identifier_workflows_parameters.go | WithIdentifier | func (o *PostNodesIdentifierWorkflowsParams) WithIdentifier(identifier string) *PostNodesIdentifierWorkflowsParams {
o.Identifier = identifier
return o
} | go | func (o *PostNodesIdentifierWorkflowsParams) WithIdentifier(identifier string) *PostNodesIdentifierWorkflowsParams {
o.Identifier = identifier
return o
} | [
"func",
"(",
"o",
"*",
"PostNodesIdentifierWorkflowsParams",
")",
"WithIdentifier",
"(",
"identifier",
"string",
")",
"*",
"PostNodesIdentifierWorkflowsParams",
"{",
"o",
".",
"Identifier",
"=",
"identifier",
"\n",
"return",
"o",
"\n",
"}"
] | // WithIdentifier adds the identifier to the post nodes identifier workflows params | [
"WithIdentifier",
"adds",
"the",
"identifier",
"to",
"the",
"post",
"nodes",
"identifier",
"workflows",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/nodes/post_nodes_identifier_workflows_parameters.go#L66-L69 |
153,755 | thecodeteam/gorackhd | client/nodes/post_nodes_identifier_workflows_parameters.go | WithName | func (o *PostNodesIdentifierWorkflowsParams) WithName(name string) *PostNodesIdentifierWorkflowsParams {
o.Name = name
return o
} | go | func (o *PostNodesIdentifierWorkflowsParams) WithName(name string) *PostNodesIdentifierWorkflowsParams {
o.Name = name
return o
} | [
"func",
"(",
"o",
"*",
"PostNodesIdentifierWorkflowsParams",
")",
"WithName",
"(",
"name",
"string",
")",
"*",
"PostNodesIdentifierWorkflowsParams",
"{",
"o",
".",
"Name",
"=",
"name",
"\n",
"return",
"o",
"\n",
"}"
] | // WithName adds the name to the post nodes identifier workflows params | [
"WithName",
"adds",
"the",
"name",
"to",
"the",
"post",
"nodes",
"identifier",
"workflows",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/nodes/post_nodes_identifier_workflows_parameters.go#L72-L75 |
153,756 | bearded-web/bearded | models/scan/scan.go | GetAllChildren | func (p *Session) GetAllChildren() []*Session {
result := []*Session{}
result = append(result, p.Children...)
for _, child := range p.Children {
result = append(result, child.GetAllChildren()...)
}
return result
} | go | func (p *Session) GetAllChildren() []*Session {
result := []*Session{}
result = append(result, p.Children...)
for _, child := range p.Children {
result = append(result, child.GetAllChildren()...)
}
return result
} | [
"func",
"(",
"p",
"*",
"Session",
")",
"GetAllChildren",
"(",
")",
"[",
"]",
"*",
"Session",
"{",
"result",
":=",
"[",
"]",
"*",
"Session",
"{",
"}",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"p",
".",
"Children",
"...",
")",
"\n",
"for"... | // get all children from this session and all children recursively | [
"get",
"all",
"children",
"from",
"this",
"session",
"and",
"all",
"children",
"recursively"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/models/scan/scan.go#L52-L59 |
153,757 | bearded-web/bearded | models/scan/scan.go | GetAllSessions | func (p *Scan) GetAllSessions() []*Session {
result := []*Session{}
result = append(result, p.Sessions...)
for _, child := range p.Sessions {
result = append(result, child.GetAllChildren()...)
}
return result
} | go | func (p *Scan) GetAllSessions() []*Session {
result := []*Session{}
result = append(result, p.Sessions...)
for _, child := range p.Sessions {
result = append(result, child.GetAllChildren()...)
}
return result
} | [
"func",
"(",
"p",
"*",
"Scan",
")",
"GetAllSessions",
"(",
")",
"[",
"]",
"*",
"Session",
"{",
"result",
":=",
"[",
"]",
"*",
"Session",
"{",
"}",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"p",
".",
"Sessions",
"...",
")",
"\n",
"for",
... | // get all session from this session and all children recursively | [
"get",
"all",
"session",
"from",
"this",
"session",
"and",
"all",
"children",
"recursively"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/models/scan/scan.go#L112-L119 |
153,758 | thecodeteam/gorackhd | models/node.go | Validate | func (m *Node) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCatalogs(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateName(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateWorkflows(formats); err != nil {
// prop
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | go | func (m *Node) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCatalogs(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateName(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateWorkflows(formats); err != nil {
// prop
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | [
"func",
"(",
"m",
"*",
"Node",
")",
"Validate",
"(",
"formats",
"strfmt",
".",
"Registry",
")",
"error",
"{",
"var",
"res",
"[",
"]",
"error",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validateCatalogs",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
"{... | // Validate validates this node | [
"Validate",
"validates",
"this",
"node"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/models/node.go#L76-L98 |
153,759 | bearded-web/bearded | models/report/report.go | SetScan | func (r *Report) SetScan(scanId bson.ObjectId) {
r.Scan = scanId
if r.Type == TypeMulti {
for _, rep := range r.Multi {
rep.SetScan(scanId)
}
}
} | go | func (r *Report) SetScan(scanId bson.ObjectId) {
r.Scan = scanId
if r.Type == TypeMulti {
for _, rep := range r.Multi {
rep.SetScan(scanId)
}
}
} | [
"func",
"(",
"r",
"*",
"Report",
")",
"SetScan",
"(",
"scanId",
"bson",
".",
"ObjectId",
")",
"{",
"r",
".",
"Scan",
"=",
"scanId",
"\n",
"if",
"r",
".",
"Type",
"==",
"TypeMulti",
"{",
"for",
"_",
",",
"rep",
":=",
"range",
"r",
".",
"Multi",
... | // set scan to report and all underlying multi reports if they are existed | [
"set",
"scan",
"to",
"report",
"and",
"all",
"underlying",
"multi",
"reports",
"if",
"they",
"are",
"existed"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/models/report/report.go#L40-L47 |
153,760 | bearded-web/bearded | models/report/report.go | GetAllIssues | func (r *Report) GetAllIssues() []*issue.Issue {
var issues []*issue.Issue
switch r.Type {
case TypeMulti:
for _, subReport := range r.Multi {
issues = append(issues, subReport.GetAllIssues()...)
}
case TypeIssues:
issues = append(issues, r.Issues...)
}
return issues
} | go | func (r *Report) GetAllIssues() []*issue.Issue {
var issues []*issue.Issue
switch r.Type {
case TypeMulti:
for _, subReport := range r.Multi {
issues = append(issues, subReport.GetAllIssues()...)
}
case TypeIssues:
issues = append(issues, r.Issues...)
}
return issues
} | [
"func",
"(",
"r",
"*",
"Report",
")",
"GetAllIssues",
"(",
")",
"[",
"]",
"*",
"issue",
".",
"Issue",
"{",
"var",
"issues",
"[",
"]",
"*",
"issue",
".",
"Issue",
"\n",
"switch",
"r",
".",
"Type",
"{",
"case",
"TypeMulti",
":",
"for",
"_",
",",
... | // get all issues from the report and underlying multi reports | [
"get",
"all",
"issues",
"from",
"the",
"report",
"and",
"underlying",
"multi",
"reports"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/models/report/report.go#L59-L70 |
153,761 | bearded-web/bearded | models/report/report.go | GetAllTechs | func (r *Report) GetAllTechs() []*tech.Tech {
var techs []*tech.Tech
switch r.Type {
case TypeMulti:
for _, subReport := range r.Multi {
techs = append(techs, subReport.GetAllTechs()...)
}
case TypeTechs:
techs = append(techs, r.Techs...)
}
return techs
} | go | func (r *Report) GetAllTechs() []*tech.Tech {
var techs []*tech.Tech
switch r.Type {
case TypeMulti:
for _, subReport := range r.Multi {
techs = append(techs, subReport.GetAllTechs()...)
}
case TypeTechs:
techs = append(techs, r.Techs...)
}
return techs
} | [
"func",
"(",
"r",
"*",
"Report",
")",
"GetAllTechs",
"(",
")",
"[",
"]",
"*",
"tech",
".",
"Tech",
"{",
"var",
"techs",
"[",
"]",
"*",
"tech",
".",
"Tech",
"\n",
"switch",
"r",
".",
"Type",
"{",
"case",
"TypeMulti",
":",
"for",
"_",
",",
"subRe... | // get all techs from the report and underlying multi reports | [
"get",
"all",
"techs",
"from",
"the",
"report",
"and",
"underlying",
"multi",
"reports"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/models/report/report.go#L73-L84 |
153,762 | bearded-web/bearded | pkg/client/agents.go | List | func (s *AgentsService) List(ctx context.Context, opt *AgentsListOpts) (*agent.AgentList, error) {
agentList := &agent.AgentList{}
return agentList, s.client.List(ctx, agentsUrl, opt, agentList)
} | go | func (s *AgentsService) List(ctx context.Context, opt *AgentsListOpts) (*agent.AgentList, error) {
agentList := &agent.AgentList{}
return agentList, s.client.List(ctx, agentsUrl, opt, agentList)
} | [
"func",
"(",
"s",
"*",
"AgentsService",
")",
"List",
"(",
"ctx",
"context",
".",
"Context",
",",
"opt",
"*",
"AgentsListOpts",
")",
"(",
"*",
"agent",
".",
"AgentList",
",",
"error",
")",
"{",
"agentList",
":=",
"&",
"agent",
".",
"AgentList",
"{",
"... | // List agents.
//
// | [
"List",
"agents",
"."
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/pkg/client/agents.go#L31-L34 |
153,763 | bearded-web/bearded | pkg/utils/async/async.go | Any | func Any(asyncs ...Async) Async {
return &asyncImpl{
cancel: func() {
for _, a := range asyncs {
a.Cancel()
}
},
promise: Promise(func() error {
// TODO (m0sth8): rewrite this with select for every async
for _, a := range asyncs {
err := <-a.Result()
if err != nil {
return err
}
}
return nil
}),
}
} | go | func Any(asyncs ...Async) Async {
return &asyncImpl{
cancel: func() {
for _, a := range asyncs {
a.Cancel()
}
},
promise: Promise(func() error {
// TODO (m0sth8): rewrite this with select for every async
for _, a := range asyncs {
err := <-a.Result()
if err != nil {
return err
}
}
return nil
}),
}
} | [
"func",
"Any",
"(",
"asyncs",
"...",
"Async",
")",
"Async",
"{",
"return",
"&",
"asyncImpl",
"{",
"cancel",
":",
"func",
"(",
")",
"{",
"for",
"_",
",",
"a",
":=",
"range",
"asyncs",
"{",
"a",
".",
"Cancel",
"(",
")",
"\n",
"}",
"\n",
"}",
",",... | // group asyncs and return err in Result for the first async with error | [
"group",
"asyncs",
"and",
"return",
"err",
"in",
"Result",
"for",
"the",
"first",
"async",
"with",
"error"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/pkg/utils/async/async.go#L50-L68 |
153,764 | bearded-web/bearded | pkg/utils/async/async.go | All | func All(asyncs ...Async) Async {
return &asyncImpl{
cancel: func() {
for _, a := range asyncs {
a.Cancel()
}
},
promise: Promise(func() error {
errs := make([]error, 0)
for _, a := range asyncs {
err := <-a.Result()
if err != nil {
errs = append(errs, err)
}
}
if len(errs) > 0 {
return &GroupError{Errs: errs}
}
return nil
}),
}
} | go | func All(asyncs ...Async) Async {
return &asyncImpl{
cancel: func() {
for _, a := range asyncs {
a.Cancel()
}
},
promise: Promise(func() error {
errs := make([]error, 0)
for _, a := range asyncs {
err := <-a.Result()
if err != nil {
errs = append(errs, err)
}
}
if len(errs) > 0 {
return &GroupError{Errs: errs}
}
return nil
}),
}
} | [
"func",
"All",
"(",
"asyncs",
"...",
"Async",
")",
"Async",
"{",
"return",
"&",
"asyncImpl",
"{",
"cancel",
":",
"func",
"(",
")",
"{",
"for",
"_",
",",
"a",
":=",
"range",
"asyncs",
"{",
"a",
".",
"Cancel",
"(",
")",
"\n",
"}",
"\n",
"}",
",",... | // group asyncs and return grouped err after all async is finished | [
"group",
"asyncs",
"and",
"return",
"grouped",
"err",
"after",
"all",
"async",
"is",
"finished"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/pkg/utils/async/async.go#L71-L92 |
153,765 | thecodeteam/gorackhd | client/get/get_catalogs_parameters.go | WithQuery | func (o *GetCatalogsParams) WithQuery(query *string) *GetCatalogsParams {
o.Query = query
return o
} | go | func (o *GetCatalogsParams) WithQuery(query *string) *GetCatalogsParams {
o.Query = query
return o
} | [
"func",
"(",
"o",
"*",
"GetCatalogsParams",
")",
"WithQuery",
"(",
"query",
"*",
"string",
")",
"*",
"GetCatalogsParams",
"{",
"o",
".",
"Query",
"=",
"query",
"\n",
"return",
"o",
"\n",
"}"
] | // WithQuery adds the query to the get catalogs params | [
"WithQuery",
"adds",
"the",
"query",
"to",
"the",
"get",
"catalogs",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/get/get_catalogs_parameters.go#L51-L54 |
153,766 | thecodeteam/gorackhd | client/get/get_pollers_library_identifier_parameters.go | WithIdentifier | func (o *GetPollersLibraryIdentifierParams) WithIdentifier(identifier string) *GetPollersLibraryIdentifierParams {
o.Identifier = identifier
return o
} | go | func (o *GetPollersLibraryIdentifierParams) WithIdentifier(identifier string) *GetPollersLibraryIdentifierParams {
o.Identifier = identifier
return o
} | [
"func",
"(",
"o",
"*",
"GetPollersLibraryIdentifierParams",
")",
"WithIdentifier",
"(",
"identifier",
"string",
")",
"*",
"GetPollersLibraryIdentifierParams",
"{",
"o",
".",
"Identifier",
"=",
"identifier",
"\n",
"return",
"o",
"\n",
"}"
] | // WithIdentifier adds the identifier to the get pollers library identifier params | [
"WithIdentifier",
"adds",
"the",
"identifier",
"to",
"the",
"get",
"pollers",
"library",
"identifier",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/get/get_pollers_library_identifier_parameters.go#L52-L55 |
153,767 | thecodeteam/gorackhd | client/obm/get_nodes_identifier_obm_parameters.go | WithIdentifier | func (o *GetNodesIdentifierObmParams) WithIdentifier(identifier string) *GetNodesIdentifierObmParams {
o.Identifier = identifier
return o
} | go | func (o *GetNodesIdentifierObmParams) WithIdentifier(identifier string) *GetNodesIdentifierObmParams {
o.Identifier = identifier
return o
} | [
"func",
"(",
"o",
"*",
"GetNodesIdentifierObmParams",
")",
"WithIdentifier",
"(",
"identifier",
"string",
")",
"*",
"GetNodesIdentifierObmParams",
"{",
"o",
".",
"Identifier",
"=",
"identifier",
"\n",
"return",
"o",
"\n",
"}"
] | // WithIdentifier adds the identifier to the get nodes identifier obm params | [
"WithIdentifier",
"adds",
"the",
"identifier",
"to",
"the",
"get",
"nodes",
"identifier",
"obm",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/obm/get_nodes_identifier_obm_parameters.go#L53-L56 |
153,768 | thecodeteam/gorackhd | client/files/delete_files_fileidentifier_parameters.go | WithFileidentifier | func (o *DeleteFilesFileidentifierParams) WithFileidentifier(fileidentifier string) *DeleteFilesFileidentifierParams {
o.Fileidentifier = fileidentifier
return o
} | go | func (o *DeleteFilesFileidentifierParams) WithFileidentifier(fileidentifier string) *DeleteFilesFileidentifierParams {
o.Fileidentifier = fileidentifier
return o
} | [
"func",
"(",
"o",
"*",
"DeleteFilesFileidentifierParams",
")",
"WithFileidentifier",
"(",
"fileidentifier",
"string",
")",
"*",
"DeleteFilesFileidentifierParams",
"{",
"o",
".",
"Fileidentifier",
"=",
"fileidentifier",
"\n",
"return",
"o",
"\n",
"}"
] | // WithFileidentifier adds the fileidentifier to the delete files fileidentifier params | [
"WithFileidentifier",
"adds",
"the",
"fileidentifier",
"to",
"the",
"delete",
"files",
"fileidentifier",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/files/delete_files_fileidentifier_parameters.go#L51-L54 |
153,769 | bearded-web/bearded | pkg/passlib/reset/reset.go | newTokenSinceNow | func newTokenSinceNow(user string, dur time.Duration, secret []byte) string {
return newToken(user, time.Now().Add(dur), secret)
} | go | func newTokenSinceNow(user string, dur time.Duration, secret []byte) string {
return newToken(user, time.Now().Add(dur), secret)
} | [
"func",
"newTokenSinceNow",
"(",
"user",
"string",
",",
"dur",
"time",
".",
"Duration",
",",
"secret",
"[",
"]",
"byte",
")",
"string",
"{",
"return",
"newToken",
"(",
"user",
",",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"dur",
")",
",",
"se... | // NewSinceNow returns a signed authentication token for the given login,
// duration since current time, and secret key. | [
"NewSinceNow",
"returns",
"a",
"signed",
"authentication",
"token",
"for",
"the",
"given",
"login",
"duration",
"since",
"current",
"time",
"and",
"secret",
"key",
"."
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/pkg/passlib/reset/reset.go#L87-L89 |
153,770 | bearded-web/bearded | pkg/agent/server.go | NewRemoteServer | func NewRemoteServer(transp transport.Transport, api *client.Client, sess *scan.Session) (*RemoteServer, error) {
server := &RemoteServer{
transp: transp,
sess: sess,
api: api,
}
return server, nil
} | go | func NewRemoteServer(transp transport.Transport, api *client.Client, sess *scan.Session) (*RemoteServer, error) {
server := &RemoteServer{
transp: transp,
sess: sess,
api: api,
}
return server, nil
} | [
"func",
"NewRemoteServer",
"(",
"transp",
"transport",
".",
"Transport",
",",
"api",
"*",
"client",
".",
"Client",
",",
"sess",
"*",
"scan",
".",
"Session",
")",
"(",
"*",
"RemoteServer",
",",
"error",
")",
"{",
"server",
":=",
"&",
"RemoteServer",
"{",
... | // Server connects agent with plugin script | [
"Server",
"connects",
"agent",
"with",
"plugin",
"script"
] | c937b9e05d299400e95143a433836214a6ffa649 | https://github.com/bearded-web/bearded/blob/c937b9e05d299400e95143a433836214a6ffa649/pkg/agent/server.go#L27-L34 |
153,771 | thecodeteam/gorackhd | client/profiles/delete_skus_identifier_parameters.go | WithIdentifier | func (o *DeleteSkusIdentifierParams) WithIdentifier(identifier string) *DeleteSkusIdentifierParams {
o.Identifier = identifier
return o
} | go | func (o *DeleteSkusIdentifierParams) WithIdentifier(identifier string) *DeleteSkusIdentifierParams {
o.Identifier = identifier
return o
} | [
"func",
"(",
"o",
"*",
"DeleteSkusIdentifierParams",
")",
"WithIdentifier",
"(",
"identifier",
"string",
")",
"*",
"DeleteSkusIdentifierParams",
"{",
"o",
".",
"Identifier",
"=",
"identifier",
"\n",
"return",
"o",
"\n",
"}"
] | // WithIdentifier adds the identifier to the delete skus identifier params | [
"WithIdentifier",
"adds",
"the",
"identifier",
"to",
"the",
"delete",
"skus",
"identifier",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/profiles/delete_skus_identifier_parameters.go#L52-L55 |
153,772 | thecodeteam/gorackhd | models/graphobject.go | Validate | func (m *Graphobject) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateNode(formats); err != nil {
// prop
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | go | func (m *Graphobject) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateNode(formats); err != nil {
// prop
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | [
"func",
"(",
"m",
"*",
"Graphobject",
")",
"Validate",
"(",
"formats",
"strfmt",
".",
"Registry",
")",
"error",
"{",
"var",
"res",
"[",
"]",
"error",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validateNode",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
... | // Validate validates this graphobject | [
"Validate",
"validates",
"this",
"graphobject"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/models/graphobject.go#L49-L61 |
153,773 | thecodeteam/gorackhd | client/lookups/patch_lookups_id_parameters.go | WithID | func (o *PatchLookupsIDParams) WithID(id string) *PatchLookupsIDParams {
o.ID = id
return o
} | go | func (o *PatchLookupsIDParams) WithID(id string) *PatchLookupsIDParams {
o.ID = id
return o
} | [
"func",
"(",
"o",
"*",
"PatchLookupsIDParams",
")",
"WithID",
"(",
"id",
"string",
")",
"*",
"PatchLookupsIDParams",
"{",
"o",
".",
"ID",
"=",
"id",
"\n",
"return",
"o",
"\n",
"}"
] | // WithID adds the id to the patch lookups ID params | [
"WithID",
"adds",
"the",
"id",
"to",
"the",
"patch",
"lookups",
"ID",
"params"
] | 66bd88ab29593b880ba59b35db2c17a4b4bab1f1 | https://github.com/thecodeteam/gorackhd/blob/66bd88ab29593b880ba59b35db2c17a4b4bab1f1/client/lookups/patch_lookups_id_parameters.go#L63-L66 |
153,774 | ghetzel/diecast | actions.go | RegisterActionStep | func RegisterActionStep(typeName string, performable Performable) {
if performable != nil {
steps[typeName] = performable
} else {
panic("cannot register nil step for type " + typeName)
}
} | go | func RegisterActionStep(typeName string, performable Performable) {
if performable != nil {
steps[typeName] = performable
} else {
panic("cannot register nil step for type " + typeName)
}
} | [
"func",
"RegisterActionStep",
"(",
"typeName",
"string",
",",
"performable",
"Performable",
")",
"{",
"if",
"performable",
"!=",
"nil",
"{",
"steps",
"[",
"typeName",
"]",
"=",
"performable",
"\n",
"}",
"else",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"typeName... | // Register a performable step type to the given type name. | [
"Register",
"a",
"performable",
"step",
"type",
"to",
"the",
"given",
"type",
"name",
"."
] | 3cf4315555ad6d1e50e51ddf7778eedb91da56ca | https://github.com/ghetzel/diecast/blob/3cf4315555ad6d1e50e51ddf7778eedb91da56ca/actions.go#L26-L32 |
153,775 | ghetzel/diecast | actions.go | ServeHTTP | func (self *Action) ServeHTTP(w http.ResponseWriter, req *http.Request) {
started := time.Now()
name := self.Name
if name == `` {
name = fmt.Sprintf("%s %s", req.Method, req.URL.Path)
}
prev := &StepConfig{
Type: `input`,
Output: req.Body,
index: -1,
}
log.Debugf("\u256d Run action %s", name)
for i, step := range self.Steps {
step.index = i
step.logstep("\u2502 step %d: type=%v data=%T", i, step.Type, step.Data)
out, err := step.Perform(step, w, req, prev)
prev = step
prev.Output = out
prev.Error = err
prev.postprocess()
step.logstep("output=%T err=%v", prev.Output, prev.Error)
if prev.Error != nil && prev.Error.Error() == `stop` {
step.logstep("break early", i)
return
}
}
if prev != nil {
if err := prev.Error; err != nil {
httputil.RespondJSON(w, err)
} else {
httputil.RespondJSON(w, prev.Output)
}
} else {
w.WriteHeader(http.StatusNoContent)
}
log.Debugf("\u2570 response sent (took: %v)", time.Since(started))
} | go | func (self *Action) ServeHTTP(w http.ResponseWriter, req *http.Request) {
started := time.Now()
name := self.Name
if name == `` {
name = fmt.Sprintf("%s %s", req.Method, req.URL.Path)
}
prev := &StepConfig{
Type: `input`,
Output: req.Body,
index: -1,
}
log.Debugf("\u256d Run action %s", name)
for i, step := range self.Steps {
step.index = i
step.logstep("\u2502 step %d: type=%v data=%T", i, step.Type, step.Data)
out, err := step.Perform(step, w, req, prev)
prev = step
prev.Output = out
prev.Error = err
prev.postprocess()
step.logstep("output=%T err=%v", prev.Output, prev.Error)
if prev.Error != nil && prev.Error.Error() == `stop` {
step.logstep("break early", i)
return
}
}
if prev != nil {
if err := prev.Error; err != nil {
httputil.RespondJSON(w, err)
} else {
httputil.RespondJSON(w, prev.Output)
}
} else {
w.WriteHeader(http.StatusNoContent)
}
log.Debugf("\u2570 response sent (took: %v)", time.Since(started))
} | [
"func",
"(",
"self",
"*",
"Action",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"started",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"name",
":=",
"self",
".",
"Name",
"\n\n",
"if",
... | // Performs the action in response to an HTTP request, evaluating all action steps. Steps are
// responsible for generating and manipulating output. The output of the last step will be returned,
// or an error will be returned if not nil. | [
"Performs",
"the",
"action",
"in",
"response",
"to",
"an",
"HTTP",
"request",
"evaluating",
"all",
"action",
"steps",
".",
"Steps",
"are",
"responsible",
"for",
"generating",
"and",
"manipulating",
"output",
".",
"The",
"output",
"of",
"the",
"last",
"step",
... | 3cf4315555ad6d1e50e51ddf7778eedb91da56ca | https://github.com/ghetzel/diecast/blob/3cf4315555ad6d1e50e51ddf7778eedb91da56ca/actions.go#L154-L199 |
153,776 | caarlos0-graveyard/alelogo | alelo.go | New | func New(cpf, pwd string, configs ...Config) (*Client, error) {
var config = DefaultConfig
if len(configs) > 0 {
config = configs[0]
}
jar, err := cookiejar.New(nil)
if err != nil {
return nil, err
}
client := &Client{
http.Client{
Timeout: time.Duration(config.Timeout) * time.Second,
Jar: jar,
}, config.BaseURL,
}
return client, client.login(cpf, pwd)
} | go | func New(cpf, pwd string, configs ...Config) (*Client, error) {
var config = DefaultConfig
if len(configs) > 0 {
config = configs[0]
}
jar, err := cookiejar.New(nil)
if err != nil {
return nil, err
}
client := &Client{
http.Client{
Timeout: time.Duration(config.Timeout) * time.Second,
Jar: jar,
}, config.BaseURL,
}
return client, client.login(cpf, pwd)
} | [
"func",
"New",
"(",
"cpf",
",",
"pwd",
"string",
",",
"configs",
"...",
"Config",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"var",
"config",
"=",
"DefaultConfig",
"\n",
"if",
"len",
"(",
"configs",
")",
">",
"0",
"{",
"config",
"=",
"configs... | // New client with defaults | [
"New",
"client",
"with",
"defaults"
] | 30ca52ddb1f49256928793cf2e7240605f090426 | https://github.com/caarlos0-graveyard/alelogo/blob/30ca52ddb1f49256928793cf2e7240605f090426/alelo.go#L38-L54 |
153,777 | caarlos0-graveyard/alelogo | alelo.go | Cards | func (client *Client) Cards() (cards []Card, err error) {
req, err := http.NewRequest(
"GET",
client.BaseURL+"/user/card/preference/list",
nil,
)
if err != nil {
return cards, err
}
resp, err := client.Do(req)
if err != nil {
return cards, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
// this should never happen
return cards, ErrDumbass
}
var preferences preferencesJSON
err = json.NewDecoder(resp.Body).Decode(&preferences)
return preferences.List, err
} | go | func (client *Client) Cards() (cards []Card, err error) {
req, err := http.NewRequest(
"GET",
client.BaseURL+"/user/card/preference/list",
nil,
)
if err != nil {
return cards, err
}
resp, err := client.Do(req)
if err != nil {
return cards, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
// this should never happen
return cards, ErrDumbass
}
var preferences preferencesJSON
err = json.NewDecoder(resp.Body).Decode(&preferences)
return preferences.List, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"Cards",
"(",
")",
"(",
"cards",
"[",
"]",
"Card",
",",
"err",
"error",
")",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"client",
".",
"BaseURL",
"+",
"\"",
"\"",
",... | // Cards get the user card's balances | [
"Cards",
"get",
"the",
"user",
"card",
"s",
"balances"
] | 30ca52ddb1f49256928793cf2e7240605f090426 | https://github.com/caarlos0-graveyard/alelogo/blob/30ca52ddb1f49256928793cf2e7240605f090426/alelo.go#L82-L103 |
153,778 | caarlos0-graveyard/alelogo | alelo.go | Details | func (client *Client) Details(card Card) (CardDetails, error) {
var details CardDetails
req, err := http.NewRequest(
"GET",
client.BaseURL+"/user/card/balance?selectedCardNumberId="+card.ID,
nil,
)
if err != nil {
return details, err
}
resp, err := client.Do(req)
if err != nil {
return details, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
// this should never happen
return details, ErrDumbass
}
err = json.NewDecoder(resp.Body).Decode(&details)
return details, err
} | go | func (client *Client) Details(card Card) (CardDetails, error) {
var details CardDetails
req, err := http.NewRequest(
"GET",
client.BaseURL+"/user/card/balance?selectedCardNumberId="+card.ID,
nil,
)
if err != nil {
return details, err
}
resp, err := client.Do(req)
if err != nil {
return details, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
// this should never happen
return details, ErrDumbass
}
err = json.NewDecoder(resp.Body).Decode(&details)
return details, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"Details",
"(",
"card",
"Card",
")",
"(",
"CardDetails",
",",
"error",
")",
"{",
"var",
"details",
"CardDetails",
"\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"client",
"."... | // Details of a card, including balance | [
"Details",
"of",
"a",
"card",
"including",
"balance"
] | 30ca52ddb1f49256928793cf2e7240605f090426 | https://github.com/caarlos0-graveyard/alelogo/blob/30ca52ddb1f49256928793cf2e7240605f090426/alelo.go#L106-L127 |
153,779 | brankas/envcfg | envcfg.go | New | func New(opts ...Option) (*Envcfg, error) {
var err error
// default values
ec := &Envcfg{
envVarName: DefaultVarName,
configFile: DefaultConfigFile,
envKey: DefaultEnvKey,
hostKey: DefaultHostKey,
portKey: DefaultPortKey,
certPathKey: DefaultCertPathKey,
certProviderKey: DefaultCertProviderKey,
certWaitKey: DefaultCertWaitKey,
certDelayKey: DefaultCertDelayKey,
filters: make(map[string]Filter),
}
// apply options
for _, o := range opts {
o(ec)
}
// load environment data from $ENV{$envVarName} or from file $configFile
if envdata := os.Getenv(ec.envVarName); envdata != "" {
// if the data is supplied in $ENV{$envVarName}, then base64 decode the data
var data []byte
data, err = base64.StdEncoding.DecodeString(envdata)
if err == nil {
ec.config, err = ini.Load(bytes.NewReader(data))
}
} else {
ec.configFile, err = realpath.Realpath(ec.configFile)
if err == nil {
ec.config, err = ini.LoadFile(ec.configFile)
}
}
// ensure no err
if err != nil {
return nil, err
}
// ensure log funcs always are set
if ec.logf == nil {
ec.logf = func(string, ...interface{}) {}
}
if ec.errf == nil {
ec.errf = func(s string, v ...interface{}) {
ec.logf("ERROR: "+s, v...)
}
}
// set git style config
ec.config.SectionNameFunc = ini.GitSectionNameFunc
ec.config.SectionManipFunc = ini.GitSectionManipFunc
ec.config.ValueManipFunc = func(val string) string {
val = strings.TrimSpace(val)
if str, err := strconv.Unquote(val); err == nil {
val = str
}
return val
}
return ec, nil
} | go | func New(opts ...Option) (*Envcfg, error) {
var err error
// default values
ec := &Envcfg{
envVarName: DefaultVarName,
configFile: DefaultConfigFile,
envKey: DefaultEnvKey,
hostKey: DefaultHostKey,
portKey: DefaultPortKey,
certPathKey: DefaultCertPathKey,
certProviderKey: DefaultCertProviderKey,
certWaitKey: DefaultCertWaitKey,
certDelayKey: DefaultCertDelayKey,
filters: make(map[string]Filter),
}
// apply options
for _, o := range opts {
o(ec)
}
// load environment data from $ENV{$envVarName} or from file $configFile
if envdata := os.Getenv(ec.envVarName); envdata != "" {
// if the data is supplied in $ENV{$envVarName}, then base64 decode the data
var data []byte
data, err = base64.StdEncoding.DecodeString(envdata)
if err == nil {
ec.config, err = ini.Load(bytes.NewReader(data))
}
} else {
ec.configFile, err = realpath.Realpath(ec.configFile)
if err == nil {
ec.config, err = ini.LoadFile(ec.configFile)
}
}
// ensure no err
if err != nil {
return nil, err
}
// ensure log funcs always are set
if ec.logf == nil {
ec.logf = func(string, ...interface{}) {}
}
if ec.errf == nil {
ec.errf = func(s string, v ...interface{}) {
ec.logf("ERROR: "+s, v...)
}
}
// set git style config
ec.config.SectionNameFunc = ini.GitSectionNameFunc
ec.config.SectionManipFunc = ini.GitSectionManipFunc
ec.config.ValueManipFunc = func(val string) string {
val = strings.TrimSpace(val)
if str, err := strconv.Unquote(val); err == nil {
val = str
}
return val
}
return ec, nil
} | [
"func",
"New",
"(",
"opts",
"...",
"Option",
")",
"(",
"*",
"Envcfg",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// default values",
"ec",
":=",
"&",
"Envcfg",
"{",
"envVarName",
":",
"DefaultVarName",
",",
"configFile",
":",
"DefaultConfigFil... | // New creates a new environment configuration loader. | [
"New",
"creates",
"a",
"new",
"environment",
"configuration",
"loader",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L110-L175 |
153,780 | brankas/envcfg | envcfg.go | GetBool | func (ec *Envcfg) GetBool(key string) bool {
b, _ := strconv.ParseBool(ec.GetKey(key))
return b
} | go | func (ec *Envcfg) GetBool(key string) bool {
b, _ := strconv.ParseBool(ec.GetKey(key))
return b
} | [
"func",
"(",
"ec",
"*",
"Envcfg",
")",
"GetBool",
"(",
"key",
"string",
")",
"bool",
"{",
"b",
",",
"_",
":=",
"strconv",
".",
"ParseBool",
"(",
"ec",
".",
"GetKey",
"(",
"key",
")",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // GetBool retrieves the value for key from the environment, or the supplied
// configuration data, returning it as a bool. | [
"GetBool",
"retrieves",
"the",
"value",
"for",
"key",
"from",
"the",
"environment",
"or",
"the",
"supplied",
"configuration",
"data",
"returning",
"it",
"as",
"a",
"bool",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L249-L252 |
153,781 | brankas/envcfg | envcfg.go | GetFloat | func (ec *Envcfg) GetFloat(key string, bitSize int) float64 {
f, _ := strconv.ParseFloat(ec.GetKey(key), bitSize)
return f
} | go | func (ec *Envcfg) GetFloat(key string, bitSize int) float64 {
f, _ := strconv.ParseFloat(ec.GetKey(key), bitSize)
return f
} | [
"func",
"(",
"ec",
"*",
"Envcfg",
")",
"GetFloat",
"(",
"key",
"string",
",",
"bitSize",
"int",
")",
"float64",
"{",
"f",
",",
"_",
":=",
"strconv",
".",
"ParseFloat",
"(",
"ec",
".",
"GetKey",
"(",
"key",
")",
",",
"bitSize",
")",
"\n",
"return",
... | // GetFloat retrieves the value for key from the environment, or the supplied
// configuration data, returning it as a float64. Uses bitSize as the
// precision. | [
"GetFloat",
"retrieves",
"the",
"value",
"for",
"key",
"from",
"the",
"environment",
"or",
"the",
"supplied",
"configuration",
"data",
"returning",
"it",
"as",
"a",
"float64",
".",
"Uses",
"bitSize",
"as",
"the",
"precision",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L257-L260 |
153,782 | brankas/envcfg | envcfg.go | GetInt64 | func (ec *Envcfg) GetInt64(key string, base, bitSize int) int64 {
i, _ := strconv.ParseInt(ec.GetKey(key), base, bitSize)
return i
} | go | func (ec *Envcfg) GetInt64(key string, base, bitSize int) int64 {
i, _ := strconv.ParseInt(ec.GetKey(key), base, bitSize)
return i
} | [
"func",
"(",
"ec",
"*",
"Envcfg",
")",
"GetInt64",
"(",
"key",
"string",
",",
"base",
",",
"bitSize",
"int",
")",
"int64",
"{",
"i",
",",
"_",
":=",
"strconv",
".",
"ParseInt",
"(",
"ec",
".",
"GetKey",
"(",
"key",
")",
",",
"base",
",",
"bitSize... | // GetInt64 retrieves the value for key from the environment, or the supplied
// configuration data, returning it as a int64. Uses base and bitSize to parse. | [
"GetInt64",
"retrieves",
"the",
"value",
"for",
"key",
"from",
"the",
"environment",
"or",
"the",
"supplied",
"configuration",
"data",
"returning",
"it",
"as",
"a",
"int64",
".",
"Uses",
"base",
"and",
"bitSize",
"to",
"parse",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L264-L267 |
153,783 | brankas/envcfg | envcfg.go | GetUint64 | func (ec *Envcfg) GetUint64(key string, base, bitSize int) uint64 {
u, _ := strconv.ParseUint(ec.GetKey(key), base, bitSize)
return u
} | go | func (ec *Envcfg) GetUint64(key string, base, bitSize int) uint64 {
u, _ := strconv.ParseUint(ec.GetKey(key), base, bitSize)
return u
} | [
"func",
"(",
"ec",
"*",
"Envcfg",
")",
"GetUint64",
"(",
"key",
"string",
",",
"base",
",",
"bitSize",
"int",
")",
"uint64",
"{",
"u",
",",
"_",
":=",
"strconv",
".",
"ParseUint",
"(",
"ec",
".",
"GetKey",
"(",
"key",
")",
",",
"base",
",",
"bitS... | // GetUint64 retrieves the value for key from the environment, or the supplied
// configuration data, returning it as a uint64. Uses base and bitSize to
// parse. | [
"GetUint64",
"retrieves",
"the",
"value",
"for",
"key",
"from",
"the",
"environment",
"or",
"the",
"supplied",
"configuration",
"data",
"returning",
"it",
"as",
"a",
"uint64",
".",
"Uses",
"base",
"and",
"bitSize",
"to",
"parse",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L272-L275 |
153,784 | brankas/envcfg | envcfg.go | GetInt | func (ec *Envcfg) GetInt(key string) int {
i, _ := strconv.Atoi(ec.GetKey(key))
return i
} | go | func (ec *Envcfg) GetInt(key string) int {
i, _ := strconv.Atoi(ec.GetKey(key))
return i
} | [
"func",
"(",
"ec",
"*",
"Envcfg",
")",
"GetInt",
"(",
"key",
"string",
")",
"int",
"{",
"i",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"ec",
".",
"GetKey",
"(",
"key",
")",
")",
"\n",
"return",
"i",
"\n",
"}"
] | // GetInt retrieves the value for key from the environment, or the supplied
// configuration data, returning it as a int. Expects numbers to be base 10 and
// no larger than 32 bits. | [
"GetInt",
"retrieves",
"the",
"value",
"for",
"key",
"from",
"the",
"environment",
"or",
"the",
"supplied",
"configuration",
"data",
"returning",
"it",
"as",
"a",
"int",
".",
"Expects",
"numbers",
"to",
"be",
"base",
"10",
"and",
"no",
"larger",
"than",
"3... | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L280-L283 |
153,785 | brankas/envcfg | envcfg.go | GetDuration | func (ec *Envcfg) GetDuration(key string) time.Duration {
d, _ := time.ParseDuration(ec.GetKey(key))
return d
} | go | func (ec *Envcfg) GetDuration(key string) time.Duration {
d, _ := time.ParseDuration(ec.GetKey(key))
return d
} | [
"func",
"(",
"ec",
"*",
"Envcfg",
")",
"GetDuration",
"(",
"key",
"string",
")",
"time",
".",
"Duration",
"{",
"d",
",",
"_",
":=",
"time",
".",
"ParseDuration",
"(",
"ec",
".",
"GetKey",
"(",
"key",
")",
")",
"\n",
"return",
"d",
"\n",
"}"
] | // GetDuration retrievses the value for key from the environment, or the
// supplied configuration data, returning it as a time.Duration. | [
"GetDuration",
"retrievses",
"the",
"value",
"for",
"key",
"from",
"the",
"environment",
"or",
"the",
"supplied",
"configuration",
"data",
"returning",
"it",
"as",
"a",
"time",
".",
"Duration",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L287-L290 |
153,786 | brankas/envcfg | envcfg.go | Env | func (ec *Envcfg) Env() string {
if env := ec.GetKey(ec.envKey); env != "" {
return env
}
return DefaultEnvironment
} | go | func (ec *Envcfg) Env() string {
if env := ec.GetKey(ec.envKey); env != "" {
return env
}
return DefaultEnvironment
} | [
"func",
"(",
"ec",
"*",
"Envcfg",
")",
"Env",
"(",
")",
"string",
"{",
"if",
"env",
":=",
"ec",
".",
"GetKey",
"(",
"ec",
".",
"envKey",
")",
";",
"env",
"!=",
"\"",
"\"",
"{",
"return",
"env",
"\n",
"}",
"\n",
"return",
"DefaultEnvironment",
"\n... | // Env retrieves the value for the runtime environment key. | [
"Env",
"retrieves",
"the",
"value",
"for",
"the",
"runtime",
"environment",
"key",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L314-L319 |
153,787 | brankas/envcfg | envcfg.go | CertPath | func (ec *Envcfg) CertPath() string {
path := ec.GetKey(ec.certPathKey)
if path == "" {
path = DefaultCertPath
}
// ensure the directory exists
fi, err := os.Stat(path)
switch {
case err != nil && os.IsNotExist(err):
if err := os.MkdirAll(path, 0700); err != nil {
panic(fmt.Sprintf("cannot create directory: %v", err))
}
case err != nil:
panic(err)
case !fi.IsDir():
panic(fmt.Sprintf("%s must be a directory", path))
}
return path
} | go | func (ec *Envcfg) CertPath() string {
path := ec.GetKey(ec.certPathKey)
if path == "" {
path = DefaultCertPath
}
// ensure the directory exists
fi, err := os.Stat(path)
switch {
case err != nil && os.IsNotExist(err):
if err := os.MkdirAll(path, 0700); err != nil {
panic(fmt.Sprintf("cannot create directory: %v", err))
}
case err != nil:
panic(err)
case !fi.IsDir():
panic(fmt.Sprintf("%s must be a directory", path))
}
return path
} | [
"func",
"(",
"ec",
"*",
"Envcfg",
")",
"CertPath",
"(",
")",
"string",
"{",
"path",
":=",
"ec",
".",
"GetKey",
"(",
"ec",
".",
"certPathKey",
")",
"\n",
"if",
"path",
"==",
"\"",
"\"",
"{",
"path",
"=",
"DefaultCertPath",
"\n",
"}",
"\n\n",
"// ens... | // CertPath retrieves the value for the server certificate path key. | [
"CertPath",
"retrieves",
"the",
"value",
"for",
"the",
"server",
"certificate",
"path",
"key",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L337-L357 |
153,788 | brankas/envcfg | envcfg.go | CertWait | func (ec *Envcfg) CertWait() time.Duration {
if d := ec.GetDuration(ec.certWaitKey); d != 0 {
return d
}
return DefaultCertWait
} | go | func (ec *Envcfg) CertWait() time.Duration {
if d := ec.GetDuration(ec.certWaitKey); d != 0 {
return d
}
return DefaultCertWait
} | [
"func",
"(",
"ec",
"*",
"Envcfg",
")",
"CertWait",
"(",
")",
"time",
".",
"Duration",
"{",
"if",
"d",
":=",
"ec",
".",
"GetDuration",
"(",
"ec",
".",
"certWaitKey",
")",
";",
"d",
"!=",
"0",
"{",
"return",
"d",
"\n",
"}",
"\n",
"return",
"Default... | // CertWait retrieves the certificate provider wait duration. | [
"CertWait",
"retrieves",
"the",
"certificate",
"provider",
"wait",
"duration",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L360-L365 |
153,789 | brankas/envcfg | envcfg.go | CertDelay | func (ec *Envcfg) CertDelay() time.Duration {
if d := ec.GetDuration(ec.certDelayKey); d != 0 {
return d
}
return DefaultCertDelay
} | go | func (ec *Envcfg) CertDelay() time.Duration {
if d := ec.GetDuration(ec.certDelayKey); d != 0 {
return d
}
return DefaultCertDelay
} | [
"func",
"(",
"ec",
"*",
"Envcfg",
")",
"CertDelay",
"(",
")",
"time",
".",
"Duration",
"{",
"if",
"d",
":=",
"ec",
".",
"GetDuration",
"(",
"ec",
".",
"certDelayKey",
")",
";",
"d",
"!=",
"0",
"{",
"return",
"d",
"\n",
"}",
"\n",
"return",
"Defau... | // CertDelay retrieves the certificate provider delay duration. | [
"CertDelay",
"retrieves",
"the",
"certificate",
"provider",
"delay",
"duration",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L368-L373 |
153,790 | brankas/envcfg | envcfg.go | TLS | func (ec *Envcfg) TLS() *tls.Config {
ec.once.Do(func() {
// build cert provider
certProvider := ec.buildCertProvider()
if certProvider == nil {
return
}
// set tls config
ec.tls = &tls.Config{
NextProtos: []string{"h2", "http/1.1"},
ServerName: ec.Host(),
GetCertificate: certProvider.GetCertificate,
// qualys A+ settings
MinVersion: tls.VersionTLS12,
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
PreferServerCipherSuites: true,
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
},
}
})
return ec.tls
} | go | func (ec *Envcfg) TLS() *tls.Config {
ec.once.Do(func() {
// build cert provider
certProvider := ec.buildCertProvider()
if certProvider == nil {
return
}
// set tls config
ec.tls = &tls.Config{
NextProtos: []string{"h2", "http/1.1"},
ServerName: ec.Host(),
GetCertificate: certProvider.GetCertificate,
// qualys A+ settings
MinVersion: tls.VersionTLS12,
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
PreferServerCipherSuites: true,
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
},
}
})
return ec.tls
} | [
"func",
"(",
"ec",
"*",
"Envcfg",
")",
"TLS",
"(",
")",
"*",
"tls",
".",
"Config",
"{",
"ec",
".",
"once",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"// build cert provider",
"certProvider",
":=",
"ec",
".",
"buildCertProvider",
"(",
")",
"\n",
"if",
... | // TLS retrieves the TLS configuration for use by a server. | [
"TLS",
"retrieves",
"the",
"TLS",
"configuration",
"for",
"use",
"by",
"a",
"server",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L376-L404 |
153,791 | brankas/envcfg | envcfg.go | buildCertProvider | func (ec *Envcfg) buildCertProvider() CertificateProvider {
provider := ec.GetKey(ec.certProviderKey)
var params []string
if i := strings.Index(provider, ":"); i != -1 {
provider, params = strings.TrimSpace(provider[:i]), strings.Split(provider[i+1:], ":")
}
switch provider {
case "", "auto":
return &autocert.Manager{
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist(ec.Host()),
Cache: autocert.DirCache(ec.CertPath()),
}
case "dns":
return ec.dnsCertProvider(params)
case "disk":
return ec.diskCertProvider(params)
case "none":
return nil
default:
panic("unknown certificate provider type: " + provider)
}
} | go | func (ec *Envcfg) buildCertProvider() CertificateProvider {
provider := ec.GetKey(ec.certProviderKey)
var params []string
if i := strings.Index(provider, ":"); i != -1 {
provider, params = strings.TrimSpace(provider[:i]), strings.Split(provider[i+1:], ":")
}
switch provider {
case "", "auto":
return &autocert.Manager{
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist(ec.Host()),
Cache: autocert.DirCache(ec.CertPath()),
}
case "dns":
return ec.dnsCertProvider(params)
case "disk":
return ec.diskCertProvider(params)
case "none":
return nil
default:
panic("unknown certificate provider type: " + provider)
}
} | [
"func",
"(",
"ec",
"*",
"Envcfg",
")",
"buildCertProvider",
"(",
")",
"CertificateProvider",
"{",
"provider",
":=",
"ec",
".",
"GetKey",
"(",
"ec",
".",
"certProviderKey",
")",
"\n",
"var",
"params",
"[",
"]",
"string",
"\n",
"if",
"i",
":=",
"strings",
... | // buildCertProvider builds the CertificateProvider. | [
"buildCertProvider",
"builds",
"the",
"CertificateProvider",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L407-L434 |
153,792 | brankas/envcfg | envcfg.go | diskCertProvider | func (ec *Envcfg) diskCertProvider(params []string) CertificateProvider {
// "certname:keyname"
if len(params) < 2 {
panic("invalid certificate provider params")
}
dir := ec.CertPath()
certPath, keyPath := filepath.Join(dir, params[0]), filepath.Join(dir, params[1])
dcp, err := newDiskCertProvider(certPath, keyPath, ec.logf, ec.errf)
if err != nil {
panic(fmt.Sprintf("unable to load certificate and key from disk: %v", err))
}
return dcp
} | go | func (ec *Envcfg) diskCertProvider(params []string) CertificateProvider {
// "certname:keyname"
if len(params) < 2 {
panic("invalid certificate provider params")
}
dir := ec.CertPath()
certPath, keyPath := filepath.Join(dir, params[0]), filepath.Join(dir, params[1])
dcp, err := newDiskCertProvider(certPath, keyPath, ec.logf, ec.errf)
if err != nil {
panic(fmt.Sprintf("unable to load certificate and key from disk: %v", err))
}
return dcp
} | [
"func",
"(",
"ec",
"*",
"Envcfg",
")",
"diskCertProvider",
"(",
"params",
"[",
"]",
"string",
")",
"CertificateProvider",
"{",
"// \"certname:keyname\"",
"if",
"len",
"(",
"params",
")",
"<",
"2",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
... | // diskCertProvider creates a certificate provider from a certificate and key
// pair stored on disk.
//
// Uses fsnotify to watch for changes to reload immediately. | [
"diskCertProvider",
"creates",
"a",
"certificate",
"provider",
"from",
"a",
"certificate",
"and",
"key",
"pair",
"stored",
"on",
"disk",
".",
"Uses",
"fsnotify",
"to",
"watch",
"for",
"changes",
"to",
"reload",
"immediately",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L507-L521 |
153,793 | brankas/envcfg | envcfg.go | newDiskCertProvider | func newDiskCertProvider(certPath, keyPath string, logf, errf func(string, ...interface{})) (*diskCertProvider, error) {
dcp := &diskCertProvider{
certPath: certPath,
keyPath: keyPath,
}
if err := dcp.loadCertAndKey(); err != nil {
return nil, err
}
// create watcher
watcher, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
// don't close, as it runs forever
// defer watcher.Close()
addWatch := func(path string) error {
if err := watcher.Add(certPath); err != nil {
return err
}
// if this is a valid symlink, watch its target too
if path, err := filepath.EvalSymlinks(certPath); err == nil && path != certPath {
if err := watcher.Add(path); err != nil {
return err
}
}
return nil
}
go func() {
for {
select {
case <-watcher.Events:
if err := dcp.loadCertAndKey(); err != nil {
errf("could not load cert and key: %v", err)
} else {
logf("loaded updated certificate")
}
// in case we're dealing with symlinks and the target changed,
// make sure we continue to watch properly
if err := addWatch(certPath); err != nil {
errf("could not add watch: %v", err)
}
case err := <-watcher.Errors:
errf("%v", err)
}
}
}()
// watch the first certificate file
if err := addWatch(certPath); err != nil {
return nil, err
}
return dcp, nil
} | go | func newDiskCertProvider(certPath, keyPath string, logf, errf func(string, ...interface{})) (*diskCertProvider, error) {
dcp := &diskCertProvider{
certPath: certPath,
keyPath: keyPath,
}
if err := dcp.loadCertAndKey(); err != nil {
return nil, err
}
// create watcher
watcher, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
// don't close, as it runs forever
// defer watcher.Close()
addWatch := func(path string) error {
if err := watcher.Add(certPath); err != nil {
return err
}
// if this is a valid symlink, watch its target too
if path, err := filepath.EvalSymlinks(certPath); err == nil && path != certPath {
if err := watcher.Add(path); err != nil {
return err
}
}
return nil
}
go func() {
for {
select {
case <-watcher.Events:
if err := dcp.loadCertAndKey(); err != nil {
errf("could not load cert and key: %v", err)
} else {
logf("loaded updated certificate")
}
// in case we're dealing with symlinks and the target changed,
// make sure we continue to watch properly
if err := addWatch(certPath); err != nil {
errf("could not add watch: %v", err)
}
case err := <-watcher.Errors:
errf("%v", err)
}
}
}()
// watch the first certificate file
if err := addWatch(certPath); err != nil {
return nil, err
}
return dcp, nil
} | [
"func",
"newDiskCertProvider",
"(",
"certPath",
",",
"keyPath",
"string",
",",
"logf",
",",
"errf",
"func",
"(",
"string",
",",
"...",
"interface",
"{",
"}",
")",
")",
"(",
"*",
"diskCertProvider",
",",
"error",
")",
"{",
"dcp",
":=",
"&",
"diskCertProvi... | // newDiskCertProvider creates a disk cert provider that watches dirPath for
// cert and key. | [
"newDiskCertProvider",
"creates",
"a",
"disk",
"cert",
"provider",
"that",
"watches",
"dirPath",
"for",
"cert",
"and",
"key",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L537-L597 |
153,794 | brankas/envcfg | envcfg.go | loadCertAndKey | func (dcp *diskCertProvider) loadCertAndKey() error {
cert, err := tls.LoadX509KeyPair(dcp.certPath, dcp.keyPath)
if err != nil {
return err
}
dcp.Lock()
defer dcp.Unlock()
dcp.cert = &cert
return nil
} | go | func (dcp *diskCertProvider) loadCertAndKey() error {
cert, err := tls.LoadX509KeyPair(dcp.certPath, dcp.keyPath)
if err != nil {
return err
}
dcp.Lock()
defer dcp.Unlock()
dcp.cert = &cert
return nil
} | [
"func",
"(",
"dcp",
"*",
"diskCertProvider",
")",
"loadCertAndKey",
"(",
")",
"error",
"{",
"cert",
",",
"err",
":=",
"tls",
".",
"LoadX509KeyPair",
"(",
"dcp",
".",
"certPath",
",",
"dcp",
".",
"keyPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r... | // loadCertAndKey tries to load the cert and key from disk. | [
"loadCertAndKey",
"tries",
"to",
"load",
"the",
"cert",
"and",
"key",
"from",
"disk",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L600-L611 |
153,795 | brankas/envcfg | envcfg.go | GetCertificate | func (dcp *diskCertProvider) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error) {
dcp.RLock()
defer dcp.RUnlock()
return dcp.cert, nil
} | go | func (dcp *diskCertProvider) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error) {
dcp.RLock()
defer dcp.RUnlock()
return dcp.cert, nil
} | [
"func",
"(",
"dcp",
"*",
"diskCertProvider",
")",
"GetCertificate",
"(",
"hello",
"*",
"tls",
".",
"ClientHelloInfo",
")",
"(",
"*",
"tls",
".",
"Certificate",
",",
"error",
")",
"{",
"dcp",
".",
"RLock",
"(",
")",
"\n",
"defer",
"dcp",
".",
"RUnlock",... | // GetCertificate satisfies the CertificateProvider interface. | [
"GetCertificate",
"satisfies",
"the",
"CertificateProvider",
"interface",
"."
] | 11e4db35a7fbbc24210c5b24d548f404cc88f491 | https://github.com/brankas/envcfg/blob/11e4db35a7fbbc24210c5b24d548f404cc88f491/envcfg.go#L614-L619 |
153,796 | ghetzel/diecast | server.go | SetMounts | func (self *Server) SetMounts(mounts []Mount) {
if len(self.Mounts) > 0 {
self.Mounts = append(self.Mounts, mounts...)
} else {
self.Mounts = mounts
}
} | go | func (self *Server) SetMounts(mounts []Mount) {
if len(self.Mounts) > 0 {
self.Mounts = append(self.Mounts, mounts...)
} else {
self.Mounts = mounts
}
} | [
"func",
"(",
"self",
"*",
"Server",
")",
"SetMounts",
"(",
"mounts",
"[",
"]",
"Mount",
")",
"{",
"if",
"len",
"(",
"self",
".",
"Mounts",
")",
">",
"0",
"{",
"self",
".",
"Mounts",
"=",
"append",
"(",
"self",
".",
"Mounts",
",",
"mounts",
"...",... | // Append the specified mounts to the current server. | [
"Append",
"the",
"specified",
"mounts",
"to",
"the",
"current",
"server",
"."
] | 3cf4315555ad6d1e50e51ddf7778eedb91da56ca | https://github.com/ghetzel/diecast/blob/3cf4315555ad6d1e50e51ddf7778eedb91da56ca/server.go#L273-L279 |
153,797 | ghetzel/diecast | server.go | shouldApplyTemplate | func (self *Server) shouldApplyTemplate(requestPath string) bool {
baseName := filepath.Base(requestPath)
for _, pattern := range self.TemplatePatterns {
if strings.HasPrefix(pattern, `/`) {
if match, err := filepath.Match(pattern, requestPath); err == nil && match {
return true
}
} else {
if match, err := filepath.Match(pattern, baseName); err == nil && match {
return true
}
}
}
return false
} | go | func (self *Server) shouldApplyTemplate(requestPath string) bool {
baseName := filepath.Base(requestPath)
for _, pattern := range self.TemplatePatterns {
if strings.HasPrefix(pattern, `/`) {
if match, err := filepath.Match(pattern, requestPath); err == nil && match {
return true
}
} else {
if match, err := filepath.Match(pattern, baseName); err == nil && match {
return true
}
}
}
return false
} | [
"func",
"(",
"self",
"*",
"Server",
")",
"shouldApplyTemplate",
"(",
"requestPath",
"string",
")",
"bool",
"{",
"baseName",
":=",
"filepath",
".",
"Base",
"(",
"requestPath",
")",
"\n\n",
"for",
"_",
",",
"pattern",
":=",
"range",
"self",
".",
"TemplatePat... | // return whether the request path matches any of the configured TemplatePatterns. | [
"return",
"whether",
"the",
"request",
"path",
"matches",
"any",
"of",
"the",
"configured",
"TemplatePatterns",
"."
] | 3cf4315555ad6d1e50e51ddf7778eedb91da56ca | https://github.com/ghetzel/diecast/blob/3cf4315555ad6d1e50e51ddf7778eedb91da56ca/server.go#L371-L387 |
153,798 | ghetzel/diecast | server.go | tryLocalFile | func (self *Server) tryLocalFile(requestPath string, req *http.Request) (http.File, string, error) {
// if we got here, try to serve the file from the filesystem
if file, err := self.fs.Open(requestPath); err == nil {
if stat, err := file.Stat(); err == nil {
if !stat.IsDir() {
if mimetype := httputil.Q(req, `mimetype`); mimetype != `` {
return file, mimetype, nil
} else if mimetype, err := figureOutMimeType(stat.Name(), file); err == nil {
return file, mimetype, nil
} else {
return file, ``, err
}
} else {
return nil, ``, fmt.Errorf("is a directory")
}
} else {
return nil, ``, fmt.Errorf("failed to stat file %v: %v", requestPath, err)
}
} else {
return nil, ``, err
}
} | go | func (self *Server) tryLocalFile(requestPath string, req *http.Request) (http.File, string, error) {
// if we got here, try to serve the file from the filesystem
if file, err := self.fs.Open(requestPath); err == nil {
if stat, err := file.Stat(); err == nil {
if !stat.IsDir() {
if mimetype := httputil.Q(req, `mimetype`); mimetype != `` {
return file, mimetype, nil
} else if mimetype, err := figureOutMimeType(stat.Name(), file); err == nil {
return file, mimetype, nil
} else {
return file, ``, err
}
} else {
return nil, ``, fmt.Errorf("is a directory")
}
} else {
return nil, ``, fmt.Errorf("failed to stat file %v: %v", requestPath, err)
}
} else {
return nil, ``, err
}
} | [
"func",
"(",
"self",
"*",
"Server",
")",
"tryLocalFile",
"(",
"requestPath",
"string",
",",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"http",
".",
"File",
",",
"string",
",",
"error",
")",
"{",
"// if we got here, try to serve the file from the filesystem",
... | // Attempt to resolve the given path into a real file and return that file and mime type.
// Non-existent files, unreadable files, and directories will return an error. | [
"Attempt",
"to",
"resolve",
"the",
"given",
"path",
"into",
"a",
"real",
"file",
"and",
"return",
"that",
"file",
"and",
"mime",
"type",
".",
"Non",
"-",
"existent",
"files",
"unreadable",
"files",
"and",
"directories",
"will",
"return",
"an",
"error",
"."... | 3cf4315555ad6d1e50e51ddf7778eedb91da56ca | https://github.com/ghetzel/diecast/blob/3cf4315555ad6d1e50e51ddf7778eedb91da56ca/server.go#L1127-L1148 |
153,799 | ghetzel/diecast | server.go | tryMounts | func (self *Server) tryMounts(requestPath string, req *http.Request) (Mount, *MountResponse, error) {
var body *bytes.Reader
// buffer the request body because we need to repeatedly pass it to multiple mounts
if data, err := ioutil.ReadAll(req.Body); err == nil {
if len(data) > 0 {
log.Debugf(" read %d bytes from request body\n", len(data))
}
body = bytes.NewReader(data)
} else {
return nil, nil, err
}
// find a mount that has this file
for _, mount := range self.Mounts {
// seek the body buffer back to the beginning
if _, err := body.Seek(0, 0); err != nil {
return nil, nil, err
}
if mount.WillRespondTo(requestPath, req, body) {
// attempt to open the file entry
if mountResponse, err := mount.OpenWithType(requestPath, req, body); err == nil {
return mount, mountResponse, nil
} else if IsHardStop(err) {
return nil, nil, err
} else {
log.Warningf("%v", err)
}
}
}
return nil, nil, fmt.Errorf("%q not found", requestPath)
} | go | func (self *Server) tryMounts(requestPath string, req *http.Request) (Mount, *MountResponse, error) {
var body *bytes.Reader
// buffer the request body because we need to repeatedly pass it to multiple mounts
if data, err := ioutil.ReadAll(req.Body); err == nil {
if len(data) > 0 {
log.Debugf(" read %d bytes from request body\n", len(data))
}
body = bytes.NewReader(data)
} else {
return nil, nil, err
}
// find a mount that has this file
for _, mount := range self.Mounts {
// seek the body buffer back to the beginning
if _, err := body.Seek(0, 0); err != nil {
return nil, nil, err
}
if mount.WillRespondTo(requestPath, req, body) {
// attempt to open the file entry
if mountResponse, err := mount.OpenWithType(requestPath, req, body); err == nil {
return mount, mountResponse, nil
} else if IsHardStop(err) {
return nil, nil, err
} else {
log.Warningf("%v", err)
}
}
}
return nil, nil, fmt.Errorf("%q not found", requestPath)
} | [
"func",
"(",
"self",
"*",
"Server",
")",
"tryMounts",
"(",
"requestPath",
"string",
",",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"Mount",
",",
"*",
"MountResponse",
",",
"error",
")",
"{",
"var",
"body",
"*",
"bytes",
".",
"Reader",
"\n\n",
"//... | // Try to load the given path from each of the mounts, and return the matching mount and its response
// if found. | [
"Try",
"to",
"load",
"the",
"given",
"path",
"from",
"each",
"of",
"the",
"mounts",
"and",
"return",
"the",
"matching",
"mount",
"and",
"its",
"response",
"if",
"found",
"."
] | 3cf4315555ad6d1e50e51ddf7778eedb91da56ca | https://github.com/ghetzel/diecast/blob/3cf4315555ad6d1e50e51ddf7778eedb91da56ca/server.go#L1152-L1186 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.