id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
145,300 | jimstudt/http-authentication | basic/htpasswd.go | New | func New(realm string, filename string, parsers []PasswdParser, bad BadLineHandler) (*HtpasswdFile, error) {
bf := HtpasswdFile{
realm: realm,
filePath: filename,
parsers: parsers,
}
if err := bf.Reload(bad); err != nil {
return nil, err
}
return &bf, nil
} | go | func New(realm string, filename string, parsers []PasswdParser, bad BadLineHandler) (*HtpasswdFile, error) {
bf := HtpasswdFile{
realm: realm,
filePath: filename,
parsers: parsers,
}
if err := bf.Reload(bad); err != nil {
return nil, err
}
return &bf, nil
} | [
"func",
"New",
"(",
"realm",
"string",
",",
"filename",
"string",
",",
"parsers",
"[",
"]",
"PasswdParser",
",",
"bad",
"BadLineHandler",
")",
"(",
"*",
"HtpasswdFile",
",",
"error",
")",
"{",
"bf",
":=",
"HtpasswdFile",
"{",
"realm",
":",
"realm",
",",
... | // New creates an HtpasswdFile from an Apache-style htpasswd file for HTTP Basic Authentication.
//
// The realm is presented to the user in the login dialog.
//
// The filename must exist and be accessible to the process, as well as being a valid htpasswd file.
//
// parsers is a list of functions to handle various ha... | [
"New",
"creates",
"an",
"HtpasswdFile",
"from",
"an",
"Apache",
"-",
"style",
"htpasswd",
"file",
"for",
"HTTP",
"Basic",
"Authentication",
".",
"The",
"realm",
"is",
"presented",
"to",
"the",
"user",
"in",
"the",
"login",
"dialog",
".",
"The",
"filename",
... | 3eca13d6893afd7ecabe15f4445f5d2872a1b012 | https://github.com/jimstudt/http-authentication/blob/3eca13d6893afd7ecabe15f4445f5d2872a1b012/basic/htpasswd.go#L77-L89 |
145,301 | jimstudt/http-authentication | basic/htpasswd.go | ServeHTTP | func (bf *HtpasswdFile) ServeHTTP(res http.ResponseWriter, req *http.Request) {
// if everything works, we return, otherwise we get to the
// end where we do an http.Error to stop the request
auth := req.Header.Get("Authorization")
if auth != "" {
userPassword, err := base64.StdEncoding.DecodeString(strings.Trim... | go | func (bf *HtpasswdFile) ServeHTTP(res http.ResponseWriter, req *http.Request) {
// if everything works, we return, otherwise we get to the
// end where we do an http.Error to stop the request
auth := req.Header.Get("Authorization")
if auth != "" {
userPassword, err := base64.StdEncoding.DecodeString(strings.Trim... | [
"func",
"(",
"bf",
"*",
"HtpasswdFile",
")",
"ServeHTTP",
"(",
"res",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"// if everything works, we return, otherwise we get to the",
"// end where we do an http.Error to stop the request",
"a... | // A Martini middleware handler to enforce HTTP Basic Auth using the policy read from the htpasswd file. | [
"A",
"Martini",
"middleware",
"handler",
"to",
"enforce",
"HTTP",
"Basic",
"Auth",
"using",
"the",
"policy",
"read",
"from",
"the",
"htpasswd",
"file",
"."
] | 3eca13d6893afd7ecabe15f4445f5d2872a1b012 | https://github.com/jimstudt/http-authentication/blob/3eca13d6893afd7ecabe15f4445f5d2872a1b012/basic/htpasswd.go#L92-L119 |
145,302 | jimstudt/http-authentication | basic/htpasswd.go | Reload | func (bf *HtpasswdFile) Reload(bad BadLineHandler) error {
// with the file...
f, err := os.Open(bf.filePath)
if err != nil {
return err
}
defer f.Close()
// ... and a new map ...
newPasswdMap := passwdTable{}
// ... for each line ...
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.T... | go | func (bf *HtpasswdFile) Reload(bad BadLineHandler) error {
// with the file...
f, err := os.Open(bf.filePath)
if err != nil {
return err
}
defer f.Close()
// ... and a new map ...
newPasswdMap := passwdTable{}
// ... for each line ...
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.T... | [
"func",
"(",
"bf",
"*",
"HtpasswdFile",
")",
"Reload",
"(",
"bad",
"BadLineHandler",
")",
"error",
"{",
"// with the file...",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"bf",
".",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"... | // Reread the password file for this HtpasswdFile.
// You will need to call this to notice any changes to the password file.
// This function is thread safe. Someone versed in fsnotify might make it
// happen automatically. Likewise you might also connect a SIGHUP handler to
// this function. | [
"Reread",
"the",
"password",
"file",
"for",
"this",
"HtpasswdFile",
".",
"You",
"will",
"need",
"to",
"call",
"this",
"to",
"notice",
"any",
"changes",
"to",
"the",
"password",
"file",
".",
"This",
"function",
"is",
"thread",
"safe",
".",
"Someone",
"verse... | 3eca13d6893afd7ecabe15f4445f5d2872a1b012 | https://github.com/jimstudt/http-authentication/blob/3eca13d6893afd7ecabe15f4445f5d2872a1b012/basic/htpasswd.go#L126-L157 |
145,303 | jimstudt/http-authentication | basic/htpasswd.go | ReloadOn | func (bf *HtpasswdFile) ReloadOn(when os.Signal, onbad BadLineHandler) {
// this is rather common with code in digest, but I don't have a common area...
c := make(chan os.Signal, 1)
signal.Notify(c, when)
go func() {
for {
_ = <-c
bf.Reload(onbad)
}
}()
} | go | func (bf *HtpasswdFile) ReloadOn(when os.Signal, onbad BadLineHandler) {
// this is rather common with code in digest, but I don't have a common area...
c := make(chan os.Signal, 1)
signal.Notify(c, when)
go func() {
for {
_ = <-c
bf.Reload(onbad)
}
}()
} | [
"func",
"(",
"bf",
"*",
"HtpasswdFile",
")",
"ReloadOn",
"(",
"when",
"os",
".",
"Signal",
",",
"onbad",
"BadLineHandler",
")",
"{",
"// this is rather common with code in digest, but I don't have a common area...",
"c",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal... | // Reload the htpasswd file on a signal. If there is an error, the old data will be kept instead.
// Typically you would use syscall.SIGHUP for the value of "when" | [
"Reload",
"the",
"htpasswd",
"file",
"on",
"a",
"signal",
".",
"If",
"there",
"is",
"an",
"error",
"the",
"old",
"data",
"will",
"be",
"kept",
"instead",
".",
"Typically",
"you",
"would",
"use",
"syscall",
".",
"SIGHUP",
"for",
"the",
"value",
"of",
"w... | 3eca13d6893afd7ecabe15f4445f5d2872a1b012 | https://github.com/jimstudt/http-authentication/blob/3eca13d6893afd7ecabe15f4445f5d2872a1b012/basic/htpasswd.go#L161-L172 |
145,304 | jimstudt/http-authentication | basic/sha.go | AcceptSha | func AcceptSha(src string) (EncodedPasswd, error) {
if !strings.HasPrefix(src, "{SHA}") {
return nil, nil
}
b64 := strings.TrimPrefix(src, "{SHA}")
hashed, err := base64.StdEncoding.DecodeString(b64)
if err != nil {
return nil, fmt.Errorf("Malformed sha1(%s): %s", src, err.Error())
}
if len(hashed) != sha1.... | go | func AcceptSha(src string) (EncodedPasswd, error) {
if !strings.HasPrefix(src, "{SHA}") {
return nil, nil
}
b64 := strings.TrimPrefix(src, "{SHA}")
hashed, err := base64.StdEncoding.DecodeString(b64)
if err != nil {
return nil, fmt.Errorf("Malformed sha1(%s): %s", src, err.Error())
}
if len(hashed) != sha1.... | [
"func",
"AcceptSha",
"(",
"src",
"string",
")",
"(",
"EncodedPasswd",
",",
"error",
")",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"src",
",",
"\"",
"\"",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"b64",
":=",
"strings",
"."... | // Accept valid SHA encoded passwords. | [
"Accept",
"valid",
"SHA",
"encoded",
"passwords",
"."
] | 3eca13d6893afd7ecabe15f4445f5d2872a1b012 | https://github.com/jimstudt/http-authentication/blob/3eca13d6893afd7ecabe15f4445f5d2872a1b012/basic/sha.go#L16-L30 |
145,305 | jimstudt/http-authentication | basic/md5.go | AcceptMd5 | func AcceptMd5(src string) (EncodedPasswd, error) {
if !strings.HasPrefix(src, "$apr1$") {
return nil, nil
}
rest := strings.TrimPrefix(src, "$apr1$")
mparts := strings.SplitN(rest, "$", 2)
if len(mparts) != 2 {
return nil, fmt.Errorf("malformed md5 password: %s", src)
}
salt, hashed := mparts[0], mparts[1... | go | func AcceptMd5(src string) (EncodedPasswd, error) {
if !strings.HasPrefix(src, "$apr1$") {
return nil, nil
}
rest := strings.TrimPrefix(src, "$apr1$")
mparts := strings.SplitN(rest, "$", 2)
if len(mparts) != 2 {
return nil, fmt.Errorf("malformed md5 password: %s", src)
}
salt, hashed := mparts[0], mparts[1... | [
"func",
"AcceptMd5",
"(",
"src",
"string",
")",
"(",
"EncodedPasswd",
",",
"error",
")",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"src",
",",
"\"",
"\"",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"rest",
":=",
"strings",
".... | // Accept valid MD5 encoded passwords | [
"Accept",
"valid",
"MD5",
"encoded",
"passwords"
] | 3eca13d6893afd7ecabe15f4445f5d2872a1b012 | https://github.com/jimstudt/http-authentication/blob/3eca13d6893afd7ecabe15f4445f5d2872a1b012/basic/md5.go#L16-L29 |
145,306 | jimstudt/http-authentication | basic/md5.go | RejectMd5 | func RejectMd5(src string) (EncodedPasswd, error) {
if !strings.HasPrefix(src, "$apr1$") {
return nil, nil
}
return nil, fmt.Errorf("md5 password rejected: %s", src)
} | go | func RejectMd5(src string) (EncodedPasswd, error) {
if !strings.HasPrefix(src, "$apr1$") {
return nil, nil
}
return nil, fmt.Errorf("md5 password rejected: %s", src)
} | [
"func",
"RejectMd5",
"(",
"src",
"string",
")",
"(",
"EncodedPasswd",
",",
"error",
")",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"src",
",",
"\"",
"\"",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
... | // Reject any MD5 encoded password | [
"Reject",
"any",
"MD5",
"encoded",
"password"
] | 3eca13d6893afd7ecabe15f4445f5d2872a1b012 | https://github.com/jimstudt/http-authentication/blob/3eca13d6893afd7ecabe15f4445f5d2872a1b012/basic/md5.go#L32-L37 |
145,307 | jordwest/imap-server | conn/command_fetch.go | init | func init() {
peekRE = regexp.MustCompile("\\.PEEK")
registeredFetchParams = make([]fetchParamDefinition, 0)
registerFetchParam("UID", fetchUID)
registerFetchParam("FLAGS", fetchFlags)
registerFetchParam("RFC822\\.SIZE", fetchRfcSize)
registerFetchParam("INTERNALDATE", fetchInternalDate)
registerFetchParam("BODY... | go | func init() {
peekRE = regexp.MustCompile("\\.PEEK")
registeredFetchParams = make([]fetchParamDefinition, 0)
registerFetchParam("UID", fetchUID)
registerFetchParam("FLAGS", fetchFlags)
registerFetchParam("RFC822\\.SIZE", fetchRfcSize)
registerFetchParam("INTERNALDATE", fetchInternalDate)
registerFetchParam("BODY... | [
"func",
"init",
"(",
")",
"{",
"peekRE",
"=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\\\",
"\"",
")",
"\n",
"registeredFetchParams",
"=",
"make",
"(",
"[",
"]",
"fetchParamDefinition",
",",
"0",
")",
"\n",
"registerFetchParam",
"(",
"\"",
"\"",
",",
... | // Register all supported fetch parameters | [
"Register",
"all",
"supported",
"fetch",
"parameters"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/command_fetch.go#L34-L46 |
145,308 | jordwest/imap-server | conn/command_fetch.go | fetchParam | func fetchParam(param string, c *Conn, m mailstore.Message) (string, error) {
peek := false
if peekRE.MatchString(param) {
peek = true
}
// Search through the parameter list until a parameter handler is found
for _, element := range registeredFetchParams {
if element.re.MatchString(param) {
return element.h... | go | func fetchParam(param string, c *Conn, m mailstore.Message) (string, error) {
peek := false
if peekRE.MatchString(param) {
peek = true
}
// Search through the parameter list until a parameter handler is found
for _, element := range registeredFetchParams {
if element.re.MatchString(param) {
return element.h... | [
"func",
"fetchParam",
"(",
"param",
"string",
",",
"c",
"*",
"Conn",
",",
"m",
"mailstore",
".",
"Message",
")",
"(",
"string",
",",
"error",
")",
"{",
"peek",
":=",
"false",
"\n",
"if",
"peekRE",
".",
"MatchString",
"(",
"param",
")",
"{",
"peek",
... | // Match a single fetch parameter and return the data | [
"Match",
"a",
"single",
"fetch",
"parameter",
"and",
"return",
"the",
"data"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/command_fetch.go#L127-L139 |
145,309 | jordwest/imap-server | conn/command_fetch.go | fetchUID | func fetchUID(args []string, c *Conn, m mailstore.Message, peekOnly bool) string {
return fmt.Sprintf("UID %d", m.UID())
} | go | func fetchUID(args []string, c *Conn, m mailstore.Message, peekOnly bool) string {
return fmt.Sprintf("UID %d", m.UID())
} | [
"func",
"fetchUID",
"(",
"args",
"[",
"]",
"string",
",",
"c",
"*",
"Conn",
",",
"m",
"mailstore",
".",
"Message",
",",
"peekOnly",
"bool",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"m",
".",
"UID",
"(",
")",
")",... | // Fetch the UID of the mail message | [
"Fetch",
"the",
"UID",
"of",
"the",
"mail",
"message"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/command_fetch.go#L150-L152 |
145,310 | jordwest/imap-server | conn/command_append.go | cmdAppend | func cmdAppend(args commandArgs, c *Conn) {
if !c.assertAuthenticated(args.ID()) {
return
}
mailboxName := args.Arg(appendArgMailbox)
mailbox, err := c.User.MailboxByName(mailboxName)
if err != nil {
c.writeResponse(args.ID(), "NO could not get mailbox")
return
}
length, err := strconv.ParseUint(args.Arg... | go | func cmdAppend(args commandArgs, c *Conn) {
if !c.assertAuthenticated(args.ID()) {
return
}
mailboxName := args.Arg(appendArgMailbox)
mailbox, err := c.User.MailboxByName(mailboxName)
if err != nil {
c.writeResponse(args.ID(), "NO could not get mailbox")
return
}
length, err := strconv.ParseUint(args.Arg... | [
"func",
"cmdAppend",
"(",
"args",
"commandArgs",
",",
"c",
"*",
"Conn",
")",
"{",
"if",
"!",
"c",
".",
"assertAuthenticated",
"(",
"args",
".",
"ID",
"(",
")",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"mailboxName",
":=",
"args",
".",
"Arg",
"(",
"ap... | // Add a new message to a mailbox | [
"Add",
"a",
"new",
"message",
"to",
"a",
"mailbox"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/command_append.go#L17-L67 |
145,311 | jordwest/imap-server | types/flags.go | CombineFlags | func CombineFlags(flags ...Flags) Flags {
returnFlags := Flags(0)
for _, f := range flags {
returnFlags |= f
}
return returnFlags
} | go | func CombineFlags(flags ...Flags) Flags {
returnFlags := Flags(0)
for _, f := range flags {
returnFlags |= f
}
return returnFlags
} | [
"func",
"CombineFlags",
"(",
"flags",
"...",
"Flags",
")",
"Flags",
"{",
"returnFlags",
":=",
"Flags",
"(",
"0",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"flags",
"{",
"returnFlags",
"|=",
"f",
"\n",
"}",
"\n",
"return",
"returnFlags",
"\n",
"... | // CombineFlags meshes several flags into one so that all of them are set. | [
"CombineFlags",
"meshes",
"several",
"flags",
"into",
"one",
"so",
"that",
"all",
"of",
"them",
"are",
"set",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/types/flags.go#L19-L25 |
145,312 | jordwest/imap-server | types/flags.go | FlagsFromString | func FlagsFromString(imapFlagString string) Flags {
var f Flags
for _, flag := range strings.Split(imapFlagString, " ") {
switch flag {
case "\\Seen":
f = f.SetFlags(FlagSeen)
case "\\Answered":
f = f.SetFlags(FlagAnswered)
case "\\Flagged":
f = f.SetFlags(FlagFlagged)
case "\\Deleted":
f = f.S... | go | func FlagsFromString(imapFlagString string) Flags {
var f Flags
for _, flag := range strings.Split(imapFlagString, " ") {
switch flag {
case "\\Seen":
f = f.SetFlags(FlagSeen)
case "\\Answered":
f = f.SetFlags(FlagAnswered)
case "\\Flagged":
f = f.SetFlags(FlagFlagged)
case "\\Deleted":
f = f.S... | [
"func",
"FlagsFromString",
"(",
"imapFlagString",
"string",
")",
"Flags",
"{",
"var",
"f",
"Flags",
"\n\n",
"for",
"_",
",",
"flag",
":=",
"range",
"strings",
".",
"Split",
"(",
"imapFlagString",
",",
"\"",
"\"",
")",
"{",
"switch",
"flag",
"{",
"case",
... | // FlagsFromString returns the flags based on the input IMAP format string. | [
"FlagsFromString",
"returns",
"the",
"flags",
"based",
"on",
"the",
"input",
"IMAP",
"format",
"string",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/types/flags.go#L28-L49 |
145,313 | jordwest/imap-server | types/flags.go | Strings | func (f Flags) Strings() []string {
flags := make([]string, 0, 6) // Up to 6 flags
if f.HasFlags(FlagAnswered) {
flags = append(flags, "\\Answered")
}
if f.HasFlags(FlagSeen) {
flags = append(flags, "\\Seen")
}
if f.HasFlags(FlagRecent) {
flags = append(flags, "\\Recent")
}
if f.HasFlags(FlagDeleted) {
... | go | func (f Flags) Strings() []string {
flags := make([]string, 0, 6) // Up to 6 flags
if f.HasFlags(FlagAnswered) {
flags = append(flags, "\\Answered")
}
if f.HasFlags(FlagSeen) {
flags = append(flags, "\\Seen")
}
if f.HasFlags(FlagRecent) {
flags = append(flags, "\\Recent")
}
if f.HasFlags(FlagDeleted) {
... | [
"func",
"(",
"f",
"Flags",
")",
"Strings",
"(",
")",
"[",
"]",
"string",
"{",
"flags",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"6",
")",
"// Up to 6 flags",
"\n",
"if",
"f",
".",
"HasFlags",
"(",
"FlagAnswered",
")",
"{",
"flags",
"... | // Strings convert flags to list of IMAP format flags. | [
"Strings",
"convert",
"flags",
"to",
"list",
"of",
"IMAP",
"format",
"flags",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/types/flags.go#L69-L90 |
145,314 | jordwest/imap-server | conn/command_authenticate.go | cmdAuthPlain | func cmdAuthPlain(args commandArgs, c *Conn) {
// Compile login regex
loginRE := regexp.MustCompile("(?:[A-z0-9]+)?\x00([A-z0-9]+)\x00([A-z0-9]+)")
// Tell client to go ahead
c.writeResponse("+", "")
// Wait for client to send auth details
ok := c.RwcScanner.Scan()
if !ok {
return
}
authDetails := c.RwcSca... | go | func cmdAuthPlain(args commandArgs, c *Conn) {
// Compile login regex
loginRE := regexp.MustCompile("(?:[A-z0-9]+)?\x00([A-z0-9]+)\x00([A-z0-9]+)")
// Tell client to go ahead
c.writeResponse("+", "")
// Wait for client to send auth details
ok := c.RwcScanner.Scan()
if !ok {
return
}
authDetails := c.RwcSca... | [
"func",
"cmdAuthPlain",
"(",
"args",
"commandArgs",
",",
"c",
"*",
"Conn",
")",
"{",
"// Compile login regex",
"loginRE",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\\x00",
"\\x00",
"\"",
")",
"\n\n",
"// Tell client to go ahead",
"c",
".",
"writeResponse",... | // Handles PLAIN text AUTHENTICATE command | [
"Handles",
"PLAIN",
"text",
"AUTHENTICATE",
"command"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/command_authenticate.go#L9-L40 |
145,315 | jordwest/imap-server | conn/command_login.go | cmdLogin | func cmdLogin(args commandArgs, c *Conn) {
user, err := c.Mailstore.Authenticate(args.Arg(0), args.Arg(1))
c.User = user
if err != nil {
c.writeResponse(args.ID(), "NO Incorrect username/password")
return
}
c.SetState(StateAuthenticated)
c.writeResponse(args.ID(), "OK Authenticated")
} | go | func cmdLogin(args commandArgs, c *Conn) {
user, err := c.Mailstore.Authenticate(args.Arg(0), args.Arg(1))
c.User = user
if err != nil {
c.writeResponse(args.ID(), "NO Incorrect username/password")
return
}
c.SetState(StateAuthenticated)
c.writeResponse(args.ID(), "OK Authenticated")
} | [
"func",
"cmdLogin",
"(",
"args",
"commandArgs",
",",
"c",
"*",
"Conn",
")",
"{",
"user",
",",
"err",
":=",
"c",
".",
"Mailstore",
".",
"Authenticate",
"(",
"args",
".",
"Arg",
"(",
"0",
")",
",",
"args",
".",
"Arg",
"(",
"1",
")",
")",
"\n",
"c... | // Handles PLAIN text LOGIN command | [
"Handles",
"PLAIN",
"text",
"LOGIN",
"command"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/command_login.go#L4-L13 |
145,316 | jordwest/imap-server | mailstore/dummy_mailstore.go | NewDummyMailstore | func NewDummyMailstore() *DummyMailstore {
ms := &DummyMailstore{
User: &DummyUser{
authenticated: false,
mailboxes: make([]*DummyMailbox, 2),
},
}
ms.User.mailstore = ms
ms.User.mailboxes[0] = newDummyMailbox("INBOX")
ms.User.mailboxes[0].ID = 0
ms.User.mailboxes[0].mailstore = ms
// Mon Jan 2 15:... | go | func NewDummyMailstore() *DummyMailstore {
ms := &DummyMailstore{
User: &DummyUser{
authenticated: false,
mailboxes: make([]*DummyMailbox, 2),
},
}
ms.User.mailstore = ms
ms.User.mailboxes[0] = newDummyMailbox("INBOX")
ms.User.mailboxes[0].ID = 0
ms.User.mailboxes[0].mailstore = ms
// Mon Jan 2 15:... | [
"func",
"NewDummyMailstore",
"(",
")",
"*",
"DummyMailstore",
"{",
"ms",
":=",
"&",
"DummyMailstore",
"{",
"User",
":",
"&",
"DummyUser",
"{",
"authenticated",
":",
"false",
",",
"mailboxes",
":",
"make",
"(",
"[",
"]",
"*",
"DummyMailbox",
",",
"2",
")"... | // NewDummyMailstore performs some initialisation and should always be
// used to create a new DummyMailstore | [
"NewDummyMailstore",
"performs",
"some",
"initialisation",
"and",
"should",
"always",
"be",
"used",
"to",
"create",
"a",
"new",
"DummyMailstore"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L29-L55 |
145,317 | jordwest/imap-server | mailstore/dummy_mailstore.go | Authenticate | func (d *DummyMailstore) Authenticate(username string, password string) (User, error) {
if username != "username" {
return &DummyUser{}, errors.New("Invalid username. Use 'username'")
}
if password != "password" {
return &DummyUser{}, errors.New("Invalid password. Use 'password'")
}
d.User.authenticated = tr... | go | func (d *DummyMailstore) Authenticate(username string, password string) (User, error) {
if username != "username" {
return &DummyUser{}, errors.New("Invalid username. Use 'username'")
}
if password != "password" {
return &DummyUser{}, errors.New("Invalid password. Use 'password'")
}
d.User.authenticated = tr... | [
"func",
"(",
"d",
"*",
"DummyMailstore",
")",
"Authenticate",
"(",
"username",
"string",
",",
"password",
"string",
")",
"(",
"User",
",",
"error",
")",
"{",
"if",
"username",
"!=",
"\"",
"\"",
"{",
"return",
"&",
"DummyUser",
"{",
"}",
",",
"errors",
... | // Authenticate implements the Authenticate method on the Mailstore interface | [
"Authenticate",
"implements",
"the",
"Authenticate",
"method",
"on",
"the",
"Mailstore",
"interface"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L58-L69 |
145,318 | jordwest/imap-server | mailstore/dummy_mailstore.go | Mailboxes | func (u *DummyUser) Mailboxes() []Mailbox {
mailboxes := make([]Mailbox, len(u.mailboxes))
index := 0
for _, element := range u.mailboxes {
mailboxes[index] = element
index++
}
return mailboxes
} | go | func (u *DummyUser) Mailboxes() []Mailbox {
mailboxes := make([]Mailbox, len(u.mailboxes))
index := 0
for _, element := range u.mailboxes {
mailboxes[index] = element
index++
}
return mailboxes
} | [
"func",
"(",
"u",
"*",
"DummyUser",
")",
"Mailboxes",
"(",
")",
"[",
"]",
"Mailbox",
"{",
"mailboxes",
":=",
"make",
"(",
"[",
"]",
"Mailbox",
",",
"len",
"(",
"u",
".",
"mailboxes",
")",
")",
"\n",
"index",
":=",
"0",
"\n",
"for",
"_",
",",
"e... | // Mailboxes implements the Mailboxes method on the User interface | [
"Mailboxes",
"implements",
"the",
"Mailboxes",
"method",
"on",
"the",
"User",
"interface"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L79-L87 |
145,319 | jordwest/imap-server | mailstore/dummy_mailstore.go | MailboxByName | func (u *DummyUser) MailboxByName(name string) (Mailbox, error) {
for _, mailbox := range u.mailboxes {
if mailbox.Name() == name {
return mailbox, nil
}
}
return nil, errors.New("Invalid mailbox")
} | go | func (u *DummyUser) MailboxByName(name string) (Mailbox, error) {
for _, mailbox := range u.mailboxes {
if mailbox.Name() == name {
return mailbox, nil
}
}
return nil, errors.New("Invalid mailbox")
} | [
"func",
"(",
"u",
"*",
"DummyUser",
")",
"MailboxByName",
"(",
"name",
"string",
")",
"(",
"Mailbox",
",",
"error",
")",
"{",
"for",
"_",
",",
"mailbox",
":=",
"range",
"u",
".",
"mailboxes",
"{",
"if",
"mailbox",
".",
"Name",
"(",
")",
"==",
"name... | // MailboxByName returns a DummyMailbox object, given the mailbox's name | [
"MailboxByName",
"returns",
"a",
"DummyMailbox",
"object",
"given",
"the",
"mailbox",
"s",
"name"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L90-L97 |
145,320 | jordwest/imap-server | mailstore/dummy_mailstore.go | LastUID | func (m *DummyMailbox) LastUID() uint32 {
lastMsgIndex := len(m.messages) - 1
// If no messages in the mailbox, return the next UID
if lastMsgIndex == -1 {
return m.NextUID()
}
return m.messages[lastMsgIndex].UID()
} | go | func (m *DummyMailbox) LastUID() uint32 {
lastMsgIndex := len(m.messages) - 1
// If no messages in the mailbox, return the next UID
if lastMsgIndex == -1 {
return m.NextUID()
}
return m.messages[lastMsgIndex].UID()
} | [
"func",
"(",
"m",
"*",
"DummyMailbox",
")",
"LastUID",
"(",
")",
"uint32",
"{",
"lastMsgIndex",
":=",
"len",
"(",
"m",
".",
"messages",
")",
"-",
"1",
"\n\n",
"// If no messages in the mailbox, return the next UID",
"if",
"lastMsgIndex",
"==",
"-",
"1",
"{",
... | // LastUID returns the UID of the last message in the mailbox or if the
// mailbox is empty, the next expected UID | [
"LastUID",
"returns",
"the",
"UID",
"of",
"the",
"last",
"message",
"in",
"the",
"mailbox",
"or",
"if",
"the",
"mailbox",
"is",
"empty",
"the",
"next",
"expected",
"UID"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L123-L132 |
145,321 | jordwest/imap-server | mailstore/dummy_mailstore.go | Recent | func (m *DummyMailbox) Recent() uint32 {
var count uint32
for _, message := range m.messages {
if message.Flags().HasFlags(types.FlagRecent) {
count++
}
}
return count
} | go | func (m *DummyMailbox) Recent() uint32 {
var count uint32
for _, message := range m.messages {
if message.Flags().HasFlags(types.FlagRecent) {
count++
}
}
return count
} | [
"func",
"(",
"m",
"*",
"DummyMailbox",
")",
"Recent",
"(",
")",
"uint32",
"{",
"var",
"count",
"uint32",
"\n",
"for",
"_",
",",
"message",
":=",
"range",
"m",
".",
"messages",
"{",
"if",
"message",
".",
"Flags",
"(",
")",
".",
"HasFlags",
"(",
"typ... | // Recent returns the number of messages in the mailbox which are currently
// marked with the 'Recent' flag | [
"Recent",
"returns",
"the",
"number",
"of",
"messages",
"in",
"the",
"mailbox",
"which",
"are",
"currently",
"marked",
"with",
"the",
"Recent",
"flag"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L136-L144 |
145,322 | jordwest/imap-server | mailstore/dummy_mailstore.go | Unseen | func (m *DummyMailbox) Unseen() uint32 {
count := uint32(0)
for _, message := range m.messages {
if !message.Flags().HasFlags(types.FlagSeen) {
count++
}
}
return count
} | go | func (m *DummyMailbox) Unseen() uint32 {
count := uint32(0)
for _, message := range m.messages {
if !message.Flags().HasFlags(types.FlagSeen) {
count++
}
}
return count
} | [
"func",
"(",
"m",
"*",
"DummyMailbox",
")",
"Unseen",
"(",
")",
"uint32",
"{",
"count",
":=",
"uint32",
"(",
"0",
")",
"\n",
"for",
"_",
",",
"message",
":=",
"range",
"m",
".",
"messages",
"{",
"if",
"!",
"message",
".",
"Flags",
"(",
")",
".",
... | // Unseen returns the number of messages in the mailbox which are currently
// marked with the 'Unseen' flag | [
"Unseen",
"returns",
"the",
"number",
"of",
"messages",
"in",
"the",
"mailbox",
"which",
"are",
"currently",
"marked",
"with",
"the",
"Unseen",
"flag"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L151-L159 |
145,323 | jordwest/imap-server | mailstore/dummy_mailstore.go | MessageBySequenceNumber | func (m *DummyMailbox) MessageBySequenceNumber(seqno uint32) Message {
if seqno > uint32(len(m.messages)) {
return nil
}
return m.messages[seqno-1]
} | go | func (m *DummyMailbox) MessageBySequenceNumber(seqno uint32) Message {
if seqno > uint32(len(m.messages)) {
return nil
}
return m.messages[seqno-1]
} | [
"func",
"(",
"m",
"*",
"DummyMailbox",
")",
"MessageBySequenceNumber",
"(",
"seqno",
"uint32",
")",
"Message",
"{",
"if",
"seqno",
">",
"uint32",
"(",
"len",
"(",
"m",
".",
"messages",
")",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"m",
"... | // MessageBySequenceNumber returns a single message given the message's sequence number | [
"MessageBySequenceNumber",
"returns",
"a",
"single",
"message",
"given",
"the",
"message",
"s",
"sequence",
"number"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L162-L167 |
145,324 | jordwest/imap-server | mailstore/dummy_mailstore.go | MessageByUID | func (m *DummyMailbox) MessageByUID(uidno uint32) Message {
for _, message := range m.messages {
if message.UID() == uidno {
return message
}
}
// No message found
return nil
} | go | func (m *DummyMailbox) MessageByUID(uidno uint32) Message {
for _, message := range m.messages {
if message.UID() == uidno {
return message
}
}
// No message found
return nil
} | [
"func",
"(",
"m",
"*",
"DummyMailbox",
")",
"MessageByUID",
"(",
"uidno",
"uint32",
")",
"Message",
"{",
"for",
"_",
",",
"message",
":=",
"range",
"m",
".",
"messages",
"{",
"if",
"message",
".",
"UID",
"(",
")",
"==",
"uidno",
"{",
"return",
"messa... | // MessageByUID returns a single message given the message's sequence number | [
"MessageByUID",
"returns",
"a",
"single",
"message",
"given",
"the",
"message",
"s",
"sequence",
"number"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L170-L179 |
145,325 | jordwest/imap-server | mailstore/dummy_mailstore.go | MessageSetBySequenceNumber | func (m *DummyMailbox) MessageSetBySequenceNumber(set types.SequenceSet) []Message {
var msgs []Message
// If the mailbox is empty, return empty array
if m.Messages() == 0 {
return msgs
}
// For each sequence range in the sequence set
for _, msgRange := range set {
// If Min is "*", meaning the last message... | go | func (m *DummyMailbox) MessageSetBySequenceNumber(set types.SequenceSet) []Message {
var msgs []Message
// If the mailbox is empty, return empty array
if m.Messages() == 0 {
return msgs
}
// For each sequence range in the sequence set
for _, msgRange := range set {
// If Min is "*", meaning the last message... | [
"func",
"(",
"m",
"*",
"DummyMailbox",
")",
"MessageSetBySequenceNumber",
"(",
"set",
"types",
".",
"SequenceSet",
")",
"[",
"]",
"Message",
"{",
"var",
"msgs",
"[",
"]",
"Message",
"\n\n",
"// If the mailbox is empty, return empty array",
"if",
"m",
".",
"Messa... | // MessageSetBySequenceNumber returns a slice of messages given a set of
// sequence number ranges | [
"MessageSetBySequenceNumber",
"returns",
"a",
"slice",
"of",
"messages",
"given",
"a",
"set",
"of",
"sequence",
"number",
"ranges"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L250-L309 |
145,326 | jordwest/imap-server | mailstore/dummy_mailstore.go | NewMessage | func (m *DummyMailbox) NewMessage() Message {
return &DummyMessage{
sequenceNumber: 0,
uid: 0,
header: make(textproto.MIMEHeader),
internalDate: time.Now(),
flags: types.Flags(0),
mailstore: m.mailstore,
mailboxID: m.ID,
body: "",
}
} | go | func (m *DummyMailbox) NewMessage() Message {
return &DummyMessage{
sequenceNumber: 0,
uid: 0,
header: make(textproto.MIMEHeader),
internalDate: time.Now(),
flags: types.Flags(0),
mailstore: m.mailstore,
mailboxID: m.ID,
body: "",
}
} | [
"func",
"(",
"m",
"*",
"DummyMailbox",
")",
"NewMessage",
"(",
")",
"Message",
"{",
"return",
"&",
"DummyMessage",
"{",
"sequenceNumber",
":",
"0",
",",
"uid",
":",
"0",
",",
"header",
":",
"make",
"(",
"textproto",
".",
"MIMEHeader",
")",
",",
"intern... | // NewMessage creates a new message in the dummy mailbox. | [
"NewMessage",
"creates",
"a",
"new",
"message",
"in",
"the",
"dummy",
"mailbox",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L312-L323 |
145,327 | jordwest/imap-server | mailstore/dummy_mailstore.go | Size | func (m *DummyMessage) Size() uint32 {
hdrStr := fmt.Sprintf("%s\r\n", m.Header())
return uint32(len(hdrStr)) + uint32(len(m.Body()))
} | go | func (m *DummyMessage) Size() uint32 {
hdrStr := fmt.Sprintf("%s\r\n", m.Header())
return uint32(len(hdrStr)) + uint32(len(m.Body()))
} | [
"func",
"(",
"m",
"*",
"DummyMessage",
")",
"Size",
"(",
")",
"uint32",
"{",
"hdrStr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\r",
"\\n",
"\"",
",",
"m",
".",
"Header",
"(",
")",
")",
"\n",
"return",
"uint32",
"(",
"len",
"(",
"hdrStr",
")",
... | // Size returns the message's full RFC822 size, including full message header
// and body. | [
"Size",
"returns",
"the",
"message",
"s",
"full",
"RFC822",
"size",
"including",
"full",
"message",
"header",
"and",
"body",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L375-L378 |
145,328 | jordwest/imap-server | mailstore/dummy_mailstore.go | OverwriteFlags | func (m *DummyMessage) OverwriteFlags(newFlags types.Flags) Message {
m.flags = newFlags
return m
} | go | func (m *DummyMessage) OverwriteFlags(newFlags types.Flags) Message {
m.flags = newFlags
return m
} | [
"func",
"(",
"m",
"*",
"DummyMessage",
")",
"OverwriteFlags",
"(",
"newFlags",
"types",
".",
"Flags",
")",
"Message",
"{",
"m",
".",
"flags",
"=",
"newFlags",
"\n",
"return",
"m",
"\n",
"}"
] | // OverwriteFlags replaces any flags on the message with those specified. | [
"OverwriteFlags",
"replaces",
"any",
"flags",
"on",
"the",
"message",
"with",
"those",
"specified",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L403-L406 |
145,329 | jordwest/imap-server | mailstore/dummy_mailstore.go | AddFlags | func (m *DummyMessage) AddFlags(newFlags types.Flags) Message {
m.flags = m.flags.SetFlags(newFlags)
return m
} | go | func (m *DummyMessage) AddFlags(newFlags types.Flags) Message {
m.flags = m.flags.SetFlags(newFlags)
return m
} | [
"func",
"(",
"m",
"*",
"DummyMessage",
")",
"AddFlags",
"(",
"newFlags",
"types",
".",
"Flags",
")",
"Message",
"{",
"m",
".",
"flags",
"=",
"m",
".",
"flags",
".",
"SetFlags",
"(",
"newFlags",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // AddFlags adds the given flag to the message. | [
"AddFlags",
"adds",
"the",
"given",
"flag",
"to",
"the",
"message",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L409-L412 |
145,330 | jordwest/imap-server | mailstore/dummy_mailstore.go | RemoveFlags | func (m *DummyMessage) RemoveFlags(newFlags types.Flags) Message {
m.flags = m.flags.ResetFlags(newFlags)
return m
} | go | func (m *DummyMessage) RemoveFlags(newFlags types.Flags) Message {
m.flags = m.flags.ResetFlags(newFlags)
return m
} | [
"func",
"(",
"m",
"*",
"DummyMessage",
")",
"RemoveFlags",
"(",
"newFlags",
"types",
".",
"Flags",
")",
"Message",
"{",
"m",
".",
"flags",
"=",
"m",
".",
"flags",
".",
"ResetFlags",
"(",
"newFlags",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // RemoveFlags removes the given flag from the message. | [
"RemoveFlags",
"removes",
"the",
"given",
"flag",
"from",
"the",
"message",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L415-L418 |
145,331 | jordwest/imap-server | mailstore/dummy_mailstore.go | SetHeaders | func (m *DummyMessage) SetHeaders(newHeader textproto.MIMEHeader) Message {
m.header = newHeader
return m
} | go | func (m *DummyMessage) SetHeaders(newHeader textproto.MIMEHeader) Message {
m.header = newHeader
return m
} | [
"func",
"(",
"m",
"*",
"DummyMessage",
")",
"SetHeaders",
"(",
"newHeader",
"textproto",
".",
"MIMEHeader",
")",
"Message",
"{",
"m",
".",
"header",
"=",
"newHeader",
"\n",
"return",
"m",
"\n",
"}"
] | // SetHeaders sets the e-mail headers of the message. | [
"SetHeaders",
"sets",
"the",
"e",
"-",
"mail",
"headers",
"of",
"the",
"message",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L421-L424 |
145,332 | jordwest/imap-server | mailstore/dummy_mailstore.go | Save | func (m *DummyMessage) Save() (Message, error) {
mailbox := m.mailstore.User.mailboxes[m.mailboxID]
if m.sequenceNumber == 0 {
// Message is new
m.uid = mailbox.nextuid
mailbox.nextuid++
m.sequenceNumber = uint32(len(mailbox.messages))
mailbox.messages = append(mailbox.messages, m)
} else {
// Message ex... | go | func (m *DummyMessage) Save() (Message, error) {
mailbox := m.mailstore.User.mailboxes[m.mailboxID]
if m.sequenceNumber == 0 {
// Message is new
m.uid = mailbox.nextuid
mailbox.nextuid++
m.sequenceNumber = uint32(len(mailbox.messages))
mailbox.messages = append(mailbox.messages, m)
} else {
// Message ex... | [
"func",
"(",
"m",
"*",
"DummyMessage",
")",
"Save",
"(",
")",
"(",
"Message",
",",
"error",
")",
"{",
"mailbox",
":=",
"m",
".",
"mailstore",
".",
"User",
".",
"mailboxes",
"[",
"m",
".",
"mailboxID",
"]",
"\n",
"if",
"m",
".",
"sequenceNumber",
"=... | // Save saves the message to the mailbox it belongs to. | [
"Save",
"saves",
"the",
"message",
"to",
"the",
"mailbox",
"it",
"belongs",
"to",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L433-L446 |
145,333 | jordwest/imap-server | mailstore/dummy_mailstore.go | DeleteFlaggedMessages | func (m *DummyMailbox) DeleteFlaggedMessages() ([]Message, error) {
var delIDs []int
var delMsgs []Message
// Find messages to be deleted.
for i, msg := range m.messages {
if msg.Flags().HasFlags(types.FlagDeleted) {
delIDs = append(delIDs, i)
delMsgs = append(delMsgs, msg)
}
}
// Delete message from ... | go | func (m *DummyMailbox) DeleteFlaggedMessages() ([]Message, error) {
var delIDs []int
var delMsgs []Message
// Find messages to be deleted.
for i, msg := range m.messages {
if msg.Flags().HasFlags(types.FlagDeleted) {
delIDs = append(delIDs, i)
delMsgs = append(delMsgs, msg)
}
}
// Delete message from ... | [
"func",
"(",
"m",
"*",
"DummyMailbox",
")",
"DeleteFlaggedMessages",
"(",
")",
"(",
"[",
"]",
"Message",
",",
"error",
")",
"{",
"var",
"delIDs",
"[",
"]",
"int",
"\n",
"var",
"delMsgs",
"[",
"]",
"Message",
"\n\n",
"// Find messages to be deleted.",
"for"... | // DeleteFlaggedMessages deletes messages marked with the Delete flag and
// returns them. | [
"DeleteFlaggedMessages",
"deletes",
"messages",
"marked",
"with",
"the",
"Delete",
"flag",
"and",
"returns",
"them",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/mailstore/dummy_mailstore.go#L450-L478 |
145,334 | jordwest/imap-server | types/rfc2822_message.go | MessageFromBytes | func MessageFromBytes(msgBytes []byte) (msg RFC2822Message, err error) {
// The header and body are separated by a double new-line
splitMessage := bytes.SplitN(msgBytes, []byte("\r\n\r\n"), 2)
// Read the headers
headerReader := textproto.NewReader(bufio.NewReader(bytes.NewReader(splitMessage[0])))
msg.Headers, e... | go | func MessageFromBytes(msgBytes []byte) (msg RFC2822Message, err error) {
// The header and body are separated by a double new-line
splitMessage := bytes.SplitN(msgBytes, []byte("\r\n\r\n"), 2)
// Read the headers
headerReader := textproto.NewReader(bufio.NewReader(bytes.NewReader(splitMessage[0])))
msg.Headers, e... | [
"func",
"MessageFromBytes",
"(",
"msgBytes",
"[",
"]",
"byte",
")",
"(",
"msg",
"RFC2822Message",
",",
"err",
"error",
")",
"{",
"// The header and body are separated by a double new-line",
"splitMessage",
":=",
"bytes",
".",
"SplitN",
"(",
"msgBytes",
",",
"[",
"... | // MessageFromBytes creates a RFC2822Message from its byte representation. | [
"MessageFromBytes",
"creates",
"a",
"RFC2822Message",
"from",
"its",
"byte",
"representation",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/types/rfc2822_message.go#L17-L34 |
145,335 | jordwest/imap-server | conn/conn.go | SetState | func (c *Conn) SetState(state connState) {
c.state = state
// As a precaution, reset any mailbox write access when changing states
c.SetReadOnly()
} | go | func (c *Conn) SetState(state connState) {
c.state = state
// As a precaution, reset any mailbox write access when changing states
c.SetReadOnly()
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SetState",
"(",
"state",
"connState",
")",
"{",
"c",
".",
"state",
"=",
"state",
"\n\n",
"// As a precaution, reset any mailbox write access when changing states",
"c",
".",
"SetReadOnly",
"(",
")",
"\n",
"}"
] | // SetState sets the state that an IMAP client is in. It also resets any mailbox
// write access. | [
"SetState",
"sets",
"the",
"state",
"that",
"an",
"IMAP",
"client",
"is",
"in",
".",
"It",
"also",
"resets",
"any",
"mailbox",
"write",
"access",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/conn.go#L69-L74 |
145,336 | jordwest/imap-server | conn/conn.go | Write | func (c *Conn) Write(p []byte) (n int, err error) {
fmt.Fprintf(c.Transcript, "S: %s", p)
return c.Rwc.Write(p)
} | go | func (c *Conn) Write(p []byte) (n int, err error) {
fmt.Fprintf(c.Transcript, "S: %s", p)
return c.Rwc.Write(p)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Transcript",
",",
"\"",
"\"",
",",
"p",
")",
"\n\n",
"return",
"c",
".",
"R... | // Write a response to the client. Implements io.Writer. | [
"Write",
"a",
"response",
"to",
"the",
"client",
".",
"Implements",
"io",
".",
"Writer",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/conn.go#L96-L100 |
145,337 | jordwest/imap-server | conn/conn.go | writeResponse | func (c *Conn) writeResponse(seq string, command string) {
if seq == "" {
seq = "*"
}
// Ensure the command is terminated with a line ending
if !strings.HasSuffix(command, lineEnding) {
command += lineEnding
}
fmt.Fprintf(c, "%s %s", seq, command)
} | go | func (c *Conn) writeResponse(seq string, command string) {
if seq == "" {
seq = "*"
}
// Ensure the command is terminated with a line ending
if !strings.HasSuffix(command, lineEnding) {
command += lineEnding
}
fmt.Fprintf(c, "%s %s", seq, command)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"writeResponse",
"(",
"seq",
"string",
",",
"command",
"string",
")",
"{",
"if",
"seq",
"==",
"\"",
"\"",
"{",
"seq",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"// Ensure the command is terminated with a line ending",
"if",
"!",... | // Write a response to the client. | [
"Write",
"a",
"response",
"to",
"the",
"client",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/conn.go#L103-L112 |
145,338 | jordwest/imap-server | conn/conn.go | sendWelcome | func (c *Conn) sendWelcome() error {
if c.state != StateNew {
return errors.New("Welcome already sent")
}
c.writeResponse("", "OK IMAP4rev1 Service Ready")
c.SetState(StateNotAuthenticated)
return nil
} | go | func (c *Conn) sendWelcome() error {
if c.state != StateNew {
return errors.New("Welcome already sent")
}
c.writeResponse("", "OK IMAP4rev1 Service Ready")
c.SetState(StateNotAuthenticated)
return nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"sendWelcome",
"(",
")",
"error",
"{",
"if",
"c",
".",
"state",
"!=",
"StateNew",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"c",
".",
"writeResponse",
"(",
"\"",
"\"",
",",
"... | // Send the server greeting to the client. | [
"Send",
"the",
"server",
"greeting",
"to",
"the",
"client",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/conn.go#L115-L122 |
145,339 | jordwest/imap-server | conn/conn.go | Close | func (c *Conn) Close() error {
fmt.Fprintf(c.Transcript, "Server closing connection\n")
return c.Rwc.Close()
} | go | func (c *Conn) Close() error {
fmt.Fprintf(c.Transcript, "Server closing connection\n")
return c.Rwc.Close()
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Close",
"(",
")",
"error",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Transcript",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"return",
"c",
".",
"Rwc",
".",
"Close",
"(",
")",
"\n",
"}"
] | // Close forces the server to close the client's connection. | [
"Close",
"forces",
"the",
"server",
"to",
"close",
"the",
"client",
"s",
"connection",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/conn.go#L161-L164 |
145,340 | jordwest/imap-server | conn/conn.go | ReadLine | func (c *Conn) ReadLine() (text string, ok bool) {
ok = c.RwcScanner.Scan()
return c.RwcScanner.Text(), ok
} | go | func (c *Conn) ReadLine() (text string, ok bool) {
ok = c.RwcScanner.Scan()
return c.RwcScanner.Text(), ok
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ReadLine",
"(",
")",
"(",
"text",
"string",
",",
"ok",
"bool",
")",
"{",
"ok",
"=",
"c",
".",
"RwcScanner",
".",
"Scan",
"(",
")",
"\n",
"return",
"c",
".",
"RwcScanner",
".",
"Text",
"(",
")",
",",
"ok",
... | // ReadLine awaits a single line from the client. | [
"ReadLine",
"awaits",
"a",
"single",
"line",
"from",
"the",
"client",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/conn.go#L167-L170 |
145,341 | jordwest/imap-server | conn/conn.go | ReadFixedLength | func (c *Conn) ReadFixedLength(length int) (data []byte, err error) {
// Read the whole message into a buffer
data = make([]byte, length)
receivedLength := 0
for receivedLength < length {
bytesRead, err := c.Rwc.Read(data[receivedLength:])
if err != nil {
return data, err
}
receivedLength += bytesRead
}... | go | func (c *Conn) ReadFixedLength(length int) (data []byte, err error) {
// Read the whole message into a buffer
data = make([]byte, length)
receivedLength := 0
for receivedLength < length {
bytesRead, err := c.Rwc.Read(data[receivedLength:])
if err != nil {
return data, err
}
receivedLength += bytesRead
}... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ReadFixedLength",
"(",
"length",
"int",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"// Read the whole message into a buffer",
"data",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"length",
")",
"... | // ReadFixedLength reads data from the connection up to the specified length. | [
"ReadFixedLength",
"reads",
"data",
"from",
"the",
"connection",
"up",
"to",
"the",
"specified",
"length",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/conn.go#L173-L186 |
145,342 | jordwest/imap-server | types/sequence_numbers.go | InterpretMessageRange | func InterpretMessageRange(imapMessageRange string) (seqRange SequenceRange, err error) {
result := rangeRegexp.FindStringSubmatch(imapMessageRange)
if len(result) == 0 {
return SequenceRange{}, errInvalidRangeString(imapMessageRange)
}
first := SequenceNumber(result[1])
second := SequenceNumber(result[2])
//... | go | func InterpretMessageRange(imapMessageRange string) (seqRange SequenceRange, err error) {
result := rangeRegexp.FindStringSubmatch(imapMessageRange)
if len(result) == 0 {
return SequenceRange{}, errInvalidRangeString(imapMessageRange)
}
first := SequenceNumber(result[1])
second := SequenceNumber(result[2])
//... | [
"func",
"InterpretMessageRange",
"(",
"imapMessageRange",
"string",
")",
"(",
"seqRange",
"SequenceRange",
",",
"err",
"error",
")",
"{",
"result",
":=",
"rangeRegexp",
".",
"FindStringSubmatch",
"(",
"imapMessageRange",
")",
"\n",
"if",
"len",
"(",
"result",
")... | // InterpretMessageRange creates a SequenceRange from the given string in the
// IMAP format. | [
"InterpretMessageRange",
"creates",
"a",
"SequenceRange",
"from",
"the",
"given",
"string",
"in",
"the",
"IMAP",
"format",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/types/sequence_numbers.go#L95-L124 |
145,343 | jordwest/imap-server | types/sequence_numbers.go | InterpretSequenceSet | func InterpretSequenceSet(imapSequenceSet string) (seqSet SequenceSet, err error) {
// Ensure the sequence set is valid
if !setRegexp.MatchString(imapSequenceSet) {
return nil, errInvalidSequenceSetString(imapSequenceSet)
}
ranges := strings.Split(imapSequenceSet, ",")
seqSet = make(SequenceSet, len(ranges))
... | go | func InterpretSequenceSet(imapSequenceSet string) (seqSet SequenceSet, err error) {
// Ensure the sequence set is valid
if !setRegexp.MatchString(imapSequenceSet) {
return nil, errInvalidSequenceSetString(imapSequenceSet)
}
ranges := strings.Split(imapSequenceSet, ",")
seqSet = make(SequenceSet, len(ranges))
... | [
"func",
"InterpretSequenceSet",
"(",
"imapSequenceSet",
"string",
")",
"(",
"seqSet",
"SequenceSet",
",",
"err",
"error",
")",
"{",
"// Ensure the sequence set is valid",
"if",
"!",
"setRegexp",
".",
"MatchString",
"(",
"imapSequenceSet",
")",
"{",
"return",
"nil",
... | // InterpretSequenceSet creates a SequenceSet from the given string in the IMAP
// format. | [
"InterpretSequenceSet",
"creates",
"a",
"SequenceSet",
"from",
"the",
"given",
"string",
"in",
"the",
"IMAP",
"format",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/types/sequence_numbers.go#L128-L145 |
145,344 | jordwest/imap-server | util/formatting.go | SplitParams | func SplitParams(params string) []string {
paramsOpen := false
result := strings.FieldsFunc(params, func(r rune) bool {
if r == '[' {
paramsOpen = true
}
if r == ']' {
paramsOpen = false
}
if r == ' ' && !paramsOpen {
return true
}
return false
})
return result
} | go | func SplitParams(params string) []string {
paramsOpen := false
result := strings.FieldsFunc(params, func(r rune) bool {
if r == '[' {
paramsOpen = true
}
if r == ']' {
paramsOpen = false
}
if r == ' ' && !paramsOpen {
return true
}
return false
})
return result
} | [
"func",
"SplitParams",
"(",
"params",
"string",
")",
"[",
"]",
"string",
"{",
"paramsOpen",
":=",
"false",
"\n",
"result",
":=",
"strings",
".",
"FieldsFunc",
"(",
"params",
",",
"func",
"(",
"r",
"rune",
")",
"bool",
"{",
"if",
"r",
"==",
"'['",
"{"... | // SplitParams splits parameters in IMAP arguments so that they're easily
// readable. | [
"SplitParams",
"splits",
"parameters",
"in",
"IMAP",
"arguments",
"so",
"that",
"they",
"re",
"easily",
"readable",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/util/formatting.go#L25-L40 |
145,345 | jordwest/imap-server | util/formatting.go | MIMEHeaderToString | func MIMEHeaderToString(header textproto.MIMEHeader) string {
buf := &bytes.Buffer{}
_, err := WriteMIMEHeader(buf, header)
if err != nil {
panic(err)
}
return buf.String()
} | go | func MIMEHeaderToString(header textproto.MIMEHeader) string {
buf := &bytes.Buffer{}
_, err := WriteMIMEHeader(buf, header)
if err != nil {
panic(err)
}
return buf.String()
} | [
"func",
"MIMEHeaderToString",
"(",
"header",
"textproto",
".",
"MIMEHeader",
")",
"string",
"{",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"_",
",",
"err",
":=",
"WriteMIMEHeader",
"(",
"buf",
",",
"header",
")",
"\n",
"if",
"err",
"!="... | // MIMEHeaderToString converts a textproto.MIMEHeader into its string
// representation. | [
"MIMEHeaderToString",
"converts",
"a",
"textproto",
".",
"MIMEHeader",
"into",
"its",
"string",
"representation",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/util/formatting.go#L60-L67 |
145,346 | jordwest/imap-server | conn/command_capability.go | cmdCapability | func cmdCapability(args commandArgs, c *Conn) {
c.writeResponse("", "CAPABILITY IMAP4rev1 AUTH=PLAIN")
c.writeResponse(args.ID(), "OK CAPABILITY completed")
} | go | func cmdCapability(args commandArgs, c *Conn) {
c.writeResponse("", "CAPABILITY IMAP4rev1 AUTH=PLAIN")
c.writeResponse(args.ID(), "OK CAPABILITY completed")
} | [
"func",
"cmdCapability",
"(",
"args",
"commandArgs",
",",
"c",
"*",
"Conn",
")",
"{",
"c",
".",
"writeResponse",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"c",
".",
"writeResponse",
"(",
"args",
".",
"ID",
"(",
")",
",",
"\"",
"\"",
")",
"\n",... | // Handles a CAPABILITY command | [
"Handles",
"a",
"CAPABILITY",
"command"
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/command_capability.go#L4-L7 |
145,347 | jordwest/imap-server | conn/commands.go | init | func init() {
commands = make([]command, 0)
// A sequence set consists only of digits, colons, stars and commas.
// eg: 5,9,10:15,256:*,566
sequenceSet := "[\\d\\:\\*\\,]+"
registerCommand("(?i:CAPABILITY)", cmdCapability)
registerCommand("(?i:LOGIN) \"([A-z0-9]+)\" \"([A-z0-9]+)\"", cmdLogin)
registerCommand(... | go | func init() {
commands = make([]command, 0)
// A sequence set consists only of digits, colons, stars and commas.
// eg: 5,9,10:15,256:*,566
sequenceSet := "[\\d\\:\\*\\,]+"
registerCommand("(?i:CAPABILITY)", cmdCapability)
registerCommand("(?i:LOGIN) \"([A-z0-9]+)\" \"([A-z0-9]+)\"", cmdLogin)
registerCommand(... | [
"func",
"init",
"(",
")",
"{",
"commands",
"=",
"make",
"(",
"[",
"]",
"command",
",",
"0",
")",
"\n\n",
"// A sequence set consists only of digits, colons, stars and commas.",
"// eg: 5,9,10:15,256:*,566",
"sequenceSet",
":=",
"\"",
"\\\\",
"\\\\",
"\\\\",
"\\\\",
... | // Register all supported client command handlers
// with the server. This function is run on server startup and
// panics if a command regex is invalid. | [
"Register",
"all",
"supported",
"client",
"command",
"handlers",
"with",
"the",
"server",
".",
"This",
"function",
"is",
"run",
"on",
"server",
"startup",
"and",
"panics",
"if",
"a",
"command",
"regex",
"is",
"invalid",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/conn/commands.go#L46-L80 |
145,348 | jordwest/imap-server | server.go | Serve | func (s *Server) Serve(l net.Listener) error {
fmt.Fprintf(s.Transcript, "Serving on %s\n", l.Addr().String())
defer l.Close()
for {
conn, err := l.Accept()
if err != nil {
return fmt.Errorf("Error accepting connection: %s\n", err)
}
fmt.Fprintf(s.Transcript, "Connection accepted\n")
c, err := s.newCon... | go | func (s *Server) Serve(l net.Listener) error {
fmt.Fprintf(s.Transcript, "Serving on %s\n", l.Addr().String())
defer l.Close()
for {
conn, err := l.Accept()
if err != nil {
return fmt.Errorf("Error accepting connection: %s\n", err)
}
fmt.Fprintf(s.Transcript, "Connection accepted\n")
c, err := s.newCon... | [
"func",
"(",
"s",
"*",
"Server",
")",
"Serve",
"(",
"l",
"net",
".",
"Listener",
")",
"error",
"{",
"fmt",
".",
"Fprintf",
"(",
"s",
".",
"Transcript",
",",
"\"",
"\\n",
"\"",
",",
"l",
".",
"Addr",
"(",
")",
".",
"String",
"(",
")",
")",
"\n... | // Serve starts the server and spawns new goroutines to handle each client
// connection as they come in. This function blocks. | [
"Serve",
"starts",
"the",
"server",
"and",
"spawns",
"new",
"goroutines",
"to",
"handle",
"each",
"client",
"connection",
"as",
"they",
"come",
"in",
".",
"This",
"function",
"blocks",
"."
] | b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f | https://github.com/jordwest/imap-server/blob/b35c7199ddb255f2b4e1d47a9d5aa8d78c1fe61f/server.go#L53-L70 |
145,349 | blacktear23/go-proxyprotocol | proxy_protocol.go | checkAllowed | func (l *proxyProtocolListener) checkAllowed(raddr net.Addr) bool {
if l.allowAll {
return true
}
taddr, ok := raddr.(*net.TCPAddr)
if !ok {
return false
}
cip := taddr.IP
for _, ipnet := range l.allowedNets {
if ipnet.Contains(cip) {
return true
}
}
return false
} | go | func (l *proxyProtocolListener) checkAllowed(raddr net.Addr) bool {
if l.allowAll {
return true
}
taddr, ok := raddr.(*net.TCPAddr)
if !ok {
return false
}
cip := taddr.IP
for _, ipnet := range l.allowedNets {
if ipnet.Contains(cip) {
return true
}
}
return false
} | [
"func",
"(",
"l",
"*",
"proxyProtocolListener",
")",
"checkAllowed",
"(",
"raddr",
"net",
".",
"Addr",
")",
"bool",
"{",
"if",
"l",
".",
"allowAll",
"{",
"return",
"true",
"\n",
"}",
"\n",
"taddr",
",",
"ok",
":=",
"raddr",
".",
"(",
"*",
"net",
".... | // Check remote address is allowed | [
"Check",
"remote",
"address",
"is",
"allowed"
] | af7a81e8dd0d5cc4e9ec408495d8f251684565c3 | https://github.com/blacktear23/go-proxyprotocol/blob/af7a81e8dd0d5cc4e9ec408495d8f251684565c3/proxy_protocol.go#L101-L116 |
145,350 | blacktear23/go-proxyprotocol | proxy_protocol.go | createProxyProtocolConn | func (l *proxyProtocolListener) createProxyProtocolConn(conn net.Conn) (*proxyProtocolConn, error) {
ppconn := &proxyProtocolConn{
Conn: conn,
headerReadTimeout: l.headerReadTimeout,
}
err := ppconn.readClientAddrBehindProxy(conn.RemoteAddr())
if err != nil {
ppconn.Close()
return nil, err
}
... | go | func (l *proxyProtocolListener) createProxyProtocolConn(conn net.Conn) (*proxyProtocolConn, error) {
ppconn := &proxyProtocolConn{
Conn: conn,
headerReadTimeout: l.headerReadTimeout,
}
err := ppconn.readClientAddrBehindProxy(conn.RemoteAddr())
if err != nil {
ppconn.Close()
return nil, err
}
... | [
"func",
"(",
"l",
"*",
"proxyProtocolListener",
")",
"createProxyProtocolConn",
"(",
"conn",
"net",
".",
"Conn",
")",
"(",
"*",
"proxyProtocolConn",
",",
"error",
")",
"{",
"ppconn",
":=",
"&",
"proxyProtocolConn",
"{",
"Conn",
":",
"conn",
",",
"headerReadT... | // Create proxyProtocolConn instance | [
"Create",
"proxyProtocolConn",
"instance"
] | af7a81e8dd0d5cc4e9ec408495d8f251684565c3 | https://github.com/blacktear23/go-proxyprotocol/blob/af7a81e8dd0d5cc4e9ec408495d8f251684565c3/proxy_protocol.go#L119-L130 |
145,351 | blacktear23/go-proxyprotocol | proxy_protocol.go | Accept | func (l *proxyProtocolListener) Accept() (net.Conn, error) {
ce := <-l.acceptQueue
if opErr, ok := ce.err.(*net.OpError); ok {
if opErr.Err.Error() == "use of closed network connection" {
close(l.acceptQueue)
}
}
return ce.conn, ce.err
} | go | func (l *proxyProtocolListener) Accept() (net.Conn, error) {
ce := <-l.acceptQueue
if opErr, ok := ce.err.(*net.OpError); ok {
if opErr.Err.Error() == "use of closed network connection" {
close(l.acceptQueue)
}
}
return ce.conn, ce.err
} | [
"func",
"(",
"l",
"*",
"proxyProtocolListener",
")",
"Accept",
"(",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"ce",
":=",
"<-",
"l",
".",
"acceptQueue",
"\n",
"if",
"opErr",
",",
"ok",
":=",
"ce",
".",
"err",
".",
"(",
"*",
"net",
"... | // Accept new connection
// You should check error instead of panic it.
// As PROXY protocol SPEC wrote, if invalid PROXY protocol header
// received, or valid header received but connection's address not
// allowed, Accept function will return an error and close this connection. | [
"Accept",
"new",
"connection",
"You",
"should",
"check",
"error",
"instead",
"of",
"panic",
"it",
".",
"As",
"PROXY",
"protocol",
"SPEC",
"wrote",
"if",
"invalid",
"PROXY",
"protocol",
"header",
"received",
"or",
"valid",
"header",
"received",
"but",
"connecti... | af7a81e8dd0d5cc4e9ec408495d8f251684565c3 | https://github.com/blacktear23/go-proxyprotocol/blob/af7a81e8dd0d5cc4e9ec408495d8f251684565c3/proxy_protocol.go#L165-L173 |
145,352 | blacktear23/go-proxyprotocol | proxy_protocol.go | Read | func (c *proxyProtocolConn) Read(buffer []byte) (int, error) {
if c.exceedBufferReaded {
return c.Conn.Read(buffer)
}
if c.exceedBufferLen == 0 || c.exceedBufferStart >= c.exceedBufferLen {
c.exceedBufferReaded = true
return c.Conn.Read(buffer)
}
buflen := len(buffer)
nExceedRead := c.exceedBufferLen - c.e... | go | func (c *proxyProtocolConn) Read(buffer []byte) (int, error) {
if c.exceedBufferReaded {
return c.Conn.Read(buffer)
}
if c.exceedBufferLen == 0 || c.exceedBufferStart >= c.exceedBufferLen {
c.exceedBufferReaded = true
return c.Conn.Read(buffer)
}
buflen := len(buffer)
nExceedRead := c.exceedBufferLen - c.e... | [
"func",
"(",
"c",
"*",
"proxyProtocolConn",
")",
"Read",
"(",
"buffer",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"c",
".",
"exceedBufferReaded",
"{",
"return",
"c",
".",
"Conn",
".",
"Read",
"(",
"buffer",
")",
"\n",
"}",
... | // Read received data | [
"Read",
"received",
"data"
] | af7a81e8dd0d5cc4e9ec408495d8f251684565c3 | https://github.com/blacktear23/go-proxyprotocol/blob/af7a81e8dd0d5cc4e9ec408495d8f251684565c3/proxy_protocol.go#L291-L318 |
145,353 | getlantern/goexpr | substr.go | Substr | func Substr(source Expr, from Expr, length Expr) Expr {
return &substr{source, from, length}
} | go | func Substr(source Expr, from Expr, length Expr) Expr {
return &substr{source, from, length}
} | [
"func",
"Substr",
"(",
"source",
"Expr",
",",
"from",
"Expr",
",",
"length",
"Expr",
")",
"Expr",
"{",
"return",
"&",
"substr",
"{",
"source",
",",
"from",
",",
"length",
"}",
"\n",
"}"
] | // Substr takes a substring of the given source starting at the given index
// capped to the given length. | [
"Substr",
"takes",
"a",
"substring",
"of",
"the",
"given",
"source",
"starting",
"at",
"the",
"given",
"index",
"capped",
"to",
"the",
"given",
"length",
"."
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/substr.go#L9-L11 |
145,354 | getlantern/goexpr | isp/caching_provider.go | ASN | func (c *cachingProvider) ASN(ip string) (asn int, found bool) {
_asn, _found := c.asnCache.Get(ip)
if !_found {
_asn, _found = c.Provider.ASN(ip)
c.asnCache.Add(ip, _asn)
}
found = _asn != 0
if found {
asn = _asn.(int)
}
return
} | go | func (c *cachingProvider) ASN(ip string) (asn int, found bool) {
_asn, _found := c.asnCache.Get(ip)
if !_found {
_asn, _found = c.Provider.ASN(ip)
c.asnCache.Add(ip, _asn)
}
found = _asn != 0
if found {
asn = _asn.(int)
}
return
} | [
"func",
"(",
"c",
"*",
"cachingProvider",
")",
"ASN",
"(",
"ip",
"string",
")",
"(",
"asn",
"int",
",",
"found",
"bool",
")",
"{",
"_asn",
",",
"_found",
":=",
"c",
".",
"asnCache",
".",
"Get",
"(",
"ip",
")",
"\n",
"if",
"!",
"_found",
"{",
"_... | // ASN looks up the Autonomous System Number corresponding to the given ip. | [
"ASN",
"looks",
"up",
"the",
"Autonomous",
"System",
"Number",
"corresponding",
"to",
"the",
"given",
"ip",
"."
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/isp/caching_provider.go#L59-L70 |
145,355 | getlantern/goexpr | bool.go | Boolean | func Boolean(operator string, left Expr, right Expr) (Expr, error) {
var bfn boolFN
switch operator {
case "AND":
bfn = and
case "OR":
bfn = or
default:
return nil, fmt.Errorf("Unknown boolean operator %v", operator)
}
return &booleanExpr{operator, bfn, left, right}, nil
} | go | func Boolean(operator string, left Expr, right Expr) (Expr, error) {
var bfn boolFN
switch operator {
case "AND":
bfn = and
case "OR":
bfn = or
default:
return nil, fmt.Errorf("Unknown boolean operator %v", operator)
}
return &booleanExpr{operator, bfn, left, right}, nil
} | [
"func",
"Boolean",
"(",
"operator",
"string",
",",
"left",
"Expr",
",",
"right",
"Expr",
")",
"(",
"Expr",
",",
"error",
")",
"{",
"var",
"bfn",
"boolFN",
"\n",
"switch",
"operator",
"{",
"case",
"\"",
"\"",
":",
"bfn",
"=",
"and",
"\n",
"case",
"\... | // Boolean accepts the operators AND, OR and returns a short-circuiting
// expression that evaluates left first and right second. | [
"Boolean",
"accepts",
"the",
"operators",
"AND",
"OR",
"and",
"returns",
"a",
"short",
"-",
"circuiting",
"expression",
"that",
"evaluates",
"left",
"first",
"and",
"right",
"second",
"."
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/bool.go#L11-L22 |
145,356 | getlantern/goexpr | geo/geo.go | Init | func Init(dbFile string, cacheSize int) error {
if cacheSize <= 0 {
cacheSize = DefaultCacheSize
log.Debugf("Defaulted ip cache size to %v", cacheSize)
}
_db, dbDate, err := readDbFromFile(dbFile)
if err != nil {
_db, dbDate, err = readDbFromWeb(dbFile)
if err != nil {
return fmt.Errorf("Unable to read D... | go | func Init(dbFile string, cacheSize int) error {
if cacheSize <= 0 {
cacheSize = DefaultCacheSize
log.Debugf("Defaulted ip cache size to %v", cacheSize)
}
_db, dbDate, err := readDbFromFile(dbFile)
if err != nil {
_db, dbDate, err = readDbFromWeb(dbFile)
if err != nil {
return fmt.Errorf("Unable to read D... | [
"func",
"Init",
"(",
"dbFile",
"string",
",",
"cacheSize",
"int",
")",
"error",
"{",
"if",
"cacheSize",
"<=",
"0",
"{",
"cacheSize",
"=",
"DefaultCacheSize",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"cacheSize",
")",
"\n",
"}",
"\n",
"_db",
... | // Init initializes the Geolocation subsystem, storing the database file at the
// given dbFile location. It will periodically fetch updates from the maxmind
// website. | [
"Init",
"initializes",
"the",
"Geolocation",
"subsystem",
"storing",
"the",
"database",
"file",
"at",
"the",
"given",
"dbFile",
"location",
".",
"It",
"will",
"periodically",
"fetch",
"updates",
"from",
"the",
"maxmind",
"website",
"."
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/geo/geo.go#L49-L70 |
145,357 | getlantern/goexpr | geo/geo.go | readDbFromFile | func readDbFromFile(dbFile string) (*geoip2.Reader, time.Time, error) {
dbData, err := ioutil.ReadFile(dbFile)
if err != nil {
return nil, time.Time{}, fmt.Errorf("Unable to read db file %s: %s", dbFile, err)
}
fileInfo, err := os.Stat(dbFile)
if err != nil {
return nil, time.Time{}, fmt.Errorf("Unable to stat... | go | func readDbFromFile(dbFile string) (*geoip2.Reader, time.Time, error) {
dbData, err := ioutil.ReadFile(dbFile)
if err != nil {
return nil, time.Time{}, fmt.Errorf("Unable to read db file %s: %s", dbFile, err)
}
fileInfo, err := os.Stat(dbFile)
if err != nil {
return nil, time.Time{}, fmt.Errorf("Unable to stat... | [
"func",
"readDbFromFile",
"(",
"dbFile",
"string",
")",
"(",
"*",
"geoip2",
".",
"Reader",
",",
"time",
".",
"Time",
",",
"error",
")",
"{",
"dbData",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"dbFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // readDbFromFile reads the MaxMind database and timestamp from a file | [
"readDbFromFile",
"reads",
"the",
"MaxMind",
"database",
"and",
"timestamp",
"from",
"a",
"file"
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/geo/geo.go#L265-L280 |
145,358 | getlantern/goexpr | geo/geo.go | readDbFromWeb | func readDbFromWeb(dbFile string) (*geoip2.Reader, time.Time, error) {
dbResp, err := http.Get(dbURL)
if err != nil {
return nil, time.Time{}, fmt.Errorf("Unable to get database from %v: %v", dbURL, err)
}
gzipDbData, err := gzip.NewReader(dbResp.Body)
if err != nil {
return nil, time.Time{}, fmt.Errorf("Unabl... | go | func readDbFromWeb(dbFile string) (*geoip2.Reader, time.Time, error) {
dbResp, err := http.Get(dbURL)
if err != nil {
return nil, time.Time{}, fmt.Errorf("Unable to get database from %v: %v", dbURL, err)
}
gzipDbData, err := gzip.NewReader(dbResp.Body)
if err != nil {
return nil, time.Time{}, fmt.Errorf("Unabl... | [
"func",
"readDbFromWeb",
"(",
"dbFile",
"string",
")",
"(",
"*",
"geoip2",
".",
"Reader",
",",
"time",
".",
"Time",
",",
"error",
")",
"{",
"dbResp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"dbURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r... | // readDbFromWeb reads the MaxMind database and timestamp from the web | [
"readDbFromWeb",
"reads",
"the",
"MaxMind",
"database",
"and",
"timestamp",
"from",
"the",
"web"
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/geo/geo.go#L318-L345 |
145,359 | getlantern/goexpr | geo/geo.go | lastModified | func lastModified(resp *http.Response) (time.Time, error) {
lastModified := resp.Header.Get("Last-Modified")
return http.ParseTime(lastModified)
} | go | func lastModified(resp *http.Response) (time.Time, error) {
lastModified := resp.Header.Get("Last-Modified")
return http.ParseTime(lastModified)
} | [
"func",
"lastModified",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"lastModified",
":=",
"resp",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"return",
"http",
".",
"ParseTime",
"(",
... | // lastModified parses the Last-Modified header from a response | [
"lastModified",
"parses",
"the",
"Last",
"-",
"Modified",
"header",
"from",
"a",
"response"
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/geo/geo.go#L348-L351 |
145,360 | getlantern/goexpr | geo/geo.go | openDb | func openDb(dbData []byte) (*geoip2.Reader, error) {
db, err := geoip2.FromBytes(dbData)
if err != nil {
return nil, fmt.Errorf("Unable to open database: %s", err)
}
return db, nil
} | go | func openDb(dbData []byte) (*geoip2.Reader, error) {
db, err := geoip2.FromBytes(dbData)
if err != nil {
return nil, fmt.Errorf("Unable to open database: %s", err)
}
return db, nil
} | [
"func",
"openDb",
"(",
"dbData",
"[",
"]",
"byte",
")",
"(",
"*",
"geoip2",
".",
"Reader",
",",
"error",
")",
"{",
"db",
",",
"err",
":=",
"geoip2",
".",
"FromBytes",
"(",
"dbData",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
... | // openDb opens a MaxMind in-memory db using the geoip2.Reader | [
"openDb",
"opens",
"a",
"MaxMind",
"in",
"-",
"memory",
"db",
"using",
"the",
"geoip2",
".",
"Reader"
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/geo/geo.go#L354-L360 |
145,361 | getlantern/goexpr | isp/ip2location/provider.go | ipStringToInt | func ipStringToInt(ipnr string) int64 {
bits := strings.Split(ipnr, ".")
if len(bits) != 4 {
return -1
}
b0, _ := strconv.Atoi(bits[0])
b1, _ := strconv.Atoi(bits[1])
b2, _ := strconv.Atoi(bits[2])
b3, _ := strconv.Atoi(bits[3])
var sum int64
sum += int64(b0) << 24
sum += int64(b1) << 16
sum += int64(b2... | go | func ipStringToInt(ipnr string) int64 {
bits := strings.Split(ipnr, ".")
if len(bits) != 4 {
return -1
}
b0, _ := strconv.Atoi(bits[0])
b1, _ := strconv.Atoi(bits[1])
b2, _ := strconv.Atoi(bits[2])
b3, _ := strconv.Atoi(bits[3])
var sum int64
sum += int64(b0) << 24
sum += int64(b1) << 16
sum += int64(b2... | [
"func",
"ipStringToInt",
"(",
"ipnr",
"string",
")",
"int64",
"{",
"bits",
":=",
"strings",
".",
"Split",
"(",
"ipnr",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"bits",
")",
"!=",
"4",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n\n",
"b0",
",",
... | // Convert net.IP to int64 | [
"Convert",
"net",
".",
"IP",
"to",
"int64"
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/isp/ip2location/provider.go#L140-L159 |
145,362 | getlantern/goexpr | split.go | Split | func Split(source Expr, delim Expr, idx Expr) Expr {
return &split{source, delim, idx}
} | go | func Split(source Expr, delim Expr, idx Expr) Expr {
return &split{source, delim, idx}
} | [
"func",
"Split",
"(",
"source",
"Expr",
",",
"delim",
"Expr",
",",
"idx",
"Expr",
")",
"Expr",
"{",
"return",
"&",
"split",
"{",
"source",
",",
"delim",
",",
"idx",
"}",
"\n",
"}"
] | // Split splits a given source on a delimiter and returns the value at the given
// index. If index is negative, it is treated relative to the end of the split
// list, with -1 being the very last element, -2 the 2nd to last, etc.If no
// value exists at the given index, this method returns nil. | [
"Split",
"splits",
"a",
"given",
"source",
"on",
"a",
"delimiter",
"and",
"returns",
"the",
"value",
"at",
"the",
"given",
"index",
".",
"If",
"index",
"is",
"negative",
"it",
"is",
"treated",
"relative",
"to",
"the",
"end",
"of",
"the",
"split",
"list",... | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/split.go#L12-L14 |
145,363 | getlantern/goexpr | isp/maxmind/provider.go | NewProvider | func NewProvider(datafile string) (isp.Provider, error) {
r, err := geoip2.Open(datafile)
if err != nil {
return nil, fmt.Errorf("Unable to open datafile at %v: %v", datafile, err)
}
prov := &provider{r}
return prov, nil
} | go | func NewProvider(datafile string) (isp.Provider, error) {
r, err := geoip2.Open(datafile)
if err != nil {
return nil, fmt.Errorf("Unable to open datafile at %v: %v", datafile, err)
}
prov := &provider{r}
return prov, nil
} | [
"func",
"NewProvider",
"(",
"datafile",
"string",
")",
"(",
"isp",
".",
"Provider",
",",
"error",
")",
"{",
"r",
",",
"err",
":=",
"geoip2",
".",
"Open",
"(",
"datafile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
... | // NewProvider creates a new provider using the specified MaxMind GeoIP2 ISP
// datafile. | [
"NewProvider",
"creates",
"a",
"new",
"provider",
"using",
"the",
"specified",
"MaxMind",
"GeoIP2",
"ISP",
"datafile",
"."
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/isp/maxmind/provider.go#L13-L20 |
145,364 | getlantern/goexpr | isp/isp.go | SetProvider | func SetProvider(prov Provider, cacheSize int) {
if cacheSize <= 0 {
cacheSize = DefaultCacheSize
log.Debugf("Defaulted ip cache size to %v", cacheSize)
}
provider.Store(withCaching(prov, cacheSize))
} | go | func SetProvider(prov Provider, cacheSize int) {
if cacheSize <= 0 {
cacheSize = DefaultCacheSize
log.Debugf("Defaulted ip cache size to %v", cacheSize)
}
provider.Store(withCaching(prov, cacheSize))
} | [
"func",
"SetProvider",
"(",
"prov",
"Provider",
",",
"cacheSize",
"int",
")",
"{",
"if",
"cacheSize",
"<=",
"0",
"{",
"cacheSize",
"=",
"DefaultCacheSize",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"cacheSize",
")",
"\n",
"}",
"\n",
"provider",
... | // SetProvider sets the ISP data provider | [
"SetProvider",
"sets",
"the",
"ISP",
"data",
"provider"
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/isp/isp.go#L46-L52 |
145,365 | getlantern/goexpr | isp/isp.go | ISP | func ISP(ip goexpr.Expr) goexpr.Expr {
return &ispExpr{"ISP", ip, func(ip string) (interface{}, bool) {
return getProvider().ISP(ip)
}}
} | go | func ISP(ip goexpr.Expr) goexpr.Expr {
return &ispExpr{"ISP", ip, func(ip string) (interface{}, bool) {
return getProvider().ISP(ip)
}}
} | [
"func",
"ISP",
"(",
"ip",
"goexpr",
".",
"Expr",
")",
"goexpr",
".",
"Expr",
"{",
"return",
"&",
"ispExpr",
"{",
"\"",
"\"",
",",
"ip",
",",
"func",
"(",
"ip",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"return",
"getProvid... | // ISP returns the ISP name for a given IPv4 address | [
"ISP",
"returns",
"the",
"ISP",
"name",
"for",
"a",
"given",
"IPv4",
"address"
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/isp/isp.go#L59-L63 |
145,366 | getlantern/goexpr | isp/isp.go | ASN | func ASN(ip goexpr.Expr) goexpr.Expr {
return &ispExpr{"ASN", ip, func(ip string) (interface{}, bool) {
return getProvider().ASN(ip)
}}
} | go | func ASN(ip goexpr.Expr) goexpr.Expr {
return &ispExpr{"ASN", ip, func(ip string) (interface{}, bool) {
return getProvider().ASN(ip)
}}
} | [
"func",
"ASN",
"(",
"ip",
"goexpr",
".",
"Expr",
")",
"goexpr",
".",
"Expr",
"{",
"return",
"&",
"ispExpr",
"{",
"\"",
"\"",
",",
"ip",
",",
"func",
"(",
"ip",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"return",
"getProvid... | // ASN returns the ASN number for a given IPv4 address as an int | [
"ASN",
"returns",
"the",
"ASN",
"number",
"for",
"a",
"given",
"IPv4",
"address",
"as",
"an",
"int"
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/isp/isp.go#L74-L78 |
145,367 | getlantern/goexpr | isp/isp.go | ASName | func ASName(ip goexpr.Expr) goexpr.Expr {
return &ispExpr{"ASNAME", ip, func(ip string) (interface{}, bool) {
return getProvider().ASName(ip)
}}
} | go | func ASName(ip goexpr.Expr) goexpr.Expr {
return &ispExpr{"ASNAME", ip, func(ip string) (interface{}, bool) {
return getProvider().ASName(ip)
}}
} | [
"func",
"ASName",
"(",
"ip",
"goexpr",
".",
"Expr",
")",
"goexpr",
".",
"Expr",
"{",
"return",
"&",
"ispExpr",
"{",
"\"",
"\"",
",",
"ip",
",",
"func",
"(",
"ip",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"return",
"getPro... | // ASName returns the ASN name for a given IPv4 address | [
"ASName",
"returns",
"the",
"ASN",
"name",
"for",
"a",
"given",
"IPv4",
"address"
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/isp/isp.go#L81-L85 |
145,368 | getlantern/goexpr | replace.go | ReplaceAll | func ReplaceAll(source Expr, regex Expr, replacement Expr) Expr {
regexString := ""
_regex, ok := regex.(*constant)
if ok {
regexString = fmt.Sprint(_regex.Eval(nil))
} else {
fmt.Println("Regex is not a constant!")
regexString = ""
}
e := &replaceAll{Source: source, Regex: regexString, Replacement: replace... | go | func ReplaceAll(source Expr, regex Expr, replacement Expr) Expr {
regexString := ""
_regex, ok := regex.(*constant)
if ok {
regexString = fmt.Sprint(_regex.Eval(nil))
} else {
fmt.Println("Regex is not a constant!")
regexString = ""
}
e := &replaceAll{Source: source, Regex: regexString, Replacement: replace... | [
"func",
"ReplaceAll",
"(",
"source",
"Expr",
",",
"regex",
"Expr",
",",
"replacement",
"Expr",
")",
"Expr",
"{",
"regexString",
":=",
"\"",
"\"",
"\n",
"_regex",
",",
"ok",
":=",
"regex",
".",
"(",
"*",
"constant",
")",
"\n",
"if",
"ok",
"{",
"regexS... | // ReplaceAll replaces all occurrences of the regex with the replacement. | [
"ReplaceAll",
"replaces",
"all",
"occurrences",
"of",
"the",
"regex",
"with",
"the",
"replacement",
"."
] | 64ec90b5c995f627388affb6ac64181f1fb7dea0 | https://github.com/getlantern/goexpr/blob/64ec90b5c995f627388affb6ac64181f1fb7dea0/replace.go#L11-L23 |
145,369 | lafikl/fluent | fluent.go | Post | func (f *Request) Post(url string) *Request {
f.Url(url).Method("POST")
return f
} | go | func (f *Request) Post(url string) *Request {
f.Url(url).Method("POST")
return f
} | [
"func",
"(",
"f",
"*",
"Request",
")",
"Post",
"(",
"url",
"string",
")",
"*",
"Request",
"{",
"f",
".",
"Url",
"(",
"url",
")",
".",
"Method",
"(",
"\"",
"\"",
")",
"\n",
"return",
"f",
"\n",
"}"
] | // This is a shorthand method that calls f.Method with `POST`
// and calls f.Url with the url you give to her | [
"This",
"is",
"a",
"shorthand",
"method",
"that",
"calls",
"f",
".",
"Method",
"with",
"POST",
"and",
"calls",
"f",
".",
"Url",
"with",
"the",
"url",
"you",
"give",
"to",
"her"
] | 392b95b3b5b2e8244507ab65a06ca188b20b4a9f | https://github.com/lafikl/fluent/blob/392b95b3b5b2e8244507ab65a06ca188b20b4a9f/fluent.go#L65-L68 |
145,370 | lafikl/fluent | fluent.go | Put | func (f *Request) Put(url string) *Request {
f.Url(url).Method("PUT")
return f
} | go | func (f *Request) Put(url string) *Request {
f.Url(url).Method("PUT")
return f
} | [
"func",
"(",
"f",
"*",
"Request",
")",
"Put",
"(",
"url",
"string",
")",
"*",
"Request",
"{",
"f",
".",
"Url",
"(",
"url",
")",
".",
"Method",
"(",
"\"",
"\"",
")",
"\n",
"return",
"f",
"\n",
"}"
] | // Same as f.Post but the method is `PUT` | [
"Same",
"as",
"f",
".",
"Post",
"but",
"the",
"method",
"is",
"PUT"
] | 392b95b3b5b2e8244507ab65a06ca188b20b4a9f | https://github.com/lafikl/fluent/blob/392b95b3b5b2e8244507ab65a06ca188b20b4a9f/fluent.go#L71-L74 |
145,371 | lafikl/fluent | fluent.go | Patch | func (f *Request) Patch(url string) *Request {
f.Url(url).Method("PATCH")
return f
} | go | func (f *Request) Patch(url string) *Request {
f.Url(url).Method("PATCH")
return f
} | [
"func",
"(",
"f",
"*",
"Request",
")",
"Patch",
"(",
"url",
"string",
")",
"*",
"Request",
"{",
"f",
".",
"Url",
"(",
"url",
")",
".",
"Method",
"(",
"\"",
"\"",
")",
"\n",
"return",
"f",
"\n",
"}"
] | // Same as f.Post but the method is `PATCH` | [
"Same",
"as",
"f",
".",
"Post",
"but",
"the",
"method",
"is",
"PATCH"
] | 392b95b3b5b2e8244507ab65a06ca188b20b4a9f | https://github.com/lafikl/fluent/blob/392b95b3b5b2e8244507ab65a06ca188b20b4a9f/fluent.go#L77-L80 |
145,372 | lafikl/fluent | fluent.go | Get | func (f *Request) Get(url string) *Request {
f.Url(url).Method("GET")
return f
} | go | func (f *Request) Get(url string) *Request {
f.Url(url).Method("GET")
return f
} | [
"func",
"(",
"f",
"*",
"Request",
")",
"Get",
"(",
"url",
"string",
")",
"*",
"Request",
"{",
"f",
".",
"Url",
"(",
"url",
")",
".",
"Method",
"(",
"\"",
"\"",
")",
"\n",
"return",
"f",
"\n",
"}"
] | // Same as f.Post but the method is `GET` | [
"Same",
"as",
"f",
".",
"Post",
"but",
"the",
"method",
"is",
"GET"
] | 392b95b3b5b2e8244507ab65a06ca188b20b4a9f | https://github.com/lafikl/fluent/blob/392b95b3b5b2e8244507ab65a06ca188b20b4a9f/fluent.go#L83-L86 |
145,373 | lafikl/fluent | fluent.go | Delete | func (f *Request) Delete(url string) *Request {
f.Url(url).Method("DELETE")
return f
} | go | func (f *Request) Delete(url string) *Request {
f.Url(url).Method("DELETE")
return f
} | [
"func",
"(",
"f",
"*",
"Request",
")",
"Delete",
"(",
"url",
"string",
")",
"*",
"Request",
"{",
"f",
".",
"Url",
"(",
"url",
")",
".",
"Method",
"(",
"\"",
"\"",
")",
"\n",
"return",
"f",
"\n",
"}"
] | // Same as f.Post but the method is `DELETE` | [
"Same",
"as",
"f",
".",
"Post",
"but",
"the",
"method",
"is",
"DELETE"
] | 392b95b3b5b2e8244507ab65a06ca188b20b4a9f | https://github.com/lafikl/fluent/blob/392b95b3b5b2e8244507ab65a06ca188b20b4a9f/fluent.go#L89-L92 |
145,374 | lafikl/fluent | fluent.go | Body | func (f *Request) Body(b io.Reader) *Request {
f.body = b
return f
} | go | func (f *Request) Body(b io.Reader) *Request {
f.body = b
return f
} | [
"func",
"(",
"f",
"*",
"Request",
")",
"Body",
"(",
"b",
"io",
".",
"Reader",
")",
"*",
"Request",
"{",
"f",
".",
"body",
"=",
"b",
"\n",
"return",
"f",
"\n",
"}"
] | // Whatever you pass to it will be passed to http.NewRequest | [
"Whatever",
"you",
"pass",
"to",
"it",
"will",
"be",
"passed",
"to",
"http",
".",
"NewRequest"
] | 392b95b3b5b2e8244507ab65a06ca188b20b4a9f | https://github.com/lafikl/fluent/blob/392b95b3b5b2e8244507ab65a06ca188b20b4a9f/fluent.go#L105-L108 |
145,375 | lafikl/fluent | fluent.go | SetHeader | func (f *Request) SetHeader(key, value string) *Request {
f.header[key] = value
return f
} | go | func (f *Request) SetHeader(key, value string) *Request {
f.header[key] = value
return f
} | [
"func",
"(",
"f",
"*",
"Request",
")",
"SetHeader",
"(",
"key",
",",
"value",
"string",
")",
"*",
"Request",
"{",
"f",
".",
"header",
"[",
"key",
"]",
"=",
"value",
"\n",
"return",
"f",
"\n",
"}"
] | // sets the header entries associated with key to the element value.
//
// It replaces any existing values associated with key. | [
"sets",
"the",
"header",
"entries",
"associated",
"with",
"key",
"to",
"the",
"element",
"value",
".",
"It",
"replaces",
"any",
"existing",
"values",
"associated",
"with",
"key",
"."
] | 392b95b3b5b2e8244507ab65a06ca188b20b4a9f | https://github.com/lafikl/fluent/blob/392b95b3b5b2e8244507ab65a06ca188b20b4a9f/fluent.go#L113-L116 |
145,376 | lafikl/fluent | fluent.go | Timeout | func (f *Request) Timeout(t time.Duration) *Request {
f.timeout = t
return f
} | go | func (f *Request) Timeout(t time.Duration) *Request {
f.timeout = t
return f
} | [
"func",
"(",
"f",
"*",
"Request",
")",
"Timeout",
"(",
"t",
"time",
".",
"Duration",
")",
"*",
"Request",
"{",
"f",
".",
"timeout",
"=",
"t",
"\n",
"return",
"f",
"\n",
"}"
] | // Timeout specifies a time limit for requests made by this
// Client. The timeout includes connection time, any
// redirects, and reading the response body. The timer remains
// running after Get, Head, Post, or Do return and will
// interrupt reading of the Response.Body.
//
// A Timeout of zero means no timeout. | [
"Timeout",
"specifies",
"a",
"time",
"limit",
"for",
"requests",
"made",
"by",
"this",
"Client",
".",
"The",
"timeout",
"includes",
"connection",
"time",
"any",
"redirects",
"and",
"reading",
"the",
"response",
"body",
".",
"The",
"timer",
"remains",
"running"... | 392b95b3b5b2e8244507ab65a06ca188b20b4a9f | https://github.com/lafikl/fluent/blob/392b95b3b5b2e8244507ab65a06ca188b20b4a9f/fluent.go#L125-L128 |
145,377 | lafikl/fluent | fluent.go | Retry | func (f *Request) Retry(r int) *Request {
f.retry = r
return f
} | go | func (f *Request) Retry(r int) *Request {
f.retry = r
return f
} | [
"func",
"(",
"f",
"*",
"Request",
")",
"Retry",
"(",
"r",
"int",
")",
"*",
"Request",
"{",
"f",
".",
"retry",
"=",
"r",
"\n",
"return",
"f",
"\n",
"}"
] | // Set how many times to retry if the request
// timedout or the server returned 5xx response. | [
"Set",
"how",
"many",
"times",
"to",
"retry",
"if",
"the",
"request",
"timedout",
"or",
"the",
"server",
"returned",
"5xx",
"response",
"."
] | 392b95b3b5b2e8244507ab65a06ca188b20b4a9f | https://github.com/lafikl/fluent/blob/392b95b3b5b2e8244507ab65a06ca188b20b4a9f/fluent.go#L182-L185 |
145,378 | lafikl/fluent | fluent.go | Proxy | func (f *Request) Proxy(p string) *Request {
f.proxy = p
return f
} | go | func (f *Request) Proxy(p string) *Request {
f.proxy = p
return f
} | [
"func",
"(",
"f",
"*",
"Request",
")",
"Proxy",
"(",
"p",
"string",
")",
"*",
"Request",
"{",
"f",
".",
"proxy",
"=",
"p",
"\n",
"return",
"f",
"\n",
"}"
] | // Set a HTTP proxy | [
"Set",
"a",
"HTTP",
"proxy"
] | 392b95b3b5b2e8244507ab65a06ca188b20b4a9f | https://github.com/lafikl/fluent/blob/392b95b3b5b2e8244507ab65a06ca188b20b4a9f/fluent.go#L188-L191 |
145,379 | lafikl/fluent | fluent.go | Send | func (f *Request) Send() (*http.Response, error) {
c := *http.DefaultClient
if f.timeout != 0 {
nc := f.newClient()
c = *nc
}
if f.proxy != "" {
proxyUrl, err := url.Parse(f.proxy)
if err != nil {
return nil, err
}
c.Transport = &http.Transport{
Proxy: http.ProxyURL(proxyUrl),
}
}
res, err... | go | func (f *Request) Send() (*http.Response, error) {
c := *http.DefaultClient
if f.timeout != 0 {
nc := f.newClient()
c = *nc
}
if f.proxy != "" {
proxyUrl, err := url.Parse(f.proxy)
if err != nil {
return nil, err
}
c.Transport = &http.Transport{
Proxy: http.ProxyURL(proxyUrl),
}
}
res, err... | [
"func",
"(",
"f",
"*",
"Request",
")",
"Send",
"(",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"c",
":=",
"*",
"http",
".",
"DefaultClient",
"\n",
"if",
"f",
".",
"timeout",
"!=",
"0",
"{",
"nc",
":=",
"f",
".",
"newClient"... | // It will construct the client and the request, then send it
//
// This function has to be called as the last thing,
// after setting the other properties | [
"It",
"will",
"construct",
"the",
"client",
"and",
"the",
"request",
"then",
"send",
"it",
"This",
"function",
"has",
"to",
"be",
"called",
"as",
"the",
"last",
"thing",
"after",
"setting",
"the",
"other",
"properties"
] | 392b95b3b5b2e8244507ab65a06ca188b20b4a9f | https://github.com/lafikl/fluent/blob/392b95b3b5b2e8244507ab65a06ca188b20b4a9f/fluent.go#L245-L266 |
145,380 | lafikl/fluent | fluent.go | New | func New() *Request {
f := &Request{}
f.header = map[string]string{}
f.backoff = backoff.NewExponentialBackOff()
f.err = nil
return f
} | go | func New() *Request {
f := &Request{}
f.header = map[string]string{}
f.backoff = backoff.NewExponentialBackOff()
f.err = nil
return f
} | [
"func",
"New",
"(",
")",
"*",
"Request",
"{",
"f",
":=",
"&",
"Request",
"{",
"}",
"\n",
"f",
".",
"header",
"=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"f",
".",
"backoff",
"=",
"backoff",
".",
"NewExponentialBackOff",
"(",
")",
"\... | // Create a new request | [
"Create",
"a",
"new",
"request"
] | 392b95b3b5b2e8244507ab65a06ca188b20b4a9f | https://github.com/lafikl/fluent/blob/392b95b3b5b2e8244507ab65a06ca188b20b4a9f/fluent.go#L269-L275 |
145,381 | manifoldco/go-manifold | zz_oag_generated_catalog.go | Current | func (i *PlanIter) Current() (*Plan, error) {
if i.err != nil {
return nil, i.err
}
return &i.page[i.i], nil
} | go | func (i *PlanIter) Current() (*Plan, error) {
if i.err != nil {
return nil, i.err
}
return &i.page[i.i], nil
} | [
"func",
"(",
"i",
"*",
"PlanIter",
")",
"Current",
"(",
")",
"(",
"*",
"Plan",
",",
"error",
")",
"{",
"if",
"i",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"i",
".",
"err",
"\n",
"}",
"\n",
"return",
"&",
"i",
".",
"page",
"[",
"i... | // Current returns the current Plan, and an optional error. Once an error has been returned,
// the PlanIter is closed, or the end of iteration is reached, subsequent calls to Current
// will return an error. | [
"Current",
"returns",
"the",
"current",
"Plan",
"and",
"an",
"optional",
"error",
".",
"Once",
"an",
"error",
"has",
"been",
"returned",
"the",
"PlanIter",
"is",
"closed",
"or",
"the",
"end",
"of",
"iteration",
"is",
"reached",
"subsequent",
"calls",
"to",
... | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/zz_oag_generated_catalog.go#L229-L234 |
145,382 | manifoldco/go-manifold | zz_oag_generated_catalog.go | Current | func (i *ProductIter) Current() (*Product, error) {
if i.err != nil {
return nil, i.err
}
return &i.page[i.i], nil
} | go | func (i *ProductIter) Current() (*Product, error) {
if i.err != nil {
return nil, i.err
}
return &i.page[i.i], nil
} | [
"func",
"(",
"i",
"*",
"ProductIter",
")",
"Current",
"(",
")",
"(",
"*",
"Product",
",",
"error",
")",
"{",
"if",
"i",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"i",
".",
"err",
"\n",
"}",
"\n",
"return",
"&",
"i",
".",
"page",
"["... | // Current returns the current Product, and an optional error. Once an error has been returned,
// the ProductIter is closed, or the end of iteration is reached, subsequent calls to Current
// will return an error. | [
"Current",
"returns",
"the",
"current",
"Product",
"and",
"an",
"optional",
"error",
".",
"Once",
"an",
"error",
"has",
"been",
"returned",
"the",
"ProductIter",
"is",
"closed",
"or",
"the",
"end",
"of",
"iteration",
"is",
"reached",
"subsequent",
"calls",
"... | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/zz_oag_generated_catalog.go#L265-L270 |
145,383 | manifoldco/go-manifold | zz_oag_generated_catalog.go | Current | func (i *ProviderIter) Current() (*Provider, error) {
if i.err != nil {
return nil, i.err
}
return &i.page[i.i], nil
} | go | func (i *ProviderIter) Current() (*Provider, error) {
if i.err != nil {
return nil, i.err
}
return &i.page[i.i], nil
} | [
"func",
"(",
"i",
"*",
"ProviderIter",
")",
"Current",
"(",
")",
"(",
"*",
"Provider",
",",
"error",
")",
"{",
"if",
"i",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"i",
".",
"err",
"\n",
"}",
"\n",
"return",
"&",
"i",
".",
"page",
"... | // Current returns the current Provider, and an optional error. Once an error has been returned,
// the ProviderIter is closed, or the end of iteration is reached, subsequent calls to Current
// will return an error. | [
"Current",
"returns",
"the",
"current",
"Provider",
"and",
"an",
"optional",
"error",
".",
"Once",
"an",
"error",
"has",
"been",
"returned",
"the",
"ProviderIter",
"is",
"closed",
"or",
"the",
"end",
"of",
"iteration",
"is",
"reached",
"subsequent",
"calls",
... | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/zz_oag_generated_catalog.go#L301-L306 |
145,384 | manifoldco/go-manifold | zz_oag_generated_catalog.go | Current | func (i *RegionIter) Current() (*Region, error) {
if i.err != nil {
return nil, i.err
}
return &i.page[i.i], nil
} | go | func (i *RegionIter) Current() (*Region, error) {
if i.err != nil {
return nil, i.err
}
return &i.page[i.i], nil
} | [
"func",
"(",
"i",
"*",
"RegionIter",
")",
"Current",
"(",
")",
"(",
"*",
"Region",
",",
"error",
")",
"{",
"if",
"i",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"i",
".",
"err",
"\n",
"}",
"\n",
"return",
"&",
"i",
".",
"page",
"[",
... | // Current returns the current Region, and an optional error. Once an error has been returned,
// the RegionIter is closed, or the end of iteration is reached, subsequent calls to Current
// will return an error. | [
"Current",
"returns",
"the",
"current",
"Region",
"and",
"an",
"optional",
"error",
".",
"Once",
"an",
"error",
"has",
"been",
"returned",
"the",
"RegionIter",
"is",
"closed",
"or",
"the",
"end",
"of",
"iteration",
"is",
"reached",
"subsequent",
"calls",
"to... | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/zz_oag_generated_catalog.go#L337-L342 |
145,385 | manifoldco/go-manifold | zz_oag_generated_catalog.go | NewCatalog | func NewCatalog() *CatalogClient {
c := &CatalogClient{}
c.common.backend = DefaultBackend()
c.Plans = (*PlansClient)(&c.common)
c.Products = (*ProductsClient)(&c.common)
c.Providers = (*ProvidersClient)(&c.common)
c.Regions = (*RegionsClient)(&c.common)
return c
} | go | func NewCatalog() *CatalogClient {
c := &CatalogClient{}
c.common.backend = DefaultBackend()
c.Plans = (*PlansClient)(&c.common)
c.Products = (*ProductsClient)(&c.common)
c.Providers = (*ProvidersClient)(&c.common)
c.Regions = (*RegionsClient)(&c.common)
return c
} | [
"func",
"NewCatalog",
"(",
")",
"*",
"CatalogClient",
"{",
"c",
":=",
"&",
"CatalogClient",
"{",
"}",
"\n",
"c",
".",
"common",
".",
"backend",
"=",
"DefaultBackend",
"(",
")",
"\n\n",
"c",
".",
"Plans",
"=",
"(",
"*",
"PlansClient",
")",
"(",
"&",
... | // NewCatalog returns a new CatalogClient with the default configuration. | [
"NewCatalog",
"returns",
"a",
"new",
"CatalogClient",
"with",
"the",
"default",
"configuration",
"."
] | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/zz_oag_generated_catalog.go#L758-L768 |
145,386 | cybozu-go/netutil | v4util.go | IP4ToInt | func IP4ToInt(ip net.IP) uint32 {
ip = ip.To4()
if ip == nil {
return 0
}
return binary.BigEndian.Uint32(ip)
} | go | func IP4ToInt(ip net.IP) uint32 {
ip = ip.To4()
if ip == nil {
return 0
}
return binary.BigEndian.Uint32(ip)
} | [
"func",
"IP4ToInt",
"(",
"ip",
"net",
".",
"IP",
")",
"uint32",
"{",
"ip",
"=",
"ip",
".",
"To4",
"(",
")",
"\n",
"if",
"ip",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"ip",
")",... | // IP4ToInt returns uint32 value for an IPv4 address.
// If ip is not an IPv4 address, this returns 0. | [
"IP4ToInt",
"returns",
"uint32",
"value",
"for",
"an",
"IPv4",
"address",
".",
"If",
"ip",
"is",
"not",
"an",
"IPv4",
"address",
"this",
"returns",
"0",
"."
] | 635e66124747b7034c7f21e7c7031cfa1b4039e1 | https://github.com/cybozu-go/netutil/blob/635e66124747b7034c7f21e7c7031cfa1b4039e1/v4util.go#L16-L22 |
145,387 | cybozu-go/netutil | v4util.go | IntToIP4 | func IntToIP4(n uint32) net.IP {
ip := make([]byte, 4)
binary.BigEndian.PutUint32(ip, n)
return ip
} | go | func IntToIP4(n uint32) net.IP {
ip := make([]byte, 4)
binary.BigEndian.PutUint32(ip, n)
return ip
} | [
"func",
"IntToIP4",
"(",
"n",
"uint32",
")",
"net",
".",
"IP",
"{",
"ip",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"ip",
",",
"n",
")",
"\n",
"return",
"ip",
"\n",
"}"
] | // IntToIP4 does the reverse of IP4ToInt. | [
"IntToIP4",
"does",
"the",
"reverse",
"of",
"IP4ToInt",
"."
] | 635e66124747b7034c7f21e7c7031cfa1b4039e1 | https://github.com/cybozu-go/netutil/blob/635e66124747b7034c7f21e7c7031cfa1b4039e1/v4util.go#L25-L29 |
145,388 | cybozu-go/netutil | v4util.go | HostsFunc | func HostsFunc(n *net.IPNet) (func() net.IP, error) {
if n.IP.To4() == nil {
return nil, ErrIPv6
}
ones, bits := n.Mask.Size()
count := (1 << uint(bits-ones)) - 2
current := IP4ToInt(n.IP) + 1
return func() net.IP {
if count <= 0 {
return nil
}
ip := IntToIP4(current)
current++
count--
return ip... | go | func HostsFunc(n *net.IPNet) (func() net.IP, error) {
if n.IP.To4() == nil {
return nil, ErrIPv6
}
ones, bits := n.Mask.Size()
count := (1 << uint(bits-ones)) - 2
current := IP4ToInt(n.IP) + 1
return func() net.IP {
if count <= 0 {
return nil
}
ip := IntToIP4(current)
current++
count--
return ip... | [
"func",
"HostsFunc",
"(",
"n",
"*",
"net",
".",
"IPNet",
")",
"(",
"func",
"(",
")",
"net",
".",
"IP",
",",
"error",
")",
"{",
"if",
"n",
".",
"IP",
".",
"To4",
"(",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrIPv6",
"\n",
"}",
"\n\n",
... | // HostsFunc returns a function to generate all IP addresses in a
// network. The network address and the broadcast address of the network
// will be excluded.
//
// The returned function will finally generate nil to tell the end.
//
// The network must be an IPv4 network. | [
"HostsFunc",
"returns",
"a",
"function",
"to",
"generate",
"all",
"IP",
"addresses",
"in",
"a",
"network",
".",
"The",
"network",
"address",
"and",
"the",
"broadcast",
"address",
"of",
"the",
"network",
"will",
"be",
"excluded",
".",
"The",
"returned",
"func... | 635e66124747b7034c7f21e7c7031cfa1b4039e1 | https://github.com/cybozu-go/netutil/blob/635e66124747b7034c7f21e7c7031cfa1b4039e1/v4util.go#L38-L55 |
145,389 | manifoldco/go-manifold | id.go | NewMutableID | func NewMutableID(body Mutable) (ID, error) {
t := body.Type()
return NewID(t)
} | go | func NewMutableID(body Mutable) (ID, error) {
t := body.Type()
return NewID(t)
} | [
"func",
"NewMutableID",
"(",
"body",
"Mutable",
")",
"(",
"ID",
",",
"error",
")",
"{",
"t",
":=",
"body",
".",
"Type",
"(",
")",
"\n",
"return",
"NewID",
"(",
"t",
")",
"\n",
"}"
] | // NewMutableID returns a new ID for a mutable object. | [
"NewMutableID",
"returns",
"a",
"new",
"ID",
"for",
"a",
"mutable",
"object",
"."
] | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/id.go#L56-L59 |
145,390 | manifoldco/go-manifold | id.go | NewFakeMutableID | func NewFakeMutableID(body Mutable, source string) (ID, error) {
h, err := blake2b.New(&blake2b.Config{Size: 16})
if err != nil {
return ID{}, err
}
h.Write([]byte(source))
preamble := body.Type()
id := ID{idVersion<<4 | preamble.Upper(), preamble.Lower()}
copy(id[2:], h.Sum(nil))
return id, nil
} | go | func NewFakeMutableID(body Mutable, source string) (ID, error) {
h, err := blake2b.New(&blake2b.Config{Size: 16})
if err != nil {
return ID{}, err
}
h.Write([]byte(source))
preamble := body.Type()
id := ID{idVersion<<4 | preamble.Upper(), preamble.Lower()}
copy(id[2:], h.Sum(nil))
return id, nil
} | [
"func",
"NewFakeMutableID",
"(",
"body",
"Mutable",
",",
"source",
"string",
")",
"(",
"ID",
",",
"error",
")",
"{",
"h",
",",
"err",
":=",
"blake2b",
".",
"New",
"(",
"&",
"blake2b",
".",
"Config",
"{",
"Size",
":",
"16",
"}",
")",
"\n",
"if",
"... | // NewFakeMutableID returns an ID for a fake mutable object, not relying on
// the Body contents of the supplied mutable to generate the ID | [
"NewFakeMutableID",
"returns",
"an",
"ID",
"for",
"a",
"fake",
"mutable",
"object",
"not",
"relying",
"on",
"the",
"Body",
"contents",
"of",
"the",
"supplied",
"mutable",
"to",
"generate",
"the",
"ID"
] | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/id.go#L63-L75 |
145,391 | manifoldco/go-manifold | id.go | DeriveMutableID | func DeriveMutableID(body Mutable, base ID, derivableType idtype.Type) ID {
preamble := body.Type()
id := ID{idVersion<<4 | preamble.Upper(), preamble.Lower(), derivableType.Upper(), derivableType.Lower()}
copy(id[3:], base[3:17])
return id
} | go | func DeriveMutableID(body Mutable, base ID, derivableType idtype.Type) ID {
preamble := body.Type()
id := ID{idVersion<<4 | preamble.Upper(), preamble.Lower(), derivableType.Upper(), derivableType.Lower()}
copy(id[3:], base[3:17])
return id
} | [
"func",
"DeriveMutableID",
"(",
"body",
"Mutable",
",",
"base",
"ID",
",",
"derivableType",
"idtype",
".",
"Type",
")",
"ID",
"{",
"preamble",
":=",
"body",
".",
"Type",
"(",
")",
"\n",
"id",
":=",
"ID",
"{",
"idVersion",
"<<",
"4",
"|",
"preamble",
... | // DeriveMutableID returns a ID for a mutable object based on another ID. | [
"DeriveMutableID",
"returns",
"a",
"ID",
"for",
"a",
"mutable",
"object",
"based",
"on",
"another",
"ID",
"."
] | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/id.go#L78-L84 |
145,392 | manifoldco/go-manifold | id.go | NewID | func NewID(t idtype.Type) (ID, error) {
if !t.Mutable() {
return ID{}, errors.New("Cannot generate ID for non-mutable type")
}
id := ID{idVersion<<4 | t.Upper(), t.Lower()}
_, err := rand.Read(id[2:])
if err != nil {
return ID{}, err
}
return id, nil
} | go | func NewID(t idtype.Type) (ID, error) {
if !t.Mutable() {
return ID{}, errors.New("Cannot generate ID for non-mutable type")
}
id := ID{idVersion<<4 | t.Upper(), t.Lower()}
_, err := rand.Read(id[2:])
if err != nil {
return ID{}, err
}
return id, nil
} | [
"func",
"NewID",
"(",
"t",
"idtype",
".",
"Type",
")",
"(",
"ID",
",",
"error",
")",
"{",
"if",
"!",
"t",
".",
"Mutable",
"(",
")",
"{",
"return",
"ID",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"id",
":=... | // NewID returns a new ID for a Mutable idtype using only the Type | [
"NewID",
"returns",
"a",
"new",
"ID",
"for",
"a",
"Mutable",
"idtype",
"using",
"only",
"the",
"Type"
] | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/id.go#L87-L99 |
145,393 | manifoldco/go-manifold | id.go | NewImmutableID | func NewImmutableID(obj Immutable, sig interface{}) (ID, error) {
h, err := blake2b.New(&blake2b.Config{Size: 16})
if err != nil {
return ID{}, err
}
h.Write([]byte(strconv.Itoa(obj.Version())))
b, err := json.Marshal(obj.GetBody())
if err != nil {
return ID{}, err
}
h.Write(b)
b, err = json.Marshal(sig... | go | func NewImmutableID(obj Immutable, sig interface{}) (ID, error) {
h, err := blake2b.New(&blake2b.Config{Size: 16})
if err != nil {
return ID{}, err
}
h.Write([]byte(strconv.Itoa(obj.Version())))
b, err := json.Marshal(obj.GetBody())
if err != nil {
return ID{}, err
}
h.Write(b)
b, err = json.Marshal(sig... | [
"func",
"NewImmutableID",
"(",
"obj",
"Immutable",
",",
"sig",
"interface",
"{",
"}",
")",
"(",
"ID",
",",
"error",
")",
"{",
"h",
",",
"err",
":=",
"blake2b",
".",
"New",
"(",
"&",
"blake2b",
".",
"Config",
"{",
"Size",
":",
"16",
"}",
")",
"\n"... | // NewImmutableID returns a new signed ID for an immutable object.
//
// sig should be a registry.Signature type | [
"NewImmutableID",
"returns",
"a",
"new",
"signed",
"ID",
"for",
"an",
"immutable",
"object",
".",
"sig",
"should",
"be",
"a",
"registry",
".",
"Signature",
"type"
] | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/id.go#L104-L130 |
145,394 | manifoldco/go-manifold | id.go | DecodeIDFromString | func DecodeIDFromString(value string) (ID, error) {
buf, err := decodeFromByte([]byte(value))
if err != nil {
return ID{}, err
}
id := ID{}
copy(id[:], buf)
return id, nil
} | go | func DecodeIDFromString(value string) (ID, error) {
buf, err := decodeFromByte([]byte(value))
if err != nil {
return ID{}, err
}
id := ID{}
copy(id[:], buf)
return id, nil
} | [
"func",
"DecodeIDFromString",
"(",
"value",
"string",
")",
"(",
"ID",
",",
"error",
")",
"{",
"buf",
",",
"err",
":=",
"decodeFromByte",
"(",
"[",
"]",
"byte",
"(",
"value",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ID",
"{",
"}",
... | // DecodeIDFromString returns an ID that is stored in the given string. | [
"DecodeIDFromString",
"returns",
"an",
"ID",
"that",
"is",
"stored",
"in",
"the",
"given",
"string",
"."
] | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/id.go#L133-L142 |
145,395 | manifoldco/go-manifold | idtype/idtype.go | Upper | func (t Type) Upper() byte {
o := make([]byte, 2)
binary.BigEndian.PutUint16(o, uint16(t))
return o[0]
} | go | func (t Type) Upper() byte {
o := make([]byte, 2)
binary.BigEndian.PutUint16(o, uint16(t))
return o[0]
} | [
"func",
"(",
"t",
"Type",
")",
"Upper",
"(",
")",
"byte",
"{",
"o",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"2",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"o",
",",
"uint16",
"(",
"t",
")",
")",
"\n\n",
"return",
"o",
"[... | // Upper returns the upper byte of the type | [
"Upper",
"returns",
"the",
"upper",
"byte",
"of",
"the",
"type"
] | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/idtype/idtype.go#L96-L101 |
145,396 | manifoldco/go-manifold | idtype/idtype.go | Collection | func (t Type) Collection() string {
defn := getDefn(t)
switch {
case strings.HasSuffix(defn.name, "access"):
return defn.name
default:
return fmt.Sprintf("%ss", defn.name)
}
} | go | func (t Type) Collection() string {
defn := getDefn(t)
switch {
case strings.HasSuffix(defn.name, "access"):
return defn.name
default:
return fmt.Sprintf("%ss", defn.name)
}
} | [
"func",
"(",
"t",
"Type",
")",
"Collection",
"(",
")",
"string",
"{",
"defn",
":=",
"getDefn",
"(",
"t",
")",
"\n",
"switch",
"{",
"case",
"strings",
".",
"HasSuffix",
"(",
"defn",
".",
"name",
",",
"\"",
"\"",
")",
":",
"return",
"defn",
".",
"n... | // Collection returns the name for a collection of these types | [
"Collection",
"returns",
"the",
"name",
"for",
"a",
"collection",
"of",
"these",
"types"
] | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/idtype/idtype.go#L118-L126 |
145,397 | manifoldco/go-manifold | idtype/idtype.go | Decode | func Decode(upper, lower byte) Type {
return Type(binary.BigEndian.Uint16([]byte{upper, lower}))
} | go | func Decode(upper, lower byte) Type {
return Type(binary.BigEndian.Uint16([]byte{upper, lower}))
} | [
"func",
"Decode",
"(",
"upper",
",",
"lower",
"byte",
")",
"Type",
"{",
"return",
"Type",
"(",
"binary",
".",
"BigEndian",
".",
"Uint16",
"(",
"[",
"]",
"byte",
"{",
"upper",
",",
"lower",
"}",
")",
")",
"\n",
"}"
] | // Decode decodes a Type from a byte pair | [
"Decode",
"decodes",
"a",
"Type",
"from",
"a",
"byte",
"pair"
] | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/idtype/idtype.go#L140-L142 |
145,398 | manifoldco/go-manifold | idtype/idtype.go | TypeFromString | func TypeFromString(str string) Type {
for t, d := range definitions {
if d.name == str {
return t
}
}
panic("Type not registered")
} | go | func TypeFromString(str string) Type {
for t, d := range definitions {
if d.name == str {
return t
}
}
panic("Type not registered")
} | [
"func",
"TypeFromString",
"(",
"str",
"string",
")",
"Type",
"{",
"for",
"t",
",",
"d",
":=",
"range",
"definitions",
"{",
"if",
"d",
".",
"name",
"==",
"str",
"{",
"return",
"t",
"\n",
"}",
"\n",
"}",
"\n\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",... | // TypeFromString will return the type from a string interpretation of the type.
// If the type is not found, this will panic. | [
"TypeFromString",
"will",
"return",
"the",
"type",
"from",
"a",
"string",
"interpretation",
"of",
"the",
"type",
".",
"If",
"the",
"type",
"is",
"not",
"found",
"this",
"will",
"panic",
"."
] | 8458bf091a9e8b6242d12d26f08571ca3acc483d | https://github.com/manifoldco/go-manifold/blob/8458bf091a9e8b6242d12d26f08571ca3acc483d/idtype/idtype.go#L170-L178 |
145,399 | st3v/translator | google/api.go | NewTranslator | func NewTranslator(apiKey string) translator.Translator {
authenticator := newAuthenticator(apiKey)
router := newRouter()
return &api{
lp: newLanguageProvider(authenticator, router),
tp: newTranslationProvider(authenticator, router),
}
} | go | func NewTranslator(apiKey string) translator.Translator {
authenticator := newAuthenticator(apiKey)
router := newRouter()
return &api{
lp: newLanguageProvider(authenticator, router),
tp: newTranslationProvider(authenticator, router),
}
} | [
"func",
"NewTranslator",
"(",
"apiKey",
"string",
")",
"translator",
".",
"Translator",
"{",
"authenticator",
":=",
"newAuthenticator",
"(",
"apiKey",
")",
"\n",
"router",
":=",
"newRouter",
"(",
")",
"\n\n",
"return",
"&",
"api",
"{",
"lp",
":",
"newLanguag... | // NewTranslator instantiates a new Translator for Google's Translate API. | [
"NewTranslator",
"instantiates",
"a",
"new",
"Translator",
"for",
"Google",
"s",
"Translate",
"API",
"."
] | d13056a5929704f264d21b102987311c0f379fc3 | https://github.com/st3v/translator/blob/d13056a5929704f264d21b102987311c0f379fc3/google/api.go#L11-L19 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.