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
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
|---|---|---|---|---|---|---|---|---|---|---|---|
18,400
|
ns3777k/go-shodan
|
shodan/alert.go
|
GetAlert
|
func (c *Client) GetAlert(ctx context.Context, id string) (*Alert, error) {
var alert Alert
path := fmt.Sprintf(alertInfoPath, id)
req, err := c.NewRequest("GET", path, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &alert); err != nil {
return nil, err
}
return &alert, err
}
|
go
|
func (c *Client) GetAlert(ctx context.Context, id string) (*Alert, error) {
var alert Alert
path := fmt.Sprintf(alertInfoPath, id)
req, err := c.NewRequest("GET", path, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &alert); err != nil {
return nil, err
}
return &alert, err
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetAlert",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"(",
"*",
"Alert",
",",
"error",
")",
"{",
"var",
"alert",
"Alert",
"\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"alertInfoPath",
",",
"id",
")",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"path",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"alert",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"alert",
",",
"err",
"\n",
"}"
] |
// GetAlert returns the information about a specific network alert.
|
[
"GetAlert",
"returns",
"the",
"information",
"about",
"a",
"specific",
"network",
"alert",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/alert.go#L84-L98
|
18,401
|
ns3777k/go-shodan
|
shodan/alert.go
|
DeleteAlert
|
func (c *Client) DeleteAlert(ctx context.Context, id string) (bool, error) {
path := fmt.Sprintf(alertDeletePath, id)
req, err := c.NewRequest("DELETE", path, nil, nil)
if err != nil {
return false, err
}
if err := c.Do(ctx, req, nil); err != nil {
return false, err
}
return true, nil
}
|
go
|
func (c *Client) DeleteAlert(ctx context.Context, id string) (bool, error) {
path := fmt.Sprintf(alertDeletePath, id)
req, err := c.NewRequest("DELETE", path, nil, nil)
if err != nil {
return false, err
}
if err := c.Do(ctx, req, nil); err != nil {
return false, err
}
return true, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"DeleteAlert",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"alertDeletePath",
",",
"id",
")",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"path",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] |
// DeleteAlert removes the specified network alert.
|
[
"DeleteAlert",
"removes",
"the",
"specified",
"network",
"alert",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/alert.go#L101-L114
|
18,402
|
ns3777k/go-shodan
|
shodan/account.go
|
GetAccountProfile
|
func (c *Client) GetAccountProfile(ctx context.Context) (*Profile, error) {
var profile Profile
req, err := c.NewRequest("GET", profilePath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &profile); err != nil {
return nil, err
}
return &profile, err
}
|
go
|
func (c *Client) GetAccountProfile(ctx context.Context) (*Profile, error) {
var profile Profile
req, err := c.NewRequest("GET", profilePath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &profile); err != nil {
return nil, err
}
return &profile, err
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetAccountProfile",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"Profile",
",",
"error",
")",
"{",
"var",
"profile",
"Profile",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"profilePath",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"profile",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"profile",
",",
"err",
"\n",
"}"
] |
// GetAccountProfile returns information about the Shodan account linked to the API key
|
[
"GetAccountProfile",
"returns",
"information",
"about",
"the",
"Shodan",
"account",
"linked",
"to",
"the",
"API",
"key"
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/account.go#L20-L33
|
18,403
|
ns3777k/go-shodan
|
shodan/host.go
|
GetServicesForHost
|
func (c *Client) GetServicesForHost(ctx context.Context, ip string, options *HostServicesOptions) (*Host, error) {
var host Host
req, err := c.NewRequest("GET", hostPath+"/"+ip, options, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &host); err != nil {
return nil, err
}
return &host, nil
}
|
go
|
func (c *Client) GetServicesForHost(ctx context.Context, ip string, options *HostServicesOptions) (*Host, error) {
var host Host
req, err := c.NewRequest("GET", hostPath+"/"+ip, options, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &host); err != nil {
return nil, err
}
return &host, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetServicesForHost",
"(",
"ctx",
"context",
".",
"Context",
",",
"ip",
"string",
",",
"options",
"*",
"HostServicesOptions",
")",
"(",
"*",
"Host",
",",
"error",
")",
"{",
"var",
"host",
"Host",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"hostPath",
"+",
"\"",
"\"",
"+",
"ip",
",",
"options",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"host",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"host",
",",
"nil",
"\n",
"}"
] |
// GetServicesForHost returns all services that have been found on the given host IP
|
[
"GetServicesForHost",
"returns",
"all",
"services",
"that",
"have",
"been",
"found",
"on",
"the",
"given",
"host",
"IP"
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/host.go#L173-L186
|
18,404
|
ns3777k/go-shodan
|
shodan/host.go
|
BreakQueryIntoTokens
|
func (c *Client) BreakQueryIntoTokens(ctx context.Context, query string) (*HostQueryTokens, error) {
var tokens HostQueryTokens
options := struct {
Query string `url:"query"`
}{Query: query}
req, err := c.NewRequest("GET", hostSearchTokensPath, options, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &tokens); err != nil {
return nil, err
}
return &tokens, nil
}
|
go
|
func (c *Client) BreakQueryIntoTokens(ctx context.Context, query string) (*HostQueryTokens, error) {
var tokens HostQueryTokens
options := struct {
Query string `url:"query"`
}{Query: query}
req, err := c.NewRequest("GET", hostSearchTokensPath, options, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &tokens); err != nil {
return nil, err
}
return &tokens, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"BreakQueryIntoTokens",
"(",
"ctx",
"context",
".",
"Context",
",",
"query",
"string",
")",
"(",
"*",
"HostQueryTokens",
",",
"error",
")",
"{",
"var",
"tokens",
"HostQueryTokens",
"\n\n",
"options",
":=",
"struct",
"{",
"Query",
"string",
"`url:\"query\"`",
"\n",
"}",
"{",
"Query",
":",
"query",
"}",
"\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"hostSearchTokensPath",
",",
"options",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"tokens",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"tokens",
",",
"nil",
"\n",
"}"
] |
// BreakQueryIntoTokens determines which filters are being used by the query string
// and what parameters were provided to the filters.
|
[
"BreakQueryIntoTokens",
"determines",
"which",
"filters",
"are",
"being",
"used",
"by",
"the",
"query",
"string",
"and",
"what",
"parameters",
"were",
"provided",
"to",
"the",
"filters",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/host.go#L229-L245
|
18,405
|
ns3777k/go-shodan
|
shodan/protocols.go
|
GetProtocols
|
func (c *Client) GetProtocols(ctx context.Context) (map[string]string, error) {
var protocols map[string]string
req, err := c.NewRequest("GET", protocolsPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &protocols); err != nil {
return nil, err
}
return protocols, err
}
|
go
|
func (c *Client) GetProtocols(ctx context.Context) (map[string]string, error) {
var protocols map[string]string
req, err := c.NewRequest("GET", protocolsPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &protocols); err != nil {
return nil, err
}
return protocols, err
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetProtocols",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"var",
"protocols",
"map",
"[",
"string",
"]",
"string",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"protocolsPath",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"protocols",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"protocols",
",",
"err",
"\n",
"}"
] |
// GetProtocols returns an object containing all the protocols that can be
// used when launching an Internet scan.
|
[
"GetProtocols",
"returns",
"an",
"object",
"containing",
"all",
"the",
"protocols",
"that",
"can",
"be",
"used",
"when",
"launching",
"an",
"Internet",
"scan",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/protocols.go#L13-L26
|
18,406
|
ns3777k/go-shodan
|
shodan/shodan.go
|
NewClient
|
func NewClient(client *http.Client, token string) *Client {
if client == nil {
client = http.DefaultClient
}
return &Client{
Token: token,
BaseURL: baseURL,
ExploitBaseURL: exploitBaseURL,
StreamBaseURL: streamBaseURL,
Client: client,
m: &sync.Mutex{},
}
}
|
go
|
func NewClient(client *http.Client, token string) *Client {
if client == nil {
client = http.DefaultClient
}
return &Client{
Token: token,
BaseURL: baseURL,
ExploitBaseURL: exploitBaseURL,
StreamBaseURL: streamBaseURL,
Client: client,
m: &sync.Mutex{},
}
}
|
[
"func",
"NewClient",
"(",
"client",
"*",
"http",
".",
"Client",
",",
"token",
"string",
")",
"*",
"Client",
"{",
"if",
"client",
"==",
"nil",
"{",
"client",
"=",
"http",
".",
"DefaultClient",
"\n",
"}",
"\n\n",
"return",
"&",
"Client",
"{",
"Token",
":",
"token",
",",
"BaseURL",
":",
"baseURL",
",",
"ExploitBaseURL",
":",
"exploitBaseURL",
",",
"StreamBaseURL",
":",
"streamBaseURL",
",",
"Client",
":",
"client",
",",
"m",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"}",
"\n",
"}"
] |
// NewClient creates new Shodan client
|
[
"NewClient",
"creates",
"new",
"Shodan",
"client"
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/shodan.go#L35-L48
|
18,407
|
ns3777k/go-shodan
|
shodan/shodan.go
|
SetDebug
|
func (c *Client) SetDebug(debug bool) {
c.m.Lock()
defer c.m.Unlock()
c.Debug = debug
}
|
go
|
func (c *Client) SetDebug(debug bool) {
c.m.Lock()
defer c.m.Unlock()
c.Debug = debug
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"SetDebug",
"(",
"debug",
"bool",
")",
"{",
"c",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"c",
".",
"Debug",
"=",
"debug",
"\n",
"}"
] |
// SetDebug toggles the debug mode.
|
[
"SetDebug",
"toggles",
"the",
"debug",
"mode",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/shodan.go#L57-L62
|
18,408
|
ns3777k/go-shodan
|
shodan/shodan.go
|
NewExploitRequest
|
func (c *Client) NewExploitRequest(method string, path string, params interface{}, body io.Reader) (*http.Request, error) {
u, err := url.Parse(c.ExploitBaseURL + path)
if err != nil {
return nil, err
}
return c.newRequest(method, u, params, body)
}
|
go
|
func (c *Client) NewExploitRequest(method string, path string, params interface{}, body io.Reader) (*http.Request, error) {
u, err := url.Parse(c.ExploitBaseURL + path)
if err != nil {
return nil, err
}
return c.newRequest(method, u, params, body)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"NewExploitRequest",
"(",
"method",
"string",
",",
"path",
"string",
",",
"params",
"interface",
"{",
"}",
",",
"body",
"io",
".",
"Reader",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"c",
".",
"ExploitBaseURL",
"+",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"newRequest",
"(",
"method",
",",
"u",
",",
"params",
",",
"body",
")",
"\n",
"}"
] |
// NewExploitRequest prepares new request to exploit shodan api.
|
[
"NewExploitRequest",
"prepares",
"new",
"request",
"to",
"exploit",
"shodan",
"api",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/shodan.go#L65-L72
|
18,409
|
ns3777k/go-shodan
|
shodan/dns.go
|
GetDNSResolve
|
func (c *Client) GetDNSResolve(ctx context.Context, hostnames []string) (map[string]*net.IP, error) {
dnsResolved := make(map[string]*net.IP)
params := struct {
Hostnames string `url:"hostnames"`
}{strings.Join(hostnames, ",")}
req, err := c.NewRequest("GET", resolvePath, params, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &dnsResolved); err != nil {
return nil, err
}
return dnsResolved, nil
}
|
go
|
func (c *Client) GetDNSResolve(ctx context.Context, hostnames []string) (map[string]*net.IP, error) {
dnsResolved := make(map[string]*net.IP)
params := struct {
Hostnames string `url:"hostnames"`
}{strings.Join(hostnames, ",")}
req, err := c.NewRequest("GET", resolvePath, params, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &dnsResolved); err != nil {
return nil, err
}
return dnsResolved, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetDNSResolve",
"(",
"ctx",
"context",
".",
"Context",
",",
"hostnames",
"[",
"]",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"net",
".",
"IP",
",",
"error",
")",
"{",
"dnsResolved",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"net",
".",
"IP",
")",
"\n",
"params",
":=",
"struct",
"{",
"Hostnames",
"string",
"`url:\"hostnames\"`",
"\n",
"}",
"{",
"strings",
".",
"Join",
"(",
"hostnames",
",",
"\"",
"\"",
")",
"}",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"resolvePath",
",",
"params",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"dnsResolved",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"dnsResolved",
",",
"nil",
"\n",
"}"
] |
// GetDNSResolve looks up the IP address for the provided list of hostnames
|
[
"GetDNSResolve",
"looks",
"up",
"the",
"IP",
"address",
"for",
"the",
"provided",
"list",
"of",
"hostnames"
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/dns.go#L15-L31
|
18,410
|
ns3777k/go-shodan
|
shodan/dns.go
|
GetDNSReverse
|
func (c *Client) GetDNSReverse(ctx context.Context, ip []net.IP) (map[string]*[]string, error) {
ips := make([]string, 0)
for _, ipAddress := range ip {
ips = append(ips, ipAddress.String())
}
dnsReversed := make(map[string]*[]string)
params := struct {
IP string `url:"ips"`
}{strings.Join(ips, ",")}
req, err := c.NewRequest("GET", reversePath, params, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &dnsReversed); err != nil {
return nil, err
}
return dnsReversed, nil
}
|
go
|
func (c *Client) GetDNSReverse(ctx context.Context, ip []net.IP) (map[string]*[]string, error) {
ips := make([]string, 0)
for _, ipAddress := range ip {
ips = append(ips, ipAddress.String())
}
dnsReversed := make(map[string]*[]string)
params := struct {
IP string `url:"ips"`
}{strings.Join(ips, ",")}
req, err := c.NewRequest("GET", reversePath, params, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &dnsReversed); err != nil {
return nil, err
}
return dnsReversed, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetDNSReverse",
"(",
"ctx",
"context",
".",
"Context",
",",
"ip",
"[",
"]",
"net",
".",
"IP",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"[",
"]",
"string",
",",
"error",
")",
"{",
"ips",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n\n",
"for",
"_",
",",
"ipAddress",
":=",
"range",
"ip",
"{",
"ips",
"=",
"append",
"(",
"ips",
",",
"ipAddress",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"dnsReversed",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"[",
"]",
"string",
")",
"\n",
"params",
":=",
"struct",
"{",
"IP",
"string",
"`url:\"ips\"`",
"\n",
"}",
"{",
"strings",
".",
"Join",
"(",
"ips",
",",
"\"",
"\"",
")",
"}",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"reversePath",
",",
"params",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"dnsReversed",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"dnsReversed",
",",
"nil",
"\n",
"}"
] |
// GetDNSReverse looks up the hostnames that have been defined for the given list of IP addresses
|
[
"GetDNSReverse",
"looks",
"up",
"the",
"hostnames",
"that",
"have",
"been",
"defined",
"for",
"the",
"given",
"list",
"of",
"IP",
"addresses"
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/dns.go#L34-L56
|
18,411
|
ns3777k/go-shodan
|
shodan/scan.go
|
ScanInternet
|
func (c *Client) ScanInternet(ctx context.Context, port int, protocol string) (string, error) {
crawlScanInternetStatus := new(struct {
ID string `json:"id"`
})
body := neturl.Values{}
body.Add("port", strconv.Itoa(port))
body.Add("protocol", protocol)
req, err := c.NewRequest("POST", scanInternetPath, nil, strings.NewReader(body.Encode()))
if err != nil {
return "", err
}
if err := c.Do(ctx, req, crawlScanInternetStatus); err != nil {
return "", err
}
return crawlScanInternetStatus.ID, nil
}
|
go
|
func (c *Client) ScanInternet(ctx context.Context, port int, protocol string) (string, error) {
crawlScanInternetStatus := new(struct {
ID string `json:"id"`
})
body := neturl.Values{}
body.Add("port", strconv.Itoa(port))
body.Add("protocol", protocol)
req, err := c.NewRequest("POST", scanInternetPath, nil, strings.NewReader(body.Encode()))
if err != nil {
return "", err
}
if err := c.Do(ctx, req, crawlScanInternetStatus); err != nil {
return "", err
}
return crawlScanInternetStatus.ID, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ScanInternet",
"(",
"ctx",
"context",
".",
"Context",
",",
"port",
"int",
",",
"protocol",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"crawlScanInternetStatus",
":=",
"new",
"(",
"struct",
"{",
"ID",
"string",
"`json:\"id\"`",
"\n",
"}",
")",
"\n\n",
"body",
":=",
"neturl",
".",
"Values",
"{",
"}",
"\n",
"body",
".",
"Add",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"port",
")",
")",
"\n",
"body",
".",
"Add",
"(",
"\"",
"\"",
",",
"protocol",
")",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"scanInternetPath",
",",
"nil",
",",
"strings",
".",
"NewReader",
"(",
"body",
".",
"Encode",
"(",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"crawlScanInternetStatus",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"crawlScanInternetStatus",
".",
"ID",
",",
"nil",
"\n",
"}"
] |
// ScanInternet requests Shodan to crawl the Internet for a specific port.
// This method is restricted to security researchers and companies with a Shodan Data license.
|
[
"ScanInternet",
"requests",
"Shodan",
"to",
"crawl",
"the",
"Internet",
"for",
"a",
"specific",
"port",
".",
"This",
"method",
"is",
"restricted",
"to",
"security",
"researchers",
"and",
"companies",
"with",
"a",
"Shodan",
"Data",
"license",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/scan.go#L69-L88
|
18,412
|
ns3777k/go-shodan
|
shodan/scan.go
|
GetScanStatus
|
func (c *Client) GetScanStatus(ctx context.Context, id string) (*ScanStatus, error) {
var scanStatus ScanStatus
path := fmt.Sprintf(scanStatusPath, id)
req, err := c.NewRequest("GET", path, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &scanStatus); err != nil {
return nil, err
}
return &scanStatus, nil
}
|
go
|
func (c *Client) GetScanStatus(ctx context.Context, id string) (*ScanStatus, error) {
var scanStatus ScanStatus
path := fmt.Sprintf(scanStatusPath, id)
req, err := c.NewRequest("GET", path, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &scanStatus); err != nil {
return nil, err
}
return &scanStatus, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetScanStatus",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"(",
"*",
"ScanStatus",
",",
"error",
")",
"{",
"var",
"scanStatus",
"ScanStatus",
"\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"scanStatusPath",
",",
"id",
")",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"path",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"scanStatus",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"scanStatus",
",",
"nil",
"\n",
"}"
] |
// GetScanStatus checks the progress of a previously submitted scan request.
|
[
"GetScanStatus",
"checks",
"the",
"progress",
"of",
"a",
"previously",
"submitted",
"scan",
"request",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/scan.go#L91-L105
|
18,413
|
ns3777k/go-shodan
|
shodan/helpers.go
|
UnmarshalJSON
|
func (v *IntString) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err == nil {
*v = IntString(s)
return nil
}
var n int
if err := json.Unmarshal(b, &n); err != nil {
return err
}
*v = IntString(strconv.Itoa(n))
return nil
}
|
go
|
func (v *IntString) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err == nil {
*v = IntString(s)
return nil
}
var n int
if err := json.Unmarshal(b, &n); err != nil {
return err
}
*v = IntString(strconv.Itoa(n))
return nil
}
|
[
"func",
"(",
"v",
"*",
"IntString",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"s",
"string",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"s",
")",
";",
"err",
"==",
"nil",
"{",
"*",
"v",
"=",
"IntString",
"(",
"s",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"n",
"int",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"n",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"*",
"v",
"=",
"IntString",
"(",
"strconv",
".",
"Itoa",
"(",
"n",
")",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON handles either a string or a number
// and casts it to string.
|
[
"UnmarshalJSON",
"handles",
"either",
"a",
"string",
"or",
"a",
"number",
"and",
"casts",
"it",
"to",
"string",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/helpers.go#L13-L28
|
18,414
|
ns3777k/go-shodan
|
shodan/info.go
|
GetAPIInfo
|
func (c *Client) GetAPIInfo(ctx context.Context) (*APIInfo, error) {
var apiInfo APIInfo
req, err := c.NewRequest("GET", infoPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &apiInfo); err != nil {
return nil, err
}
return &apiInfo, nil
}
|
go
|
func (c *Client) GetAPIInfo(ctx context.Context) (*APIInfo, error) {
var apiInfo APIInfo
req, err := c.NewRequest("GET", infoPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &apiInfo); err != nil {
return nil, err
}
return &apiInfo, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetAPIInfo",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"APIInfo",
",",
"error",
")",
"{",
"var",
"apiInfo",
"APIInfo",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"infoPath",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"apiInfo",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"apiInfo",
",",
"nil",
"\n",
"}"
] |
// GetAPIInfo returns information about the API plan belonging to the given API key.
|
[
"GetAPIInfo",
"returns",
"information",
"about",
"the",
"API",
"plan",
"belonging",
"to",
"the",
"given",
"API",
"key",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/info.go#L23-L36
|
18,415
|
ns3777k/go-shodan
|
shodan/tools.go
|
GetMyIP
|
func (c *Client) GetMyIP(ctx context.Context) (net.IP, error) {
var ip bytes.Buffer
req, err := c.NewRequest("GET", ipPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &ip); err != nil {
return nil, err
}
return net.ParseIP(strings.Trim(ip.String(), "\"")), nil
}
|
go
|
func (c *Client) GetMyIP(ctx context.Context) (net.IP, error) {
var ip bytes.Buffer
req, err := c.NewRequest("GET", ipPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &ip); err != nil {
return nil, err
}
return net.ParseIP(strings.Trim(ip.String(), "\"")), nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetMyIP",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"net",
".",
"IP",
",",
"error",
")",
"{",
"var",
"ip",
"bytes",
".",
"Buffer",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"ipPath",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"ip",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"net",
".",
"ParseIP",
"(",
"strings",
".",
"Trim",
"(",
"ip",
".",
"String",
"(",
")",
",",
"\"",
"\\\"",
"\"",
")",
")",
",",
"nil",
"\n",
"}"
] |
// GetMyIP returns your current IP address as seen from the Internet
// API key for this method is unnecessary.
|
[
"GetMyIP",
"returns",
"your",
"current",
"IP",
"address",
"as",
"seen",
"from",
"the",
"Internet",
"API",
"key",
"for",
"this",
"method",
"is",
"unnecessary",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/tools.go#L17-L30
|
18,416
|
ns3777k/go-shodan
|
shodan/tools.go
|
GetHTTPHeaders
|
func (c *Client) GetHTTPHeaders(ctx context.Context) (map[string]string, error) {
var headers map[string]string
req, err := c.NewRequest("GET", headersPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &headers); err != nil {
return nil, err
}
return headers, nil
}
|
go
|
func (c *Client) GetHTTPHeaders(ctx context.Context) (map[string]string, error) {
var headers map[string]string
req, err := c.NewRequest("GET", headersPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &headers); err != nil {
return nil, err
}
return headers, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetHTTPHeaders",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"var",
"headers",
"map",
"[",
"string",
"]",
"string",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"headersPath",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"headers",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"headers",
",",
"nil",
"\n",
"}"
] |
// GetHTTPHeaders shows the HTTP headers that your client sends
// when connecting to a webserver.
|
[
"GetHTTPHeaders",
"shows",
"the",
"HTTP",
"headers",
"that",
"your",
"client",
"sends",
"when",
"connecting",
"to",
"a",
"webserver",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/tools.go#L34-L47
|
18,417
|
ns3777k/go-shodan
|
shodan/services.go
|
GetServices
|
func (c *Client) GetServices(ctx context.Context) (map[string]string, error) {
var services map[string]string
req, err := c.NewRequest("GET", servicesPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &services); err != nil {
return nil, err
}
return services, err
}
|
go
|
func (c *Client) GetServices(ctx context.Context) (map[string]string, error) {
var services map[string]string
req, err := c.NewRequest("GET", servicesPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &services); err != nil {
return nil, err
}
return services, err
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetServices",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"var",
"services",
"map",
"[",
"string",
"]",
"string",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"servicesPath",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"services",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"services",
",",
"err",
"\n",
"}"
] |
// GetServices returns an object containing all the services that the Shodan crawlers look at
// It can also be used as a quick and practical way to resolve a port number to the name of a service
|
[
"GetServices",
"returns",
"an",
"object",
"containing",
"all",
"the",
"services",
"that",
"the",
"Shodan",
"crawlers",
"look",
"at",
"It",
"can",
"also",
"be",
"used",
"as",
"a",
"quick",
"and",
"practical",
"way",
"to",
"resolve",
"a",
"port",
"number",
"to",
"the",
"name",
"of",
"a",
"service"
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/services.go#L13-L26
|
18,418
|
ns3777k/go-shodan
|
shodan/stream.go
|
NewStreamingRequest
|
func (c *Client) NewStreamingRequest(path string, params interface{}) (*http.Request, error) {
u, err := url.Parse(c.StreamBaseURL + path)
if err != nil {
return nil, err
}
return c.newRequest("GET", u, params, nil)
}
|
go
|
func (c *Client) NewStreamingRequest(path string, params interface{}) (*http.Request, error) {
u, err := url.Parse(c.StreamBaseURL + path)
if err != nil {
return nil, err
}
return c.newRequest("GET", u, params, nil)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"NewStreamingRequest",
"(",
"path",
"string",
",",
"params",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"c",
".",
"StreamBaseURL",
"+",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"newRequest",
"(",
"\"",
"\"",
",",
"u",
",",
"params",
",",
"nil",
")",
"\n",
"}"
] |
// NewStreamingRequest prepares new request to streaming api.
|
[
"NewStreamingRequest",
"prepares",
"new",
"request",
"to",
"streaming",
"api",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/stream.go#L53-L60
|
18,419
|
ns3777k/go-shodan
|
shodan/stream.go
|
DoStream
|
func (c *Client) DoStream(ctx context.Context, req *http.Request) (*http.Response, error) {
resp, err := c.do(ctx, req)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
resp.Body.Close()
return nil, getErrorFromResponse(resp)
}
return resp, nil
}
|
go
|
func (c *Client) DoStream(ctx context.Context, req *http.Request) (*http.Response, error) {
resp, err := c.do(ctx, req)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
resp.Body.Close()
return nil, getErrorFromResponse(resp)
}
return resp, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"DoStream",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"c",
".",
"do",
"(",
"ctx",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"getErrorFromResponse",
"(",
"resp",
")",
"\n",
"}",
"\n\n",
"return",
"resp",
",",
"nil",
"\n",
"}"
] |
// DoStream executes streaming request.
|
[
"DoStream",
"executes",
"streaming",
"request",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/stream.go#L63-L75
|
18,420
|
ns3777k/go-shodan
|
shodan/stream.go
|
startStreaming
|
func (c *Client) startStreaming(ctx context.Context, path string) (*http.Response, error) {
req, err := c.NewStreamingRequest(path, nil)
if err != nil {
return nil, err
}
resp, err := c.DoStream(ctx, req)
if err != nil {
return nil, err
}
return resp, nil
}
|
go
|
func (c *Client) startStreaming(ctx context.Context, path string) (*http.Response, error) {
req, err := c.NewStreamingRequest(path, nil)
if err != nil {
return nil, err
}
resp, err := c.DoStream(ctx, req)
if err != nil {
return nil, err
}
return resp, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"startStreaming",
"(",
"ctx",
"context",
".",
"Context",
",",
"path",
"string",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewStreamingRequest",
"(",
"path",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"c",
".",
"DoStream",
"(",
"ctx",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"resp",
",",
"nil",
"\n",
"}"
] |
// startStreaming creates new streaming request and sends it.
|
[
"startStreaming",
"creates",
"new",
"streaming",
"request",
"and",
"sends",
"it",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/stream.go#L78-L90
|
18,421
|
ns3777k/go-shodan
|
shodan/stream.go
|
GetBannersByASN
|
func (c *Client) GetBannersByASN(ctx context.Context, asn []string, ch chan *HostData) error {
path := fmt.Sprintf(bannersASNPath, strings.Join(asn, ","))
resp, err := c.startStreaming(ctx, path)
if err != nil {
return err
}
go c.handleResponseStream(resp, ch)
return nil
}
|
go
|
func (c *Client) GetBannersByASN(ctx context.Context, asn []string, ch chan *HostData) error {
path := fmt.Sprintf(bannersASNPath, strings.Join(asn, ","))
resp, err := c.startStreaming(ctx, path)
if err != nil {
return err
}
go c.handleResponseStream(resp, ch)
return nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetBannersByASN",
"(",
"ctx",
"context",
".",
"Context",
",",
"asn",
"[",
"]",
"string",
",",
"ch",
"chan",
"*",
"HostData",
")",
"error",
"{",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"bannersASNPath",
",",
"strings",
".",
"Join",
"(",
"asn",
",",
"\"",
"\"",
")",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"startStreaming",
"(",
"ctx",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"go",
"c",
".",
"handleResponseStream",
"(",
"resp",
",",
"ch",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// GetBannersByASN provides a filtered, bandwidth-saving view of the Banners stream in case
// you are only interested in devices located in certain ASNs.
|
[
"GetBannersByASN",
"provides",
"a",
"filtered",
"bandwidth",
"-",
"saving",
"view",
"of",
"the",
"Banners",
"stream",
"in",
"case",
"you",
"are",
"only",
"interested",
"in",
"devices",
"located",
"in",
"certain",
"ASNs",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/stream.go#L94-L104
|
18,422
|
ns3777k/go-shodan
|
shodan/stream.go
|
GetBannersByCountries
|
func (c *Client) GetBannersByCountries(ctx context.Context, countries []string, ch chan *HostData) error {
strCountries := make([]string, 0)
for _, country := range countries {
strCountries = append(strCountries, strings.ToUpper(country))
}
path := fmt.Sprintf(bannersCountryPath, strings.Join(strCountries, ","))
resp, err := c.startStreaming(ctx, path)
if err != nil {
return err
}
go c.handleResponseStream(resp, ch)
return nil
}
|
go
|
func (c *Client) GetBannersByCountries(ctx context.Context, countries []string, ch chan *HostData) error {
strCountries := make([]string, 0)
for _, country := range countries {
strCountries = append(strCountries, strings.ToUpper(country))
}
path := fmt.Sprintf(bannersCountryPath, strings.Join(strCountries, ","))
resp, err := c.startStreaming(ctx, path)
if err != nil {
return err
}
go c.handleResponseStream(resp, ch)
return nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetBannersByCountries",
"(",
"ctx",
"context",
".",
"Context",
",",
"countries",
"[",
"]",
"string",
",",
"ch",
"chan",
"*",
"HostData",
")",
"error",
"{",
"strCountries",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"for",
"_",
",",
"country",
":=",
"range",
"countries",
"{",
"strCountries",
"=",
"append",
"(",
"strCountries",
",",
"strings",
".",
"ToUpper",
"(",
"country",
")",
")",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"bannersCountryPath",
",",
"strings",
".",
"Join",
"(",
"strCountries",
",",
"\"",
"\"",
")",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"startStreaming",
"(",
"ctx",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"go",
"c",
".",
"handleResponseStream",
"(",
"resp",
",",
"ch",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// GetBannersByCountries provides a filtered, bandwidth-saving view of the Banners
// stream in case you are only interested in devices located in certain countries.
|
[
"GetBannersByCountries",
"provides",
"a",
"filtered",
"bandwidth",
"-",
"saving",
"view",
"of",
"the",
"Banners",
"stream",
"in",
"case",
"you",
"are",
"only",
"interested",
"in",
"devices",
"located",
"in",
"certain",
"countries",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/stream.go#L108-L123
|
18,423
|
ns3777k/go-shodan
|
shodan/stream.go
|
GetBannersByPorts
|
func (c *Client) GetBannersByPorts(ctx context.Context, ports []int, ch chan *HostData) error {
strPorts := make([]string, 0)
for _, port := range ports {
strPorts = append(strPorts, strconv.Itoa(port))
}
path := fmt.Sprintf(bannersPortsPath, strings.Join(strPorts, ","))
resp, err := c.startStreaming(ctx, path)
if err != nil {
return err
}
go c.handleResponseStream(resp, ch)
return nil
}
|
go
|
func (c *Client) GetBannersByPorts(ctx context.Context, ports []int, ch chan *HostData) error {
strPorts := make([]string, 0)
for _, port := range ports {
strPorts = append(strPorts, strconv.Itoa(port))
}
path := fmt.Sprintf(bannersPortsPath, strings.Join(strPorts, ","))
resp, err := c.startStreaming(ctx, path)
if err != nil {
return err
}
go c.handleResponseStream(resp, ch)
return nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetBannersByPorts",
"(",
"ctx",
"context",
".",
"Context",
",",
"ports",
"[",
"]",
"int",
",",
"ch",
"chan",
"*",
"HostData",
")",
"error",
"{",
"strPorts",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"for",
"_",
",",
"port",
":=",
"range",
"ports",
"{",
"strPorts",
"=",
"append",
"(",
"strPorts",
",",
"strconv",
".",
"Itoa",
"(",
"port",
")",
")",
"\n",
"}",
"\n\n",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"bannersPortsPath",
",",
"strings",
".",
"Join",
"(",
"strPorts",
",",
"\"",
"\"",
")",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"startStreaming",
"(",
"ctx",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"go",
"c",
".",
"handleResponseStream",
"(",
"resp",
",",
"ch",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// GetBannersByPorts returns only banner data for the list of specified hosts.
// This stream provides a filtered, bandwidth-saving view of the Banners stream
// in case you are only interested in a specific list of ports.
|
[
"GetBannersByPorts",
"returns",
"only",
"banner",
"data",
"for",
"the",
"list",
"of",
"specified",
"hosts",
".",
"This",
"stream",
"provides",
"a",
"filtered",
"bandwidth",
"-",
"saving",
"view",
"of",
"the",
"Banners",
"stream",
"in",
"case",
"you",
"are",
"only",
"interested",
"in",
"a",
"specific",
"list",
"of",
"ports",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/stream.go#L128-L143
|
18,424
|
ns3777k/go-shodan
|
shodan/stream.go
|
GetBannersByAlert
|
func (c *Client) GetBannersByAlert(ctx context.Context, id string, ch chan *HostData) error {
path := fmt.Sprintf(bannersAlertPath, id)
resp, err := c.startStreaming(ctx, path)
if err != nil {
return err
}
go c.handleResponseStream(resp, ch)
return nil
}
|
go
|
func (c *Client) GetBannersByAlert(ctx context.Context, id string, ch chan *HostData) error {
path := fmt.Sprintf(bannersAlertPath, id)
resp, err := c.startStreaming(ctx, path)
if err != nil {
return err
}
go c.handleResponseStream(resp, ch)
return nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetBannersByAlert",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
",",
"ch",
"chan",
"*",
"HostData",
")",
"error",
"{",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"bannersAlertPath",
",",
"id",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"startStreaming",
"(",
"ctx",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"go",
"c",
".",
"handleResponseStream",
"(",
"resp",
",",
"ch",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// GetBannersByAlert subscribes to banners discovered on the IP range defined
// in a specific network alert.
|
[
"GetBannersByAlert",
"subscribes",
"to",
"banners",
"discovered",
"on",
"the",
"IP",
"range",
"defined",
"in",
"a",
"specific",
"network",
"alert",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/stream.go#L147-L157
|
18,425
|
ns3777k/go-shodan
|
shodan/stream.go
|
GetBannersByAlerts
|
func (c *Client) GetBannersByAlerts(ctx context.Context, ch chan *HostData) error {
resp, err := c.startStreaming(ctx, bannersAlertsPath)
if err != nil {
return err
}
go c.handleResponseStream(resp, ch)
return nil
}
|
go
|
func (c *Client) GetBannersByAlerts(ctx context.Context, ch chan *HostData) error {
resp, err := c.startStreaming(ctx, bannersAlertsPath)
if err != nil {
return err
}
go c.handleResponseStream(resp, ch)
return nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetBannersByAlerts",
"(",
"ctx",
"context",
".",
"Context",
",",
"ch",
"chan",
"*",
"HostData",
")",
"error",
"{",
"resp",
",",
"err",
":=",
"c",
".",
"startStreaming",
"(",
"ctx",
",",
"bannersAlertsPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"go",
"c",
".",
"handleResponseStream",
"(",
"resp",
",",
"ch",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// GetBannersByAlerts subscribes to banners discovered on all IP ranges described
// in the network alerts.
|
[
"GetBannersByAlerts",
"subscribes",
"to",
"banners",
"discovered",
"on",
"all",
"IP",
"ranges",
"described",
"in",
"the",
"network",
"alerts",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/stream.go#L161-L170
|
18,426
|
ns3777k/go-shodan
|
shodan/ports.go
|
GetPorts
|
func (c *Client) GetPorts(ctx context.Context) ([]int, error) {
var ports []int
req, err := c.NewRequest("GET", portsPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &ports); err != nil {
return nil, err
}
return ports, nil
}
|
go
|
func (c *Client) GetPorts(ctx context.Context) ([]int, error) {
var ports []int
req, err := c.NewRequest("GET", portsPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &ports); err != nil {
return nil, err
}
return ports, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetPorts",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"int",
",",
"error",
")",
"{",
"var",
"ports",
"[",
"]",
"int",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"portsPath",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"ports",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ports",
",",
"nil",
"\n",
"}"
] |
// GetPorts returns a list of port numbers that the crawlers are looking for
|
[
"GetPorts",
"returns",
"a",
"list",
"of",
"port",
"numbers",
"that",
"the",
"crawlers",
"are",
"looking",
"for"
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/ports.go#L12-L25
|
18,427
|
ns3777k/go-shodan
|
shodan/exploits.go
|
SearchExploits
|
func (c *Client) SearchExploits(ctx context.Context, options *ExploitSearchOptions) (*ExploitSearch, error) {
if options == nil || options.Query == "" {
return nil, ErrInvalidQuery
}
req, err := c.NewExploitRequest("GET", exploitSearchPath, options, nil)
if err != nil {
return nil, err
}
var found ExploitSearch
if err := c.Do(ctx, req, &found); err != nil {
return nil, err
}
return &found, nil
}
|
go
|
func (c *Client) SearchExploits(ctx context.Context, options *ExploitSearchOptions) (*ExploitSearch, error) {
if options == nil || options.Query == "" {
return nil, ErrInvalidQuery
}
req, err := c.NewExploitRequest("GET", exploitSearchPath, options, nil)
if err != nil {
return nil, err
}
var found ExploitSearch
if err := c.Do(ctx, req, &found); err != nil {
return nil, err
}
return &found, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"SearchExploits",
"(",
"ctx",
"context",
".",
"Context",
",",
"options",
"*",
"ExploitSearchOptions",
")",
"(",
"*",
"ExploitSearch",
",",
"error",
")",
"{",
"if",
"options",
"==",
"nil",
"||",
"options",
".",
"Query",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrInvalidQuery",
"\n",
"}",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewExploitRequest",
"(",
"\"",
"\"",
",",
"exploitSearchPath",
",",
"options",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"found",
"ExploitSearch",
"\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"found",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"found",
",",
"nil",
"\n",
"}"
] |
// SearchExploits searches across a variety of data sources for exploits and
// use facets to get summary information.
|
[
"SearchExploits",
"searches",
"across",
"a",
"variety",
"of",
"data",
"sources",
"for",
"exploits",
"and",
"use",
"facets",
"to",
"get",
"summary",
"information",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/exploits.go#L165-L181
|
18,428
|
ns3777k/go-shodan
|
shodan/query.go
|
GetQueryTags
|
func (c *Client) GetQueryTags(ctx context.Context, options *QueryTagsOptions) (*QueryTags, error) {
var queryTags QueryTags
req, err := c.NewRequest("GET", queryTagsPath, options, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &queryTags); err != nil {
return nil, err
}
return &queryTags, nil
}
|
go
|
func (c *Client) GetQueryTags(ctx context.Context, options *QueryTagsOptions) (*QueryTags, error) {
var queryTags QueryTags
req, err := c.NewRequest("GET", queryTagsPath, options, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &queryTags); err != nil {
return nil, err
}
return &queryTags, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetQueryTags",
"(",
"ctx",
"context",
".",
"Context",
",",
"options",
"*",
"QueryTagsOptions",
")",
"(",
"*",
"QueryTags",
",",
"error",
")",
"{",
"var",
"queryTags",
"QueryTags",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"queryTagsPath",
",",
"options",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"queryTags",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"queryTags",
",",
"nil",
"\n",
"}"
] |
// GetQueryTags obtains a list of popular tags for the saved search queries in Shodan.
|
[
"GetQueryTags",
"obtains",
"a",
"list",
"of",
"popular",
"tags",
"for",
"the",
"saved",
"search",
"queries",
"in",
"Shodan",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/query.go#L69-L82
|
18,429
|
ns3777k/go-shodan
|
shodan/query.go
|
GetQueries
|
func (c *Client) GetQueries(ctx context.Context, options *QueryOptions) (*QuerySearch, error) {
var querySearch QuerySearch
req, err := c.NewRequest("GET", queryPath, options, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &querySearch); err != nil {
return nil, err
}
return &querySearch, nil
}
|
go
|
func (c *Client) GetQueries(ctx context.Context, options *QueryOptions) (*QuerySearch, error) {
var querySearch QuerySearch
req, err := c.NewRequest("GET", queryPath, options, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &querySearch); err != nil {
return nil, err
}
return &querySearch, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetQueries",
"(",
"ctx",
"context",
".",
"Context",
",",
"options",
"*",
"QueryOptions",
")",
"(",
"*",
"QuerySearch",
",",
"error",
")",
"{",
"var",
"querySearch",
"QuerySearch",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"queryPath",
",",
"options",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"querySearch",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"querySearch",
",",
"nil",
"\n",
"}"
] |
// GetQueries obtains a list of search queries that users have saved in Shodan.
|
[
"GetQueries",
"obtains",
"a",
"list",
"of",
"search",
"queries",
"that",
"users",
"have",
"saved",
"in",
"Shodan",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/query.go#L85-L98
|
18,430
|
ns3777k/go-shodan
|
shodan/query.go
|
SearchQueries
|
func (c *Client) SearchQueries(ctx context.Context, options *SearchQueryOptions) (*QuerySearch, error) {
if options == nil || options.Query == "" {
return nil, ErrInvalidQuery
}
var querySearch QuerySearch
req, err := c.NewRequest("GET", querySearchPath, options, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &querySearch); err != nil {
return nil, err
}
return &querySearch, nil
}
|
go
|
func (c *Client) SearchQueries(ctx context.Context, options *SearchQueryOptions) (*QuerySearch, error) {
if options == nil || options.Query == "" {
return nil, ErrInvalidQuery
}
var querySearch QuerySearch
req, err := c.NewRequest("GET", querySearchPath, options, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &querySearch); err != nil {
return nil, err
}
return &querySearch, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"SearchQueries",
"(",
"ctx",
"context",
".",
"Context",
",",
"options",
"*",
"SearchQueryOptions",
")",
"(",
"*",
"QuerySearch",
",",
"error",
")",
"{",
"if",
"options",
"==",
"nil",
"||",
"options",
".",
"Query",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrInvalidQuery",
"\n",
"}",
"\n\n",
"var",
"querySearch",
"QuerySearch",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"querySearchPath",
",",
"options",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"&",
"querySearch",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"querySearch",
",",
"nil",
"\n",
"}"
] |
// SearchQueries searches the directory of search queries that users have saved in Shodan.
|
[
"SearchQueries",
"searches",
"the",
"directory",
"of",
"search",
"queries",
"that",
"users",
"have",
"saved",
"in",
"Shodan",
"."
] |
1320f6c93371f1828788ee9b7f3fcf568de18142
|
https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/query.go#L101-L118
|
18,431
|
brian-armstrong/gpio
|
watcher.go
|
NewWatcher
|
func NewWatcher() *Watcher {
w := &Watcher{
pins: make(map[uintptr]Pin),
fds: fdHeap{},
cmdChan: make(chan watcherCmd, watcherCmdChanLen),
Notification: make(chan WatcherNotification, notificationLen),
}
heap.Init(&w.fds)
go w.watch()
return w
}
|
go
|
func NewWatcher() *Watcher {
w := &Watcher{
pins: make(map[uintptr]Pin),
fds: fdHeap{},
cmdChan: make(chan watcherCmd, watcherCmdChanLen),
Notification: make(chan WatcherNotification, notificationLen),
}
heap.Init(&w.fds)
go w.watch()
return w
}
|
[
"func",
"NewWatcher",
"(",
")",
"*",
"Watcher",
"{",
"w",
":=",
"&",
"Watcher",
"{",
"pins",
":",
"make",
"(",
"map",
"[",
"uintptr",
"]",
"Pin",
")",
",",
"fds",
":",
"fdHeap",
"{",
"}",
",",
"cmdChan",
":",
"make",
"(",
"chan",
"watcherCmd",
",",
"watcherCmdChanLen",
")",
",",
"Notification",
":",
"make",
"(",
"chan",
"WatcherNotification",
",",
"notificationLen",
")",
",",
"}",
"\n",
"heap",
".",
"Init",
"(",
"&",
"w",
".",
"fds",
")",
"\n",
"go",
"w",
".",
"watch",
"(",
")",
"\n",
"return",
"w",
"\n",
"}"
] |
// NewWatcher creates a new Watcher instance for asynchronous inputs
|
[
"NewWatcher",
"creates",
"a",
"new",
"Watcher",
"instance",
"for",
"asynchronous",
"inputs"
] |
72b0058bbbcb724245929a8778d844e5b4fc639f
|
https://github.com/brian-armstrong/gpio/blob/72b0058bbbcb724245929a8778d844e5b4fc639f/watcher.go#L74-L84
|
18,432
|
brian-armstrong/gpio
|
watcher.go
|
removePin
|
func (w *Watcher) removePin(p Pin) {
// we don't index by pin, so go looking
for fd, pin := range w.pins {
if pin.Number == p.Number {
// found pin
w.removeFd(fd)
return
}
}
}
|
go
|
func (w *Watcher) removePin(p Pin) {
// we don't index by pin, so go looking
for fd, pin := range w.pins {
if pin.Number == p.Number {
// found pin
w.removeFd(fd)
return
}
}
}
|
[
"func",
"(",
"w",
"*",
"Watcher",
")",
"removePin",
"(",
"p",
"Pin",
")",
"{",
"// we don't index by pin, so go looking",
"for",
"fd",
",",
"pin",
":=",
"range",
"w",
".",
"pins",
"{",
"if",
"pin",
".",
"Number",
"==",
"p",
".",
"Number",
"{",
"// found pin",
"w",
".",
"removeFd",
"(",
"fd",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// removePin is only a wrapper around removeFd
// it finds fd given pin and then calls removeFd
|
[
"removePin",
"is",
"only",
"a",
"wrapper",
"around",
"removeFd",
"it",
"finds",
"fd",
"given",
"pin",
"and",
"then",
"calls",
"removeFd"
] |
72b0058bbbcb724245929a8778d844e5b4fc639f
|
https://github.com/brian-armstrong/gpio/blob/72b0058bbbcb724245929a8778d844e5b4fc639f/watcher.go#L148-L157
|
18,433
|
brian-armstrong/gpio
|
watcher.go
|
AddPin
|
func (w *Watcher) AddPin(p uint) {
w.AddPinWithEdgeAndLogic(p, EdgeBoth, ActiveHigh)
}
|
go
|
func (w *Watcher) AddPin(p uint) {
w.AddPinWithEdgeAndLogic(p, EdgeBoth, ActiveHigh)
}
|
[
"func",
"(",
"w",
"*",
"Watcher",
")",
"AddPin",
"(",
"p",
"uint",
")",
"{",
"w",
".",
"AddPinWithEdgeAndLogic",
"(",
"p",
",",
"EdgeBoth",
",",
"ActiveHigh",
")",
"\n",
"}"
] |
// AddPin adds a new pin to be watched for changes.
// The pin is configured with logic level "active high"
// and watched for both rising and falling edges.
// The pin provided should be the pin known by the kernel
|
[
"AddPin",
"adds",
"a",
"new",
"pin",
"to",
"be",
"watched",
"for",
"changes",
".",
"The",
"pin",
"is",
"configured",
"with",
"logic",
"level",
"active",
"high",
"and",
"watched",
"for",
"both",
"rising",
"and",
"falling",
"edges",
".",
"The",
"pin",
"provided",
"should",
"be",
"the",
"pin",
"known",
"by",
"the",
"kernel"
] |
72b0058bbbcb724245929a8778d844e5b4fc639f
|
https://github.com/brian-armstrong/gpio/blob/72b0058bbbcb724245929a8778d844e5b4fc639f/watcher.go#L206-L208
|
18,434
|
brian-armstrong/gpio
|
watcher.go
|
AddPinWithEdgeAndLogic
|
func (w *Watcher) AddPinWithEdgeAndLogic(p uint, edge Edge, logicLevel LogicLevel) {
pin := NewInput(p)
setLogicLevel(pin, logicLevel)
setEdgeTrigger(pin, edge)
w.cmdChan <- watcherCmd{
pin: pin,
action: watcherAdd,
}
}
|
go
|
func (w *Watcher) AddPinWithEdgeAndLogic(p uint, edge Edge, logicLevel LogicLevel) {
pin := NewInput(p)
setLogicLevel(pin, logicLevel)
setEdgeTrigger(pin, edge)
w.cmdChan <- watcherCmd{
pin: pin,
action: watcherAdd,
}
}
|
[
"func",
"(",
"w",
"*",
"Watcher",
")",
"AddPinWithEdgeAndLogic",
"(",
"p",
"uint",
",",
"edge",
"Edge",
",",
"logicLevel",
"LogicLevel",
")",
"{",
"pin",
":=",
"NewInput",
"(",
"p",
")",
"\n",
"setLogicLevel",
"(",
"pin",
",",
"logicLevel",
")",
"\n",
"setEdgeTrigger",
"(",
"pin",
",",
"edge",
")",
"\n",
"w",
".",
"cmdChan",
"<-",
"watcherCmd",
"{",
"pin",
":",
"pin",
",",
"action",
":",
"watcherAdd",
",",
"}",
"\n",
"}"
] |
// AddPinWithEdgeAndLogic adds a new pin to be watched for changes.
// Edges can be configured to be either rising, falling, or both.
// Logic level can be active high or active low.
// The pin provided should be the pin known by the kernel.
|
[
"AddPinWithEdgeAndLogic",
"adds",
"a",
"new",
"pin",
"to",
"be",
"watched",
"for",
"changes",
".",
"Edges",
"can",
"be",
"configured",
"to",
"be",
"either",
"rising",
"falling",
"or",
"both",
".",
"Logic",
"level",
"can",
"be",
"active",
"high",
"or",
"active",
"low",
".",
"The",
"pin",
"provided",
"should",
"be",
"the",
"pin",
"known",
"by",
"the",
"kernel",
"."
] |
72b0058bbbcb724245929a8778d844e5b4fc639f
|
https://github.com/brian-armstrong/gpio/blob/72b0058bbbcb724245929a8778d844e5b4fc639f/watcher.go#L214-L222
|
18,435
|
brian-armstrong/gpio
|
watcher.go
|
RemovePin
|
func (w *Watcher) RemovePin(p uint) {
pin := Pin{
Number: p,
}
w.cmdChan <- watcherCmd{
pin: pin,
action: watcherRemove,
}
}
|
go
|
func (w *Watcher) RemovePin(p uint) {
pin := Pin{
Number: p,
}
w.cmdChan <- watcherCmd{
pin: pin,
action: watcherRemove,
}
}
|
[
"func",
"(",
"w",
"*",
"Watcher",
")",
"RemovePin",
"(",
"p",
"uint",
")",
"{",
"pin",
":=",
"Pin",
"{",
"Number",
":",
"p",
",",
"}",
"\n",
"w",
".",
"cmdChan",
"<-",
"watcherCmd",
"{",
"pin",
":",
"pin",
",",
"action",
":",
"watcherRemove",
",",
"}",
"\n",
"}"
] |
// RemovePin stops the watcher from watching the specified pin
|
[
"RemovePin",
"stops",
"the",
"watcher",
"from",
"watching",
"the",
"specified",
"pin"
] |
72b0058bbbcb724245929a8778d844e5b4fc639f
|
https://github.com/brian-armstrong/gpio/blob/72b0058bbbcb724245929a8778d844e5b4fc639f/watcher.go#L225-L233
|
18,436
|
brian-armstrong/gpio
|
watcher.go
|
Close
|
func (w *Watcher) Close() {
w.cmdChan <- watcherCmd{
pin: Pin{},
action: watcherClose,
}
}
|
go
|
func (w *Watcher) Close() {
w.cmdChan <- watcherCmd{
pin: Pin{},
action: watcherClose,
}
}
|
[
"func",
"(",
"w",
"*",
"Watcher",
")",
"Close",
"(",
")",
"{",
"w",
".",
"cmdChan",
"<-",
"watcherCmd",
"{",
"pin",
":",
"Pin",
"{",
"}",
",",
"action",
":",
"watcherClose",
",",
"}",
"\n",
"}"
] |
// Close stops the watcher and releases all resources
|
[
"Close",
"stops",
"the",
"watcher",
"and",
"releases",
"all",
"resources"
] |
72b0058bbbcb724245929a8778d844e5b4fc639f
|
https://github.com/brian-armstrong/gpio/blob/72b0058bbbcb724245929a8778d844e5b4fc639f/watcher.go#L247-L252
|
18,437
|
brian-armstrong/gpio
|
io.go
|
NewInput
|
func NewInput(p uint) Pin {
pin := Pin{
Number: p,
}
exportGPIO(pin)
time.Sleep(10 * time.Millisecond)
pin.direction = inDirection
setDirection(pin, inDirection, 0)
pin = openPin(pin, false)
return pin
}
|
go
|
func NewInput(p uint) Pin {
pin := Pin{
Number: p,
}
exportGPIO(pin)
time.Sleep(10 * time.Millisecond)
pin.direction = inDirection
setDirection(pin, inDirection, 0)
pin = openPin(pin, false)
return pin
}
|
[
"func",
"NewInput",
"(",
"p",
"uint",
")",
"Pin",
"{",
"pin",
":=",
"Pin",
"{",
"Number",
":",
"p",
",",
"}",
"\n",
"exportGPIO",
"(",
"pin",
")",
"\n",
"time",
".",
"Sleep",
"(",
"10",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"pin",
".",
"direction",
"=",
"inDirection",
"\n",
"setDirection",
"(",
"pin",
",",
"inDirection",
",",
"0",
")",
"\n",
"pin",
"=",
"openPin",
"(",
"pin",
",",
"false",
")",
"\n",
"return",
"pin",
"\n",
"}"
] |
// NewInput opens the given pin number for reading. The number provided should be the pin number known by the kernel
|
[
"NewInput",
"opens",
"the",
"given",
"pin",
"number",
"for",
"reading",
".",
"The",
"number",
"provided",
"should",
"be",
"the",
"pin",
"number",
"known",
"by",
"the",
"kernel"
] |
72b0058bbbcb724245929a8778d844e5b4fc639f
|
https://github.com/brian-armstrong/gpio/blob/72b0058bbbcb724245929a8778d844e5b4fc639f/io.go#L17-L27
|
18,438
|
brian-armstrong/gpio
|
io.go
|
Read
|
func (p Pin) Read() (value uint, err error) {
if p.direction != inDirection {
return 0, errors.New("pin is not configured for input")
}
return readPin(p)
}
|
go
|
func (p Pin) Read() (value uint, err error) {
if p.direction != inDirection {
return 0, errors.New("pin is not configured for input")
}
return readPin(p)
}
|
[
"func",
"(",
"p",
"Pin",
")",
"Read",
"(",
")",
"(",
"value",
"uint",
",",
"err",
"error",
")",
"{",
"if",
"p",
".",
"direction",
"!=",
"inDirection",
"{",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"readPin",
"(",
"p",
")",
"\n",
"}"
] |
// Read returns the value read at the pin as reported by the kernel. This should only be used for input pins
|
[
"Read",
"returns",
"the",
"value",
"read",
"at",
"the",
"pin",
"as",
"reported",
"by",
"the",
"kernel",
".",
"This",
"should",
"only",
"be",
"used",
"for",
"input",
"pins"
] |
72b0058bbbcb724245929a8778d844e5b4fc639f
|
https://github.com/brian-armstrong/gpio/blob/72b0058bbbcb724245929a8778d844e5b4fc639f/io.go#L62-L67
|
18,439
|
brian-armstrong/gpio
|
io.go
|
High
|
func (p Pin) High() error {
if p.direction != outDirection {
return errors.New("pin is not configured for output")
}
return writePin(p, 1)
}
|
go
|
func (p Pin) High() error {
if p.direction != outDirection {
return errors.New("pin is not configured for output")
}
return writePin(p, 1)
}
|
[
"func",
"(",
"p",
"Pin",
")",
"High",
"(",
")",
"error",
"{",
"if",
"p",
".",
"direction",
"!=",
"outDirection",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"writePin",
"(",
"p",
",",
"1",
")",
"\n",
"}"
] |
// High sets the value of an output pin to logic high
|
[
"High",
"sets",
"the",
"value",
"of",
"an",
"output",
"pin",
"to",
"logic",
"high"
] |
72b0058bbbcb724245929a8778d844e5b4fc639f
|
https://github.com/brian-armstrong/gpio/blob/72b0058bbbcb724245929a8778d844e5b4fc639f/io.go#L76-L81
|
18,440
|
mailhog/mhsendmail
|
cmd/cmd.go
|
Go
|
func Go() {
host, err := os.Hostname()
if err != nil {
host = "localhost"
}
username := "nobody"
user, err := user.Current()
if err == nil && user != nil && len(user.Username) > 0 {
username = user.Username
}
fromAddr := username + "@" + host
smtpAddr := "localhost:1025"
var recip []string
// defaults from envars if provided
if len(os.Getenv("MH_SENDMAIL_SMTP_ADDR")) > 0 {
smtpAddr = os.Getenv("MH_SENDMAIL_SMTP_ADDR")
}
if len(os.Getenv("MH_SENDMAIL_FROM")) > 0 {
fromAddr = os.Getenv("MH_SENDMAIL_FROM")
}
var verbose bool
// override defaults from cli flags
flag.StringVar(&smtpAddr, "smtp-addr", smtpAddr, "SMTP server address")
flag.StringVarP(&fromAddr, "from", "f", fromAddr, "SMTP sender")
flag.BoolP("long-i", "i", true, "Ignored. This flag exists for sendmail compatibility.")
flag.BoolP("long-o", "o", true, "Ignored. This flag exists for sendmail compatibility.")
flag.BoolP("long-t", "t", true, "Ignored. This flag exists for sendmail compatibility.")
flag.BoolVarP(&verbose, "verbose", "v", false, "Verbose mode (sends debug output to stderr)")
flag.Parse()
// allow recipient to be passed as an argument
recip = flag.Args()
if verbose {
fmt.Fprintln(os.Stderr, smtpAddr, fromAddr)
}
body, err := ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintln(os.Stderr, "error reading stdin")
os.Exit(11)
}
msg, err := mail.ReadMessage(bytes.NewReader(body))
if err != nil {
fmt.Fprintln(os.Stderr, "error parsing message body")
os.Exit(11)
}
if len(recip) == 0 {
// We only need to parse the message to get a recipient if none where
// provided on the command line.
recip = append(recip, msg.Header.Get("To"))
}
err = smtp.SendMail(smtpAddr, nil, fromAddr, recip, body)
if err != nil {
fmt.Fprintln(os.Stderr, "error sending mail")
log.Fatal(err)
}
}
|
go
|
func Go() {
host, err := os.Hostname()
if err != nil {
host = "localhost"
}
username := "nobody"
user, err := user.Current()
if err == nil && user != nil && len(user.Username) > 0 {
username = user.Username
}
fromAddr := username + "@" + host
smtpAddr := "localhost:1025"
var recip []string
// defaults from envars if provided
if len(os.Getenv("MH_SENDMAIL_SMTP_ADDR")) > 0 {
smtpAddr = os.Getenv("MH_SENDMAIL_SMTP_ADDR")
}
if len(os.Getenv("MH_SENDMAIL_FROM")) > 0 {
fromAddr = os.Getenv("MH_SENDMAIL_FROM")
}
var verbose bool
// override defaults from cli flags
flag.StringVar(&smtpAddr, "smtp-addr", smtpAddr, "SMTP server address")
flag.StringVarP(&fromAddr, "from", "f", fromAddr, "SMTP sender")
flag.BoolP("long-i", "i", true, "Ignored. This flag exists for sendmail compatibility.")
flag.BoolP("long-o", "o", true, "Ignored. This flag exists for sendmail compatibility.")
flag.BoolP("long-t", "t", true, "Ignored. This flag exists for sendmail compatibility.")
flag.BoolVarP(&verbose, "verbose", "v", false, "Verbose mode (sends debug output to stderr)")
flag.Parse()
// allow recipient to be passed as an argument
recip = flag.Args()
if verbose {
fmt.Fprintln(os.Stderr, smtpAddr, fromAddr)
}
body, err := ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintln(os.Stderr, "error reading stdin")
os.Exit(11)
}
msg, err := mail.ReadMessage(bytes.NewReader(body))
if err != nil {
fmt.Fprintln(os.Stderr, "error parsing message body")
os.Exit(11)
}
if len(recip) == 0 {
// We only need to parse the message to get a recipient if none where
// provided on the command line.
recip = append(recip, msg.Header.Get("To"))
}
err = smtp.SendMail(smtpAddr, nil, fromAddr, recip, body)
if err != nil {
fmt.Fprintln(os.Stderr, "error sending mail")
log.Fatal(err)
}
}
|
[
"func",
"Go",
"(",
")",
"{",
"host",
",",
"err",
":=",
"os",
".",
"Hostname",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"host",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"username",
":=",
"\"",
"\"",
"\n",
"user",
",",
"err",
":=",
"user",
".",
"Current",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"user",
"!=",
"nil",
"&&",
"len",
"(",
"user",
".",
"Username",
")",
">",
"0",
"{",
"username",
"=",
"user",
".",
"Username",
"\n",
"}",
"\n\n",
"fromAddr",
":=",
"username",
"+",
"\"",
"\"",
"+",
"host",
"\n",
"smtpAddr",
":=",
"\"",
"\"",
"\n",
"var",
"recip",
"[",
"]",
"string",
"\n\n",
"// defaults from envars if provided",
"if",
"len",
"(",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
")",
">",
"0",
"{",
"smtpAddr",
"=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
")",
">",
"0",
"{",
"fromAddr",
"=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"verbose",
"bool",
"\n\n",
"// override defaults from cli flags",
"flag",
".",
"StringVar",
"(",
"&",
"smtpAddr",
",",
"\"",
"\"",
",",
"smtpAddr",
",",
"\"",
"\"",
")",
"\n",
"flag",
".",
"StringVarP",
"(",
"&",
"fromAddr",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fromAddr",
",",
"\"",
"\"",
")",
"\n",
"flag",
".",
"BoolP",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"true",
",",
"\"",
"\"",
")",
"\n",
"flag",
".",
"BoolP",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"true",
",",
"\"",
"\"",
")",
"\n",
"flag",
".",
"BoolP",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"true",
",",
"\"",
"\"",
")",
"\n",
"flag",
".",
"BoolVarP",
"(",
"&",
"verbose",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
",",
"\"",
"\"",
")",
"\n",
"flag",
".",
"Parse",
"(",
")",
"\n\n",
"// allow recipient to be passed as an argument",
"recip",
"=",
"flag",
".",
"Args",
"(",
")",
"\n\n",
"if",
"verbose",
"{",
"fmt",
".",
"Fprintln",
"(",
"os",
".",
"Stderr",
",",
"smtpAddr",
",",
"fromAddr",
")",
"\n",
"}",
"\n\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"os",
".",
"Stdin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
")",
"\n",
"os",
".",
"Exit",
"(",
"11",
")",
"\n",
"}",
"\n\n",
"msg",
",",
"err",
":=",
"mail",
".",
"ReadMessage",
"(",
"bytes",
".",
"NewReader",
"(",
"body",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
")",
"\n",
"os",
".",
"Exit",
"(",
"11",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"recip",
")",
"==",
"0",
"{",
"// We only need to parse the message to get a recipient if none where",
"// provided on the command line.",
"recip",
"=",
"append",
"(",
"recip",
",",
"msg",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"smtp",
".",
"SendMail",
"(",
"smtpAddr",
",",
"nil",
",",
"fromAddr",
",",
"recip",
",",
"body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
")",
"\n",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"}"
] |
// Go runs the MailHog sendmail replacement.
|
[
"Go",
"runs",
"the",
"MailHog",
"sendmail",
"replacement",
"."
] |
9e70164f299c9e06af61402e636f5bbdf03e7dbb
|
https://github.com/mailhog/mhsendmail/blob/9e70164f299c9e06af61402e636f5bbdf03e7dbb/cmd/cmd.go#L17-L83
|
18,441
|
ahmetb/go-dexec
|
execution.go
|
ByCreatingContainer
|
func ByCreatingContainer(opts docker.CreateContainerOptions) (Execution, error) {
if opts.Config == nil {
return nil, errors.New("dexec: Config is nil")
}
return &createContainer{opt: opts}, nil
}
|
go
|
func ByCreatingContainer(opts docker.CreateContainerOptions) (Execution, error) {
if opts.Config == nil {
return nil, errors.New("dexec: Config is nil")
}
return &createContainer{opt: opts}, nil
}
|
[
"func",
"ByCreatingContainer",
"(",
"opts",
"docker",
".",
"CreateContainerOptions",
")",
"(",
"Execution",
",",
"error",
")",
"{",
"if",
"opts",
".",
"Config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"createContainer",
"{",
"opt",
":",
"opts",
"}",
",",
"nil",
"\n",
"}"
] |
// ByCreatingContainer is the execution strategy where a new container with specified
// options is created to execute the command.
//
// The container will be created and started with Cmd.Start and will be deleted
// before Cmd.Wait returns.
|
[
"ByCreatingContainer",
"is",
"the",
"execution",
"strategy",
"where",
"a",
"new",
"container",
"with",
"specified",
"options",
"is",
"created",
"to",
"execute",
"the",
"command",
".",
"The",
"container",
"will",
"be",
"created",
"and",
"started",
"with",
"Cmd",
".",
"Start",
"and",
"will",
"be",
"deleted",
"before",
"Cmd",
".",
"Wait",
"returns",
"."
] |
2538e5e2198f293ab61ffcab998efd691276af67
|
https://github.com/ahmetb/go-dexec/blob/2538e5e2198f293ab61ffcab998efd691276af67/execution.go#L34-L39
|
18,442
|
ahmetb/go-dexec
|
cmd.go
|
Command
|
func (d Docker) Command(method Execution, name string, arg ...string) *Cmd {
return &Cmd{Method: method, Path: name, Args: arg, docker: d}
}
|
go
|
func (d Docker) Command(method Execution, name string, arg ...string) *Cmd {
return &Cmd{Method: method, Path: name, Args: arg, docker: d}
}
|
[
"func",
"(",
"d",
"Docker",
")",
"Command",
"(",
"method",
"Execution",
",",
"name",
"string",
",",
"arg",
"...",
"string",
")",
"*",
"Cmd",
"{",
"return",
"&",
"Cmd",
"{",
"Method",
":",
"method",
",",
"Path",
":",
"name",
",",
"Args",
":",
"arg",
",",
"docker",
":",
"d",
"}",
"\n",
"}"
] |
// Command returns the Cmd struct to execute the named program with given
// arguments using specified execution method.
//
// For each new Cmd, you should create a new instance for "method" argument.
|
[
"Command",
"returns",
"the",
"Cmd",
"struct",
"to",
"execute",
"the",
"named",
"program",
"with",
"given",
"arguments",
"using",
"specified",
"execution",
"method",
".",
"For",
"each",
"new",
"Cmd",
"you",
"should",
"create",
"a",
"new",
"instance",
"for",
"method",
"argument",
"."
] |
2538e5e2198f293ab61ffcab998efd691276af67
|
https://github.com/ahmetb/go-dexec/blob/2538e5e2198f293ab61ffcab998efd691276af67/cmd.go#L22-L24
|
18,443
|
ahmetb/go-dexec
|
cmd.go
|
Start
|
func (c *Cmd) Start() error {
if c.Dir != "" {
if err := c.Method.setDir(c.Dir); err != nil {
return err
}
}
if c.Env != nil {
if err := c.Method.setEnv(c.Env); err != nil {
return err
}
}
if c.started {
return errors.New("dexec: already started")
}
c.started = true
if c.Stdin == nil {
c.Stdin = empty
}
if c.Stdout == nil {
c.Stdout = ioutil.Discard
}
if c.Stderr == nil {
c.Stderr = ioutil.Discard
}
cmd := append([]string{c.Path}, c.Args...)
if err := c.Method.create(c.docker, cmd); err != nil {
return err
}
if err := c.Method.run(c.docker, c.Stdin, c.Stdout, c.Stderr); err != nil {
return err
}
return nil
}
|
go
|
func (c *Cmd) Start() error {
if c.Dir != "" {
if err := c.Method.setDir(c.Dir); err != nil {
return err
}
}
if c.Env != nil {
if err := c.Method.setEnv(c.Env); err != nil {
return err
}
}
if c.started {
return errors.New("dexec: already started")
}
c.started = true
if c.Stdin == nil {
c.Stdin = empty
}
if c.Stdout == nil {
c.Stdout = ioutil.Discard
}
if c.Stderr == nil {
c.Stderr = ioutil.Discard
}
cmd := append([]string{c.Path}, c.Args...)
if err := c.Method.create(c.docker, cmd); err != nil {
return err
}
if err := c.Method.run(c.docker, c.Stdin, c.Stdout, c.Stderr); err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"Cmd",
")",
"Start",
"(",
")",
"error",
"{",
"if",
"c",
".",
"Dir",
"!=",
"\"",
"\"",
"{",
"if",
"err",
":=",
"c",
".",
"Method",
".",
"setDir",
"(",
"c",
".",
"Dir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"c",
".",
"Env",
"!=",
"nil",
"{",
"if",
"err",
":=",
"c",
".",
"Method",
".",
"setEnv",
"(",
"c",
".",
"Env",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"started",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"c",
".",
"started",
"=",
"true",
"\n\n",
"if",
"c",
".",
"Stdin",
"==",
"nil",
"{",
"c",
".",
"Stdin",
"=",
"empty",
"\n",
"}",
"\n",
"if",
"c",
".",
"Stdout",
"==",
"nil",
"{",
"c",
".",
"Stdout",
"=",
"ioutil",
".",
"Discard",
"\n",
"}",
"\n",
"if",
"c",
".",
"Stderr",
"==",
"nil",
"{",
"c",
".",
"Stderr",
"=",
"ioutil",
".",
"Discard",
"\n",
"}",
"\n\n",
"cmd",
":=",
"append",
"(",
"[",
"]",
"string",
"{",
"c",
".",
"Path",
"}",
",",
"c",
".",
"Args",
"...",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"Method",
".",
"create",
"(",
"c",
".",
"docker",
",",
"cmd",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"Method",
".",
"run",
"(",
"c",
".",
"docker",
",",
"c",
".",
"Stdin",
",",
"c",
".",
"Stdout",
",",
"c",
".",
"Stderr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Start starts the specified command but does not wait for it to complete.
|
[
"Start",
"starts",
"the",
"specified",
"command",
"but",
"does",
"not",
"wait",
"for",
"it",
"to",
"complete",
"."
] |
2538e5e2198f293ab61ffcab998efd691276af67
|
https://github.com/ahmetb/go-dexec/blob/2538e5e2198f293ab61ffcab998efd691276af67/cmd.go#L71-L106
|
18,444
|
ahmetb/go-dexec
|
cmd.go
|
StdoutPipe
|
func (c *Cmd) StdoutPipe() (io.ReadCloser, error) {
if c.Stdout != nil {
return nil, errors.New("dexec: Stdout already set")
}
pr, pw := io.Pipe()
c.Stdout = pw
c.closeAfterWait = append(c.closeAfterWait, pw)
return pr, nil
}
|
go
|
func (c *Cmd) StdoutPipe() (io.ReadCloser, error) {
if c.Stdout != nil {
return nil, errors.New("dexec: Stdout already set")
}
pr, pw := io.Pipe()
c.Stdout = pw
c.closeAfterWait = append(c.closeAfterWait, pw)
return pr, nil
}
|
[
"func",
"(",
"c",
"*",
"Cmd",
")",
"StdoutPipe",
"(",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"if",
"c",
".",
"Stdout",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"pr",
",",
"pw",
":=",
"io",
".",
"Pipe",
"(",
")",
"\n",
"c",
".",
"Stdout",
"=",
"pw",
"\n",
"c",
".",
"closeAfterWait",
"=",
"append",
"(",
"c",
".",
"closeAfterWait",
",",
"pw",
")",
"\n",
"return",
"pr",
",",
"nil",
"\n",
"}"
] |
// StdoutPipe returns a pipe that will be connected to the command's standard output when
// the command starts.
//
// Wait will close the pipe after seeing the command exit or in error conditions.
|
[
"StdoutPipe",
"returns",
"a",
"pipe",
"that",
"will",
"be",
"connected",
"to",
"the",
"command",
"s",
"standard",
"output",
"when",
"the",
"command",
"starts",
".",
"Wait",
"will",
"close",
"the",
"pipe",
"after",
"seeing",
"the",
"command",
"exit",
"or",
"in",
"error",
"conditions",
"."
] |
2538e5e2198f293ab61ffcab998efd691276af67
|
https://github.com/ahmetb/go-dexec/blob/2538e5e2198f293ab61ffcab998efd691276af67/cmd.go#L206-L214
|
18,445
|
ahmetb/go-dexec
|
cmd.go
|
StderrPipe
|
func (c *Cmd) StderrPipe() (io.ReadCloser, error) {
if c.Stderr != nil {
return nil, errors.New("dexec: Stderr already set")
}
pr, pw := io.Pipe()
c.Stderr = pw
c.closeAfterWait = append(c.closeAfterWait, pw)
return pr, nil
}
|
go
|
func (c *Cmd) StderrPipe() (io.ReadCloser, error) {
if c.Stderr != nil {
return nil, errors.New("dexec: Stderr already set")
}
pr, pw := io.Pipe()
c.Stderr = pw
c.closeAfterWait = append(c.closeAfterWait, pw)
return pr, nil
}
|
[
"func",
"(",
"c",
"*",
"Cmd",
")",
"StderrPipe",
"(",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"if",
"c",
".",
"Stderr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"pr",
",",
"pw",
":=",
"io",
".",
"Pipe",
"(",
")",
"\n",
"c",
".",
"Stderr",
"=",
"pw",
"\n",
"c",
".",
"closeAfterWait",
"=",
"append",
"(",
"c",
".",
"closeAfterWait",
",",
"pw",
")",
"\n",
"return",
"pr",
",",
"nil",
"\n",
"}"
] |
// StderrPipe returns a pipe that will be connected to the command's standard error when
// the command starts.
//
// Wait will close the pipe after seeing the command exit or in error conditions.
|
[
"StderrPipe",
"returns",
"a",
"pipe",
"that",
"will",
"be",
"connected",
"to",
"the",
"command",
"s",
"standard",
"error",
"when",
"the",
"command",
"starts",
".",
"Wait",
"will",
"close",
"the",
"pipe",
"after",
"seeing",
"the",
"command",
"exit",
"or",
"in",
"error",
"conditions",
"."
] |
2538e5e2198f293ab61ffcab998efd691276af67
|
https://github.com/ahmetb/go-dexec/blob/2538e5e2198f293ab61ffcab998efd691276af67/cmd.go#L220-L228
|
18,446
|
aeden/traceroute
|
traceroute.go
|
socketAddr
|
func socketAddr() (addr [4]byte, err error) {
addrs, err := net.InterfaceAddrs()
if err != nil {
return
}
for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if len(ipnet.IP.To4()) == net.IPv4len {
copy(addr[:], ipnet.IP.To4())
return
}
}
}
err = errors.New("You do not appear to be connected to the Internet")
return
}
|
go
|
func socketAddr() (addr [4]byte, err error) {
addrs, err := net.InterfaceAddrs()
if err != nil {
return
}
for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if len(ipnet.IP.To4()) == net.IPv4len {
copy(addr[:], ipnet.IP.To4())
return
}
}
}
err = errors.New("You do not appear to be connected to the Internet")
return
}
|
[
"func",
"socketAddr",
"(",
")",
"(",
"addr",
"[",
"4",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"addrs",
",",
"err",
":=",
"net",
".",
"InterfaceAddrs",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"a",
":=",
"range",
"addrs",
"{",
"if",
"ipnet",
",",
"ok",
":=",
"a",
".",
"(",
"*",
"net",
".",
"IPNet",
")",
";",
"ok",
"&&",
"!",
"ipnet",
".",
"IP",
".",
"IsLoopback",
"(",
")",
"{",
"if",
"len",
"(",
"ipnet",
".",
"IP",
".",
"To4",
"(",
")",
")",
"==",
"net",
".",
"IPv4len",
"{",
"copy",
"(",
"addr",
"[",
":",
"]",
",",
"ipnet",
".",
"IP",
".",
"To4",
"(",
")",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}"
] |
// Return the first non-loopback address as a 4 byte IP address. This address
// is used for sending packets out.
|
[
"Return",
"the",
"first",
"non",
"-",
"loopback",
"address",
"as",
"a",
"4",
"byte",
"IP",
"address",
".",
"This",
"address",
"is",
"used",
"for",
"sending",
"packets",
"out",
"."
] |
147686d9cb0fd32a2e577e94fbd3d0e9bd3a24d2
|
https://github.com/aeden/traceroute/blob/147686d9cb0fd32a2e577e94fbd3d0e9bd3a24d2/traceroute.go#L22-L38
|
18,447
|
aeden/traceroute
|
traceroute.go
|
destAddr
|
func destAddr(dest string) (destAddr [4]byte, err error) {
addrs, err := net.LookupHost(dest)
if err != nil {
return
}
addr := addrs[0]
ipAddr, err := net.ResolveIPAddr("ip", addr)
if err != nil {
return
}
copy(destAddr[:], ipAddr.IP.To4())
return
}
|
go
|
func destAddr(dest string) (destAddr [4]byte, err error) {
addrs, err := net.LookupHost(dest)
if err != nil {
return
}
addr := addrs[0]
ipAddr, err := net.ResolveIPAddr("ip", addr)
if err != nil {
return
}
copy(destAddr[:], ipAddr.IP.To4())
return
}
|
[
"func",
"destAddr",
"(",
"dest",
"string",
")",
"(",
"destAddr",
"[",
"4",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"addrs",
",",
"err",
":=",
"net",
".",
"LookupHost",
"(",
"dest",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"addr",
":=",
"addrs",
"[",
"0",
"]",
"\n\n",
"ipAddr",
",",
"err",
":=",
"net",
".",
"ResolveIPAddr",
"(",
"\"",
"\"",
",",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"copy",
"(",
"destAddr",
"[",
":",
"]",
",",
"ipAddr",
".",
"IP",
".",
"To4",
"(",
")",
")",
"\n",
"return",
"\n",
"}"
] |
// Given a host name convert it to a 4 byte IP address.
|
[
"Given",
"a",
"host",
"name",
"convert",
"it",
"to",
"a",
"4",
"byte",
"IP",
"address",
"."
] |
147686d9cb0fd32a2e577e94fbd3d0e9bd3a24d2
|
https://github.com/aeden/traceroute/blob/147686d9cb0fd32a2e577e94fbd3d0e9bd3a24d2/traceroute.go#L41-L54
|
18,448
|
shurcooL/vfsgen
|
cmd/vfsgendev/main.go
|
goRun
|
func goRun(src string, tags string) error {
// Create a temp folder.
tempDir, err := ioutil.TempDir("", "vfsgendev_")
if err != nil {
return err
}
defer func() {
err := os.RemoveAll(tempDir)
if err != nil {
fmt.Fprintln(os.Stderr, "warning: error removing temp dir:", err)
}
}()
// Write the source code file.
tempFile := filepath.Join(tempDir, "generate.go")
err = ioutil.WriteFile(tempFile, []byte(src), 0600)
if err != nil {
return err
}
// Compile and run the program.
cmd := exec.Command("go", "run", "-tags="+tags, tempFile)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
|
go
|
func goRun(src string, tags string) error {
// Create a temp folder.
tempDir, err := ioutil.TempDir("", "vfsgendev_")
if err != nil {
return err
}
defer func() {
err := os.RemoveAll(tempDir)
if err != nil {
fmt.Fprintln(os.Stderr, "warning: error removing temp dir:", err)
}
}()
// Write the source code file.
tempFile := filepath.Join(tempDir, "generate.go")
err = ioutil.WriteFile(tempFile, []byte(src), 0600)
if err != nil {
return err
}
// Compile and run the program.
cmd := exec.Command("go", "run", "-tags="+tags, tempFile)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
|
[
"func",
"goRun",
"(",
"src",
"string",
",",
"tags",
"string",
")",
"error",
"{",
"// Create a temp folder.",
"tempDir",
",",
"err",
":=",
"ioutil",
".",
"TempDir",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"err",
":=",
"os",
".",
"RemoveAll",
"(",
"tempDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"// Write the source code file.",
"tempFile",
":=",
"filepath",
".",
"Join",
"(",
"tempDir",
",",
"\"",
"\"",
")",
"\n",
"err",
"=",
"ioutil",
".",
"WriteFile",
"(",
"tempFile",
",",
"[",
"]",
"byte",
"(",
"src",
")",
",",
"0600",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Compile and run the program.",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"tags",
",",
"tempFile",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n",
"return",
"cmd",
".",
"Run",
"(",
")",
"\n",
"}"
] |
// goRun runs Go code src with build tags.
|
[
"goRun",
"runs",
"Go",
"code",
"src",
"with",
"build",
"tags",
"."
] |
6a9ea43bcacdf716a5c1b38efff722c07adf0069
|
https://github.com/shurcooL/vfsgen/blob/6a9ea43bcacdf716a5c1b38efff722c07adf0069/cmd/vfsgendev/main.go#L86-L111
|
18,449
|
shurcooL/vfsgen
|
generator.go
|
Generate
|
func Generate(input http.FileSystem, opt Options) error {
opt.fillMissing()
// Use an in-memory buffer to generate the entire output.
buf := new(bytes.Buffer)
err := t.ExecuteTemplate(buf, "Header", opt)
if err != nil {
return err
}
var toc toc
err = findAndWriteFiles(buf, input, &toc)
if err != nil {
return err
}
err = t.ExecuteTemplate(buf, "DirEntries", toc.dirs)
if err != nil {
return err
}
err = t.ExecuteTemplate(buf, "Trailer", toc)
if err != nil {
return err
}
// Write output file (all at once).
fmt.Println("writing", opt.Filename)
err = ioutil.WriteFile(opt.Filename, buf.Bytes(), 0644)
return err
}
|
go
|
func Generate(input http.FileSystem, opt Options) error {
opt.fillMissing()
// Use an in-memory buffer to generate the entire output.
buf := new(bytes.Buffer)
err := t.ExecuteTemplate(buf, "Header", opt)
if err != nil {
return err
}
var toc toc
err = findAndWriteFiles(buf, input, &toc)
if err != nil {
return err
}
err = t.ExecuteTemplate(buf, "DirEntries", toc.dirs)
if err != nil {
return err
}
err = t.ExecuteTemplate(buf, "Trailer", toc)
if err != nil {
return err
}
// Write output file (all at once).
fmt.Println("writing", opt.Filename)
err = ioutil.WriteFile(opt.Filename, buf.Bytes(), 0644)
return err
}
|
[
"func",
"Generate",
"(",
"input",
"http",
".",
"FileSystem",
",",
"opt",
"Options",
")",
"error",
"{",
"opt",
".",
"fillMissing",
"(",
")",
"\n\n",
"// Use an in-memory buffer to generate the entire output.",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"err",
":=",
"t",
".",
"ExecuteTemplate",
"(",
"buf",
",",
"\"",
"\"",
",",
"opt",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"toc",
"toc",
"\n",
"err",
"=",
"findAndWriteFiles",
"(",
"buf",
",",
"input",
",",
"&",
"toc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"t",
".",
"ExecuteTemplate",
"(",
"buf",
",",
"\"",
"\"",
",",
"toc",
".",
"dirs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"t",
".",
"ExecuteTemplate",
"(",
"buf",
",",
"\"",
"\"",
",",
"toc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Write output file (all at once).",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"opt",
".",
"Filename",
")",
"\n",
"err",
"=",
"ioutil",
".",
"WriteFile",
"(",
"opt",
".",
"Filename",
",",
"buf",
".",
"Bytes",
"(",
")",
",",
"0644",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Generate Go code that statically implements input filesystem,
// write the output to a file specified in opt.
|
[
"Generate",
"Go",
"code",
"that",
"statically",
"implements",
"input",
"filesystem",
"write",
"the",
"output",
"to",
"a",
"file",
"specified",
"in",
"opt",
"."
] |
6a9ea43bcacdf716a5c1b38efff722c07adf0069
|
https://github.com/shurcooL/vfsgen/blob/6a9ea43bcacdf716a5c1b38efff722c07adf0069/generator.go#L23-L54
|
18,450
|
shurcooL/vfsgen
|
generator.go
|
findAndWriteFiles
|
func findAndWriteFiles(buf *bytes.Buffer, fs http.FileSystem, toc *toc) error {
walkFn := func(path string, fi os.FileInfo, r io.ReadSeeker, err error) error {
if err != nil {
// Consider all errors reading the input filesystem as fatal.
return err
}
switch fi.IsDir() {
case false:
file := &fileInfo{
Path: path,
Name: pathpkg.Base(path),
ModTime: fi.ModTime().UTC(),
UncompressedSize: fi.Size(),
}
marker := buf.Len()
// Write CompressedFileInfo.
err = writeCompressedFileInfo(buf, file, r)
switch err {
default:
return err
case nil:
toc.HasCompressedFile = true
// If compressed file is not smaller than original, revert and write original file.
case errCompressedNotSmaller:
_, err = r.Seek(0, io.SeekStart)
if err != nil {
return err
}
buf.Truncate(marker)
// Write FileInfo.
err = writeFileInfo(buf, file, r)
if err != nil {
return err
}
toc.HasFile = true
}
case true:
entries, err := readDirPaths(fs, path)
if err != nil {
return err
}
dir := &dirInfo{
Path: path,
Name: pathpkg.Base(path),
ModTime: fi.ModTime().UTC(),
Entries: entries,
}
toc.dirs = append(toc.dirs, dir)
// Write DirInfo.
err = t.ExecuteTemplate(buf, "DirInfo", dir)
if err != nil {
return err
}
}
return nil
}
err := vfsutil.WalkFiles(fs, "/", walkFn)
return err
}
|
go
|
func findAndWriteFiles(buf *bytes.Buffer, fs http.FileSystem, toc *toc) error {
walkFn := func(path string, fi os.FileInfo, r io.ReadSeeker, err error) error {
if err != nil {
// Consider all errors reading the input filesystem as fatal.
return err
}
switch fi.IsDir() {
case false:
file := &fileInfo{
Path: path,
Name: pathpkg.Base(path),
ModTime: fi.ModTime().UTC(),
UncompressedSize: fi.Size(),
}
marker := buf.Len()
// Write CompressedFileInfo.
err = writeCompressedFileInfo(buf, file, r)
switch err {
default:
return err
case nil:
toc.HasCompressedFile = true
// If compressed file is not smaller than original, revert and write original file.
case errCompressedNotSmaller:
_, err = r.Seek(0, io.SeekStart)
if err != nil {
return err
}
buf.Truncate(marker)
// Write FileInfo.
err = writeFileInfo(buf, file, r)
if err != nil {
return err
}
toc.HasFile = true
}
case true:
entries, err := readDirPaths(fs, path)
if err != nil {
return err
}
dir := &dirInfo{
Path: path,
Name: pathpkg.Base(path),
ModTime: fi.ModTime().UTC(),
Entries: entries,
}
toc.dirs = append(toc.dirs, dir)
// Write DirInfo.
err = t.ExecuteTemplate(buf, "DirInfo", dir)
if err != nil {
return err
}
}
return nil
}
err := vfsutil.WalkFiles(fs, "/", walkFn)
return err
}
|
[
"func",
"findAndWriteFiles",
"(",
"buf",
"*",
"bytes",
".",
"Buffer",
",",
"fs",
"http",
".",
"FileSystem",
",",
"toc",
"*",
"toc",
")",
"error",
"{",
"walkFn",
":=",
"func",
"(",
"path",
"string",
",",
"fi",
"os",
".",
"FileInfo",
",",
"r",
"io",
".",
"ReadSeeker",
",",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"!=",
"nil",
"{",
"// Consider all errors reading the input filesystem as fatal.",
"return",
"err",
"\n",
"}",
"\n\n",
"switch",
"fi",
".",
"IsDir",
"(",
")",
"{",
"case",
"false",
":",
"file",
":=",
"&",
"fileInfo",
"{",
"Path",
":",
"path",
",",
"Name",
":",
"pathpkg",
".",
"Base",
"(",
"path",
")",
",",
"ModTime",
":",
"fi",
".",
"ModTime",
"(",
")",
".",
"UTC",
"(",
")",
",",
"UncompressedSize",
":",
"fi",
".",
"Size",
"(",
")",
",",
"}",
"\n\n",
"marker",
":=",
"buf",
".",
"Len",
"(",
")",
"\n\n",
"// Write CompressedFileInfo.",
"err",
"=",
"writeCompressedFileInfo",
"(",
"buf",
",",
"file",
",",
"r",
")",
"\n",
"switch",
"err",
"{",
"default",
":",
"return",
"err",
"\n",
"case",
"nil",
":",
"toc",
".",
"HasCompressedFile",
"=",
"true",
"\n",
"// If compressed file is not smaller than original, revert and write original file.",
"case",
"errCompressedNotSmaller",
":",
"_",
",",
"err",
"=",
"r",
".",
"Seek",
"(",
"0",
",",
"io",
".",
"SeekStart",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"buf",
".",
"Truncate",
"(",
"marker",
")",
"\n\n",
"// Write FileInfo.",
"err",
"=",
"writeFileInfo",
"(",
"buf",
",",
"file",
",",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"toc",
".",
"HasFile",
"=",
"true",
"\n",
"}",
"\n",
"case",
"true",
":",
"entries",
",",
"err",
":=",
"readDirPaths",
"(",
"fs",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"dir",
":=",
"&",
"dirInfo",
"{",
"Path",
":",
"path",
",",
"Name",
":",
"pathpkg",
".",
"Base",
"(",
"path",
")",
",",
"ModTime",
":",
"fi",
".",
"ModTime",
"(",
")",
".",
"UTC",
"(",
")",
",",
"Entries",
":",
"entries",
",",
"}",
"\n\n",
"toc",
".",
"dirs",
"=",
"append",
"(",
"toc",
".",
"dirs",
",",
"dir",
")",
"\n\n",
"// Write DirInfo.",
"err",
"=",
"t",
".",
"ExecuteTemplate",
"(",
"buf",
",",
"\"",
"\"",
",",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"err",
":=",
"vfsutil",
".",
"WalkFiles",
"(",
"fs",
",",
"\"",
"\"",
",",
"walkFn",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// findAndWriteFiles recursively finds all the file paths in the given directory tree.
// They are added to the given map as keys. Values will be safe function names
// for each file, which will be used when generating the output code.
|
[
"findAndWriteFiles",
"recursively",
"finds",
"all",
"the",
"file",
"paths",
"in",
"the",
"given",
"directory",
"tree",
".",
"They",
"are",
"added",
"to",
"the",
"given",
"map",
"as",
"keys",
".",
"Values",
"will",
"be",
"safe",
"function",
"names",
"for",
"each",
"file",
"which",
"will",
"be",
"used",
"when",
"generating",
"the",
"output",
"code",
"."
] |
6a9ea43bcacdf716a5c1b38efff722c07adf0069
|
https://github.com/shurcooL/vfsgen/blob/6a9ea43bcacdf716a5c1b38efff722c07adf0069/generator.go#L82-L150
|
18,451
|
shurcooL/vfsgen
|
generator.go
|
readDirPaths
|
func readDirPaths(fs http.FileSystem, dirname string) ([]string, error) {
fis, err := vfsutil.ReadDir(fs, dirname)
if err != nil {
return nil, err
}
paths := make([]string, len(fis))
for i := range fis {
paths[i] = pathpkg.Join(dirname, fis[i].Name())
}
sort.Strings(paths)
return paths, nil
}
|
go
|
func readDirPaths(fs http.FileSystem, dirname string) ([]string, error) {
fis, err := vfsutil.ReadDir(fs, dirname)
if err != nil {
return nil, err
}
paths := make([]string, len(fis))
for i := range fis {
paths[i] = pathpkg.Join(dirname, fis[i].Name())
}
sort.Strings(paths)
return paths, nil
}
|
[
"func",
"readDirPaths",
"(",
"fs",
"http",
".",
"FileSystem",
",",
"dirname",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"fis",
",",
"err",
":=",
"vfsutil",
".",
"ReadDir",
"(",
"fs",
",",
"dirname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"paths",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"fis",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"fis",
"{",
"paths",
"[",
"i",
"]",
"=",
"pathpkg",
".",
"Join",
"(",
"dirname",
",",
"fis",
"[",
"i",
"]",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"paths",
")",
"\n",
"return",
"paths",
",",
"nil",
"\n",
"}"
] |
// readDirPaths reads the directory named by dirname and returns
// a sorted list of directory paths.
|
[
"readDirPaths",
"reads",
"the",
"directory",
"named",
"by",
"dirname",
"and",
"returns",
"a",
"sorted",
"list",
"of",
"directory",
"paths",
"."
] |
6a9ea43bcacdf716a5c1b38efff722c07adf0069
|
https://github.com/shurcooL/vfsgen/blob/6a9ea43bcacdf716a5c1b38efff722c07adf0069/generator.go#L154-L165
|
18,452
|
shurcooL/vfsgen
|
generator.go
|
writeCompressedFileInfo
|
func writeCompressedFileInfo(w io.Writer, file *fileInfo, r io.Reader) error {
err := t.ExecuteTemplate(w, "CompressedFileInfo-Before", file)
if err != nil {
return err
}
sw := &stringWriter{Writer: w}
gw := gzip.NewWriter(sw)
_, err = io.Copy(gw, r)
if err != nil {
return err
}
err = gw.Close()
if err != nil {
return err
}
if sw.N >= file.UncompressedSize {
return errCompressedNotSmaller
}
err = t.ExecuteTemplate(w, "CompressedFileInfo-After", file)
return err
}
|
go
|
func writeCompressedFileInfo(w io.Writer, file *fileInfo, r io.Reader) error {
err := t.ExecuteTemplate(w, "CompressedFileInfo-Before", file)
if err != nil {
return err
}
sw := &stringWriter{Writer: w}
gw := gzip.NewWriter(sw)
_, err = io.Copy(gw, r)
if err != nil {
return err
}
err = gw.Close()
if err != nil {
return err
}
if sw.N >= file.UncompressedSize {
return errCompressedNotSmaller
}
err = t.ExecuteTemplate(w, "CompressedFileInfo-After", file)
return err
}
|
[
"func",
"writeCompressedFileInfo",
"(",
"w",
"io",
".",
"Writer",
",",
"file",
"*",
"fileInfo",
",",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"err",
":=",
"t",
".",
"ExecuteTemplate",
"(",
"w",
",",
"\"",
"\"",
",",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sw",
":=",
"&",
"stringWriter",
"{",
"Writer",
":",
"w",
"}",
"\n",
"gw",
":=",
"gzip",
".",
"NewWriter",
"(",
"sw",
")",
"\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"gw",
",",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"gw",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"sw",
".",
"N",
">=",
"file",
".",
"UncompressedSize",
"{",
"return",
"errCompressedNotSmaller",
"\n",
"}",
"\n",
"err",
"=",
"t",
".",
"ExecuteTemplate",
"(",
"w",
",",
"\"",
"\"",
",",
"file",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// writeCompressedFileInfo writes CompressedFileInfo.
// It returns errCompressedNotSmaller if compressed file is not smaller than original.
|
[
"writeCompressedFileInfo",
"writes",
"CompressedFileInfo",
".",
"It",
"returns",
"errCompressedNotSmaller",
"if",
"compressed",
"file",
"is",
"not",
"smaller",
"than",
"original",
"."
] |
6a9ea43bcacdf716a5c1b38efff722c07adf0069
|
https://github.com/shurcooL/vfsgen/blob/6a9ea43bcacdf716a5c1b38efff722c07adf0069/generator.go#L169-L189
|
18,453
|
shurcooL/vfsgen
|
generator.go
|
writeFileInfo
|
func writeFileInfo(w io.Writer, file *fileInfo, r io.Reader) error {
err := t.ExecuteTemplate(w, "FileInfo-Before", file)
if err != nil {
return err
}
sw := &stringWriter{Writer: w}
_, err = io.Copy(sw, r)
if err != nil {
return err
}
err = t.ExecuteTemplate(w, "FileInfo-After", file)
return err
}
|
go
|
func writeFileInfo(w io.Writer, file *fileInfo, r io.Reader) error {
err := t.ExecuteTemplate(w, "FileInfo-Before", file)
if err != nil {
return err
}
sw := &stringWriter{Writer: w}
_, err = io.Copy(sw, r)
if err != nil {
return err
}
err = t.ExecuteTemplate(w, "FileInfo-After", file)
return err
}
|
[
"func",
"writeFileInfo",
"(",
"w",
"io",
".",
"Writer",
",",
"file",
"*",
"fileInfo",
",",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"err",
":=",
"t",
".",
"ExecuteTemplate",
"(",
"w",
",",
"\"",
"\"",
",",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sw",
":=",
"&",
"stringWriter",
"{",
"Writer",
":",
"w",
"}",
"\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"sw",
",",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"t",
".",
"ExecuteTemplate",
"(",
"w",
",",
"\"",
"\"",
",",
"file",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Write FileInfo.
|
[
"Write",
"FileInfo",
"."
] |
6a9ea43bcacdf716a5c1b38efff722c07adf0069
|
https://github.com/shurcooL/vfsgen/blob/6a9ea43bcacdf716a5c1b38efff722c07adf0069/generator.go#L194-L206
|
18,454
|
shurcooL/vfsgen
|
cmd/vfsgendev/parse.go
|
stringValue
|
func stringValue(e ast.Expr) (string, error) {
lit, ok := e.(*ast.BasicLit)
if !ok {
return "", fmt.Errorf("not a string, but %T", e)
}
if lit.Kind != token.STRING {
return "", fmt.Errorf("not a string, but %v", lit.Kind)
}
return strconv.Unquote(lit.Value)
}
|
go
|
func stringValue(e ast.Expr) (string, error) {
lit, ok := e.(*ast.BasicLit)
if !ok {
return "", fmt.Errorf("not a string, but %T", e)
}
if lit.Kind != token.STRING {
return "", fmt.Errorf("not a string, but %v", lit.Kind)
}
return strconv.Unquote(lit.Value)
}
|
[
"func",
"stringValue",
"(",
"e",
"ast",
".",
"Expr",
")",
"(",
"string",
",",
"error",
")",
"{",
"lit",
",",
"ok",
":=",
"e",
".",
"(",
"*",
"ast",
".",
"BasicLit",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"e",
")",
"\n",
"}",
"\n",
"if",
"lit",
".",
"Kind",
"!=",
"token",
".",
"STRING",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"lit",
".",
"Kind",
")",
"\n",
"}",
"\n",
"return",
"strconv",
".",
"Unquote",
"(",
"lit",
".",
"Value",
")",
"\n",
"}"
] |
// stringValue returns the string value of string literal e.
|
[
"stringValue",
"returns",
"the",
"string",
"value",
"of",
"string",
"literal",
"e",
"."
] |
6a9ea43bcacdf716a5c1b38efff722c07adf0069
|
https://github.com/shurcooL/vfsgen/blob/6a9ea43bcacdf716a5c1b38efff722c07adf0069/cmd/vfsgendev/parse.go#L47-L56
|
18,455
|
shurcooL/vfsgen
|
cmd/vfsgendev/parse.go
|
parseTagFlag
|
func parseTagFlag(tagFlag string) (tag string, err error) {
tags := strings.Fields(tagFlag)
if len(tags) != 1 {
return "", fmt.Errorf("%q is not a valid single build tag, but %q", tagFlag, tags)
}
return tags[0], nil
}
|
go
|
func parseTagFlag(tagFlag string) (tag string, err error) {
tags := strings.Fields(tagFlag)
if len(tags) != 1 {
return "", fmt.Errorf("%q is not a valid single build tag, but %q", tagFlag, tags)
}
return tags[0], nil
}
|
[
"func",
"parseTagFlag",
"(",
"tagFlag",
"string",
")",
"(",
"tag",
"string",
",",
"err",
"error",
")",
"{",
"tags",
":=",
"strings",
".",
"Fields",
"(",
"tagFlag",
")",
"\n",
"if",
"len",
"(",
"tags",
")",
"!=",
"1",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tagFlag",
",",
"tags",
")",
"\n",
"}",
"\n",
"return",
"tags",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] |
// parseTagFlag parses the "-tag" flag value. It must be a single build tag.
|
[
"parseTagFlag",
"parses",
"the",
"-",
"tag",
"flag",
"value",
".",
"It",
"must",
"be",
"a",
"single",
"build",
"tag",
"."
] |
6a9ea43bcacdf716a5c1b38efff722c07adf0069
|
https://github.com/shurcooL/vfsgen/blob/6a9ea43bcacdf716a5c1b38efff722c07adf0069/cmd/vfsgendev/parse.go#L59-L65
|
18,456
|
shurcooL/vfsgen
|
cmd/vfsgendev/parse.go
|
lookupNameAndComment
|
func lookupNameAndComment(bctx build.Context, importPath, variableName string) (packageName, variableComment string, err error) {
wd, err := os.Getwd()
if err != nil {
return "", "", err
}
bpkg, err := bctx.Import(importPath, wd, 0)
if err != nil {
return "", "", fmt.Errorf("can't import package %q: %v", importPath, err)
}
dpkg, err := computeDoc(bpkg)
if err != nil {
return "", "", fmt.Errorf("can't get godoc of package %q: %v", importPath, err)
}
for _, v := range dpkg.Vars {
if len(v.Names) == 1 && v.Names[0] == variableName {
variableComment = strings.TrimSuffix(v.Doc, "\n")
break
}
}
return bpkg.Name, variableComment, nil
}
|
go
|
func lookupNameAndComment(bctx build.Context, importPath, variableName string) (packageName, variableComment string, err error) {
wd, err := os.Getwd()
if err != nil {
return "", "", err
}
bpkg, err := bctx.Import(importPath, wd, 0)
if err != nil {
return "", "", fmt.Errorf("can't import package %q: %v", importPath, err)
}
dpkg, err := computeDoc(bpkg)
if err != nil {
return "", "", fmt.Errorf("can't get godoc of package %q: %v", importPath, err)
}
for _, v := range dpkg.Vars {
if len(v.Names) == 1 && v.Names[0] == variableName {
variableComment = strings.TrimSuffix(v.Doc, "\n")
break
}
}
return bpkg.Name, variableComment, nil
}
|
[
"func",
"lookupNameAndComment",
"(",
"bctx",
"build",
".",
"Context",
",",
"importPath",
",",
"variableName",
"string",
")",
"(",
"packageName",
",",
"variableComment",
"string",
",",
"err",
"error",
")",
"{",
"wd",
",",
"err",
":=",
"os",
".",
"Getwd",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"bpkg",
",",
"err",
":=",
"bctx",
".",
"Import",
"(",
"importPath",
",",
"wd",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"importPath",
",",
"err",
")",
"\n",
"}",
"\n",
"dpkg",
",",
"err",
":=",
"computeDoc",
"(",
"bpkg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"importPath",
",",
"err",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"dpkg",
".",
"Vars",
"{",
"if",
"len",
"(",
"v",
".",
"Names",
")",
"==",
"1",
"&&",
"v",
".",
"Names",
"[",
"0",
"]",
"==",
"variableName",
"{",
"variableComment",
"=",
"strings",
".",
"TrimSuffix",
"(",
"v",
".",
"Doc",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"bpkg",
".",
"Name",
",",
"variableComment",
",",
"nil",
"\n",
"}"
] |
// lookupNameAndComment imports package using provided build context, and
// returns the package name and variable comment.
|
[
"lookupNameAndComment",
"imports",
"package",
"using",
"provided",
"build",
"context",
"and",
"returns",
"the",
"package",
"name",
"and",
"variable",
"comment",
"."
] |
6a9ea43bcacdf716a5c1b38efff722c07adf0069
|
https://github.com/shurcooL/vfsgen/blob/6a9ea43bcacdf716a5c1b38efff722c07adf0069/cmd/vfsgendev/parse.go#L69-L89
|
18,457
|
shurcooL/vfsgen
|
cmd/vfsgendev/parse.go
|
computeDoc
|
func computeDoc(bpkg *build.Package) (*doc.Package, error) {
fset := token.NewFileSet()
files := make(map[string]*ast.File)
for _, file := range append(bpkg.GoFiles, bpkg.CgoFiles...) {
f, err := parser.ParseFile(fset, filepath.Join(bpkg.Dir, file), nil, parser.ParseComments)
if err != nil {
return nil, err
}
files[file] = f
}
apkg := &ast.Package{
Name: bpkg.Name,
Files: files,
}
return doc.New(apkg, bpkg.ImportPath, 0), nil
}
|
go
|
func computeDoc(bpkg *build.Package) (*doc.Package, error) {
fset := token.NewFileSet()
files := make(map[string]*ast.File)
for _, file := range append(bpkg.GoFiles, bpkg.CgoFiles...) {
f, err := parser.ParseFile(fset, filepath.Join(bpkg.Dir, file), nil, parser.ParseComments)
if err != nil {
return nil, err
}
files[file] = f
}
apkg := &ast.Package{
Name: bpkg.Name,
Files: files,
}
return doc.New(apkg, bpkg.ImportPath, 0), nil
}
|
[
"func",
"computeDoc",
"(",
"bpkg",
"*",
"build",
".",
"Package",
")",
"(",
"*",
"doc",
".",
"Package",
",",
"error",
")",
"{",
"fset",
":=",
"token",
".",
"NewFileSet",
"(",
")",
"\n",
"files",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"ast",
".",
"File",
")",
"\n",
"for",
"_",
",",
"file",
":=",
"range",
"append",
"(",
"bpkg",
".",
"GoFiles",
",",
"bpkg",
".",
"CgoFiles",
"...",
")",
"{",
"f",
",",
"err",
":=",
"parser",
".",
"ParseFile",
"(",
"fset",
",",
"filepath",
".",
"Join",
"(",
"bpkg",
".",
"Dir",
",",
"file",
")",
",",
"nil",
",",
"parser",
".",
"ParseComments",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"files",
"[",
"file",
"]",
"=",
"f",
"\n",
"}",
"\n",
"apkg",
":=",
"&",
"ast",
".",
"Package",
"{",
"Name",
":",
"bpkg",
".",
"Name",
",",
"Files",
":",
"files",
",",
"}",
"\n",
"return",
"doc",
".",
"New",
"(",
"apkg",
",",
"bpkg",
".",
"ImportPath",
",",
"0",
")",
",",
"nil",
"\n",
"}"
] |
// computeDoc computes the package documentation for the given package.
|
[
"computeDoc",
"computes",
"the",
"package",
"documentation",
"for",
"the",
"given",
"package",
"."
] |
6a9ea43bcacdf716a5c1b38efff722c07adf0069
|
https://github.com/shurcooL/vfsgen/blob/6a9ea43bcacdf716a5c1b38efff722c07adf0069/cmd/vfsgendev/parse.go#L101-L116
|
18,458
|
shurcooL/vfsgen
|
options.go
|
fillMissing
|
func (opt *Options) fillMissing() {
if opt.PackageName == "" {
opt.PackageName = "main"
}
if opt.VariableName == "" {
opt.VariableName = "assets"
}
if opt.Filename == "" {
opt.Filename = fmt.Sprintf("%s_vfsdata.go", strings.ToLower(opt.VariableName))
}
if opt.VariableComment == "" {
opt.VariableComment = fmt.Sprintf("%s statically implements the virtual filesystem provided to vfsgen.", opt.VariableName)
}
}
|
go
|
func (opt *Options) fillMissing() {
if opt.PackageName == "" {
opt.PackageName = "main"
}
if opt.VariableName == "" {
opt.VariableName = "assets"
}
if opt.Filename == "" {
opt.Filename = fmt.Sprintf("%s_vfsdata.go", strings.ToLower(opt.VariableName))
}
if opt.VariableComment == "" {
opt.VariableComment = fmt.Sprintf("%s statically implements the virtual filesystem provided to vfsgen.", opt.VariableName)
}
}
|
[
"func",
"(",
"opt",
"*",
"Options",
")",
"fillMissing",
"(",
")",
"{",
"if",
"opt",
".",
"PackageName",
"==",
"\"",
"\"",
"{",
"opt",
".",
"PackageName",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"opt",
".",
"VariableName",
"==",
"\"",
"\"",
"{",
"opt",
".",
"VariableName",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"opt",
".",
"Filename",
"==",
"\"",
"\"",
"{",
"opt",
".",
"Filename",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"ToLower",
"(",
"opt",
".",
"VariableName",
")",
")",
"\n",
"}",
"\n",
"if",
"opt",
".",
"VariableComment",
"==",
"\"",
"\"",
"{",
"opt",
".",
"VariableComment",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"opt",
".",
"VariableName",
")",
"\n",
"}",
"\n",
"}"
] |
// fillMissing sets default values for mandatory options that are left empty.
|
[
"fillMissing",
"sets",
"default",
"values",
"for",
"mandatory",
"options",
"that",
"are",
"left",
"empty",
"."
] |
6a9ea43bcacdf716a5c1b38efff722c07adf0069
|
https://github.com/shurcooL/vfsgen/blob/6a9ea43bcacdf716a5c1b38efff722c07adf0069/options.go#L32-L45
|
18,459
|
mitchellh/go-homedir
|
homedir.go
|
Dir
|
func Dir() (string, error) {
if !DisableCache {
cacheLock.RLock()
cached := homedirCache
cacheLock.RUnlock()
if cached != "" {
return cached, nil
}
}
cacheLock.Lock()
defer cacheLock.Unlock()
var result string
var err error
if runtime.GOOS == "windows" {
result, err = dirWindows()
} else {
// Unix-like system, so just assume Unix
result, err = dirUnix()
}
if err != nil {
return "", err
}
homedirCache = result
return result, nil
}
|
go
|
func Dir() (string, error) {
if !DisableCache {
cacheLock.RLock()
cached := homedirCache
cacheLock.RUnlock()
if cached != "" {
return cached, nil
}
}
cacheLock.Lock()
defer cacheLock.Unlock()
var result string
var err error
if runtime.GOOS == "windows" {
result, err = dirWindows()
} else {
// Unix-like system, so just assume Unix
result, err = dirUnix()
}
if err != nil {
return "", err
}
homedirCache = result
return result, nil
}
|
[
"func",
"Dir",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"!",
"DisableCache",
"{",
"cacheLock",
".",
"RLock",
"(",
")",
"\n",
"cached",
":=",
"homedirCache",
"\n",
"cacheLock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"cached",
"!=",
"\"",
"\"",
"{",
"return",
"cached",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"cacheLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cacheLock",
".",
"Unlock",
"(",
")",
"\n\n",
"var",
"result",
"string",
"\n",
"var",
"err",
"error",
"\n",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"result",
",",
"err",
"=",
"dirWindows",
"(",
")",
"\n",
"}",
"else",
"{",
"// Unix-like system, so just assume Unix",
"result",
",",
"err",
"=",
"dirUnix",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"homedirCache",
"=",
"result",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// Dir returns the home directory for the executing user.
//
// This uses an OS-specific method for discovering the home directory.
// An error is returned if a home directory cannot be detected.
|
[
"Dir",
"returns",
"the",
"home",
"directory",
"for",
"the",
"executing",
"user",
".",
"This",
"uses",
"an",
"OS",
"-",
"specific",
"method",
"for",
"discovering",
"the",
"home",
"directory",
".",
"An",
"error",
"is",
"returned",
"if",
"a",
"home",
"directory",
"cannot",
"be",
"detected",
"."
] |
af06845cf3004701891bf4fdb884bfe4920b3727
|
https://github.com/mitchellh/go-homedir/blob/af06845cf3004701891bf4fdb884bfe4920b3727/homedir.go#L26-L53
|
18,460
|
mitchellh/go-homedir
|
homedir.go
|
Expand
|
func Expand(path string) (string, error) {
if len(path) == 0 {
return path, nil
}
if path[0] != '~' {
return path, nil
}
if len(path) > 1 && path[1] != '/' && path[1] != '\\' {
return "", errors.New("cannot expand user-specific home dir")
}
dir, err := Dir()
if err != nil {
return "", err
}
return filepath.Join(dir, path[1:]), nil
}
|
go
|
func Expand(path string) (string, error) {
if len(path) == 0 {
return path, nil
}
if path[0] != '~' {
return path, nil
}
if len(path) > 1 && path[1] != '/' && path[1] != '\\' {
return "", errors.New("cannot expand user-specific home dir")
}
dir, err := Dir()
if err != nil {
return "", err
}
return filepath.Join(dir, path[1:]), nil
}
|
[
"func",
"Expand",
"(",
"path",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"len",
"(",
"path",
")",
"==",
"0",
"{",
"return",
"path",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"path",
"[",
"0",
"]",
"!=",
"'~'",
"{",
"return",
"path",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"path",
")",
">",
"1",
"&&",
"path",
"[",
"1",
"]",
"!=",
"'/'",
"&&",
"path",
"[",
"1",
"]",
"!=",
"'\\\\'",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"dir",
",",
"err",
":=",
"Dir",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"filepath",
".",
"Join",
"(",
"dir",
",",
"path",
"[",
"1",
":",
"]",
")",
",",
"nil",
"\n",
"}"
] |
// Expand expands the path to include the home directory if the path
// is prefixed with `~`. If it isn't prefixed with `~`, the path is
// returned as-is.
|
[
"Expand",
"expands",
"the",
"path",
"to",
"include",
"the",
"home",
"directory",
"if",
"the",
"path",
"is",
"prefixed",
"with",
"~",
".",
"If",
"it",
"isn",
"t",
"prefixed",
"with",
"~",
"the",
"path",
"is",
"returned",
"as",
"-",
"is",
"."
] |
af06845cf3004701891bf4fdb884bfe4920b3727
|
https://github.com/mitchellh/go-homedir/blob/af06845cf3004701891bf4fdb884bfe4920b3727/homedir.go#L58-L77
|
18,461
|
blang/semver
|
semver.go
|
String
|
func (v Version) String() string {
b := make([]byte, 0, 5)
b = strconv.AppendUint(b, v.Major, 10)
b = append(b, '.')
b = strconv.AppendUint(b, v.Minor, 10)
b = append(b, '.')
b = strconv.AppendUint(b, v.Patch, 10)
if len(v.Pre) > 0 {
b = append(b, '-')
b = append(b, v.Pre[0].String()...)
for _, pre := range v.Pre[1:] {
b = append(b, '.')
b = append(b, pre.String()...)
}
}
if len(v.Build) > 0 {
b = append(b, '+')
b = append(b, v.Build[0]...)
for _, build := range v.Build[1:] {
b = append(b, '.')
b = append(b, build...)
}
}
return string(b)
}
|
go
|
func (v Version) String() string {
b := make([]byte, 0, 5)
b = strconv.AppendUint(b, v.Major, 10)
b = append(b, '.')
b = strconv.AppendUint(b, v.Minor, 10)
b = append(b, '.')
b = strconv.AppendUint(b, v.Patch, 10)
if len(v.Pre) > 0 {
b = append(b, '-')
b = append(b, v.Pre[0].String()...)
for _, pre := range v.Pre[1:] {
b = append(b, '.')
b = append(b, pre.String()...)
}
}
if len(v.Build) > 0 {
b = append(b, '+')
b = append(b, v.Build[0]...)
for _, build := range v.Build[1:] {
b = append(b, '.')
b = append(b, build...)
}
}
return string(b)
}
|
[
"func",
"(",
"v",
"Version",
")",
"String",
"(",
")",
"string",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"5",
")",
"\n",
"b",
"=",
"strconv",
".",
"AppendUint",
"(",
"b",
",",
"v",
".",
"Major",
",",
"10",
")",
"\n",
"b",
"=",
"append",
"(",
"b",
",",
"'.'",
")",
"\n",
"b",
"=",
"strconv",
".",
"AppendUint",
"(",
"b",
",",
"v",
".",
"Minor",
",",
"10",
")",
"\n",
"b",
"=",
"append",
"(",
"b",
",",
"'.'",
")",
"\n",
"b",
"=",
"strconv",
".",
"AppendUint",
"(",
"b",
",",
"v",
".",
"Patch",
",",
"10",
")",
"\n\n",
"if",
"len",
"(",
"v",
".",
"Pre",
")",
">",
"0",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"'-'",
")",
"\n",
"b",
"=",
"append",
"(",
"b",
",",
"v",
".",
"Pre",
"[",
"0",
"]",
".",
"String",
"(",
")",
"...",
")",
"\n\n",
"for",
"_",
",",
"pre",
":=",
"range",
"v",
".",
"Pre",
"[",
"1",
":",
"]",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"'.'",
")",
"\n",
"b",
"=",
"append",
"(",
"b",
",",
"pre",
".",
"String",
"(",
")",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"v",
".",
"Build",
")",
">",
"0",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"'+'",
")",
"\n",
"b",
"=",
"append",
"(",
"b",
",",
"v",
".",
"Build",
"[",
"0",
"]",
"...",
")",
"\n\n",
"for",
"_",
",",
"build",
":=",
"range",
"v",
".",
"Build",
"[",
"1",
":",
"]",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"'.'",
")",
"\n",
"b",
"=",
"append",
"(",
"b",
",",
"build",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"string",
"(",
"b",
")",
"\n",
"}"
] |
// Version to string
|
[
"Version",
"to",
"string"
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/semver.go#L33-L62
|
18,462
|
blang/semver
|
semver.go
|
IncrementPatch
|
func (v *Version) IncrementPatch() error {
if v.Major == 0 {
return fmt.Errorf("Patch version can not be incremented for %q", v.String())
}
v.Patch += 1
return nil
}
|
go
|
func (v *Version) IncrementPatch() error {
if v.Major == 0 {
return fmt.Errorf("Patch version can not be incremented for %q", v.String())
}
v.Patch += 1
return nil
}
|
[
"func",
"(",
"v",
"*",
"Version",
")",
"IncrementPatch",
"(",
")",
"error",
"{",
"if",
"v",
".",
"Major",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"v",
".",
"Patch",
"+=",
"1",
"\n",
"return",
"nil",
"\n",
"}"
] |
// IncrementPatch increments the patch version
|
[
"IncrementPatch",
"increments",
"the",
"patch",
"version"
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/semver.go#L165-L171
|
18,463
|
blang/semver
|
semver.go
|
IncrementMinor
|
func (v *Version) IncrementMinor() error {
if v.Major == 0 {
return fmt.Errorf("Minor version can not be incremented for %q", v.String())
}
v.Minor += 1
v.Patch = 0
return nil
}
|
go
|
func (v *Version) IncrementMinor() error {
if v.Major == 0 {
return fmt.Errorf("Minor version can not be incremented for %q", v.String())
}
v.Minor += 1
v.Patch = 0
return nil
}
|
[
"func",
"(",
"v",
"*",
"Version",
")",
"IncrementMinor",
"(",
")",
"error",
"{",
"if",
"v",
".",
"Major",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"v",
".",
"Minor",
"+=",
"1",
"\n",
"v",
".",
"Patch",
"=",
"0",
"\n",
"return",
"nil",
"\n",
"}"
] |
// IncrementMinor increments the minor version
|
[
"IncrementMinor",
"increments",
"the",
"minor",
"version"
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/semver.go#L174-L181
|
18,464
|
blang/semver
|
semver.go
|
Validate
|
func (v Version) Validate() error {
// Major, Minor, Patch already validated using uint64
for _, pre := range v.Pre {
if !pre.IsNum { //Numeric prerelease versions already uint64
if len(pre.VersionStr) == 0 {
return fmt.Errorf("Prerelease can not be empty %q", pre.VersionStr)
}
if !containsOnly(pre.VersionStr, alphanum) {
return fmt.Errorf("Invalid character(s) found in prerelease %q", pre.VersionStr)
}
}
}
for _, build := range v.Build {
if len(build) == 0 {
return fmt.Errorf("Build meta data can not be empty %q", build)
}
if !containsOnly(build, alphanum) {
return fmt.Errorf("Invalid character(s) found in build meta data %q", build)
}
}
return nil
}
|
go
|
func (v Version) Validate() error {
// Major, Minor, Patch already validated using uint64
for _, pre := range v.Pre {
if !pre.IsNum { //Numeric prerelease versions already uint64
if len(pre.VersionStr) == 0 {
return fmt.Errorf("Prerelease can not be empty %q", pre.VersionStr)
}
if !containsOnly(pre.VersionStr, alphanum) {
return fmt.Errorf("Invalid character(s) found in prerelease %q", pre.VersionStr)
}
}
}
for _, build := range v.Build {
if len(build) == 0 {
return fmt.Errorf("Build meta data can not be empty %q", build)
}
if !containsOnly(build, alphanum) {
return fmt.Errorf("Invalid character(s) found in build meta data %q", build)
}
}
return nil
}
|
[
"func",
"(",
"v",
"Version",
")",
"Validate",
"(",
")",
"error",
"{",
"// Major, Minor, Patch already validated using uint64",
"for",
"_",
",",
"pre",
":=",
"range",
"v",
".",
"Pre",
"{",
"if",
"!",
"pre",
".",
"IsNum",
"{",
"//Numeric prerelease versions already uint64",
"if",
"len",
"(",
"pre",
".",
"VersionStr",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pre",
".",
"VersionStr",
")",
"\n",
"}",
"\n",
"if",
"!",
"containsOnly",
"(",
"pre",
".",
"VersionStr",
",",
"alphanum",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pre",
".",
"VersionStr",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"build",
":=",
"range",
"v",
".",
"Build",
"{",
"if",
"len",
"(",
"build",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"build",
")",
"\n",
"}",
"\n",
"if",
"!",
"containsOnly",
"(",
"build",
",",
"alphanum",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"build",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Validate validates v and returns error in case
|
[
"Validate",
"validates",
"v",
"and",
"returns",
"error",
"in",
"case"
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/semver.go#L195-L219
|
18,465
|
blang/semver
|
semver.go
|
New
|
func New(s string) (vp *Version, err error) {
v, err := Parse(s)
vp = &v
return
}
|
go
|
func New(s string) (vp *Version, err error) {
v, err := Parse(s)
vp = &v
return
}
|
[
"func",
"New",
"(",
"s",
"string",
")",
"(",
"vp",
"*",
"Version",
",",
"err",
"error",
")",
"{",
"v",
",",
"err",
":=",
"Parse",
"(",
"s",
")",
"\n",
"vp",
"=",
"&",
"v",
"\n",
"return",
"\n",
"}"
] |
// New is an alias for Parse and returns a pointer, parses version string and returns a validated Version or error
|
[
"New",
"is",
"an",
"alias",
"for",
"Parse",
"and",
"returns",
"a",
"pointer",
"parses",
"version",
"string",
"and",
"returns",
"a",
"validated",
"Version",
"or",
"error"
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/semver.go#L222-L226
|
18,466
|
blang/semver
|
semver.go
|
MustParse
|
func MustParse(s string) Version {
v, err := Parse(s)
if err != nil {
panic(`semver: Parse(` + s + `): ` + err.Error())
}
return v
}
|
go
|
func MustParse(s string) Version {
v, err := Parse(s)
if err != nil {
panic(`semver: Parse(` + s + `): ` + err.Error())
}
return v
}
|
[
"func",
"MustParse",
"(",
"s",
"string",
")",
"Version",
"{",
"v",
",",
"err",
":=",
"Parse",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"`semver: Parse(`",
"+",
"s",
"+",
"`): `",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
] |
// MustParse is like Parse but panics if the version cannot be parsed.
|
[
"MustParse",
"is",
"like",
"Parse",
"but",
"panics",
"if",
"the",
"version",
"cannot",
"be",
"parsed",
"."
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/semver.go#L353-L359
|
18,467
|
blang/semver
|
semver.go
|
NewPRVersion
|
func NewPRVersion(s string) (PRVersion, error) {
if len(s) == 0 {
return PRVersion{}, errors.New("Prerelease is empty")
}
v := PRVersion{}
if containsOnly(s, numbers) {
if hasLeadingZeroes(s) {
return PRVersion{}, fmt.Errorf("Numeric PreRelease version must not contain leading zeroes %q", s)
}
num, err := strconv.ParseUint(s, 10, 64)
// Might never be hit, but just in case
if err != nil {
return PRVersion{}, err
}
v.VersionNum = num
v.IsNum = true
} else if containsOnly(s, alphanum) {
v.VersionStr = s
v.IsNum = false
} else {
return PRVersion{}, fmt.Errorf("Invalid character(s) found in prerelease %q", s)
}
return v, nil
}
|
go
|
func NewPRVersion(s string) (PRVersion, error) {
if len(s) == 0 {
return PRVersion{}, errors.New("Prerelease is empty")
}
v := PRVersion{}
if containsOnly(s, numbers) {
if hasLeadingZeroes(s) {
return PRVersion{}, fmt.Errorf("Numeric PreRelease version must not contain leading zeroes %q", s)
}
num, err := strconv.ParseUint(s, 10, 64)
// Might never be hit, but just in case
if err != nil {
return PRVersion{}, err
}
v.VersionNum = num
v.IsNum = true
} else if containsOnly(s, alphanum) {
v.VersionStr = s
v.IsNum = false
} else {
return PRVersion{}, fmt.Errorf("Invalid character(s) found in prerelease %q", s)
}
return v, nil
}
|
[
"func",
"NewPRVersion",
"(",
"s",
"string",
")",
"(",
"PRVersion",
",",
"error",
")",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"return",
"PRVersion",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"v",
":=",
"PRVersion",
"{",
"}",
"\n",
"if",
"containsOnly",
"(",
"s",
",",
"numbers",
")",
"{",
"if",
"hasLeadingZeroes",
"(",
"s",
")",
"{",
"return",
"PRVersion",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"}",
"\n",
"num",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"s",
",",
"10",
",",
"64",
")",
"\n\n",
"// Might never be hit, but just in case",
"if",
"err",
"!=",
"nil",
"{",
"return",
"PRVersion",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"v",
".",
"VersionNum",
"=",
"num",
"\n",
"v",
".",
"IsNum",
"=",
"true",
"\n",
"}",
"else",
"if",
"containsOnly",
"(",
"s",
",",
"alphanum",
")",
"{",
"v",
".",
"VersionStr",
"=",
"s",
"\n",
"v",
".",
"IsNum",
"=",
"false",
"\n",
"}",
"else",
"{",
"return",
"PRVersion",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"}",
"\n",
"return",
"v",
",",
"nil",
"\n",
"}"
] |
// NewPRVersion creates a new valid prerelease version
|
[
"NewPRVersion",
"creates",
"a",
"new",
"valid",
"prerelease",
"version"
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/semver.go#L369-L393
|
18,468
|
blang/semver
|
semver.go
|
String
|
func (v PRVersion) String() string {
if v.IsNum {
return strconv.FormatUint(v.VersionNum, 10)
}
return v.VersionStr
}
|
go
|
func (v PRVersion) String() string {
if v.IsNum {
return strconv.FormatUint(v.VersionNum, 10)
}
return v.VersionStr
}
|
[
"func",
"(",
"v",
"PRVersion",
")",
"String",
"(",
")",
"string",
"{",
"if",
"v",
".",
"IsNum",
"{",
"return",
"strconv",
".",
"FormatUint",
"(",
"v",
".",
"VersionNum",
",",
"10",
")",
"\n",
"}",
"\n",
"return",
"v",
".",
"VersionStr",
"\n",
"}"
] |
// PreRelease version to string
|
[
"PreRelease",
"version",
"to",
"string"
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/semver.go#L429-L434
|
18,469
|
blang/semver
|
semver.go
|
NewBuildVersion
|
func NewBuildVersion(s string) (string, error) {
if len(s) == 0 {
return "", errors.New("Buildversion is empty")
}
if !containsOnly(s, alphanum) {
return "", fmt.Errorf("Invalid character(s) found in build meta data %q", s)
}
return s, nil
}
|
go
|
func NewBuildVersion(s string) (string, error) {
if len(s) == 0 {
return "", errors.New("Buildversion is empty")
}
if !containsOnly(s, alphanum) {
return "", fmt.Errorf("Invalid character(s) found in build meta data %q", s)
}
return s, nil
}
|
[
"func",
"NewBuildVersion",
"(",
"s",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"containsOnly",
"(",
"s",
",",
"alphanum",
")",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"}",
"\n",
"return",
"s",
",",
"nil",
"\n",
"}"
] |
// NewBuildVersion creates a new valid build version
|
[
"NewBuildVersion",
"creates",
"a",
"new",
"valid",
"build",
"version"
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/semver.go#L447-L455
|
18,470
|
blang/semver
|
range.go
|
rangeFunc
|
func (vr *versionRange) rangeFunc() Range {
return Range(func(v Version) bool {
return vr.c(v, vr.v)
})
}
|
go
|
func (vr *versionRange) rangeFunc() Range {
return Range(func(v Version) bool {
return vr.c(v, vr.v)
})
}
|
[
"func",
"(",
"vr",
"*",
"versionRange",
")",
"rangeFunc",
"(",
")",
"Range",
"{",
"return",
"Range",
"(",
"func",
"(",
"v",
"Version",
")",
"bool",
"{",
"return",
"vr",
".",
"c",
"(",
"v",
",",
"vr",
".",
"v",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// rangeFunc creates a Range from the given versionRange.
|
[
"rangeFunc",
"creates",
"a",
"Range",
"from",
"the",
"given",
"versionRange",
"."
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/range.go#L61-L65
|
18,471
|
blang/semver
|
range.go
|
OR
|
func (rf Range) OR(f Range) Range {
return Range(func(v Version) bool {
return rf(v) || f(v)
})
}
|
go
|
func (rf Range) OR(f Range) Range {
return Range(func(v Version) bool {
return rf(v) || f(v)
})
}
|
[
"func",
"(",
"rf",
"Range",
")",
"OR",
"(",
"f",
"Range",
")",
"Range",
"{",
"return",
"Range",
"(",
"func",
"(",
"v",
"Version",
")",
"bool",
"{",
"return",
"rf",
"(",
"v",
")",
"||",
"f",
"(",
"v",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// OR combines the existing Range with another Range using logical OR.
|
[
"OR",
"combines",
"the",
"existing",
"Range",
"with",
"another",
"Range",
"using",
"logical",
"OR",
"."
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/range.go#L75-L79
|
18,472
|
blang/semver
|
range.go
|
AND
|
func (rf Range) AND(f Range) Range {
return Range(func(v Version) bool {
return rf(v) && f(v)
})
}
|
go
|
func (rf Range) AND(f Range) Range {
return Range(func(v Version) bool {
return rf(v) && f(v)
})
}
|
[
"func",
"(",
"rf",
"Range",
")",
"AND",
"(",
"f",
"Range",
")",
"Range",
"{",
"return",
"Range",
"(",
"func",
"(",
"v",
"Version",
")",
"bool",
"{",
"return",
"rf",
"(",
"v",
")",
"&&",
"f",
"(",
"v",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// AND combines the existing Range with another Range using logical AND.
|
[
"AND",
"combines",
"the",
"existing",
"Range",
"with",
"another",
"Range",
"using",
"logical",
"AND",
"."
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/range.go#L82-L86
|
18,473
|
blang/semver
|
range.go
|
splitORParts
|
func splitORParts(parts []string) ([][]string, error) {
var ORparts [][]string
last := 0
for i, p := range parts {
if p == "||" {
if i == 0 {
return nil, fmt.Errorf("First element in range is '||'")
}
ORparts = append(ORparts, parts[last:i])
last = i + 1
}
}
if last == len(parts) {
return nil, fmt.Errorf("Last element in range is '||'")
}
ORparts = append(ORparts, parts[last:])
return ORparts, nil
}
|
go
|
func splitORParts(parts []string) ([][]string, error) {
var ORparts [][]string
last := 0
for i, p := range parts {
if p == "||" {
if i == 0 {
return nil, fmt.Errorf("First element in range is '||'")
}
ORparts = append(ORparts, parts[last:i])
last = i + 1
}
}
if last == len(parts) {
return nil, fmt.Errorf("Last element in range is '||'")
}
ORparts = append(ORparts, parts[last:])
return ORparts, nil
}
|
[
"func",
"splitORParts",
"(",
"parts",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"ORparts",
"[",
"]",
"[",
"]",
"string",
"\n",
"last",
":=",
"0",
"\n",
"for",
"i",
",",
"p",
":=",
"range",
"parts",
"{",
"if",
"p",
"==",
"\"",
"\"",
"{",
"if",
"i",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ORparts",
"=",
"append",
"(",
"ORparts",
",",
"parts",
"[",
"last",
":",
"i",
"]",
")",
"\n",
"last",
"=",
"i",
"+",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"last",
"==",
"len",
"(",
"parts",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ORparts",
"=",
"append",
"(",
"ORparts",
",",
"parts",
"[",
"last",
":",
"]",
")",
"\n",
"return",
"ORparts",
",",
"nil",
"\n",
"}"
] |
// splitORParts splits the already cleaned parts by '||'.
// Checks for invalid positions of the operator and returns an
// error if found.
|
[
"splitORParts",
"splits",
"the",
"already",
"cleaned",
"parts",
"by",
"||",
".",
"Checks",
"for",
"invalid",
"positions",
"of",
"the",
"operator",
"and",
"returns",
"an",
"error",
"if",
"found",
"."
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/range.go#L156-L173
|
18,474
|
blang/semver
|
range.go
|
inArray
|
func inArray(s byte, list []byte) bool {
for _, el := range list {
if el == s {
return true
}
}
return false
}
|
go
|
func inArray(s byte, list []byte) bool {
for _, el := range list {
if el == s {
return true
}
}
return false
}
|
[
"func",
"inArray",
"(",
"s",
"byte",
",",
"list",
"[",
"]",
"byte",
")",
"bool",
"{",
"for",
"_",
",",
"el",
":=",
"range",
"list",
"{",
"if",
"el",
"==",
"s",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// inArray checks if a byte is contained in an array of bytes
|
[
"inArray",
"checks",
"if",
"a",
"byte",
"is",
"contained",
"in",
"an",
"array",
"of",
"bytes"
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/range.go#L195-L202
|
18,475
|
blang/semver
|
range.go
|
splitAndTrim
|
func splitAndTrim(s string) (result []string) {
last := 0
var lastChar byte
excludeFromSplit := []byte{'>', '<', '='}
for i := 0; i < len(s); i++ {
if s[i] == ' ' && !inArray(lastChar, excludeFromSplit) {
if last < i-1 {
result = append(result, s[last:i])
}
last = i + 1
} else if s[i] != ' ' {
lastChar = s[i]
}
}
if last < len(s)-1 {
result = append(result, s[last:])
}
for i, v := range result {
result[i] = strings.Replace(v, " ", "", -1)
}
// parts := strings.Split(s, " ")
// for _, x := range parts {
// if s := strings.TrimSpace(x); len(s) != 0 {
// result = append(result, s)
// }
// }
return
}
|
go
|
func splitAndTrim(s string) (result []string) {
last := 0
var lastChar byte
excludeFromSplit := []byte{'>', '<', '='}
for i := 0; i < len(s); i++ {
if s[i] == ' ' && !inArray(lastChar, excludeFromSplit) {
if last < i-1 {
result = append(result, s[last:i])
}
last = i + 1
} else if s[i] != ' ' {
lastChar = s[i]
}
}
if last < len(s)-1 {
result = append(result, s[last:])
}
for i, v := range result {
result[i] = strings.Replace(v, " ", "", -1)
}
// parts := strings.Split(s, " ")
// for _, x := range parts {
// if s := strings.TrimSpace(x); len(s) != 0 {
// result = append(result, s)
// }
// }
return
}
|
[
"func",
"splitAndTrim",
"(",
"s",
"string",
")",
"(",
"result",
"[",
"]",
"string",
")",
"{",
"last",
":=",
"0",
"\n",
"var",
"lastChar",
"byte",
"\n",
"excludeFromSplit",
":=",
"[",
"]",
"byte",
"{",
"'>'",
",",
"'<'",
",",
"'='",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"s",
")",
";",
"i",
"++",
"{",
"if",
"s",
"[",
"i",
"]",
"==",
"' '",
"&&",
"!",
"inArray",
"(",
"lastChar",
",",
"excludeFromSplit",
")",
"{",
"if",
"last",
"<",
"i",
"-",
"1",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"s",
"[",
"last",
":",
"i",
"]",
")",
"\n",
"}",
"\n",
"last",
"=",
"i",
"+",
"1",
"\n",
"}",
"else",
"if",
"s",
"[",
"i",
"]",
"!=",
"' '",
"{",
"lastChar",
"=",
"s",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"last",
"<",
"len",
"(",
"s",
")",
"-",
"1",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"s",
"[",
"last",
":",
"]",
")",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"v",
":=",
"range",
"result",
"{",
"result",
"[",
"i",
"]",
"=",
"strings",
".",
"Replace",
"(",
"v",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"}",
"\n\n",
"// parts := strings.Split(s, \" \")",
"// for _, x := range parts {",
"// \tif s := strings.TrimSpace(x); len(s) != 0 {",
"// \t\tresult = append(result, s)",
"// \t}",
"// }",
"return",
"\n",
"}"
] |
// splitAndTrim splits a range string by spaces and cleans whitespaces
|
[
"splitAndTrim",
"splits",
"a",
"range",
"string",
"by",
"spaces",
"and",
"cleans",
"whitespaces"
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/range.go#L205-L234
|
18,476
|
blang/semver
|
range.go
|
splitComparatorVersion
|
func splitComparatorVersion(s string) (string, string, error) {
i := strings.IndexFunc(s, unicode.IsDigit)
if i == -1 {
return "", "", fmt.Errorf("Could not get version from string: %q", s)
}
return strings.TrimSpace(s[0:i]), s[i:], nil
}
|
go
|
func splitComparatorVersion(s string) (string, string, error) {
i := strings.IndexFunc(s, unicode.IsDigit)
if i == -1 {
return "", "", fmt.Errorf("Could not get version from string: %q", s)
}
return strings.TrimSpace(s[0:i]), s[i:], nil
}
|
[
"func",
"splitComparatorVersion",
"(",
"s",
"string",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"i",
":=",
"strings",
".",
"IndexFunc",
"(",
"s",
",",
"unicode",
".",
"IsDigit",
")",
"\n",
"if",
"i",
"==",
"-",
"1",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"}",
"\n",
"return",
"strings",
".",
"TrimSpace",
"(",
"s",
"[",
"0",
":",
"i",
"]",
")",
",",
"s",
"[",
"i",
":",
"]",
",",
"nil",
"\n",
"}"
] |
// splitComparatorVersion splits the comparator from the version.
// Input must be free of leading or trailing spaces.
|
[
"splitComparatorVersion",
"splits",
"the",
"comparator",
"from",
"the",
"version",
".",
"Input",
"must",
"be",
"free",
"of",
"leading",
"or",
"trailing",
"spaces",
"."
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/range.go#L238-L244
|
18,477
|
blang/semver
|
range.go
|
getWildcardType
|
func getWildcardType(vStr string) wildcardType {
parts := strings.Split(vStr, ".")
nparts := len(parts)
wildcard := parts[nparts-1]
possibleWildcardType := wildcardTypefromInt(nparts)
if wildcard == "x" {
return possibleWildcardType
}
return noneWildcard
}
|
go
|
func getWildcardType(vStr string) wildcardType {
parts := strings.Split(vStr, ".")
nparts := len(parts)
wildcard := parts[nparts-1]
possibleWildcardType := wildcardTypefromInt(nparts)
if wildcard == "x" {
return possibleWildcardType
}
return noneWildcard
}
|
[
"func",
"getWildcardType",
"(",
"vStr",
"string",
")",
"wildcardType",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"vStr",
",",
"\"",
"\"",
")",
"\n",
"nparts",
":=",
"len",
"(",
"parts",
")",
"\n",
"wildcard",
":=",
"parts",
"[",
"nparts",
"-",
"1",
"]",
"\n\n",
"possibleWildcardType",
":=",
"wildcardTypefromInt",
"(",
"nparts",
")",
"\n",
"if",
"wildcard",
"==",
"\"",
"\"",
"{",
"return",
"possibleWildcardType",
"\n",
"}",
"\n\n",
"return",
"noneWildcard",
"\n",
"}"
] |
// getWildcardType will return the type of wildcard that the
// passed version contains
|
[
"getWildcardType",
"will",
"return",
"the",
"type",
"of",
"wildcard",
"that",
"the",
"passed",
"version",
"contains"
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/range.go#L248-L259
|
18,478
|
blang/semver
|
range.go
|
createVersionFromWildcard
|
func createVersionFromWildcard(vStr string) string {
// handle 1.x.x
vStr2 := strings.Replace(vStr, ".x.x", ".x", 1)
vStr2 = strings.Replace(vStr2, ".x", ".0", 1)
parts := strings.Split(vStr2, ".")
// handle 1.x
if len(parts) == 2 {
return vStr2 + ".0"
}
return vStr2
}
|
go
|
func createVersionFromWildcard(vStr string) string {
// handle 1.x.x
vStr2 := strings.Replace(vStr, ".x.x", ".x", 1)
vStr2 = strings.Replace(vStr2, ".x", ".0", 1)
parts := strings.Split(vStr2, ".")
// handle 1.x
if len(parts) == 2 {
return vStr2 + ".0"
}
return vStr2
}
|
[
"func",
"createVersionFromWildcard",
"(",
"vStr",
"string",
")",
"string",
"{",
"// handle 1.x.x",
"vStr2",
":=",
"strings",
".",
"Replace",
"(",
"vStr",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"1",
")",
"\n",
"vStr2",
"=",
"strings",
".",
"Replace",
"(",
"vStr2",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"1",
")",
"\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"vStr2",
",",
"\"",
"\"",
")",
"\n\n",
"// handle 1.x",
"if",
"len",
"(",
"parts",
")",
"==",
"2",
"{",
"return",
"vStr2",
"+",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"vStr2",
"\n",
"}"
] |
// createVersionFromWildcard will convert a wildcard version
// into a regular version, replacing 'x's with '0's, handling
// special cases like '1.x.x' and '1.x'
|
[
"createVersionFromWildcard",
"will",
"convert",
"a",
"wildcard",
"version",
"into",
"a",
"regular",
"version",
"replacing",
"x",
"s",
"with",
"0",
"s",
"handling",
"special",
"cases",
"like",
"1",
".",
"x",
".",
"x",
"and",
"1",
".",
"x"
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/range.go#L264-L276
|
18,479
|
blang/semver
|
range.go
|
incrementMajorVersion
|
func incrementMajorVersion(vStr string) (string, error) {
parts := strings.Split(vStr, ".")
i, err := strconv.Atoi(parts[0])
if err != nil {
return "", err
}
parts[0] = strconv.Itoa(i + 1)
return strings.Join(parts, "."), nil
}
|
go
|
func incrementMajorVersion(vStr string) (string, error) {
parts := strings.Split(vStr, ".")
i, err := strconv.Atoi(parts[0])
if err != nil {
return "", err
}
parts[0] = strconv.Itoa(i + 1)
return strings.Join(parts, "."), nil
}
|
[
"func",
"incrementMajorVersion",
"(",
"vStr",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"vStr",
",",
"\"",
"\"",
")",
"\n",
"i",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"parts",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"parts",
"[",
"0",
"]",
"=",
"strconv",
".",
"Itoa",
"(",
"i",
"+",
"1",
")",
"\n\n",
"return",
"strings",
".",
"Join",
"(",
"parts",
",",
"\"",
"\"",
")",
",",
"nil",
"\n",
"}"
] |
// incrementMajorVersion will increment the major version
// of the passed version
|
[
"incrementMajorVersion",
"will",
"increment",
"the",
"major",
"version",
"of",
"the",
"passed",
"version"
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/range.go#L280-L289
|
18,480
|
blang/semver
|
range.go
|
MustParseRange
|
func MustParseRange(s string) Range {
r, err := ParseRange(s)
if err != nil {
panic(`semver: ParseRange(` + s + `): ` + err.Error())
}
return r
}
|
go
|
func MustParseRange(s string) Range {
r, err := ParseRange(s)
if err != nil {
panic(`semver: ParseRange(` + s + `): ` + err.Error())
}
return r
}
|
[
"func",
"MustParseRange",
"(",
"s",
"string",
")",
"Range",
"{",
"r",
",",
"err",
":=",
"ParseRange",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"`semver: ParseRange(`",
"+",
"s",
"+",
"`): `",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// MustParseRange is like ParseRange but panics if the range cannot be parsed.
|
[
"MustParseRange",
"is",
"like",
"ParseRange",
"but",
"panics",
"if",
"the",
"range",
"cannot",
"be",
"parsed",
"."
] |
1a9109f8c4a1d669a78442f567dfe8eedf982793
|
https://github.com/blang/semver/blob/1a9109f8c4a1d669a78442f567dfe8eedf982793/range.go#L410-L416
|
18,481
|
graph-gophers/dataloader
|
example/ttl-cache/go-cache.go
|
Get
|
func (c *Cache) Get(_ context.Context, key dataloader.Key) (dataloader.Thunk, bool) {
v, ok := c.c.Get(key.String())
if ok {
return v.(dataloader.Thunk), ok
}
return nil, ok
}
|
go
|
func (c *Cache) Get(_ context.Context, key dataloader.Key) (dataloader.Thunk, bool) {
v, ok := c.c.Get(key.String())
if ok {
return v.(dataloader.Thunk), ok
}
return nil, ok
}
|
[
"func",
"(",
"c",
"*",
"Cache",
")",
"Get",
"(",
"_",
"context",
".",
"Context",
",",
"key",
"dataloader",
".",
"Key",
")",
"(",
"dataloader",
".",
"Thunk",
",",
"bool",
")",
"{",
"v",
",",
"ok",
":=",
"c",
".",
"c",
".",
"Get",
"(",
"key",
".",
"String",
"(",
")",
")",
"\n",
"if",
"ok",
"{",
"return",
"v",
".",
"(",
"dataloader",
".",
"Thunk",
")",
",",
"ok",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ok",
"\n",
"}"
] |
// Get gets a value from the cache
|
[
"Get",
"gets",
"a",
"value",
"from",
"the",
"cache"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/example/ttl-cache/go-cache.go#L20-L26
|
18,482
|
graph-gophers/dataloader
|
example/ttl-cache/go-cache.go
|
Set
|
func (c *Cache) Set(_ context.Context, key dataloader.Key, value dataloader.Thunk) {
c.c.Set(key.String(), value, 0)
}
|
go
|
func (c *Cache) Set(_ context.Context, key dataloader.Key, value dataloader.Thunk) {
c.c.Set(key.String(), value, 0)
}
|
[
"func",
"(",
"c",
"*",
"Cache",
")",
"Set",
"(",
"_",
"context",
".",
"Context",
",",
"key",
"dataloader",
".",
"Key",
",",
"value",
"dataloader",
".",
"Thunk",
")",
"{",
"c",
".",
"c",
".",
"Set",
"(",
"key",
".",
"String",
"(",
")",
",",
"value",
",",
"0",
")",
"\n",
"}"
] |
// Set sets a value in the cache
|
[
"Set",
"sets",
"a",
"value",
"in",
"the",
"cache"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/example/ttl-cache/go-cache.go#L29-L31
|
18,483
|
graph-gophers/dataloader
|
example/ttl-cache/go-cache.go
|
Delete
|
func (c *Cache) Delete(_ context.Context, key dataloader.Key) bool {
if _, found := c.c.Get(key.String()); found {
c.c.Delete(key.String())
return true
}
return false
}
|
go
|
func (c *Cache) Delete(_ context.Context, key dataloader.Key) bool {
if _, found := c.c.Get(key.String()); found {
c.c.Delete(key.String())
return true
}
return false
}
|
[
"func",
"(",
"c",
"*",
"Cache",
")",
"Delete",
"(",
"_",
"context",
".",
"Context",
",",
"key",
"dataloader",
".",
"Key",
")",
"bool",
"{",
"if",
"_",
",",
"found",
":=",
"c",
".",
"c",
".",
"Get",
"(",
"key",
".",
"String",
"(",
")",
")",
";",
"found",
"{",
"c",
".",
"c",
".",
"Delete",
"(",
"key",
".",
"String",
"(",
")",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// Delete deletes and item in the cache
|
[
"Delete",
"deletes",
"and",
"item",
"in",
"the",
"cache"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/example/ttl-cache/go-cache.go#L34-L40
|
18,484
|
graph-gophers/dataloader
|
dataloader.go
|
WithWait
|
func WithWait(d time.Duration) Option {
return func(l *Loader) {
l.wait = d
}
}
|
go
|
func WithWait(d time.Duration) Option {
return func(l *Loader) {
l.wait = d
}
}
|
[
"func",
"WithWait",
"(",
"d",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"func",
"(",
"l",
"*",
"Loader",
")",
"{",
"l",
".",
"wait",
"=",
"d",
"\n",
"}",
"\n",
"}"
] |
// WithWait sets the amount of time to wait before triggering a batch.
// Default duration is 16 milliseconds.
|
[
"WithWait",
"sets",
"the",
"amount",
"of",
"time",
"to",
"wait",
"before",
"triggering",
"a",
"batch",
".",
"Default",
"duration",
"is",
"16",
"milliseconds",
"."
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/dataloader.go#L133-L137
|
18,485
|
graph-gophers/dataloader
|
dataloader.go
|
WithClearCacheOnBatch
|
func WithClearCacheOnBatch() Option {
return func(l *Loader) {
l.cacheLock.Lock()
l.clearCacheOnBatch = true
l.cacheLock.Unlock()
}
}
|
go
|
func WithClearCacheOnBatch() Option {
return func(l *Loader) {
l.cacheLock.Lock()
l.clearCacheOnBatch = true
l.cacheLock.Unlock()
}
}
|
[
"func",
"WithClearCacheOnBatch",
"(",
")",
"Option",
"{",
"return",
"func",
"(",
"l",
"*",
"Loader",
")",
"{",
"l",
".",
"cacheLock",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"clearCacheOnBatch",
"=",
"true",
"\n",
"l",
".",
"cacheLock",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// WithClearCacheOnBatch allows batching of items but no long term caching.
// It accomplishes this by clearing the cache after each batch operation.
|
[
"WithClearCacheOnBatch",
"allows",
"batching",
"of",
"items",
"but",
"no",
"long",
"term",
"caching",
".",
"It",
"accomplishes",
"this",
"by",
"clearing",
"the",
"cache",
"after",
"each",
"batch",
"operation",
"."
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/dataloader.go#L141-L147
|
18,486
|
graph-gophers/dataloader
|
dataloader.go
|
NewBatchedLoader
|
func NewBatchedLoader(batchFn BatchFunc, opts ...Option) *Loader {
loader := &Loader{
batchFn: batchFn,
inputCap: 1000,
wait: 16 * time.Millisecond,
}
// Apply options
for _, apply := range opts {
apply(loader)
}
// Set defaults
if loader.cache == nil {
loader.cache = NewCache()
}
if loader.tracer == nil {
loader.tracer = &NoopTracer{}
}
return loader
}
|
go
|
func NewBatchedLoader(batchFn BatchFunc, opts ...Option) *Loader {
loader := &Loader{
batchFn: batchFn,
inputCap: 1000,
wait: 16 * time.Millisecond,
}
// Apply options
for _, apply := range opts {
apply(loader)
}
// Set defaults
if loader.cache == nil {
loader.cache = NewCache()
}
if loader.tracer == nil {
loader.tracer = &NoopTracer{}
}
return loader
}
|
[
"func",
"NewBatchedLoader",
"(",
"batchFn",
"BatchFunc",
",",
"opts",
"...",
"Option",
")",
"*",
"Loader",
"{",
"loader",
":=",
"&",
"Loader",
"{",
"batchFn",
":",
"batchFn",
",",
"inputCap",
":",
"1000",
",",
"wait",
":",
"16",
"*",
"time",
".",
"Millisecond",
",",
"}",
"\n\n",
"// Apply options",
"for",
"_",
",",
"apply",
":=",
"range",
"opts",
"{",
"apply",
"(",
"loader",
")",
"\n",
"}",
"\n\n",
"// Set defaults",
"if",
"loader",
".",
"cache",
"==",
"nil",
"{",
"loader",
".",
"cache",
"=",
"NewCache",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"loader",
".",
"tracer",
"==",
"nil",
"{",
"loader",
".",
"tracer",
"=",
"&",
"NoopTracer",
"{",
"}",
"\n",
"}",
"\n\n",
"return",
"loader",
"\n",
"}"
] |
// NewBatchedLoader constructs a new Loader with given options.
|
[
"NewBatchedLoader",
"constructs",
"a",
"new",
"Loader",
"with",
"given",
"options",
"."
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/dataloader.go#L169-L191
|
18,487
|
graph-gophers/dataloader
|
dataloader.go
|
Clear
|
func (l *Loader) Clear(ctx context.Context, key Key) Interface {
l.cacheLock.Lock()
l.cache.Delete(ctx, key)
l.cacheLock.Unlock()
return l
}
|
go
|
func (l *Loader) Clear(ctx context.Context, key Key) Interface {
l.cacheLock.Lock()
l.cache.Delete(ctx, key)
l.cacheLock.Unlock()
return l
}
|
[
"func",
"(",
"l",
"*",
"Loader",
")",
"Clear",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"Key",
")",
"Interface",
"{",
"l",
".",
"cacheLock",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"cache",
".",
"Delete",
"(",
"ctx",
",",
"key",
")",
"\n",
"l",
".",
"cacheLock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"l",
"\n",
"}"
] |
// Clear clears the value at `key` from the cache, it it exsits. Returs self for method chaining
|
[
"Clear",
"clears",
"the",
"value",
"at",
"key",
"from",
"the",
"cache",
"it",
"it",
"exsits",
".",
"Returs",
"self",
"for",
"method",
"chaining"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/dataloader.go#L338-L343
|
18,488
|
graph-gophers/dataloader
|
dataloader.go
|
ClearAll
|
func (l *Loader) ClearAll() Interface {
l.cacheLock.Lock()
l.cache.Clear()
l.cacheLock.Unlock()
return l
}
|
go
|
func (l *Loader) ClearAll() Interface {
l.cacheLock.Lock()
l.cache.Clear()
l.cacheLock.Unlock()
return l
}
|
[
"func",
"(",
"l",
"*",
"Loader",
")",
"ClearAll",
"(",
")",
"Interface",
"{",
"l",
".",
"cacheLock",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"cache",
".",
"Clear",
"(",
")",
"\n",
"l",
".",
"cacheLock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"l",
"\n",
"}"
] |
// ClearAll clears the entire cache. To be used when some event results in unknown invalidations.
// Returns self for method chaining.
|
[
"ClearAll",
"clears",
"the",
"entire",
"cache",
".",
"To",
"be",
"used",
"when",
"some",
"event",
"results",
"in",
"unknown",
"invalidations",
".",
"Returns",
"self",
"for",
"method",
"chaining",
"."
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/dataloader.go#L347-L352
|
18,489
|
graph-gophers/dataloader
|
dataloader.go
|
Prime
|
func (l *Loader) Prime(ctx context.Context, key Key, value interface{}) Interface {
if _, ok := l.cache.Get(ctx, key); !ok {
thunk := func() (interface{}, error) {
return value, nil
}
l.cache.Set(ctx, key, thunk)
}
return l
}
|
go
|
func (l *Loader) Prime(ctx context.Context, key Key, value interface{}) Interface {
if _, ok := l.cache.Get(ctx, key); !ok {
thunk := func() (interface{}, error) {
return value, nil
}
l.cache.Set(ctx, key, thunk)
}
return l
}
|
[
"func",
"(",
"l",
"*",
"Loader",
")",
"Prime",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"Key",
",",
"value",
"interface",
"{",
"}",
")",
"Interface",
"{",
"if",
"_",
",",
"ok",
":=",
"l",
".",
"cache",
".",
"Get",
"(",
"ctx",
",",
"key",
")",
";",
"!",
"ok",
"{",
"thunk",
":=",
"func",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"return",
"value",
",",
"nil",
"\n",
"}",
"\n",
"l",
".",
"cache",
".",
"Set",
"(",
"ctx",
",",
"key",
",",
"thunk",
")",
"\n",
"}",
"\n",
"return",
"l",
"\n",
"}"
] |
// Prime adds the provided key and value to the cache. If the key already exists, no change is made.
// Returns self for method chaining
|
[
"Prime",
"adds",
"the",
"provided",
"key",
"and",
"value",
"to",
"the",
"cache",
".",
"If",
"the",
"key",
"already",
"exists",
"no",
"change",
"is",
"made",
".",
"Returns",
"self",
"for",
"method",
"chaining"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/dataloader.go#L356-L364
|
18,490
|
graph-gophers/dataloader
|
dataloader.go
|
newBatcher
|
func (l *Loader) newBatcher(silent bool, tracer Tracer) *batcher {
return &batcher{
input: make(chan *batchRequest, l.inputCap),
batchFn: l.batchFn,
silent: silent,
tracer: tracer,
}
}
|
go
|
func (l *Loader) newBatcher(silent bool, tracer Tracer) *batcher {
return &batcher{
input: make(chan *batchRequest, l.inputCap),
batchFn: l.batchFn,
silent: silent,
tracer: tracer,
}
}
|
[
"func",
"(",
"l",
"*",
"Loader",
")",
"newBatcher",
"(",
"silent",
"bool",
",",
"tracer",
"Tracer",
")",
"*",
"batcher",
"{",
"return",
"&",
"batcher",
"{",
"input",
":",
"make",
"(",
"chan",
"*",
"batchRequest",
",",
"l",
".",
"inputCap",
")",
",",
"batchFn",
":",
"l",
".",
"batchFn",
",",
"silent",
":",
"silent",
",",
"tracer",
":",
"tracer",
",",
"}",
"\n",
"}"
] |
// newBatcher returns a batcher for the current requests
// all the batcher methods must be protected by a global batchLock
|
[
"newBatcher",
"returns",
"a",
"batcher",
"for",
"the",
"current",
"requests",
"all",
"the",
"batcher",
"methods",
"must",
"be",
"protected",
"by",
"a",
"global",
"batchLock"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/dataloader.go#L385-L392
|
18,491
|
graph-gophers/dataloader
|
dataloader.go
|
end
|
func (b *batcher) end() {
if !b.finished {
close(b.input)
b.finished = true
}
}
|
go
|
func (b *batcher) end() {
if !b.finished {
close(b.input)
b.finished = true
}
}
|
[
"func",
"(",
"b",
"*",
"batcher",
")",
"end",
"(",
")",
"{",
"if",
"!",
"b",
".",
"finished",
"{",
"close",
"(",
"b",
".",
"input",
")",
"\n",
"b",
".",
"finished",
"=",
"true",
"\n",
"}",
"\n",
"}"
] |
// stop receiving input and process batch function
|
[
"stop",
"receiving",
"input",
"and",
"process",
"batch",
"function"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/dataloader.go#L395-L400
|
18,492
|
graph-gophers/dataloader
|
dataloader.go
|
batch
|
func (b *batcher) batch(originalContext context.Context) {
var (
keys = make(Keys, 0)
reqs = make([]*batchRequest, 0)
items = make([]*Result, 0)
panicErr interface{}
)
for item := range b.input {
keys = append(keys, item.key)
reqs = append(reqs, item)
}
ctx, finish := b.tracer.TraceBatch(originalContext, keys)
defer finish(items)
func() {
defer func() {
if r := recover(); r != nil {
panicErr = r
if b.silent {
return
}
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
log.Printf("Dataloader: Panic received in batch function:: %v\n%s", panicErr, buf)
}
}()
items = b.batchFn(ctx, keys)
}()
if panicErr != nil {
for _, req := range reqs {
req.channel <- &Result{Error: fmt.Errorf("Panic received in batch function: %v", panicErr)}
close(req.channel)
}
return
}
if len(items) != len(keys) {
err := &Result{Error: fmt.Errorf(`
The batch function supplied did not return an array of responses
the same length as the array of keys.
Keys:
%v
Values:
%v
`, keys, items)}
for _, req := range reqs {
req.channel <- err
close(req.channel)
}
return
}
for i, req := range reqs {
req.channel <- items[i]
close(req.channel)
}
}
|
go
|
func (b *batcher) batch(originalContext context.Context) {
var (
keys = make(Keys, 0)
reqs = make([]*batchRequest, 0)
items = make([]*Result, 0)
panicErr interface{}
)
for item := range b.input {
keys = append(keys, item.key)
reqs = append(reqs, item)
}
ctx, finish := b.tracer.TraceBatch(originalContext, keys)
defer finish(items)
func() {
defer func() {
if r := recover(); r != nil {
panicErr = r
if b.silent {
return
}
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
log.Printf("Dataloader: Panic received in batch function:: %v\n%s", panicErr, buf)
}
}()
items = b.batchFn(ctx, keys)
}()
if panicErr != nil {
for _, req := range reqs {
req.channel <- &Result{Error: fmt.Errorf("Panic received in batch function: %v", panicErr)}
close(req.channel)
}
return
}
if len(items) != len(keys) {
err := &Result{Error: fmt.Errorf(`
The batch function supplied did not return an array of responses
the same length as the array of keys.
Keys:
%v
Values:
%v
`, keys, items)}
for _, req := range reqs {
req.channel <- err
close(req.channel)
}
return
}
for i, req := range reqs {
req.channel <- items[i]
close(req.channel)
}
}
|
[
"func",
"(",
"b",
"*",
"batcher",
")",
"batch",
"(",
"originalContext",
"context",
".",
"Context",
")",
"{",
"var",
"(",
"keys",
"=",
"make",
"(",
"Keys",
",",
"0",
")",
"\n",
"reqs",
"=",
"make",
"(",
"[",
"]",
"*",
"batchRequest",
",",
"0",
")",
"\n",
"items",
"=",
"make",
"(",
"[",
"]",
"*",
"Result",
",",
"0",
")",
"\n",
"panicErr",
"interface",
"{",
"}",
"\n",
")",
"\n\n",
"for",
"item",
":=",
"range",
"b",
".",
"input",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"item",
".",
"key",
")",
"\n",
"reqs",
"=",
"append",
"(",
"reqs",
",",
"item",
")",
"\n",
"}",
"\n\n",
"ctx",
",",
"finish",
":=",
"b",
".",
"tracer",
".",
"TraceBatch",
"(",
"originalContext",
",",
"keys",
")",
"\n",
"defer",
"finish",
"(",
"items",
")",
"\n\n",
"func",
"(",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"r",
":=",
"recover",
"(",
")",
";",
"r",
"!=",
"nil",
"{",
"panicErr",
"=",
"r",
"\n",
"if",
"b",
".",
"silent",
"{",
"return",
"\n",
"}",
"\n",
"const",
"size",
"=",
"64",
"<<",
"10",
"\n",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"size",
")",
"\n",
"buf",
"=",
"buf",
"[",
":",
"runtime",
".",
"Stack",
"(",
"buf",
",",
"false",
")",
"]",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"panicErr",
",",
"buf",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"items",
"=",
"b",
".",
"batchFn",
"(",
"ctx",
",",
"keys",
")",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"panicErr",
"!=",
"nil",
"{",
"for",
"_",
",",
"req",
":=",
"range",
"reqs",
"{",
"req",
".",
"channel",
"<-",
"&",
"Result",
"{",
"Error",
":",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"panicErr",
")",
"}",
"\n",
"close",
"(",
"req",
".",
"channel",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"items",
")",
"!=",
"len",
"(",
"keys",
")",
"{",
"err",
":=",
"&",
"Result",
"{",
"Error",
":",
"fmt",
".",
"Errorf",
"(",
"`\n\t\t\tThe batch function supplied did not return an array of responses\n\t\t\tthe same length as the array of keys.\n\n\t\t\tKeys:\n\t\t\t%v\n\n\t\t\tValues:\n\t\t\t%v\n\t\t`",
",",
"keys",
",",
"items",
")",
"}",
"\n\n",
"for",
"_",
",",
"req",
":=",
"range",
"reqs",
"{",
"req",
".",
"channel",
"<-",
"err",
"\n",
"close",
"(",
"req",
".",
"channel",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"req",
":=",
"range",
"reqs",
"{",
"req",
".",
"channel",
"<-",
"items",
"[",
"i",
"]",
"\n",
"close",
"(",
"req",
".",
"channel",
")",
"\n",
"}",
"\n",
"}"
] |
// execute the batch of all items in queue
|
[
"execute",
"the",
"batch",
"of",
"all",
"items",
"in",
"queue"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/dataloader.go#L403-L467
|
18,493
|
graph-gophers/dataloader
|
dataloader.go
|
sleeper
|
func (l *Loader) sleeper(b *batcher, close chan bool) {
select {
// used by batch to close early. usually triggered by max batch size
case <-close:
return
// this will move this goroutine to the back of the callstack?
case <-time.After(l.wait):
}
// reset
// this is protected by the batchLock to avoid closing the batcher input
// channel while Load is inserting a request
l.batchLock.Lock()
b.end()
// We can end here also if the batcher has already been closed and a
// new one has been created. So reset the loader state only if the batcher
// is the current one
if l.curBatcher == b {
l.reset()
}
l.batchLock.Unlock()
}
|
go
|
func (l *Loader) sleeper(b *batcher, close chan bool) {
select {
// used by batch to close early. usually triggered by max batch size
case <-close:
return
// this will move this goroutine to the back of the callstack?
case <-time.After(l.wait):
}
// reset
// this is protected by the batchLock to avoid closing the batcher input
// channel while Load is inserting a request
l.batchLock.Lock()
b.end()
// We can end here also if the batcher has already been closed and a
// new one has been created. So reset the loader state only if the batcher
// is the current one
if l.curBatcher == b {
l.reset()
}
l.batchLock.Unlock()
}
|
[
"func",
"(",
"l",
"*",
"Loader",
")",
"sleeper",
"(",
"b",
"*",
"batcher",
",",
"close",
"chan",
"bool",
")",
"{",
"select",
"{",
"// used by batch to close early. usually triggered by max batch size",
"case",
"<-",
"close",
":",
"return",
"\n",
"// this will move this goroutine to the back of the callstack?",
"case",
"<-",
"time",
".",
"After",
"(",
"l",
".",
"wait",
")",
":",
"}",
"\n\n",
"// reset",
"// this is protected by the batchLock to avoid closing the batcher input",
"// channel while Load is inserting a request",
"l",
".",
"batchLock",
".",
"Lock",
"(",
")",
"\n",
"b",
".",
"end",
"(",
")",
"\n\n",
"// We can end here also if the batcher has already been closed and a",
"// new one has been created. So reset the loader state only if the batcher",
"// is the current one",
"if",
"l",
".",
"curBatcher",
"==",
"b",
"{",
"l",
".",
"reset",
"(",
")",
"\n",
"}",
"\n",
"l",
".",
"batchLock",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// wait the appropriate amount of time for the provided batcher
|
[
"wait",
"the",
"appropriate",
"amount",
"of",
"time",
"for",
"the",
"provided",
"batcher"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/dataloader.go#L470-L492
|
18,494
|
graph-gophers/dataloader
|
example/lru-cache/golang-lru.go
|
Set
|
func (c *Cache) Set(_ context.Context, key dataloader.Key, value dataloader.Thunk) {
c.ARCCache.Add(key, value)
}
|
go
|
func (c *Cache) Set(_ context.Context, key dataloader.Key, value dataloader.Thunk) {
c.ARCCache.Add(key, value)
}
|
[
"func",
"(",
"c",
"*",
"Cache",
")",
"Set",
"(",
"_",
"context",
".",
"Context",
",",
"key",
"dataloader",
".",
"Key",
",",
"value",
"dataloader",
".",
"Thunk",
")",
"{",
"c",
".",
"ARCCache",
".",
"Add",
"(",
"key",
",",
"value",
")",
"\n",
"}"
] |
// Set sets an item in the cache
|
[
"Set",
"sets",
"an",
"item",
"in",
"the",
"cache"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/example/lru-cache/golang-lru.go#L28-L30
|
18,495
|
graph-gophers/dataloader
|
example/lru-cache/golang-lru.go
|
Delete
|
func (c *Cache) Delete(_ context.Context, key dataloader.Key) bool {
if c.ARCCache.Contains(key) {
c.ARCCache.Remove(key)
return true
}
return false
}
|
go
|
func (c *Cache) Delete(_ context.Context, key dataloader.Key) bool {
if c.ARCCache.Contains(key) {
c.ARCCache.Remove(key)
return true
}
return false
}
|
[
"func",
"(",
"c",
"*",
"Cache",
")",
"Delete",
"(",
"_",
"context",
".",
"Context",
",",
"key",
"dataloader",
".",
"Key",
")",
"bool",
"{",
"if",
"c",
".",
"ARCCache",
".",
"Contains",
"(",
"key",
")",
"{",
"c",
".",
"ARCCache",
".",
"Remove",
"(",
"key",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// Delete deletes an item in the cache
|
[
"Delete",
"deletes",
"an",
"item",
"in",
"the",
"cache"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/example/lru-cache/golang-lru.go#L33-L39
|
18,496
|
graph-gophers/dataloader
|
key.go
|
Keys
|
func (l Keys) Keys() []string {
list := make([]string, len(l))
for i := range l {
list[i] = l[i].String()
}
return list
}
|
go
|
func (l Keys) Keys() []string {
list := make([]string, len(l))
for i := range l {
list[i] = l[i].String()
}
return list
}
|
[
"func",
"(",
"l",
"Keys",
")",
"Keys",
"(",
")",
"[",
"]",
"string",
"{",
"list",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"l",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"l",
"{",
"list",
"[",
"i",
"]",
"=",
"l",
"[",
"i",
"]",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"list",
"\n",
"}"
] |
// Keys returns the list of strings. One for each "Key" in the list
|
[
"Keys",
"returns",
"the",
"list",
"of",
"strings",
".",
"One",
"for",
"each",
"Key",
"in",
"the",
"list"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/key.go#L15-L21
|
18,497
|
graph-gophers/dataloader
|
trace.go
|
TraceLoad
|
func (OpenTracingTracer) TraceLoad(ctx context.Context, key Key) (context.Context, TraceLoadFinishFunc) {
span, spanCtx := opentracing.StartSpanFromContext(ctx, "Dataloader: load")
span.SetTag("dataloader.key", key.String())
return spanCtx, func(thunk Thunk) {
// TODO: is there anything we should do with the results?
span.Finish()
}
}
|
go
|
func (OpenTracingTracer) TraceLoad(ctx context.Context, key Key) (context.Context, TraceLoadFinishFunc) {
span, spanCtx := opentracing.StartSpanFromContext(ctx, "Dataloader: load")
span.SetTag("dataloader.key", key.String())
return spanCtx, func(thunk Thunk) {
// TODO: is there anything we should do with the results?
span.Finish()
}
}
|
[
"func",
"(",
"OpenTracingTracer",
")",
"TraceLoad",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"Key",
")",
"(",
"context",
".",
"Context",
",",
"TraceLoadFinishFunc",
")",
"{",
"span",
",",
"spanCtx",
":=",
"opentracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n\n",
"span",
".",
"SetTag",
"(",
"\"",
"\"",
",",
"key",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"spanCtx",
",",
"func",
"(",
"thunk",
"Thunk",
")",
"{",
"// TODO: is there anything we should do with the results?",
"span",
".",
"Finish",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// TraceLoad will trace a call to dataloader.LoadMany with Open Tracing
|
[
"TraceLoad",
"will",
"trace",
"a",
"call",
"to",
"dataloader",
".",
"LoadMany",
"with",
"Open",
"Tracing"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/trace.go#L27-L36
|
18,498
|
graph-gophers/dataloader
|
trace.go
|
TraceLoadMany
|
func (OpenTracingTracer) TraceLoadMany(ctx context.Context, keys Keys) (context.Context, TraceLoadManyFinishFunc) {
span, spanCtx := opentracing.StartSpanFromContext(ctx, "Dataloader: loadmany")
span.SetTag("dataloader.keys", keys.Keys())
return spanCtx, func(thunk ThunkMany) {
// TODO: is there anything we should do with the results?
span.Finish()
}
}
|
go
|
func (OpenTracingTracer) TraceLoadMany(ctx context.Context, keys Keys) (context.Context, TraceLoadManyFinishFunc) {
span, spanCtx := opentracing.StartSpanFromContext(ctx, "Dataloader: loadmany")
span.SetTag("dataloader.keys", keys.Keys())
return spanCtx, func(thunk ThunkMany) {
// TODO: is there anything we should do with the results?
span.Finish()
}
}
|
[
"func",
"(",
"OpenTracingTracer",
")",
"TraceLoadMany",
"(",
"ctx",
"context",
".",
"Context",
",",
"keys",
"Keys",
")",
"(",
"context",
".",
"Context",
",",
"TraceLoadManyFinishFunc",
")",
"{",
"span",
",",
"spanCtx",
":=",
"opentracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n\n",
"span",
".",
"SetTag",
"(",
"\"",
"\"",
",",
"keys",
".",
"Keys",
"(",
")",
")",
"\n\n",
"return",
"spanCtx",
",",
"func",
"(",
"thunk",
"ThunkMany",
")",
"{",
"// TODO: is there anything we should do with the results?",
"span",
".",
"Finish",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// TraceLoadMany will trace a call to dataloader.LoadMany with Open Tracing
|
[
"TraceLoadMany",
"will",
"trace",
"a",
"call",
"to",
"dataloader",
".",
"LoadMany",
"with",
"Open",
"Tracing"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/trace.go#L39-L48
|
18,499
|
graph-gophers/dataloader
|
trace.go
|
TraceBatch
|
func (OpenTracingTracer) TraceBatch(ctx context.Context, keys Keys) (context.Context, TraceBatchFinishFunc) {
span, spanCtx := opentracing.StartSpanFromContext(ctx, "Dataloader: batch")
span.SetTag("dataloader.keys", keys.Keys())
return spanCtx, func(results []*Result) {
// TODO: is there anything we should do with the results?
span.Finish()
}
}
|
go
|
func (OpenTracingTracer) TraceBatch(ctx context.Context, keys Keys) (context.Context, TraceBatchFinishFunc) {
span, spanCtx := opentracing.StartSpanFromContext(ctx, "Dataloader: batch")
span.SetTag("dataloader.keys", keys.Keys())
return spanCtx, func(results []*Result) {
// TODO: is there anything we should do with the results?
span.Finish()
}
}
|
[
"func",
"(",
"OpenTracingTracer",
")",
"TraceBatch",
"(",
"ctx",
"context",
".",
"Context",
",",
"keys",
"Keys",
")",
"(",
"context",
".",
"Context",
",",
"TraceBatchFinishFunc",
")",
"{",
"span",
",",
"spanCtx",
":=",
"opentracing",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n\n",
"span",
".",
"SetTag",
"(",
"\"",
"\"",
",",
"keys",
".",
"Keys",
"(",
")",
")",
"\n\n",
"return",
"spanCtx",
",",
"func",
"(",
"results",
"[",
"]",
"*",
"Result",
")",
"{",
"// TODO: is there anything we should do with the results?",
"span",
".",
"Finish",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// TraceBatch will trace a call to dataloader.LoadMany with Open Tracing
|
[
"TraceBatch",
"will",
"trace",
"a",
"call",
"to",
"dataloader",
".",
"LoadMany",
"with",
"Open",
"Tracing"
] |
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
|
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/trace.go#L51-L60
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.