id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
144,000 | domainr/dnsr | rr.go | convertRR | func convertRR(drr dns.RR) (RR, bool) {
switch t := drr.(type) {
case *dns.SOA:
return RR{toLowerFQDN(t.Hdr.Name), "SOA", toLowerFQDN(t.Ns)}, true
case *dns.NS:
return RR{toLowerFQDN(t.Hdr.Name), "NS", toLowerFQDN(t.Ns)}, true
case *dns.CNAME:
return RR{toLowerFQDN(t.Hdr.Name), "CNAME", toLowerFQDN(t.Target)}... | go | func convertRR(drr dns.RR) (RR, bool) {
switch t := drr.(type) {
case *dns.SOA:
return RR{toLowerFQDN(t.Hdr.Name), "SOA", toLowerFQDN(t.Ns)}, true
case *dns.NS:
return RR{toLowerFQDN(t.Hdr.Name), "NS", toLowerFQDN(t.Ns)}, true
case *dns.CNAME:
return RR{toLowerFQDN(t.Hdr.Name), "CNAME", toLowerFQDN(t.Target)}... | [
"func",
"convertRR",
"(",
"drr",
"dns",
".",
"RR",
")",
"(",
"RR",
",",
"bool",
")",
"{",
"switch",
"t",
":=",
"drr",
".",
"(",
"type",
")",
"{",
"case",
"*",
"dns",
".",
"SOA",
":",
"return",
"RR",
"{",
"toLowerFQDN",
"(",
"t",
".",
"Hdr",
"... | // convertRR converts a dns.RR to an RR.
// If the RR is not a type that this package uses,
// It will attempt to translate this if there are enough parameters
// Should all translation fail, it returns an undefined RR and false. | [
"convertRR",
"converts",
"a",
"dns",
".",
"RR",
"to",
"an",
"RR",
".",
"If",
"the",
"RR",
"is",
"not",
"a",
"type",
"that",
"this",
"package",
"uses",
"It",
"will",
"attempt",
"to",
"translate",
"this",
"if",
"there",
"are",
"enough",
"parameters",
"Sh... | 74d2205fe905616d3201a0329e65eefe9ecff03a | https://github.com/domainr/dnsr/blob/74d2205fe905616d3201a0329e65eefe9ecff03a/rr.go#L40-L61 |
144,001 | domainr/dnsr | resolver.go | NewWithTimeout | func NewWithTimeout(capacity int, timeout time.Duration) *Resolver {
r := &Resolver{
cache: newCache(capacity),
timeout: timeout,
}
return r
} | go | func NewWithTimeout(capacity int, timeout time.Duration) *Resolver {
r := &Resolver{
cache: newCache(capacity),
timeout: timeout,
}
return r
} | [
"func",
"NewWithTimeout",
"(",
"capacity",
"int",
",",
"timeout",
"time",
".",
"Duration",
")",
"*",
"Resolver",
"{",
"r",
":=",
"&",
"Resolver",
"{",
"cache",
":",
"newCache",
"(",
"capacity",
")",
",",
"timeout",
":",
"timeout",
",",
"}",
"\n",
"retu... | // NewWithTimeout initializes a Resolver with the specified cache size and resolution timeout. | [
"NewWithTimeout",
"initializes",
"a",
"Resolver",
"with",
"the",
"specified",
"cache",
"size",
"and",
"resolution",
"timeout",
"."
] | 74d2205fe905616d3201a0329e65eefe9ecff03a | https://github.com/domainr/dnsr/blob/74d2205fe905616d3201a0329e65eefe9ecff03a/resolver.go#L44-L50 |
144,002 | domainr/dnsr | resolver.go | saveDNSRR | func (r *Resolver) saveDNSRR(host, qname string, drrs []dns.RR) RRs {
var rrs RRs
cl := dns.CountLabel(qname)
for _, drr := range drrs {
rr, ok := convertRR(drr)
if !ok {
continue
}
if dns.CountLabel(rr.Name) < cl && dns.CompareDomainName(qname, rr.Name) < 2 {
// fmt.Fprintf(os.Stderr, "Warning: potent... | go | func (r *Resolver) saveDNSRR(host, qname string, drrs []dns.RR) RRs {
var rrs RRs
cl := dns.CountLabel(qname)
for _, drr := range drrs {
rr, ok := convertRR(drr)
if !ok {
continue
}
if dns.CountLabel(rr.Name) < cl && dns.CompareDomainName(qname, rr.Name) < 2 {
// fmt.Fprintf(os.Stderr, "Warning: potent... | [
"func",
"(",
"r",
"*",
"Resolver",
")",
"saveDNSRR",
"(",
"host",
",",
"qname",
"string",
",",
"drrs",
"[",
"]",
"dns",
".",
"RR",
")",
"RRs",
"{",
"var",
"rrs",
"RRs",
"\n",
"cl",
":=",
"dns",
".",
"CountLabel",
"(",
"qname",
")",
"\n",
"for",
... | // saveDNSRR saves 1 or more DNS records to the resolver cache. | [
"saveDNSRR",
"saves",
"1",
"or",
"more",
"DNS",
"records",
"to",
"the",
"resolver",
"cache",
"."
] | 74d2205fe905616d3201a0329e65eefe9ecff03a | https://github.com/domainr/dnsr/blob/74d2205fe905616d3201a0329e65eefe9ecff03a/resolver.go#L292-L311 |
144,003 | domainr/dnsr | resolver.go | cacheGet | func (r *Resolver) cacheGet(ctx context.Context, qname, qtype string) (RRs, error) {
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}
any := r.cache.get(qname)
if any == nil {
any = rootCache.get(qname)
}
if any == nil {
return nil, nil
}
if len(any) == 0 {
return nil, NXDOMAIN
}
rrs := ... | go | func (r *Resolver) cacheGet(ctx context.Context, qname, qtype string) (RRs, error) {
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}
any := r.cache.get(qname)
if any == nil {
any = rootCache.get(qname)
}
if any == nil {
return nil, nil
}
if len(any) == 0 {
return nil, NXDOMAIN
}
rrs := ... | [
"func",
"(",
"r",
"*",
"Resolver",
")",
"cacheGet",
"(",
"ctx",
"context",
".",
"Context",
",",
"qname",
",",
"qtype",
"string",
")",
"(",
"RRs",
",",
"error",
")",
"{",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"n... | // cacheGet returns a randomly ordered slice of DNS records. | [
"cacheGet",
"returns",
"a",
"randomly",
"ordered",
"slice",
"of",
"DNS",
"records",
"."
] | 74d2205fe905616d3201a0329e65eefe9ecff03a | https://github.com/domainr/dnsr/blob/74d2205fe905616d3201a0329e65eefe9ecff03a/resolver.go#L314-L340 |
144,004 | tsuru/gandalf | bin/gandalf.go | requestedRepository | func requestedRepository() (repository.Repository, error) {
_, repoName, err := parseGitCommand()
if err != nil {
return repository.Repository{}, err
}
var repo repository.Repository
conn, err := db.Conn()
if err != nil {
return repository.Repository{}, err
}
defer conn.Close()
if err := conn.Repository().... | go | func requestedRepository() (repository.Repository, error) {
_, repoName, err := parseGitCommand()
if err != nil {
return repository.Repository{}, err
}
var repo repository.Repository
conn, err := db.Conn()
if err != nil {
return repository.Repository{}, err
}
defer conn.Close()
if err := conn.Repository().... | [
"func",
"requestedRepository",
"(",
")",
"(",
"repository",
".",
"Repository",
",",
"error",
")",
"{",
"_",
",",
"repoName",
",",
"err",
":=",
"parseGitCommand",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"repository",
".",
"Repository",
"{... | // Get the repository name requested in SSH_ORIGINAL_COMMAND and retrieves
// the related document on the database and returns it.
// This function does two distinct things, parses the SSH_ORIGINAL_COMMAND and
// returns a "validation" error if it doesn't matches the expected format
// and gets the repository from the ... | [
"Get",
"the",
"repository",
"name",
"requested",
"in",
"SSH_ORIGINAL_COMMAND",
"and",
"retrieves",
"the",
"related",
"document",
"on",
"the",
"database",
"and",
"returns",
"it",
".",
"This",
"function",
"does",
"two",
"distinct",
"things",
"parses",
"the",
"SSH_... | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/bin/gandalf.go#L71-L86 |
144,005 | tsuru/gandalf | bin/gandalf.go | executeAction | func executeAction(f func(*user.User, *repository.Repository) bool, errMsg string, stdout io.Writer) {
var u user.User
conn, err := db.Conn()
if err != nil {
return
}
defer conn.Close()
if err = conn.User().Find(bson.M{"_id": os.Args[1]}).One(&u); err != nil {
log.Err("Error obtaining user. Gandalf database i... | go | func executeAction(f func(*user.User, *repository.Repository) bool, errMsg string, stdout io.Writer) {
var u user.User
conn, err := db.Conn()
if err != nil {
return
}
defer conn.Close()
if err = conn.User().Find(bson.M{"_id": os.Args[1]}).One(&u); err != nil {
log.Err("Error obtaining user. Gandalf database i... | [
"func",
"executeAction",
"(",
"f",
"func",
"(",
"*",
"user",
".",
"User",
",",
"*",
"repository",
".",
"Repository",
")",
"bool",
",",
"errMsg",
"string",
",",
"stdout",
"io",
".",
"Writer",
")",
"{",
"var",
"u",
"user",
".",
"User",
"\n",
"conn",
... | // Executes the SSH_ORIGINAL_COMMAND based on the condition
// defined by the `f` parameter.
// Also receives a custom error message to print to the end user and a
// stdout object, where the SSH_ORIGINAL_COMMAND output is going to be written | [
"Executes",
"the",
"SSH_ORIGINAL_COMMAND",
"based",
"on",
"the",
"condition",
"defined",
"by",
"the",
"f",
"parameter",
".",
"Also",
"receives",
"a",
"custom",
"error",
"message",
"to",
"print",
"to",
"the",
"end",
"user",
"and",
"a",
"stdout",
"object",
"wh... | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/bin/gandalf.go#L115-L162 |
144,006 | tsuru/gandalf | db/conn.go | conn | func conn() (*storage.Storage, error) {
url, dbname := DbConfig()
return storage.Open(url, dbname)
} | go | func conn() (*storage.Storage, error) {
url, dbname := DbConfig()
return storage.Open(url, dbname)
} | [
"func",
"conn",
"(",
")",
"(",
"*",
"storage",
".",
"Storage",
",",
"error",
")",
"{",
"url",
",",
"dbname",
":=",
"DbConfig",
"(",
")",
"\n",
"return",
"storage",
".",
"Open",
"(",
"url",
",",
"dbname",
")",
"\n",
"}"
] | // conn reads the gandalf config and calls storage.Open to get a database connection.
//
// Most gandalf packages should probably use this function. storage.Open is intended for
// use when supporting more than one database. | [
"conn",
"reads",
"the",
"gandalf",
"config",
"and",
"calls",
"storage",
".",
"Open",
"to",
"get",
"a",
"database",
"connection",
".",
"Most",
"gandalf",
"packages",
"should",
"probably",
"use",
"this",
"function",
".",
"storage",
".",
"Open",
"is",
"intended... | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/db/conn.go#L27-L30 |
144,007 | tsuru/gandalf | hook/hook.go | Add | func Add(name string, repos []string, content []byte) error {
configParam := "git:bare:template"
if len(repos) > 0 {
configParam = "git:bare:location"
}
path, err := config.GetString(configParam)
if err != nil {
return err
}
if len(repos) > 0 {
for _, repo := range repos {
repo += ".git"
s := []strin... | go | func Add(name string, repos []string, content []byte) error {
configParam := "git:bare:template"
if len(repos) > 0 {
configParam = "git:bare:location"
}
path, err := config.GetString(configParam)
if err != nil {
return err
}
if len(repos) > 0 {
for _, repo := range repos {
repo += ".git"
s := []strin... | [
"func",
"Add",
"(",
"name",
"string",
",",
"repos",
"[",
"]",
"string",
",",
"content",
"[",
"]",
"byte",
")",
"error",
"{",
"configParam",
":=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"repos",
")",
">",
"0",
"{",
"configParam",
"=",
"\"",
"\"",
"\n... | // Adds a hook script. | [
"Adds",
"a",
"hook",
"script",
"."
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/hook/hook.go#L29-L60 |
144,008 | tsuru/gandalf | user/user.go | AddKey | func AddKey(username string, k map[string]string) error {
var u User
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
if err := conn.User().FindId(username).One(&u); err != nil {
return ErrUserNotFound
}
return addKeys(k, u.Name)
} | go | func AddKey(username string, k map[string]string) error {
var u User
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
if err := conn.User().FindId(username).One(&u); err != nil {
return ErrUserNotFound
}
return addKeys(k, u.Name)
} | [
"func",
"AddKey",
"(",
"username",
"string",
",",
"k",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"var",
"u",
"User",
"\n",
"conn",
",",
"err",
":=",
"db",
".",
"Conn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
... | // AddKey adds new SSH keys to the list of user keys for the provided username.
//
// Returns an error in case the user does not exist. | [
"AddKey",
"adds",
"new",
"SSH",
"keys",
"to",
"the",
"list",
"of",
"user",
"keys",
"for",
"the",
"provided",
"username",
".",
"Returns",
"an",
"error",
"in",
"case",
"the",
"user",
"does",
"not",
"exist",
"."
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/user/user.go#L124-L135 |
144,009 | tsuru/gandalf | user/user.go | UpdateKey | func UpdateKey(username string, k Key) error {
var u User
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
if err := conn.User().FindId(username).One(&u); err != nil {
return ErrUserNotFound
}
return updateKey(k.Name, k.Body, u.Name)
} | go | func UpdateKey(username string, k Key) error {
var u User
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
if err := conn.User().FindId(username).One(&u); err != nil {
return ErrUserNotFound
}
return updateKey(k.Name, k.Body, u.Name)
} | [
"func",
"UpdateKey",
"(",
"username",
"string",
",",
"k",
"Key",
")",
"error",
"{",
"var",
"u",
"User",
"\n",
"conn",
",",
"err",
":=",
"db",
".",
"Conn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
... | // UpdateKey updates the content of the given key. | [
"UpdateKey",
"updates",
"the",
"content",
"of",
"the",
"given",
"key",
"."
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/user/user.go#L138-L149 |
144,010 | tsuru/gandalf | user/user.go | RemoveKey | func RemoveKey(username, keyname string) error {
var u User
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
if err := conn.User().FindId(username).One(&u); err != nil {
return ErrUserNotFound
}
return removeKey(keyname, username)
} | go | func RemoveKey(username, keyname string) error {
var u User
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
if err := conn.User().FindId(username).One(&u); err != nil {
return ErrUserNotFound
}
return removeKey(keyname, username)
} | [
"func",
"RemoveKey",
"(",
"username",
",",
"keyname",
"string",
")",
"error",
"{",
"var",
"u",
"User",
"\n",
"conn",
",",
"err",
":=",
"db",
".",
"Conn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"c... | // RemoveKey removes the key from the database and from authorized_keys file.
//
// If the user or the key is not found, returns an error. | [
"RemoveKey",
"removes",
"the",
"key",
"from",
"the",
"database",
"and",
"from",
"authorized_keys",
"file",
".",
"If",
"the",
"user",
"or",
"the",
"key",
"is",
"not",
"found",
"returns",
"an",
"error",
"."
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/user/user.go#L154-L165 |
144,011 | tsuru/gandalf | repository/repository.go | MarshalJSON | func (r *Repository) MarshalJSON() ([]byte, error) {
data := map[string]interface{}{
"name": r.Name,
"public": r.IsPublic,
"ssh_url": r.ReadWriteURL(),
"git_url": r.ReadOnlyURL(),
}
return json.Marshal(&data)
} | go | func (r *Repository) MarshalJSON() ([]byte, error) {
data := map[string]interface{}{
"name": r.Name,
"public": r.IsPublic,
"ssh_url": r.ReadWriteURL(),
"git_url": r.ReadOnlyURL(),
}
return json.Marshal(&data)
} | [
"func",
"(",
"r",
"*",
"Repository",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"data",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"r",
".",
"Name",
",",
"\"",
"\"",
":",
"r... | // MarshalJSON marshals the Repository in json format. | [
"MarshalJSON",
"marshals",
"the",
"Repository",
"in",
"json",
"format",
"."
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/repository/repository.go#L111-L119 |
144,012 | tsuru/gandalf | repository/repository.go | New | func New(name string, users, readOnlyUsers []string, isPublic bool) (*Repository, error) {
log.Debugf("Creating repository %q", name)
r := &Repository{Name: name, Users: users, ReadOnlyUsers: readOnlyUsers, IsPublic: isPublic}
if v, err := r.isValid(); !v {
log.Errorf("repository.New: Invalid repository %q: %s", n... | go | func New(name string, users, readOnlyUsers []string, isPublic bool) (*Repository, error) {
log.Debugf("Creating repository %q", name)
r := &Repository{Name: name, Users: users, ReadOnlyUsers: readOnlyUsers, IsPublic: isPublic}
if v, err := r.isValid(); !v {
log.Errorf("repository.New: Invalid repository %q: %s", n... | [
"func",
"New",
"(",
"name",
"string",
",",
"users",
",",
"readOnlyUsers",
"[",
"]",
"string",
",",
"isPublic",
"bool",
")",
"(",
"*",
"Repository",
",",
"error",
")",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"r",
":=",
... | // New creates a representation of a git repository. It creates a Git
// repository using the "bare-dir" setting and saves repository's meta data in
// the database. | [
"New",
"creates",
"a",
"representation",
"of",
"a",
"git",
"repository",
".",
"It",
"creates",
"a",
"Git",
"repository",
"using",
"the",
"bare",
"-",
"dir",
"setting",
"and",
"saves",
"repository",
"s",
"meta",
"data",
"in",
"the",
"database",
"."
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/repository/repository.go#L124-L155 |
144,013 | tsuru/gandalf | repository/repository.go | Get | func Get(name string) (Repository, error) {
var r Repository
conn, err := db.Conn()
if err != nil {
return r, err
}
defer conn.Close()
err = conn.Repository().FindId(name).One(&r)
if err == mgo.ErrNotFound {
return r, ErrRepositoryNotFound
}
return r, err
} | go | func Get(name string) (Repository, error) {
var r Repository
conn, err := db.Conn()
if err != nil {
return r, err
}
defer conn.Close()
err = conn.Repository().FindId(name).One(&r)
if err == mgo.ErrNotFound {
return r, ErrRepositoryNotFound
}
return r, err
} | [
"func",
"Get",
"(",
"name",
"string",
")",
"(",
"Repository",
",",
"error",
")",
"{",
"var",
"r",
"Repository",
"\n",
"conn",
",",
"err",
":=",
"db",
".",
"Conn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"r",
",",
"err",
"\n",
"... | // Get find a repository by name. | [
"Get",
"find",
"a",
"repository",
"by",
"name",
"."
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/repository/repository.go#L158-L170 |
144,014 | tsuru/gandalf | repository/repository.go | Remove | func Remove(name string) error {
log.Debugf("Removing repository %q", name)
if err := removeBare(name); err != nil {
log.Errorf("repository.Remove: Error removing bare repository %q: %s", name, err)
}
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
if err := conn.Repository().RemoveId... | go | func Remove(name string) error {
log.Debugf("Removing repository %q", name)
if err := removeBare(name); err != nil {
log.Errorf("repository.Remove: Error removing bare repository %q: %s", name, err)
}
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
if err := conn.Repository().RemoveId... | [
"func",
"Remove",
"(",
"name",
"string",
")",
"error",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"if",
"err",
":=",
"removeBare",
"(",
"name",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
"... | // Remove deletes the repository from the database and removes it's bare Git
// repository. | [
"Remove",
"deletes",
"the",
"repository",
"from",
"the",
"database",
"and",
"removes",
"it",
"s",
"bare",
"Git",
"repository",
"."
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/repository/repository.go#L174-L191 |
144,015 | tsuru/gandalf | repository/repository.go | Update | func Update(name string, newData Repository) error {
log.Debugf("Updating repository %q data", name)
repo, err := Get(name)
if err != nil {
log.Errorf("repository.Update(%q): %s", name, err)
return err
}
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
if len(newData.Name) > 0 && ne... | go | func Update(name string, newData Repository) error {
log.Debugf("Updating repository %q data", name)
repo, err := Get(name)
if err != nil {
log.Errorf("repository.Update(%q): %s", name, err)
return err
}
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
if len(newData.Name) > 0 && ne... | [
"func",
"Update",
"(",
"name",
"string",
",",
"newData",
"Repository",
")",
"error",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"repo",
",",
"err",
":=",
"Get",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log"... | // Update update a repository data. | [
"Update",
"update",
"a",
"repository",
"data",
"."
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/repository/repository.go#L194-L232 |
144,016 | tsuru/gandalf | repository/repository.go | ReadWriteURL | func (r *Repository) ReadWriteURL() string {
uid, err := config.GetString("uid")
if err != nil {
panic(err.Error())
}
remote := uid + "@%s:%s.git"
if useSSH, _ := config.GetBool("git:ssh:use"); useSSH {
var port string
port, err = config.GetString("git:ssh:port")
if err == nil {
remote = "ssh://" + uid ... | go | func (r *Repository) ReadWriteURL() string {
uid, err := config.GetString("uid")
if err != nil {
panic(err.Error())
}
remote := uid + "@%s:%s.git"
if useSSH, _ := config.GetBool("git:ssh:use"); useSSH {
var port string
port, err = config.GetString("git:ssh:port")
if err == nil {
remote = "ssh://" + uid ... | [
"func",
"(",
"r",
"*",
"Repository",
")",
"ReadWriteURL",
"(",
")",
"string",
"{",
"uid",
",",
"err",
":=",
"config",
".",
"GetString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
".",
"Error",
"(",
")",
")",
... | // ReadWriteURL formats the git ssh url and return it. If no remote is configured in
// gandalf.conf, this method panics. | [
"ReadWriteURL",
"formats",
"the",
"git",
"ssh",
"url",
"and",
"return",
"it",
".",
"If",
"no",
"remote",
"is",
"configured",
"in",
"gandalf",
".",
"conf",
"this",
"method",
"panics",
"."
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/repository/repository.go#L236-L256 |
144,017 | tsuru/gandalf | repository/repository.go | GetFileContents | func GetFileContents(repo, ref, path string) ([]byte, error) {
return retriever().GetContents(repo, ref, path)
} | go | func GetFileContents(repo, ref, path string) ([]byte, error) {
return retriever().GetContents(repo, ref, path)
} | [
"func",
"GetFileContents",
"(",
"repo",
",",
"ref",
",",
"path",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"retriever",
"(",
")",
".",
"GetContents",
"(",
"repo",
",",
"ref",
",",
"path",
")",
"\n",
"}"
] | // GetFileContents returns the contents for a given file
// in a given ref for the specified repository | [
"GetFileContents",
"returns",
"the",
"contents",
"for",
"a",
"given",
"file",
"in",
"a",
"given",
"ref",
"for",
"the",
"specified",
"repository"
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/repository/repository.go#L846-L848 |
144,018 | tsuru/gandalf | repository/repository.go | GetArchive | func GetArchive(repo, ref string, format ArchiveFormat) ([]byte, error) {
return retriever().GetArchive(repo, ref, format)
} | go | func GetArchive(repo, ref string, format ArchiveFormat) ([]byte, error) {
return retriever().GetArchive(repo, ref, format)
} | [
"func",
"GetArchive",
"(",
"repo",
",",
"ref",
"string",
",",
"format",
"ArchiveFormat",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"retriever",
"(",
")",
".",
"GetArchive",
"(",
"repo",
",",
"ref",
",",
"format",
")",
"\n",
"}"
] | // GetArchive returns the contents for a given file
// in a given ref for the specified repository | [
"GetArchive",
"returns",
"the",
"contents",
"for",
"a",
"given",
"file",
"in",
"a",
"given",
"ref",
"for",
"the",
"specified",
"repository"
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/repository/repository.go#L852-L854 |
144,019 | tsuru/gandalf | user/key.go | copyFile | func copyFile() (tsurufs.File, error) {
path := authKey()
fi, statErr := fs.Filesystem().Stat(path)
if statErr != nil && !os.IsNotExist(statErr) {
return nil, statErr
}
dstPath := path + ".tmp"
dst, err := fs.Filesystem().OpenFile(dstPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return nil, e... | go | func copyFile() (tsurufs.File, error) {
path := authKey()
fi, statErr := fs.Filesystem().Stat(path)
if statErr != nil && !os.IsNotExist(statErr) {
return nil, statErr
}
dstPath := path + ".tmp"
dst, err := fs.Filesystem().OpenFile(dstPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return nil, e... | [
"func",
"copyFile",
"(",
")",
"(",
"tsurufs",
".",
"File",
",",
"error",
")",
"{",
"path",
":=",
"authKey",
"(",
")",
"\n",
"fi",
",",
"statErr",
":=",
"fs",
".",
"Filesystem",
"(",
")",
".",
"Stat",
"(",
"path",
")",
"\n",
"if",
"statErr",
"!=",... | // creates a copy of the authorized_keys and returns it, with the file cursor
// pointing at the first byte of the file. | [
"creates",
"a",
"copy",
"of",
"the",
"authorized_keys",
"and",
"returns",
"it",
"with",
"the",
"file",
"cursor",
"pointing",
"at",
"the",
"first",
"byte",
"of",
"the",
"file",
"."
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/user/key.go#L103-L132 |
144,020 | tsuru/gandalf | user/key.go | removeKey | func removeKey(name, username string) error {
var k Key
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
err = conn.Key().Find(bson.M{"name": name, "username": username}).One(&k)
if err != nil {
return ErrKeyNotFound
}
conn.Key().Remove(k)
return remove(&k)
} | go | func removeKey(name, username string) error {
var k Key
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
err = conn.Key().Find(bson.M{"name": name, "username": username}).One(&k)
if err != nil {
return ErrKeyNotFound
}
conn.Key().Remove(k)
return remove(&k)
} | [
"func",
"removeKey",
"(",
"name",
",",
"username",
"string",
")",
"error",
"{",
"var",
"k",
"Key",
"\n",
"conn",
",",
"err",
":=",
"db",
".",
"Conn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"conn"... | // removes a key from the database and the authorized_keys file. | [
"removes",
"a",
"key",
"from",
"the",
"database",
"and",
"the",
"authorized_keys",
"file",
"."
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/user/key.go#L259-L272 |
144,021 | tsuru/gandalf | user/key.go | ListKeys | func ListKeys(uName string) (KeyList, error) {
conn, err := db.Conn()
if err != nil {
return nil, err
}
defer conn.Close()
n, err := conn.User().FindId(uName).Count()
if err != nil || n != 1 {
return nil, ErrUserNotFound
}
var keys []Key
err = conn.Key().Find(bson.M{"username": uName}).All(&keys)
return K... | go | func ListKeys(uName string) (KeyList, error) {
conn, err := db.Conn()
if err != nil {
return nil, err
}
defer conn.Close()
n, err := conn.User().FindId(uName).Count()
if err != nil || n != 1 {
return nil, ErrUserNotFound
}
var keys []Key
err = conn.Key().Find(bson.M{"username": uName}).All(&keys)
return K... | [
"func",
"ListKeys",
"(",
"uName",
"string",
")",
"(",
"KeyList",
",",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"db",
".",
"Conn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"conn",
... | // ListKeys lists all user's keys.
//
// If the user is not found, returns an error | [
"ListKeys",
"lists",
"all",
"user",
"s",
"keys",
".",
"If",
"the",
"user",
"is",
"not",
"found",
"returns",
"an",
"error"
] | e9a807da1616b5ffc7a3e7f875c31b83dd26b652 | https://github.com/tsuru/gandalf/blob/e9a807da1616b5ffc7a3e7f875c31b83dd26b652/user/key.go#L287-L300 |
144,022 | sacloud/libsacloud | utils/server/vnc_sender.go | NewSendCommandOption | func NewSendCommandOption() *SendCommandOption {
return &SendCommandOption{
UseUSKeyboard: false,
Debug: false,
ProgressWriter: ioutil.Discard,
}
} | go | func NewSendCommandOption() *SendCommandOption {
return &SendCommandOption{
UseUSKeyboard: false,
Debug: false,
ProgressWriter: ioutil.Discard,
}
} | [
"func",
"NewSendCommandOption",
"(",
")",
"*",
"SendCommandOption",
"{",
"return",
"&",
"SendCommandOption",
"{",
"UseUSKeyboard",
":",
"false",
",",
"Debug",
":",
"false",
",",
"ProgressWriter",
":",
"ioutil",
".",
"Discard",
",",
"}",
"\n",
"}"
] | // NewSendCommandOption returns new SendCommandOption | [
"NewSendCommandOption",
"returns",
"new",
"SendCommandOption"
] | 41c392dee98a83260abbe0fcd5c13beb7c75d103 | https://github.com/sacloud/libsacloud/blob/41c392dee98a83260abbe0fcd5c13beb7c75d103/utils/server/vnc_sender.go#L28-L34 |
144,023 | sacloud/libsacloud | utils/server/vnc_sender.go | VNCSendCommand | func VNCSendCommand(vncProxyInfo *sacloud.VNCProxyResponse, command string, option *SendCommandOption) error {
host := vncProxyInfo.ActualHost()
fmt.Fprintf(option.ProgressWriter, "Connecting to VM via VNC...\n")
// Connect to VNC
nc, err := net.Dial("tcp", fmt.Sprintf("%s:%s", host, vncProxyInfo.Port))
if err !=... | go | func VNCSendCommand(vncProxyInfo *sacloud.VNCProxyResponse, command string, option *SendCommandOption) error {
host := vncProxyInfo.ActualHost()
fmt.Fprintf(option.ProgressWriter, "Connecting to VM via VNC...\n")
// Connect to VNC
nc, err := net.Dial("tcp", fmt.Sprintf("%s:%s", host, vncProxyInfo.Port))
if err !=... | [
"func",
"VNCSendCommand",
"(",
"vncProxyInfo",
"*",
"sacloud",
".",
"VNCProxyResponse",
",",
"command",
"string",
",",
"option",
"*",
"SendCommandOption",
")",
"error",
"{",
"host",
":=",
"vncProxyInfo",
".",
"ActualHost",
"(",
")",
"\n\n",
"fmt",
".",
"Fprint... | // VNCSendCommand sends command over VNC connection | [
"VNCSendCommand",
"sends",
"command",
"over",
"VNC",
"connection"
] | 41c392dee98a83260abbe0fcd5c13beb7c75d103 | https://github.com/sacloud/libsacloud/blob/41c392dee98a83260abbe0fcd5c13beb7c75d103/utils/server/vnc_sender.go#L58-L84 |
144,024 | sacloud/libsacloud | utils/server/rdp.go | RDPFileContent | func (c *RDPOpener) RDPFileContent() string {
addr := c.IPAddress
if c.Port > 0 {
addr = fmt.Sprintf("%s:%d", c.IPAddress, c.Port)
}
template := c.RDPFileTemplate
if template == "" {
template = defaultRDPTemplate
}
return fmt.Sprintf(template, addr, c.User)
} | go | func (c *RDPOpener) RDPFileContent() string {
addr := c.IPAddress
if c.Port > 0 {
addr = fmt.Sprintf("%s:%d", c.IPAddress, c.Port)
}
template := c.RDPFileTemplate
if template == "" {
template = defaultRDPTemplate
}
return fmt.Sprintf(template, addr, c.User)
} | [
"func",
"(",
"c",
"*",
"RDPOpener",
")",
"RDPFileContent",
"(",
")",
"string",
"{",
"addr",
":=",
"c",
".",
"IPAddress",
"\n",
"if",
"c",
".",
"Port",
">",
"0",
"{",
"addr",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"IPAddress",... | // RDPFileContent represents .rdp file contents | [
"RDPFileContent",
"represents",
".",
"rdp",
"file",
"contents"
] | 41c392dee98a83260abbe0fcd5c13beb7c75d103 | https://github.com/sacloud/libsacloud/blob/41c392dee98a83260abbe0fcd5c13beb7c75d103/utils/server/rdp.go#L19-L30 |
144,025 | sacloud/libsacloud | utils/server/rdp.go | StartDefaultClient | func (c *RDPOpener) StartDefaultClient() error {
uri := ""
// create .rdp tmp-file
f, err := ioutil.TempFile("", "usacloud_open_rdp")
if err != nil {
return err
}
defer f.Close()
uri = fmt.Sprintf("%s.rdp", f.Name())
rdpContent := c.RDPFileContent()
ioutil.WriteFile(uri, []byte(rdpContent), 0755)
return ... | go | func (c *RDPOpener) StartDefaultClient() error {
uri := ""
// create .rdp tmp-file
f, err := ioutil.TempFile("", "usacloud_open_rdp")
if err != nil {
return err
}
defer f.Close()
uri = fmt.Sprintf("%s.rdp", f.Name())
rdpContent := c.RDPFileContent()
ioutil.WriteFile(uri, []byte(rdpContent), 0755)
return ... | [
"func",
"(",
"c",
"*",
"RDPOpener",
")",
"StartDefaultClient",
"(",
")",
"error",
"{",
"uri",
":=",
"\"",
"\"",
"\n\n",
"// create .rdp tmp-file",
"f",
",",
"err",
":=",
"ioutil",
".",
"TempFile",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"e... | // StartDefaultClient starts OS's default RDP client | [
"StartDefaultClient",
"starts",
"OS",
"s",
"default",
"RDP",
"client"
] | 41c392dee98a83260abbe0fcd5c13beb7c75d103 | https://github.com/sacloud/libsacloud/blob/41c392dee98a83260abbe0fcd5c13beb7c75d103/utils/server/rdp.go#L39-L54 |
144,026 | ory/pagination | limit.go | Index | func Index(limit, offset, length int) (start, end int) {
if offset > length {
return length, length
} else if limit+offset > length {
return offset, length
}
return offset, offset + limit
} | go | func Index(limit, offset, length int) (start, end int) {
if offset > length {
return length, length
} else if limit+offset > length {
return offset, length
}
return offset, offset + limit
} | [
"func",
"Index",
"(",
"limit",
",",
"offset",
",",
"length",
"int",
")",
"(",
"start",
",",
"end",
"int",
")",
"{",
"if",
"offset",
">",
"length",
"{",
"return",
"length",
",",
"length",
"\n",
"}",
"else",
"if",
"limit",
"+",
"offset",
">",
"length... | // Index uses limit, offset, and a slice's length to compute start and end indices for said slice. | [
"Index",
"uses",
"limit",
"offset",
"and",
"a",
"slice",
"s",
"length",
"to",
"compute",
"start",
"and",
"end",
"indices",
"for",
"said",
"slice",
"."
] | 05947c3e39e20ec964d080560c15368e9a7b9618 | https://github.com/ory/pagination/blob/05947c3e39e20ec964d080560c15368e9a7b9618/limit.go#L23-L31 |
144,027 | kataras/go-errors | errors.go | New | func New(errMsg string) *Error {
if NewLine {
errMsg += "\n"
}
return &Error{message: Prefix + errMsg}
} | go | func New(errMsg string) *Error {
if NewLine {
errMsg += "\n"
}
return &Error{message: Prefix + errMsg}
} | [
"func",
"New",
"(",
"errMsg",
"string",
")",
"*",
"Error",
"{",
"if",
"NewLine",
"{",
"errMsg",
"+=",
"\"",
"\\n",
"\"",
"\n",
"}",
"\n",
"return",
"&",
"Error",
"{",
"message",
":",
"Prefix",
"+",
"errMsg",
"}",
"\n",
"}"
] | // New creates and returns an Error with a pre-defined user output message
// all methods below that doesn't accept a pointer receiver because actualy they are not changing the original message | [
"New",
"creates",
"and",
"returns",
"an",
"Error",
"with",
"a",
"pre",
"-",
"defined",
"user",
"output",
"message",
"all",
"methods",
"below",
"that",
"doesn",
"t",
"accept",
"a",
"pointer",
"receiver",
"because",
"actualy",
"they",
"are",
"not",
"changing",... | 6fb46ef666f60ce19b5cc73906d531645d5bf8bc | https://github.com/kataras/go-errors/blob/6fb46ef666f60ce19b5cc73906d531645d5bf8bc/errors.go#L31-L36 |
144,028 | honeycombio/dynsampler-go | onlyonce.go | Start | func (o *OnlyOnce) Start() error {
//
if o.ClearFrequencySec == -1 {
return nil
}
if o.ClearFrequencySec == 0 {
o.ClearFrequencySec = 30
}
o.seen = make(map[string]bool)
// spin up calculator
go func() {
ticker := time.NewTicker(time.Second * time.Duration(o.ClearFrequencySec))
for range ticker.C {
... | go | func (o *OnlyOnce) Start() error {
//
if o.ClearFrequencySec == -1 {
return nil
}
if o.ClearFrequencySec == 0 {
o.ClearFrequencySec = 30
}
o.seen = make(map[string]bool)
// spin up calculator
go func() {
ticker := time.NewTicker(time.Second * time.Duration(o.ClearFrequencySec))
for range ticker.C {
... | [
"func",
"(",
"o",
"*",
"OnlyOnce",
")",
"Start",
"(",
")",
"error",
"{",
"//",
"if",
"o",
".",
"ClearFrequencySec",
"==",
"-",
"1",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"o",
".",
"ClearFrequencySec",
"==",
"0",
"{",
"o",
".",
"ClearFrequenc... | // Start initializes the static dynsampler | [
"Start",
"initializes",
"the",
"static",
"dynsampler"
] | 7e535e271d684bd0bdf07f4325c192a1eb1e95f6 | https://github.com/honeycombio/dynsampler-go/blob/7e535e271d684bd0bdf07f4325c192a1eb1e95f6/onlyonce.go#L31-L49 |
144,029 | xdg-go/stringprep | set.go | Contains | func (rr RuneRange) Contains(r rune) bool {
return rr[0] <= r && r <= rr[1]
} | go | func (rr RuneRange) Contains(r rune) bool {
return rr[0] <= r && r <= rr[1]
} | [
"func",
"(",
"rr",
"RuneRange",
")",
"Contains",
"(",
"r",
"rune",
")",
"bool",
"{",
"return",
"rr",
"[",
"0",
"]",
"<=",
"r",
"&&",
"r",
"<=",
"rr",
"[",
"1",
"]",
"\n",
"}"
] | // Contains returns true if a rune is within the bounds of the RuneRange. | [
"Contains",
"returns",
"true",
"if",
"a",
"rune",
"is",
"within",
"the",
"bounds",
"of",
"the",
"RuneRange",
"."
] | 73f8eece6fdcd902c185bf651de50f3828bed5ed | https://github.com/xdg-go/stringprep/blob/73f8eece6fdcd902c185bf651de50f3828bed5ed/set.go#L16-L18 |
144,030 | xdg-go/stringprep | set.go | Contains | func (s Set) Contains(r rune) bool {
i := sort.Search(len(s), func(i int) bool { return s[i].Contains(r) || s[i].isAbove(r) })
if i < len(s) && s[i].Contains(r) {
return true
}
return false
} | go | func (s Set) Contains(r rune) bool {
i := sort.Search(len(s), func(i int) bool { return s[i].Contains(r) || s[i].isAbove(r) })
if i < len(s) && s[i].Contains(r) {
return true
}
return false
} | [
"func",
"(",
"s",
"Set",
")",
"Contains",
"(",
"r",
"rune",
")",
"bool",
"{",
"i",
":=",
"sort",
".",
"Search",
"(",
"len",
"(",
"s",
")",
",",
"func",
"(",
"i",
"int",
")",
"bool",
"{",
"return",
"s",
"[",
"i",
"]",
".",
"Contains",
"(",
"... | // Contains returns true if a rune is within any of the RuneRanges in the
// Set. | [
"Contains",
"returns",
"true",
"if",
"a",
"rune",
"is",
"within",
"any",
"of",
"the",
"RuneRanges",
"in",
"the",
"Set",
"."
] | 73f8eece6fdcd902c185bf651de50f3828bed5ed | https://github.com/xdg-go/stringprep/blob/73f8eece6fdcd902c185bf651de50f3828bed5ed/set.go#L30-L36 |
144,031 | xdg-go/stringprep | profile.go | Prepare | func (p Profile) Prepare(s string) (string, error) {
// Optimistically, assume output will be same length as input
temp := make([]rune, 0, len(s))
// Apply maps
for _, r := range s {
rs, ok := p.applyMaps(r)
if ok {
temp = append(temp, rs...)
} else {
temp = append(temp, r)
}
}
// Normalize
var o... | go | func (p Profile) Prepare(s string) (string, error) {
// Optimistically, assume output will be same length as input
temp := make([]rune, 0, len(s))
// Apply maps
for _, r := range s {
rs, ok := p.applyMaps(r)
if ok {
temp = append(temp, rs...)
} else {
temp = append(temp, r)
}
}
// Normalize
var o... | [
"func",
"(",
"p",
"Profile",
")",
"Prepare",
"(",
"s",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Optimistically, assume output will be same length as input",
"temp",
":=",
"make",
"(",
"[",
"]",
"rune",
",",
"0",
",",
"len",
"(",
"s",
")",
... | // Prepare transforms an input string to an output string following
// the rules defined in the profile as defined by RFC-3454. | [
"Prepare",
"transforms",
"an",
"input",
"string",
"to",
"an",
"output",
"string",
"following",
"the",
"rules",
"defined",
"in",
"the",
"profile",
"as",
"defined",
"by",
"RFC",
"-",
"3454",
"."
] | 73f8eece6fdcd902c185bf651de50f3828bed5ed | https://github.com/xdg-go/stringprep/blob/73f8eece6fdcd902c185bf651de50f3828bed5ed/profile.go#L19-L56 |
144,032 | xdg-go/stringprep | bidi.go | checkBiDiProhibitedRune | func checkBiDiProhibitedRune(s string) error {
for _, r := range s {
if TableC8.Contains(r) {
return Error{Msg: errProhibited, Rune: r}
}
}
return nil
} | go | func checkBiDiProhibitedRune(s string) error {
for _, r := range s {
if TableC8.Contains(r) {
return Error{Msg: errProhibited, Rune: r}
}
}
return nil
} | [
"func",
"checkBiDiProhibitedRune",
"(",
"s",
"string",
")",
"error",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"s",
"{",
"if",
"TableC8",
".",
"Contains",
"(",
"r",
")",
"{",
"return",
"Error",
"{",
"Msg",
":",
"errProhibited",
",",
"Rune",
":",
"r",... | // Check for prohibited characters from table C.8 | [
"Check",
"for",
"prohibited",
"characters",
"from",
"table",
"C",
".",
"8"
] | 73f8eece6fdcd902c185bf651de50f3828bed5ed | https://github.com/xdg-go/stringprep/blob/73f8eece6fdcd902c185bf651de50f3828bed5ed/bidi.go#L14-L21 |
144,033 | xdg-go/stringprep | bidi.go | checkBiDiLCat | func checkBiDiLCat(s string) error {
for _, r := range s {
if TableD2.Contains(r) {
return Error{Msg: errHasLCat, Rune: r}
}
}
return nil
} | go | func checkBiDiLCat(s string) error {
for _, r := range s {
if TableD2.Contains(r) {
return Error{Msg: errHasLCat, Rune: r}
}
}
return nil
} | [
"func",
"checkBiDiLCat",
"(",
"s",
"string",
")",
"error",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"s",
"{",
"if",
"TableD2",
".",
"Contains",
"(",
"r",
")",
"{",
"return",
"Error",
"{",
"Msg",
":",
"errHasLCat",
",",
"Rune",
":",
"r",
"}",
"\n... | // Check for LCat characters from table D.2 | [
"Check",
"for",
"LCat",
"characters",
"from",
"table",
"D",
".",
"2"
] | 73f8eece6fdcd902c185bf651de50f3828bed5ed | https://github.com/xdg-go/stringprep/blob/73f8eece6fdcd902c185bf651de50f3828bed5ed/bidi.go#L24-L31 |
144,034 | xdg-go/stringprep | bidi.go | checkBadFirstAndLastRandALCat | func checkBadFirstAndLastRandALCat(s string) error {
rs := []rune(s)
if !TableD1.Contains(rs[0]) {
return Error{Msg: errFirstRune, Rune: rs[0]}
}
n := len(rs) - 1
if !TableD1.Contains(rs[n]) {
return Error{Msg: errLastRune, Rune: rs[n]}
}
return nil
} | go | func checkBadFirstAndLastRandALCat(s string) error {
rs := []rune(s)
if !TableD1.Contains(rs[0]) {
return Error{Msg: errFirstRune, Rune: rs[0]}
}
n := len(rs) - 1
if !TableD1.Contains(rs[n]) {
return Error{Msg: errLastRune, Rune: rs[n]}
}
return nil
} | [
"func",
"checkBadFirstAndLastRandALCat",
"(",
"s",
"string",
")",
"error",
"{",
"rs",
":=",
"[",
"]",
"rune",
"(",
"s",
")",
"\n",
"if",
"!",
"TableD1",
".",
"Contains",
"(",
"rs",
"[",
"0",
"]",
")",
"{",
"return",
"Error",
"{",
"Msg",
":",
"errFi... | // Check first and last characters are in table D.1; requires non-empty string | [
"Check",
"first",
"and",
"last",
"characters",
"are",
"in",
"table",
"D",
".",
"1",
";",
"requires",
"non",
"-",
"empty",
"string"
] | 73f8eece6fdcd902c185bf651de50f3828bed5ed | https://github.com/xdg-go/stringprep/blob/73f8eece6fdcd902c185bf651de50f3828bed5ed/bidi.go#L34-L44 |
144,035 | xdg-go/stringprep | bidi.go | hasBiDiRandALCat | func hasBiDiRandALCat(s string) bool {
for _, r := range s {
if TableD1.Contains(r) {
return true
}
}
return false
} | go | func hasBiDiRandALCat(s string) bool {
for _, r := range s {
if TableD1.Contains(r) {
return true
}
}
return false
} | [
"func",
"hasBiDiRandALCat",
"(",
"s",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"s",
"{",
"if",
"TableD1",
".",
"Contains",
"(",
"r",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Look for RandALCat characters from table D.1 | [
"Look",
"for",
"RandALCat",
"characters",
"from",
"table",
"D",
".",
"1"
] | 73f8eece6fdcd902c185bf651de50f3828bed5ed | https://github.com/xdg-go/stringprep/blob/73f8eece6fdcd902c185bf651de50f3828bed5ed/bidi.go#L47-L54 |
144,036 | xdg-go/stringprep | bidi.go | passesBiDiRules | func passesBiDiRules(s string) error {
if len(s) == 0 {
return nil
}
if err := checkBiDiProhibitedRune(s); err != nil {
return err
}
if hasBiDiRandALCat(s) {
if err := checkBiDiLCat(s); err != nil {
return err
}
if err := checkBadFirstAndLastRandALCat(s); err != nil {
return err
}
}
return nil
... | go | func passesBiDiRules(s string) error {
if len(s) == 0 {
return nil
}
if err := checkBiDiProhibitedRune(s); err != nil {
return err
}
if hasBiDiRandALCat(s) {
if err := checkBiDiLCat(s); err != nil {
return err
}
if err := checkBadFirstAndLastRandALCat(s); err != nil {
return err
}
}
return nil
... | [
"func",
"passesBiDiRules",
"(",
"s",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"checkBiDiProhibitedRune",
"(",
"s",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"er... | // Check that BiDi rules are satisfied ; let empty string pass this rule | [
"Check",
"that",
"BiDi",
"rules",
"are",
"satisfied",
";",
"let",
"empty",
"string",
"pass",
"this",
"rule"
] | 73f8eece6fdcd902c185bf651de50f3828bed5ed | https://github.com/xdg-go/stringprep/blob/73f8eece6fdcd902c185bf651de50f3828bed5ed/bidi.go#L57-L73 |
144,037 | lestrrat-go/apache-logformat | logformat.go | New | func New(format string) (*ApacheLog, error) {
var f Format
if err := f.compile(format); err != nil {
return nil, errors.Wrap(err, "failed to compile log format")
}
return &ApacheLog{format: &f}, nil
} | go | func New(format string) (*ApacheLog, error) {
var f Format
if err := f.compile(format); err != nil {
return nil, errors.Wrap(err, "failed to compile log format")
}
return &ApacheLog{format: &f}, nil
} | [
"func",
"New",
"(",
"format",
"string",
")",
"(",
"*",
"ApacheLog",
",",
"error",
")",
"{",
"var",
"f",
"Format",
"\n",
"if",
"err",
":=",
"f",
".",
"compile",
"(",
"format",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",... | // New creates a new ApacheLog instance from the given
// format. It will return an error if the format fails to compile. | [
"New",
"creates",
"a",
"new",
"ApacheLog",
"instance",
"from",
"the",
"given",
"format",
".",
"It",
"will",
"return",
"an",
"error",
"if",
"the",
"format",
"fails",
"to",
"compile",
"."
] | bb8451138cebab76e0759a2651b2685f56ad660a | https://github.com/lestrrat-go/apache-logformat/blob/bb8451138cebab76e0759a2651b2685f56ad660a/logformat.go#L15-L22 |
144,038 | lestrrat-go/apache-logformat | logformat.go | WriteLog | func (al *ApacheLog) WriteLog(dst io.Writer, ctx LogCtx) error {
buf := getLogBuffer()
defer releaseLogBuffer(buf)
if err := al.format.WriteTo(buf, ctx); err != nil {
return errors.Wrap(err, "failed to format log line")
}
b := buf.Bytes()
if b[len(b)-1] != '\n' {
buf.WriteByte('\n')
}
if _, err := buf.Wr... | go | func (al *ApacheLog) WriteLog(dst io.Writer, ctx LogCtx) error {
buf := getLogBuffer()
defer releaseLogBuffer(buf)
if err := al.format.WriteTo(buf, ctx); err != nil {
return errors.Wrap(err, "failed to format log line")
}
b := buf.Bytes()
if b[len(b)-1] != '\n' {
buf.WriteByte('\n')
}
if _, err := buf.Wr... | [
"func",
"(",
"al",
"*",
"ApacheLog",
")",
"WriteLog",
"(",
"dst",
"io",
".",
"Writer",
",",
"ctx",
"LogCtx",
")",
"error",
"{",
"buf",
":=",
"getLogBuffer",
"(",
")",
"\n",
"defer",
"releaseLogBuffer",
"(",
"buf",
")",
"\n\n",
"if",
"err",
":=",
"al"... | // WriteLog generates a log line using the format associated with the
// ApacheLog instance, using the values from ctx. The result is written
// to dst | [
"WriteLog",
"generates",
"a",
"log",
"line",
"using",
"the",
"format",
"associated",
"with",
"the",
"ApacheLog",
"instance",
"using",
"the",
"values",
"from",
"ctx",
".",
"The",
"result",
"is",
"written",
"to",
"dst"
] | bb8451138cebab76e0759a2651b2685f56ad660a | https://github.com/lestrrat-go/apache-logformat/blob/bb8451138cebab76e0759a2651b2685f56ad660a/logformat.go#L27-L44 |
144,039 | lestrrat-go/apache-logformat | logformat.go | Wrap | func (al *ApacheLog) Wrap(h http.Handler, dst io.Writer) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := logctx.Get(r)
defer logctx.Release(ctx)
wrapped := httputil.GetResponseWriter(w)
defer httputil.ReleaseResponseWriter(wrapped)
defer func() {
ctx.Finalize... | go | func (al *ApacheLog) Wrap(h http.Handler, dst io.Writer) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := logctx.Get(r)
defer logctx.Release(ctx)
wrapped := httputil.GetResponseWriter(w)
defer httputil.ReleaseResponseWriter(wrapped)
defer func() {
ctx.Finalize... | [
"func",
"(",
"al",
"*",
"ApacheLog",
")",
"Wrap",
"(",
"h",
"http",
".",
"Handler",
",",
"dst",
"io",
".",
"Writer",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
... | // Wrap creates a new http.Handler that logs a formatted log line
// to dst. | [
"Wrap",
"creates",
"a",
"new",
"http",
".",
"Handler",
"that",
"logs",
"a",
"formatted",
"log",
"line",
"to",
"dst",
"."
] | bb8451138cebab76e0759a2651b2685f56ad660a | https://github.com/lestrrat-go/apache-logformat/blob/bb8451138cebab76e0759a2651b2685f56ad660a/logformat.go#L48-L67 |
144,040 | stripe/go-einhorn | einhorn/worker.go | CountListeners | func CountListeners() int {
count, err := strconv.Atoi(os.Getenv("EINHORN_FD_COUNT"))
if err != nil {
return 0
}
return count
} | go | func CountListeners() int {
count, err := strconv.Atoi(os.Getenv("EINHORN_FD_COUNT"))
if err != nil {
return 0
}
return count
} | [
"func",
"CountListeners",
"(",
")",
"int",
"{",
"count",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"count",
"\n",
... | // CountListeners returns the number of listener fd's passed by the master. | [
"CountListeners",
"returns",
"the",
"number",
"of",
"listener",
"fd",
"s",
"passed",
"by",
"the",
"master",
"."
] | 79db5cd84b4be2b4c3b4d9e23f9bb8cfb3e9d6da | https://github.com/stripe/go-einhorn/blob/79db5cd84b4be2b4c3b4d9e23f9bb8cfb3e9d6da/einhorn/worker.go#L12-L18 |
144,041 | stripe/go-einhorn | einhorn/worker.go | GetListener | func GetListener(index int) (net.Listener, error) {
if CountListeners() < (index + 1) {
return nil, errors.New("einhorn: too few EINHORN_FDs passed")
}
name := fmt.Sprintf("EINHORN_FD_%d", index)
fileno, err := strconv.Atoi(os.Getenv(name))
if err != nil {
return nil, err
}
listener, err := net.FileListen... | go | func GetListener(index int) (net.Listener, error) {
if CountListeners() < (index + 1) {
return nil, errors.New("einhorn: too few EINHORN_FDs passed")
}
name := fmt.Sprintf("EINHORN_FD_%d", index)
fileno, err := strconv.Atoi(os.Getenv(name))
if err != nil {
return nil, err
}
listener, err := net.FileListen... | [
"func",
"GetListener",
"(",
"index",
"int",
")",
"(",
"net",
".",
"Listener",
",",
"error",
")",
"{",
"if",
"CountListeners",
"(",
")",
"<",
"(",
"index",
"+",
"1",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",... | // GetListener returns the passed listener with the specified index. | [
"GetListener",
"returns",
"the",
"passed",
"listener",
"with",
"the",
"specified",
"index",
"."
] | 79db5cd84b4be2b4c3b4d9e23f9bb8cfb3e9d6da | https://github.com/stripe/go-einhorn/blob/79db5cd84b4be2b4c3b4d9e23f9bb8cfb3e9d6da/einhorn/worker.go#L21-L39 |
144,042 | stripe/go-einhorn | einhorn/worker.go | IsWorker | func IsWorker() bool {
masterPid := os.Getenv("EINHORN_MASTER_PID")
if masterPid == "" {
return false
}
pid, err := strconv.Atoi(masterPid)
if err != nil {
return false
}
return pid == os.Getppid()
} | go | func IsWorker() bool {
masterPid := os.Getenv("EINHORN_MASTER_PID")
if masterPid == "" {
return false
}
pid, err := strconv.Atoi(masterPid)
if err != nil {
return false
}
return pid == os.Getppid()
} | [
"func",
"IsWorker",
"(",
")",
"bool",
"{",
"masterPid",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"masterPid",
"==",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"pid",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"... | // IsWorker returns whether the current process is an einhorn worker. | [
"IsWorker",
"returns",
"whether",
"the",
"current",
"process",
"is",
"an",
"einhorn",
"worker",
"."
] | 79db5cd84b4be2b4c3b4d9e23f9bb8cfb3e9d6da | https://github.com/stripe/go-einhorn/blob/79db5cd84b4be2b4c3b4d9e23f9bb8cfb3e9d6da/einhorn/worker.go#L42-L54 |
144,043 | stripe/go-einhorn | einhorn/worker.go | Ack | func Ack() error {
client, err := NewClientForPath(os.Getenv("EINHORN_SOCK_PATH"))
if err != nil {
return err
}
defer client.Close()
return client.SendRequest(&ClientAckRequest{
Command: "worker:ack",
Pid: os.Getpid(),
})
} | go | func Ack() error {
client, err := NewClientForPath(os.Getenv("EINHORN_SOCK_PATH"))
if err != nil {
return err
}
defer client.Close()
return client.SendRequest(&ClientAckRequest{
Command: "worker:ack",
Pid: os.Getpid(),
})
} | [
"func",
"Ack",
"(",
")",
"error",
"{",
"client",
",",
"err",
":=",
"NewClientForPath",
"(",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"defer",
"client",
".",
"Close",
... | // Ack sends an ack to the einhorn master. | [
"Ack",
"sends",
"an",
"ack",
"to",
"the",
"einhorn",
"master",
"."
] | 79db5cd84b4be2b4c3b4d9e23f9bb8cfb3e9d6da | https://github.com/stripe/go-einhorn/blob/79db5cd84b4be2b4c3b4d9e23f9bb8cfb3e9d6da/einhorn/worker.go#L57-L69 |
144,044 | mailhog/MailHog-Server | monkey/jim.go | RegisterFlags | func (j *Jim) RegisterFlags() {
flag.Float64Var(&j.DisconnectChance, "jim-disconnect", 0.005, "Chance of disconnect")
flag.Float64Var(&j.AcceptChance, "jim-accept", 0.99, "Chance of accept")
flag.Float64Var(&j.LinkSpeedAffect, "jim-linkspeed-affect", 0.1, "Chance of affecting link speed")
flag.Float64Var(&j.LinkSpe... | go | func (j *Jim) RegisterFlags() {
flag.Float64Var(&j.DisconnectChance, "jim-disconnect", 0.005, "Chance of disconnect")
flag.Float64Var(&j.AcceptChance, "jim-accept", 0.99, "Chance of accept")
flag.Float64Var(&j.LinkSpeedAffect, "jim-linkspeed-affect", 0.1, "Chance of affecting link speed")
flag.Float64Var(&j.LinkSpe... | [
"func",
"(",
"j",
"*",
"Jim",
")",
"RegisterFlags",
"(",
")",
"{",
"flag",
".",
"Float64Var",
"(",
"&",
"j",
".",
"DisconnectChance",
",",
"\"",
"\"",
",",
"0.005",
",",
"\"",
"\"",
")",
"\n",
"flag",
".",
"Float64Var",
"(",
"&",
"j",
".",
"Accep... | // RegisterFlags implements ChaosMonkey.RegisterFlags | [
"RegisterFlags",
"implements",
"ChaosMonkey",
".",
"RegisterFlags"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/monkey/jim.go#L26-L35 |
144,045 | mailhog/MailHog-Server | monkey/jim.go | Configure | func (j *Jim) Configure(logf func(string, ...interface{})) {
j.logf = logf
rand.Seed(time.Now().Unix())
} | go | func (j *Jim) Configure(logf func(string, ...interface{})) {
j.logf = logf
rand.Seed(time.Now().Unix())
} | [
"func",
"(",
"j",
"*",
"Jim",
")",
"Configure",
"(",
"logf",
"func",
"(",
"string",
",",
"...",
"interface",
"{",
"}",
")",
")",
"{",
"j",
".",
"logf",
"=",
"logf",
"\n",
"rand",
".",
"Seed",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(... | // Configure implements ChaosMonkey.Configure | [
"Configure",
"implements",
"ChaosMonkey",
".",
"Configure"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/monkey/jim.go#L38-L41 |
144,046 | mailhog/MailHog-Server | monkey/jim.go | Accept | func (j *Jim) Accept(conn net.Conn) bool {
if rand.Float64() > j.AcceptChance {
j.logf("Jim: Rejecting connection\n")
return false
}
j.logf("Jim: Allowing connection\n")
return true
} | go | func (j *Jim) Accept(conn net.Conn) bool {
if rand.Float64() > j.AcceptChance {
j.logf("Jim: Rejecting connection\n")
return false
}
j.logf("Jim: Allowing connection\n")
return true
} | [
"func",
"(",
"j",
"*",
"Jim",
")",
"Accept",
"(",
"conn",
"net",
".",
"Conn",
")",
"bool",
"{",
"if",
"rand",
".",
"Float64",
"(",
")",
">",
"j",
".",
"AcceptChance",
"{",
"j",
".",
"logf",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"return",
"false",
... | // Accept implements ChaosMonkey.Accept | [
"Accept",
"implements",
"ChaosMonkey",
".",
"Accept"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/monkey/jim.go#L50-L57 |
144,047 | mailhog/MailHog-Server | monkey/jim.go | LinkSpeed | func (j *Jim) LinkSpeed() *linkio.Throughput {
rand.Seed(time.Now().Unix())
if rand.Float64() < j.LinkSpeedAffect {
lsDiff := j.LinkSpeedMax - j.LinkSpeedMin
lsAffect := j.LinkSpeedMin + (lsDiff * rand.Float64())
f := linkio.Throughput(lsAffect) * linkio.BytePerSecond
j.logf("Jim: Restricting throughput to %s... | go | func (j *Jim) LinkSpeed() *linkio.Throughput {
rand.Seed(time.Now().Unix())
if rand.Float64() < j.LinkSpeedAffect {
lsDiff := j.LinkSpeedMax - j.LinkSpeedMin
lsAffect := j.LinkSpeedMin + (lsDiff * rand.Float64())
f := linkio.Throughput(lsAffect) * linkio.BytePerSecond
j.logf("Jim: Restricting throughput to %s... | [
"func",
"(",
"j",
"*",
"Jim",
")",
"LinkSpeed",
"(",
")",
"*",
"linkio",
".",
"Throughput",
"{",
"rand",
".",
"Seed",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(",
")",
")",
"\n",
"if",
"rand",
".",
"Float64",
"(",
")",
"<",
"j",
".",
... | // LinkSpeed implements ChaosMonkey.LinkSpeed | [
"LinkSpeed",
"implements",
"ChaosMonkey",
".",
"LinkSpeed"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/monkey/jim.go#L60-L71 |
144,048 | mailhog/MailHog-Server | monkey/jim.go | ValidRCPT | func (j *Jim) ValidRCPT(rcpt string) bool {
if rand.Float64() < j.RejectRecipientChance {
j.logf("Jim: Rejecting recipient %s\n", rcpt)
return false
}
j.logf("Jim: Allowing recipient%s\n", rcpt)
return true
} | go | func (j *Jim) ValidRCPT(rcpt string) bool {
if rand.Float64() < j.RejectRecipientChance {
j.logf("Jim: Rejecting recipient %s\n", rcpt)
return false
}
j.logf("Jim: Allowing recipient%s\n", rcpt)
return true
} | [
"func",
"(",
"j",
"*",
"Jim",
")",
"ValidRCPT",
"(",
"rcpt",
"string",
")",
"bool",
"{",
"if",
"rand",
".",
"Float64",
"(",
")",
"<",
"j",
".",
"RejectRecipientChance",
"{",
"j",
".",
"logf",
"(",
"\"",
"\\n",
"\"",
",",
"rcpt",
")",
"\n",
"retur... | // ValidRCPT implements ChaosMonkey.ValidRCPT | [
"ValidRCPT",
"implements",
"ChaosMonkey",
".",
"ValidRCPT"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/monkey/jim.go#L74-L81 |
144,049 | mailhog/MailHog-Server | monkey/jim.go | ValidMAIL | func (j *Jim) ValidMAIL(mail string) bool {
if rand.Float64() < j.RejectSenderChance {
j.logf("Jim: Rejecting sender %s\n", mail)
return false
}
j.logf("Jim: Allowing sender %s\n", mail)
return true
} | go | func (j *Jim) ValidMAIL(mail string) bool {
if rand.Float64() < j.RejectSenderChance {
j.logf("Jim: Rejecting sender %s\n", mail)
return false
}
j.logf("Jim: Allowing sender %s\n", mail)
return true
} | [
"func",
"(",
"j",
"*",
"Jim",
")",
"ValidMAIL",
"(",
"mail",
"string",
")",
"bool",
"{",
"if",
"rand",
".",
"Float64",
"(",
")",
"<",
"j",
".",
"RejectSenderChance",
"{",
"j",
".",
"logf",
"(",
"\"",
"\\n",
"\"",
",",
"mail",
")",
"\n",
"return",... | // ValidMAIL implements ChaosMonkey.ValidMAIL | [
"ValidMAIL",
"implements",
"ChaosMonkey",
".",
"ValidMAIL"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/monkey/jim.go#L84-L91 |
144,050 | mailhog/MailHog-Server | monkey/jim.go | ValidAUTH | func (j *Jim) ValidAUTH(mechanism string, args ...string) bool {
if rand.Float64() < j.RejectAuthChance {
j.logf("Jim: Rejecting authentication %s: %s\n", mechanism, args)
return false
}
j.logf("Jim: Allowing authentication %s: %s\n", mechanism, args)
return true
} | go | func (j *Jim) ValidAUTH(mechanism string, args ...string) bool {
if rand.Float64() < j.RejectAuthChance {
j.logf("Jim: Rejecting authentication %s: %s\n", mechanism, args)
return false
}
j.logf("Jim: Allowing authentication %s: %s\n", mechanism, args)
return true
} | [
"func",
"(",
"j",
"*",
"Jim",
")",
"ValidAUTH",
"(",
"mechanism",
"string",
",",
"args",
"...",
"string",
")",
"bool",
"{",
"if",
"rand",
".",
"Float64",
"(",
")",
"<",
"j",
".",
"RejectAuthChance",
"{",
"j",
".",
"logf",
"(",
"\"",
"\\n",
"\"",
... | // ValidAUTH implements ChaosMonkey.ValidAUTH | [
"ValidAUTH",
"implements",
"ChaosMonkey",
".",
"ValidAUTH"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/monkey/jim.go#L94-L101 |
144,051 | mailhog/MailHog-Server | monkey/jim.go | Disconnect | func (j *Jim) Disconnect() bool {
if rand.Float64() < j.DisconnectChance {
j.logf("Jim: Being nasty, kicking them off\n")
return true
}
j.logf("Jim: Being nice, letting them stay\n")
return false
} | go | func (j *Jim) Disconnect() bool {
if rand.Float64() < j.DisconnectChance {
j.logf("Jim: Being nasty, kicking them off\n")
return true
}
j.logf("Jim: Being nice, letting them stay\n")
return false
} | [
"func",
"(",
"j",
"*",
"Jim",
")",
"Disconnect",
"(",
")",
"bool",
"{",
"if",
"rand",
".",
"Float64",
"(",
")",
"<",
"j",
".",
"DisconnectChance",
"{",
"j",
".",
"logf",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"j",... | // Disconnect implements ChaosMonkey.Disconnect | [
"Disconnect",
"implements",
"ChaosMonkey",
".",
"Disconnect"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/monkey/jim.go#L104-L111 |
144,052 | mailhog/MailHog-Server | smtp/session.go | Accept | func Accept(remoteAddress string, conn io.ReadWriteCloser, storage storage.Storage, messageChan chan *data.Message, hostname string, monkey monkey.ChaosMonkey) {
defer conn.Close()
proto := smtp.NewProtocol()
proto.Hostname = hostname
var link *linkio.Link
reader := io.Reader(conn)
writer := io.Writer(conn)
if ... | go | func Accept(remoteAddress string, conn io.ReadWriteCloser, storage storage.Storage, messageChan chan *data.Message, hostname string, monkey monkey.ChaosMonkey) {
defer conn.Close()
proto := smtp.NewProtocol()
proto.Hostname = hostname
var link *linkio.Link
reader := io.Reader(conn)
writer := io.Writer(conn)
if ... | [
"func",
"Accept",
"(",
"remoteAddress",
"string",
",",
"conn",
"io",
".",
"ReadWriteCloser",
",",
"storage",
"storage",
".",
"Storage",
",",
"messageChan",
"chan",
"*",
"data",
".",
"Message",
",",
"hostname",
"string",
",",
"monkey",
"monkey",
".",
"ChaosMo... | // Accept starts a new SMTP session using io.ReadWriteCloser | [
"Accept",
"starts",
"a",
"new",
"SMTP",
"session",
"using",
"io",
".",
"ReadWriteCloser"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/smtp/session.go#L34-L68 |
144,053 | mailhog/MailHog-Server | smtp/session.go | Read | func (c *Session) Read() bool {
buf := make([]byte, 1024)
n, err := c.reader.Read(buf)
if n == 0 {
c.logf("Connection closed by remote host\n")
io.Closer(c.conn).Close() // not sure this is necessary?
return false
}
if err != nil {
c.logf("Error reading from socket: %s\n", err)
return false
}
text :... | go | func (c *Session) Read() bool {
buf := make([]byte, 1024)
n, err := c.reader.Read(buf)
if n == 0 {
c.logf("Connection closed by remote host\n")
io.Closer(c.conn).Close() // not sure this is necessary?
return false
}
if err != nil {
c.logf("Error reading from socket: %s\n", err)
return false
}
text :... | [
"func",
"(",
"c",
"*",
"Session",
")",
"Read",
"(",
")",
"bool",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"1024",
")",
"\n",
"n",
",",
"err",
":=",
"c",
".",
"reader",
".",
"Read",
"(",
"buf",
")",
"\n\n",
"if",
"n",
"==",
"0",... | // Read reads from the underlying net.TCPConn | [
"Read",
"reads",
"from",
"the",
"underlying",
"net",
".",
"TCPConn"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/smtp/session.go#L116-L152 |
144,054 | mailhog/MailHog-Server | smtp/session.go | Write | func (c *Session) Write(reply *smtp.Reply) {
lines := reply.Lines()
for _, l := range lines {
logText := strings.Replace(l, "\n", "\\n", -1)
logText = strings.Replace(logText, "\r", "\\r", -1)
c.logf("Sent %d bytes: '%s'", len(l), logText)
c.writer.Write([]byte(l))
}
} | go | func (c *Session) Write(reply *smtp.Reply) {
lines := reply.Lines()
for _, l := range lines {
logText := strings.Replace(l, "\n", "\\n", -1)
logText = strings.Replace(logText, "\r", "\\r", -1)
c.logf("Sent %d bytes: '%s'", len(l), logText)
c.writer.Write([]byte(l))
}
} | [
"func",
"(",
"c",
"*",
"Session",
")",
"Write",
"(",
"reply",
"*",
"smtp",
".",
"Reply",
")",
"{",
"lines",
":=",
"reply",
".",
"Lines",
"(",
")",
"\n",
"for",
"_",
",",
"l",
":=",
"range",
"lines",
"{",
"logText",
":=",
"strings",
".",
"Replace"... | // Write writes a reply to the underlying net.TCPConn | [
"Write",
"writes",
"a",
"reply",
"to",
"the",
"underlying",
"net",
".",
"TCPConn"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/smtp/session.go#L155-L163 |
144,055 | mailhog/MailHog-Server | config/config.go | DefaultConfig | func DefaultConfig() *Config {
return &Config{
SMTPBindAddr: "0.0.0.0:1025",
APIBindAddr: "0.0.0.0:8025",
Hostname: "mailhog.example",
MongoURI: "127.0.0.1:27017",
MongoDb: "mailhog",
MongoColl: "messages",
MaildirPath: "",
StorageType: "memory",
CORSOrigin: "",
WebPath: "... | go | func DefaultConfig() *Config {
return &Config{
SMTPBindAddr: "0.0.0.0:1025",
APIBindAddr: "0.0.0.0:8025",
Hostname: "mailhog.example",
MongoURI: "127.0.0.1:27017",
MongoDb: "mailhog",
MongoColl: "messages",
MaildirPath: "",
StorageType: "memory",
CORSOrigin: "",
WebPath: "... | [
"func",
"DefaultConfig",
"(",
")",
"*",
"Config",
"{",
"return",
"&",
"Config",
"{",
"SMTPBindAddr",
":",
"\"",
"\"",
",",
"APIBindAddr",
":",
"\"",
"\"",
",",
"Hostname",
":",
"\"",
"\"",
",",
"MongoURI",
":",
"\"",
"\"",
",",
"MongoDb",
":",
"\"",
... | // DefaultConfig is the default config | [
"DefaultConfig",
"is",
"the",
"default",
"config"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/config/config.go#L16-L31 |
144,056 | mailhog/MailHog-Server | config/config.go | Configure | func Configure() *Config {
switch cfg.StorageType {
case "memory":
log.Println("Using in-memory storage")
cfg.Storage = storage.CreateInMemory()
case "mongodb":
log.Println("Using MongoDB message storage")
s := storage.CreateMongoDB(cfg.MongoURI, cfg.MongoDb, cfg.MongoColl)
if s == nil {
log.Println("Mo... | go | func Configure() *Config {
switch cfg.StorageType {
case "memory":
log.Println("Using in-memory storage")
cfg.Storage = storage.CreateInMemory()
case "mongodb":
log.Println("Using MongoDB message storage")
s := storage.CreateMongoDB(cfg.MongoURI, cfg.MongoDb, cfg.MongoColl)
if s == nil {
log.Println("Mo... | [
"func",
"Configure",
"(",
")",
"*",
"Config",
"{",
"switch",
"cfg",
".",
"StorageType",
"{",
"case",
"\"",
"\"",
":",
"log",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"cfg",
".",
"Storage",
"=",
"storage",
".",
"CreateInMemory",
"(",
")",
"\n",
"... | // Configure configures stuff | [
"Configure",
"configures",
"stuff"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/config/config.go#L72-L116 |
144,057 | mailhog/MailHog-Server | config/config.go | RegisterFlags | func RegisterFlags() {
flag.StringVar(&cfg.SMTPBindAddr, "smtp-bind-addr", envconf.FromEnvP("MH_SMTP_BIND_ADDR", "0.0.0.0:1025").(string), "SMTP bind interface and port, e.g. 0.0.0.0:1025 or just :1025")
flag.StringVar(&cfg.APIBindAddr, "api-bind-addr", envconf.FromEnvP("MH_API_BIND_ADDR", "0.0.0.0:8025").(string), "... | go | func RegisterFlags() {
flag.StringVar(&cfg.SMTPBindAddr, "smtp-bind-addr", envconf.FromEnvP("MH_SMTP_BIND_ADDR", "0.0.0.0:1025").(string), "SMTP bind interface and port, e.g. 0.0.0.0:1025 or just :1025")
flag.StringVar(&cfg.APIBindAddr, "api-bind-addr", envconf.FromEnvP("MH_API_BIND_ADDR", "0.0.0.0:8025").(string), "... | [
"func",
"RegisterFlags",
"(",
")",
"{",
"flag",
".",
"StringVar",
"(",
"&",
"cfg",
".",
"SMTPBindAddr",
",",
"\"",
"\"",
",",
"envconf",
".",
"FromEnvP",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"(",
"string",
")",
",",
"\"",
"\"",
")",
"\n",
... | // RegisterFlags registers flags | [
"RegisterFlags",
"registers",
"flags"
] | 50f74a1aa2991b96313144d1ac718ce4d6739dfd | https://github.com/mailhog/MailHog-Server/blob/50f74a1aa2991b96313144d1ac718ce4d6739dfd/config/config.go#L119-L132 |
144,058 | dustin/go-jsonpointer | map.go | Get | func Get(m map[string]interface{}, path string) interface{} {
if path == "" {
return m
}
parts := strings.Split(path[1:], "/")
var rv interface{} = m
for _, p := range parts {
switch v := rv.(type) {
case map[string]interface{}:
if strings.Contains(p, "~") {
p = strings.Replace(p, "~1", "/", -1)
... | go | func Get(m map[string]interface{}, path string) interface{} {
if path == "" {
return m
}
parts := strings.Split(path[1:], "/")
var rv interface{} = m
for _, p := range parts {
switch v := rv.(type) {
case map[string]interface{}:
if strings.Contains(p, "~") {
p = strings.Replace(p, "~1", "/", -1)
... | [
"func",
"Get",
"(",
"m",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"path",
"string",
")",
"interface",
"{",
"}",
"{",
"if",
"path",
"==",
"\"",
"\"",
"{",
"return",
"m",
"\n",
"}",
"\n\n",
"parts",
":=",
"strings",
".",
"Split",
"(",... | // Get the value at the specified path. | [
"Get",
"the",
"value",
"at",
"the",
"specified",
"path",
"."
] | ba0abeacc3dcca5b9b20f31509c46794edbc9965 | https://github.com/dustin/go-jsonpointer/blob/ba0abeacc3dcca5b9b20f31509c46794edbc9965/map.go#L9-L38 |
144,059 | dustin/go-jsonpointer | bytes.go | FindDecode | func FindDecode(data []byte, path string, into interface{}) error {
d, err := Find(data, path)
if err != nil {
return err
}
return json.Unmarshal(d, into)
} | go | func FindDecode(data []byte, path string, into interface{}) error {
d, err := Find(data, path)
if err != nil {
return err
}
return json.Unmarshal(d, into)
} | [
"func",
"FindDecode",
"(",
"data",
"[",
"]",
"byte",
",",
"path",
"string",
",",
"into",
"interface",
"{",
"}",
")",
"error",
"{",
"d",
",",
"err",
":=",
"Find",
"(",
"data",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",... | // FindDecode finds an object by JSONPointer path and then decode the
// result into a user-specified object. Errors if a properly
// formatted JSON document can't be found at the given path. | [
"FindDecode",
"finds",
"an",
"object",
"by",
"JSONPointer",
"path",
"and",
"then",
"decode",
"the",
"result",
"into",
"a",
"user",
"-",
"specified",
"object",
".",
"Errors",
"if",
"a",
"properly",
"formatted",
"JSON",
"document",
"can",
"t",
"be",
"found",
... | ba0abeacc3dcca5b9b20f31509c46794edbc9965 | https://github.com/dustin/go-jsonpointer/blob/ba0abeacc3dcca5b9b20f31509c46794edbc9965/bytes.go#L115-L121 |
144,060 | dustin/go-jsonpointer | bytes.go | Find | func Find(data []byte, path string) ([]byte, error) {
if path == "" {
return data, nil
}
needle := parsePointer(path)
scan := &json.Scanner{}
scan.Reset()
offset := 0
beganLiteral := 0
current := make([]string, 0, 32)
for {
if offset >= len(data) {
break
}
newOp := scan.Step(scan, int(data[offset... | go | func Find(data []byte, path string) ([]byte, error) {
if path == "" {
return data, nil
}
needle := parsePointer(path)
scan := &json.Scanner{}
scan.Reset()
offset := 0
beganLiteral := 0
current := make([]string, 0, 32)
for {
if offset >= len(data) {
break
}
newOp := scan.Step(scan, int(data[offset... | [
"func",
"Find",
"(",
"data",
"[",
"]",
"byte",
",",
"path",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"path",
"==",
"\"",
"\"",
"{",
"return",
"data",
",",
"nil",
"\n",
"}",
"\n\n",
"needle",
":=",
"parsePointer",
"(",
... | // Find a section of raw JSON by specifying a JSONPointer. | [
"Find",
"a",
"section",
"of",
"raw",
"JSON",
"by",
"specifying",
"a",
"JSONPointer",
"."
] | ba0abeacc3dcca5b9b20f31509c46794edbc9965 | https://github.com/dustin/go-jsonpointer/blob/ba0abeacc3dcca5b9b20f31509c46794edbc9965/bytes.go#L124-L180 |
144,061 | dustin/go-jsonpointer | bytes.go | ListPointers | func ListPointers(data []byte) ([]string, error) {
if len(data) == 0 {
return nil, fmt.Errorf("Invalid JSON")
}
rv := []string{""}
scan := &json.Scanner{}
scan.Reset()
offset := 0
beganLiteral := 0
var current []string
for {
if offset >= len(data) {
return rv, nil
}
newOp := scan.Step(scan, int(da... | go | func ListPointers(data []byte) ([]string, error) {
if len(data) == 0 {
return nil, fmt.Errorf("Invalid JSON")
}
rv := []string{""}
scan := &json.Scanner{}
scan.Reset()
offset := 0
beganLiteral := 0
var current []string
for {
if offset >= len(data) {
return rv, nil
}
newOp := scan.Step(scan, int(da... | [
"func",
"ListPointers",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"len",
"(",
"data",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"rv... | // ListPointers lists all possible pointers from the given input. | [
"ListPointers",
"lists",
"all",
"possible",
"pointers",
"from",
"the",
"given",
"input",
"."
] | ba0abeacc3dcca5b9b20f31509c46794edbc9965 | https://github.com/dustin/go-jsonpointer/blob/ba0abeacc3dcca5b9b20f31509c46794edbc9965/bytes.go#L200-L242 |
144,062 | dustin/go-jsonpointer | bytes.go | FindMany | func FindMany(data []byte, paths []string) (map[string][]byte, error) {
tpaths := make([]string, 0, len(paths))
m := map[string][]byte{}
for _, p := range paths {
if p == "" {
m[p] = data
} else {
tpaths = append(tpaths, p)
}
}
sort.Strings(tpaths)
scan := &json.Scanner{}
scan.Reset()
offset := 0
... | go | func FindMany(data []byte, paths []string) (map[string][]byte, error) {
tpaths := make([]string, 0, len(paths))
m := map[string][]byte{}
for _, p := range paths {
if p == "" {
m[p] = data
} else {
tpaths = append(tpaths, p)
}
}
sort.Strings(tpaths)
scan := &json.Scanner{}
scan.Reset()
offset := 0
... | [
"func",
"FindMany",
"(",
"data",
"[",
"]",
"byte",
",",
"paths",
"[",
"]",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"tpaths",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"p... | // FindMany finds several jsonpointers in one pass through the input. | [
"FindMany",
"finds",
"several",
"jsonpointers",
"in",
"one",
"pass",
"through",
"the",
"input",
"."
] | ba0abeacc3dcca5b9b20f31509c46794edbc9965 | https://github.com/dustin/go-jsonpointer/blob/ba0abeacc3dcca5b9b20f31509c46794edbc9965/bytes.go#L245-L328 |
144,063 | dustin/go-jsonpointer | reflect.go | Reflect | func Reflect(o interface{}, path string) interface{} {
if path == "" {
return o
}
parts := parsePointer(path)
var rv interface{} = o
OUTER:
for _, p := range parts {
val := reflect.ValueOf(rv)
if val.Kind() == reflect.Ptr {
val = val.Elem()
}
if val.Kind() == reflect.Struct {
typ := val.Type()
... | go | func Reflect(o interface{}, path string) interface{} {
if path == "" {
return o
}
parts := parsePointer(path)
var rv interface{} = o
OUTER:
for _, p := range parts {
val := reflect.ValueOf(rv)
if val.Kind() == reflect.Ptr {
val = val.Elem()
}
if val.Kind() == reflect.Struct {
typ := val.Type()
... | [
"func",
"Reflect",
"(",
"o",
"interface",
"{",
"}",
",",
"path",
"string",
")",
"interface",
"{",
"}",
"{",
"if",
"path",
"==",
"\"",
"\"",
"{",
"return",
"o",
"\n",
"}",
"\n\n",
"parts",
":=",
"parsePointer",
"(",
"path",
")",
"\n",
"var",
"rv",
... | // Reflect gets the value at the specified path from a struct. | [
"Reflect",
"gets",
"the",
"value",
"at",
"the",
"specified",
"path",
"from",
"a",
"struct",
"."
] | ba0abeacc3dcca5b9b20f31509c46794edbc9965 | https://github.com/dustin/go-jsonpointer/blob/ba0abeacc3dcca5b9b20f31509c46794edbc9965/reflect.go#L10-L65 |
144,064 | dustin/go-jsonpointer | reflect.go | makeMapKeyName | func makeMapKeyName(v reflect.Value) string {
switch v.Kind() {
case reflect.Float32, reflect.Float64:
fv := v.Float()
return strconv.FormatFloat(fv, 'f', -1, v.Type().Bits())
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
iv := v.Int()
return strconv.FormatInt(iv, 10)
case ref... | go | func makeMapKeyName(v reflect.Value) string {
switch v.Kind() {
case reflect.Float32, reflect.Float64:
fv := v.Float()
return strconv.FormatFloat(fv, 'f', -1, v.Type().Bits())
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
iv := v.Int()
return strconv.FormatInt(iv, 10)
case ref... | [
"func",
"makeMapKeyName",
"(",
"v",
"reflect",
".",
"Value",
")",
"string",
"{",
"switch",
"v",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Float32",
",",
"reflect",
".",
"Float64",
":",
"fv",
":=",
"v",
".",
"Float",
"(",
")",
"\n",
"retu... | // makeMapKeyName takes a map key value and creates a string representation | [
"makeMapKeyName",
"takes",
"a",
"map",
"key",
"value",
"and",
"creates",
"a",
"string",
"representation"
] | ba0abeacc3dcca5b9b20f31509c46794edbc9965 | https://github.com/dustin/go-jsonpointer/blob/ba0abeacc3dcca5b9b20f31509c46794edbc9965/reflect.go#L117-L131 |
144,065 | dustin/go-jsonpointer | reflect.go | makeMapKeyFromString | func makeMapKeyFromString(mapKeyType reflect.Type, pointer string) (reflect.Value, bool) {
valp := reflect.New(mapKeyType)
val := reflect.Indirect(valp)
switch mapKeyType.Kind() {
case reflect.String:
return reflect.ValueOf(pointer), true
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.In... | go | func makeMapKeyFromString(mapKeyType reflect.Type, pointer string) (reflect.Value, bool) {
valp := reflect.New(mapKeyType)
val := reflect.Indirect(valp)
switch mapKeyType.Kind() {
case reflect.String:
return reflect.ValueOf(pointer), true
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.In... | [
"func",
"makeMapKeyFromString",
"(",
"mapKeyType",
"reflect",
".",
"Type",
",",
"pointer",
"string",
")",
"(",
"reflect",
".",
"Value",
",",
"bool",
")",
"{",
"valp",
":=",
"reflect",
".",
"New",
"(",
"mapKeyType",
")",
"\n",
"val",
":=",
"reflect",
".",... | // makeMapKeyFromString takes the key type for a map, and a string
// representing the key, it then tries to convert the string
// representation into a value of the correct type. | [
"makeMapKeyFromString",
"takes",
"the",
"key",
"type",
"for",
"a",
"map",
"and",
"a",
"string",
"representing",
"the",
"key",
"it",
"then",
"tries",
"to",
"convert",
"the",
"string",
"representation",
"into",
"a",
"value",
"of",
"the",
"correct",
"type",
"."... | ba0abeacc3dcca5b9b20f31509c46794edbc9965 | https://github.com/dustin/go-jsonpointer/blob/ba0abeacc3dcca5b9b20f31509c46794edbc9965/reflect.go#L136-L163 |
144,066 | dustin/go-jsonpointer | reflect.go | parseJSONTagName | func parseJSONTagName(tag string) string {
if idx := strings.Index(tag, ","); idx != -1 {
return tag[:idx]
}
return tag
} | go | func parseJSONTagName(tag string) string {
if idx := strings.Index(tag, ","); idx != -1 {
return tag[:idx]
}
return tag
} | [
"func",
"parseJSONTagName",
"(",
"tag",
"string",
")",
"string",
"{",
"if",
"idx",
":=",
"strings",
".",
"Index",
"(",
"tag",
",",
"\"",
"\"",
")",
";",
"idx",
"!=",
"-",
"1",
"{",
"return",
"tag",
"[",
":",
"idx",
"]",
"\n",
"}",
"\n",
"return",... | // parseJSONTagName extracts the JSON field name from a struct tag | [
"parseJSONTagName",
"extracts",
"the",
"JSON",
"field",
"name",
"from",
"a",
"struct",
"tag"
] | ba0abeacc3dcca5b9b20f31509c46794edbc9965 | https://github.com/dustin/go-jsonpointer/blob/ba0abeacc3dcca5b9b20f31509c46794edbc9965/reflect.go#L166-L171 |
144,067 | Songmu/timeout | exitstatus.go | IsTimedOut | func (ex *ExitStatus) IsTimedOut() bool {
return ex.typ == exitTypeTimedOut || ex.typ == exitTypeKilled
} | go | func (ex *ExitStatus) IsTimedOut() bool {
return ex.typ == exitTypeTimedOut || ex.typ == exitTypeKilled
} | [
"func",
"(",
"ex",
"*",
"ExitStatus",
")",
"IsTimedOut",
"(",
")",
"bool",
"{",
"return",
"ex",
".",
"typ",
"==",
"exitTypeTimedOut",
"||",
"ex",
".",
"typ",
"==",
"exitTypeKilled",
"\n",
"}"
] | // IsTimedOut returns the command timed out or not | [
"IsTimedOut",
"returns",
"the",
"command",
"timed",
"out",
"or",
"not"
] | 9710262dc02f66fdd69a6cd4c8143204006d5843 | https://github.com/Songmu/timeout/blob/9710262dc02f66fdd69a6cd4c8143204006d5843/exitstatus.go#L12-L14 |
144,068 | Songmu/timeout | exitstatus.go | GetExitCode | func (ex *ExitStatus) GetExitCode() int {
switch {
case ex.IsKilled():
return exitKilled
case ex.IsTimedOut():
return exitTimedOut
default:
return ex.Code
}
} | go | func (ex *ExitStatus) GetExitCode() int {
switch {
case ex.IsKilled():
return exitKilled
case ex.IsTimedOut():
return exitTimedOut
default:
return ex.Code
}
} | [
"func",
"(",
"ex",
"*",
"ExitStatus",
")",
"GetExitCode",
"(",
")",
"int",
"{",
"switch",
"{",
"case",
"ex",
".",
"IsKilled",
"(",
")",
":",
"return",
"exitKilled",
"\n",
"case",
"ex",
".",
"IsTimedOut",
"(",
")",
":",
"return",
"exitTimedOut",
"\n",
... | // GetExitCode gets the exit code for command line tools | [
"GetExitCode",
"gets",
"the",
"exit",
"code",
"for",
"command",
"line",
"tools"
] | 9710262dc02f66fdd69a6cd4c8143204006d5843 | https://github.com/Songmu/timeout/blob/9710262dc02f66fdd69a6cd4c8143204006d5843/exitstatus.go#L27-L36 |
144,069 | Songmu/timeout | timeout.go | Run | func (tio *Timeout) Run() (*ExitStatus, string, string, error) {
cmd := tio.getCmd()
var outBuffer, errBuffer bytes.Buffer
cmd.Stdout = &outBuffer
cmd.Stderr = &errBuffer
ch, err := tio.RunCommand()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return nil, string(outBuffer.Bytes()), string(errBuffer.Bytes()),... | go | func (tio *Timeout) Run() (*ExitStatus, string, string, error) {
cmd := tio.getCmd()
var outBuffer, errBuffer bytes.Buffer
cmd.Stdout = &outBuffer
cmd.Stderr = &errBuffer
ch, err := tio.RunCommand()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return nil, string(outBuffer.Bytes()), string(errBuffer.Bytes()),... | [
"func",
"(",
"tio",
"*",
"Timeout",
")",
"Run",
"(",
")",
"(",
"*",
"ExitStatus",
",",
"string",
",",
"string",
",",
"error",
")",
"{",
"cmd",
":=",
"tio",
".",
"getCmd",
"(",
")",
"\n",
"var",
"outBuffer",
",",
"errBuffer",
"bytes",
".",
"Buffer",... | // Run is synchronous interface of executing command and returning information | [
"Run",
"is",
"synchronous",
"interface",
"of",
"executing",
"command",
"and",
"returning",
"information"
] | 9710262dc02f66fdd69a6cd4c8143204006d5843 | https://github.com/Songmu/timeout/blob/9710262dc02f66fdd69a6cd4c8143204006d5843/timeout.go#L56-L69 |
144,070 | Songmu/timeout | timeout.go | RunSimple | func (tio *Timeout) RunSimple(preserveStatus bool) int {
cmd := tio.getCmd()
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
ch, err := tio.RunCommand()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return getExitCodeFromErr(err)
}
exitSt := <-ch
if preserveStatus {
return exitSt.GetChildExitCode()
}
ret... | go | func (tio *Timeout) RunSimple(preserveStatus bool) int {
cmd := tio.getCmd()
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
ch, err := tio.RunCommand()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return getExitCodeFromErr(err)
}
exitSt := <-ch
if preserveStatus {
return exitSt.GetChildExitCode()
}
ret... | [
"func",
"(",
"tio",
"*",
"Timeout",
")",
"RunSimple",
"(",
"preserveStatus",
"bool",
")",
"int",
"{",
"cmd",
":=",
"tio",
".",
"getCmd",
"(",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"... | // RunSimple executes command and only returns integer as exit code. It is mainly for go-timeout command | [
"RunSimple",
"executes",
"command",
"and",
"only",
"returns",
"integer",
"as",
"exit",
"code",
".",
"It",
"is",
"mainly",
"for",
"go",
"-",
"timeout",
"command"
] | 9710262dc02f66fdd69a6cd4c8143204006d5843 | https://github.com/Songmu/timeout/blob/9710262dc02f66fdd69a6cd4c8143204006d5843/timeout.go#L72-L88 |
144,071 | Songmu/timeout | timeout.go | RunContext | func (tio *Timeout) RunContext(ctx context.Context) (*ExitStatus, error) {
if err := tio.start(); err != nil {
return nil, err
}
return tio.wait(ctx), nil
} | go | func (tio *Timeout) RunContext(ctx context.Context) (*ExitStatus, error) {
if err := tio.start(); err != nil {
return nil, err
}
return tio.wait(ctx), nil
} | [
"func",
"(",
"tio",
"*",
"Timeout",
")",
"RunContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"ExitStatus",
",",
"error",
")",
"{",
"if",
"err",
":=",
"tio",
".",
"start",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",... | // RunContext runs command with context | [
"RunContext",
"runs",
"command",
"with",
"context"
] | 9710262dc02f66fdd69a6cd4c8143204006d5843 | https://github.com/Songmu/timeout/blob/9710262dc02f66fdd69a6cd4c8143204006d5843/timeout.go#L101-L106 |
144,072 | Songmu/timeout | timeout.go | RunCommand | func (tio *Timeout) RunCommand() (<-chan *ExitStatus, error) {
if err := tio.start(); err != nil {
return nil, err
}
exitChan := make(chan *ExitStatus)
go func() {
exitChan <- tio.wait(context.Background())
}()
return exitChan, nil
} | go | func (tio *Timeout) RunCommand() (<-chan *ExitStatus, error) {
if err := tio.start(); err != nil {
return nil, err
}
exitChan := make(chan *ExitStatus)
go func() {
exitChan <- tio.wait(context.Background())
}()
return exitChan, nil
} | [
"func",
"(",
"tio",
"*",
"Timeout",
")",
"RunCommand",
"(",
")",
"(",
"<-",
"chan",
"*",
"ExitStatus",
",",
"error",
")",
"{",
"if",
"err",
":=",
"tio",
".",
"start",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}... | // RunCommand is executing the command and handling timeout. This is primitive interface of Timeout | [
"RunCommand",
"is",
"executing",
"the",
"command",
"and",
"handling",
"timeout",
".",
"This",
"is",
"primitive",
"interface",
"of",
"Timeout"
] | 9710262dc02f66fdd69a6cd4c8143204006d5843 | https://github.com/Songmu/timeout/blob/9710262dc02f66fdd69a6cd4c8143204006d5843/timeout.go#L109-L119 |
144,073 | elgris/jsondiff | diff.go | Add | func (d *Diff) Add(item DiffItem) {
d.items = append(d.items, item)
if item.Resolution != TypeEquals {
d.hasDiff = true
}
} | go | func (d *Diff) Add(item DiffItem) {
d.items = append(d.items, item)
if item.Resolution != TypeEquals {
d.hasDiff = true
}
} | [
"func",
"(",
"d",
"*",
"Diff",
")",
"Add",
"(",
"item",
"DiffItem",
")",
"{",
"d",
".",
"items",
"=",
"append",
"(",
"d",
".",
"items",
",",
"item",
")",
"\n",
"if",
"item",
".",
"Resolution",
"!=",
"TypeEquals",
"{",
"d",
".",
"hasDiff",
"=",
... | // Add adds new item to diff object | [
"Add",
"adds",
"new",
"item",
"to",
"diff",
"object"
] | 765b5c24c302e7c7fd032fdb8c69f101918229cb | https://github.com/elgris/jsondiff/blob/765b5c24c302e7c7fd032fdb8c69f101918229cb/diff.go#L46-L51 |
144,074 | jbenet/go-base58 | base58.go | EncodeAlphabet | func EncodeAlphabet(b []byte, alphabet string) string {
x := new(big.Int)
x.SetBytes(b)
answer := make([]byte, 0, len(b)*136/100)
for x.Cmp(bigZero) > 0 {
mod := new(big.Int)
x.DivMod(x, bigRadix, mod)
answer = append(answer, alphabet[mod.Int64()])
}
// leading zero bytes
for _, i := range b {
if i != ... | go | func EncodeAlphabet(b []byte, alphabet string) string {
x := new(big.Int)
x.SetBytes(b)
answer := make([]byte, 0, len(b)*136/100)
for x.Cmp(bigZero) > 0 {
mod := new(big.Int)
x.DivMod(x, bigRadix, mod)
answer = append(answer, alphabet[mod.Int64()])
}
// leading zero bytes
for _, i := range b {
if i != ... | [
"func",
"EncodeAlphabet",
"(",
"b",
"[",
"]",
"byte",
",",
"alphabet",
"string",
")",
"string",
"{",
"x",
":=",
"new",
"(",
"big",
".",
"Int",
")",
"\n",
"x",
".",
"SetBytes",
"(",
"b",
")",
"\n\n",
"answer",
":=",
"make",
"(",
"[",
"]",
"byte",
... | // Encode encodes a byte slice to a modified base58 string, using alphabet | [
"Encode",
"encodes",
"a",
"byte",
"slice",
"to",
"a",
"modified",
"base58",
"string",
"using",
"alphabet"
] | 6237cf65f3a6f7111cd8a42be3590df99a66bc7d | https://github.com/jbenet/go-base58/blob/6237cf65f3a6f7111cd8a42be3590df99a66bc7d/base58.go#L64-L90 |
144,075 | szuecs/gin-glog | ginglog.go | ErrorLoggerT | func ErrorLoggerT(typ gin.ErrorType) gin.HandlerFunc {
return func(c *gin.Context) {
c.Next()
if !c.Writer.Written() {
json := c.Errors.ByType(typ).JSON()
if json != nil {
c.JSON(-1, json)
}
}
}
} | go | func ErrorLoggerT(typ gin.ErrorType) gin.HandlerFunc {
return func(c *gin.Context) {
c.Next()
if !c.Writer.Written() {
json := c.Errors.ByType(typ).JSON()
if json != nil {
c.JSON(-1, json)
}
}
}
} | [
"func",
"ErrorLoggerT",
"(",
"typ",
"gin",
".",
"ErrorType",
")",
"gin",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"c",
"*",
"gin",
".",
"Context",
")",
"{",
"c",
".",
"Next",
"(",
")",
"\n\n",
"if",
"!",
"c",
".",
"Writer",
".",
"Written",
... | // ErrorLoggerT returns an ErrorLoggerT middleware with the given
// type gin.ErrorType. | [
"ErrorLoggerT",
"returns",
"an",
"ErrorLoggerT",
"middleware",
"with",
"the",
"given",
"type",
"gin",
".",
"ErrorType",
"."
] | da59244bde84149ae00db0c2b8e62b9d899e6993 | https://github.com/szuecs/gin-glog/blob/da59244bde84149ae00db0c2b8e62b9d899e6993/ginglog.go#L63-L74 |
144,076 | xlab/handysort | strings.go | StringLess | func StringLess(s1, s2 string) (less bool) {
var b1, b2 []rune
var r1, r2 rune
var e1, e2 bool
var d1, d2 bool
var i, j int
for !e1 || !e2 {
// read rune from former string available
r1, i, e1 = advanceRune(i, s1)
if !e1 {
if d1 = ('0' <= r1 && r1 <= '9'); d1 {
// if digit, fill numeric buffer
b... | go | func StringLess(s1, s2 string) (less bool) {
var b1, b2 []rune
var r1, r2 rune
var e1, e2 bool
var d1, d2 bool
var i, j int
for !e1 || !e2 {
// read rune from former string available
r1, i, e1 = advanceRune(i, s1)
if !e1 {
if d1 = ('0' <= r1 && r1 <= '9'); d1 {
// if digit, fill numeric buffer
b... | [
"func",
"StringLess",
"(",
"s1",
",",
"s2",
"string",
")",
"(",
"less",
"bool",
")",
"{",
"var",
"b1",
",",
"b2",
"[",
"]",
"rune",
"\n",
"var",
"r1",
",",
"r2",
"rune",
"\n",
"var",
"e1",
",",
"e2",
"bool",
"\n",
"var",
"d1",
",",
"d2",
"boo... | // StringLess compares two alphanumeric strings correctly. | [
"StringLess",
"compares",
"two",
"alphanumeric",
"strings",
"correctly",
"."
] | fb3537ed64a14615a020f0fe8dc08424233d491f | https://github.com/xlab/handysort/blob/fb3537ed64a14615a020f0fe8dc08424233d491f/strings.go#L37-L97 |
144,077 | xlab/handysort | strings.go | advanceRune | func advanceRune(ptr int, str string) (r rune, i int, end bool) {
if ptr < len(str) {
var w int
r, w = utf8.DecodeRuneInString(str[ptr:])
i = ptr + w
return
}
return 0, ptr, true
} | go | func advanceRune(ptr int, str string) (r rune, i int, end bool) {
if ptr < len(str) {
var w int
r, w = utf8.DecodeRuneInString(str[ptr:])
i = ptr + w
return
}
return 0, ptr, true
} | [
"func",
"advanceRune",
"(",
"ptr",
"int",
",",
"str",
"string",
")",
"(",
"r",
"rune",
",",
"i",
"int",
",",
"end",
"bool",
")",
"{",
"if",
"ptr",
"<",
"len",
"(",
"str",
")",
"{",
"var",
"w",
"int",
"\n",
"r",
",",
"w",
"=",
"utf8",
".",
"... | // Advances offset in str, returns current rune if not end. | [
"Advances",
"offset",
"in",
"str",
"returns",
"current",
"rune",
"if",
"not",
"end",
"."
] | fb3537ed64a14615a020f0fe8dc08424233d491f | https://github.com/xlab/handysort/blob/fb3537ed64a14615a020f0fe8dc08424233d491f/strings.go#L125-L133 |
144,078 | xlab/handysort | strings.go | compareByDigits | func compareByDigits(n1, n2 []rune) (less, greater, equal bool) {
offset := len(n2) - len(n1)
n1n2 := offset < 0 // len(n1) > len(n2)
if n1n2 {
// if n1 longer, swap with n2
offset = -offset
n1, n2 = n2, n1
}
var j int
// len(n1) always be <= len(n2)
for i := range n2 {
var r1 rune
if offset == 0 {
... | go | func compareByDigits(n1, n2 []rune) (less, greater, equal bool) {
offset := len(n2) - len(n1)
n1n2 := offset < 0 // len(n1) > len(n2)
if n1n2 {
// if n1 longer, swap with n2
offset = -offset
n1, n2 = n2, n1
}
var j int
// len(n1) always be <= len(n2)
for i := range n2 {
var r1 rune
if offset == 0 {
... | [
"func",
"compareByDigits",
"(",
"n1",
",",
"n2",
"[",
"]",
"rune",
")",
"(",
"less",
",",
"greater",
",",
"equal",
"bool",
")",
"{",
"offset",
":=",
"len",
"(",
"n2",
")",
"-",
"len",
"(",
"n1",
")",
"\n",
"n1n2",
":=",
"offset",
"<",
"0",
"// ... | // Compares two numeric fields by their digits, if equal then
// compares initial lengths of the numeric fields provided. | [
"Compares",
"two",
"numeric",
"fields",
"by",
"their",
"digits",
"if",
"equal",
"then",
"compares",
"initial",
"lengths",
"of",
"the",
"numeric",
"fields",
"provided",
"."
] | fb3537ed64a14615a020f0fe8dc08424233d491f | https://github.com/xlab/handysort/blob/fb3537ed64a14615a020f0fe8dc08424233d491f/strings.go#L173-L212 |
144,079 | f2prateek/train | train.go | RoundTripper | func RoundTripper(rt http.RoundTripper) Interceptor {
return InterceptorFunc(func(chain Chain) (*http.Response, error) {
return rt.RoundTrip(chain.Request())
})
} | go | func RoundTripper(rt http.RoundTripper) Interceptor {
return InterceptorFunc(func(chain Chain) (*http.Response, error) {
return rt.RoundTrip(chain.Request())
})
} | [
"func",
"RoundTripper",
"(",
"rt",
"http",
".",
"RoundTripper",
")",
"Interceptor",
"{",
"return",
"InterceptorFunc",
"(",
"func",
"(",
"chain",
"Chain",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"return",
"rt",
".",
"RoundTrip",
"(... | // RoundTripper adapts an `http.RoundTripper` to an `Interceptor`. | [
"RoundTripper",
"adapts",
"an",
"http",
".",
"RoundTripper",
"to",
"an",
"Interceptor",
"."
] | 523ebcaf2f005ed0eff7096782c93ba9bfe352aa | https://github.com/f2prateek/train/blob/523ebcaf2f005ed0eff7096782c93ba9bfe352aa/train.go#L31-L35 |
144,080 | f2prateek/train | train.go | UserAgent | func UserAgent(userAgent string) Interceptor {
return InterceptorFunc(func(chain Chain) (*http.Response, error) {
req := chain.Request()
req.Header.Add("User-Agent", userAgent)
resp, err := chain.Proceed(req)
return resp, err
})
} | go | func UserAgent(userAgent string) Interceptor {
return InterceptorFunc(func(chain Chain) (*http.Response, error) {
req := chain.Request()
req.Header.Add("User-Agent", userAgent)
resp, err := chain.Proceed(req)
return resp, err
})
} | [
"func",
"UserAgent",
"(",
"userAgent",
"string",
")",
"Interceptor",
"{",
"return",
"InterceptorFunc",
"(",
"func",
"(",
"chain",
"Chain",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"req",
":=",
"chain",
".",
"Request",
"(",
")",
"... | // UserAgent returns an `Interceptor` that sets the user-agent on outgoing requests. | [
"UserAgent",
"returns",
"an",
"Interceptor",
"that",
"sets",
"the",
"user",
"-",
"agent",
"on",
"outgoing",
"requests",
"."
] | 523ebcaf2f005ed0eff7096782c93ba9bfe352aa | https://github.com/f2prateek/train/blob/523ebcaf2f005ed0eff7096782c93ba9bfe352aa/train.go#L38-L45 |
144,081 | f2prateek/train | train.go | TransportWith | func TransportWith(transport http.RoundTripper, interceptors ...Interceptor) http.RoundTripper {
return &interceptorRoundTripper{
interceptors: append([]Interceptor{}, interceptors...),
transport: transport,
}
} | go | func TransportWith(transport http.RoundTripper, interceptors ...Interceptor) http.RoundTripper {
return &interceptorRoundTripper{
interceptors: append([]Interceptor{}, interceptors...),
transport: transport,
}
} | [
"func",
"TransportWith",
"(",
"transport",
"http",
".",
"RoundTripper",
",",
"interceptors",
"...",
"Interceptor",
")",
"http",
".",
"RoundTripper",
"{",
"return",
"&",
"interceptorRoundTripper",
"{",
"interceptors",
":",
"append",
"(",
"[",
"]",
"Interceptor",
... | // Return a new http.RoundTripper with the given interceptors and a custom http.RoundTripper
// to perform the actual HTTP request. Interceptors will be called in the order they are
// provided. | [
"Return",
"a",
"new",
"http",
".",
"RoundTripper",
"with",
"the",
"given",
"interceptors",
"and",
"a",
"custom",
"http",
".",
"RoundTripper",
"to",
"perform",
"the",
"actual",
"HTTP",
"request",
".",
"Interceptors",
"will",
"be",
"called",
"in",
"the",
"orde... | 523ebcaf2f005ed0eff7096782c93ba9bfe352aa | https://github.com/f2prateek/train/blob/523ebcaf2f005ed0eff7096782c93ba9bfe352aa/train.go#L56-L61 |
144,082 | f2prateek/train | log/log.go | New | func New(out io.Writer, level Level) train.Interceptor {
return &loggingInterceptor{
out: out,
level: level,
}
} | go | func New(out io.Writer, level Level) train.Interceptor {
return &loggingInterceptor{
out: out,
level: level,
}
} | [
"func",
"New",
"(",
"out",
"io",
".",
"Writer",
",",
"level",
"Level",
")",
"train",
".",
"Interceptor",
"{",
"return",
"&",
"loggingInterceptor",
"{",
"out",
":",
"out",
",",
"level",
":",
"level",
",",
"}",
"\n",
"}"
] | // New returns a logging interceptor with the given level that writes to the given writer. | [
"New",
"returns",
"a",
"logging",
"interceptor",
"with",
"the",
"given",
"level",
"that",
"writes",
"to",
"the",
"given",
"writer",
"."
] | 523ebcaf2f005ed0eff7096782c93ba9bfe352aa | https://github.com/f2prateek/train/blob/523ebcaf2f005ed0eff7096782c93ba9bfe352aa/log/log.go#L26-L31 |
144,083 | TheThingsNetwork/go-account-lib | account/frequency_plans.go | FrequencyPlans | func (a *Account) FrequencyPlans() (map[string]FrequencyPlan, error) {
var plans map[string]FrequencyPlan
err := a.get(auth.Public, "/api/v2/frequency-plans", &plans)
if err != nil {
return nil, err
}
return plans, nil
} | go | func (a *Account) FrequencyPlans() (map[string]FrequencyPlan, error) {
var plans map[string]FrequencyPlan
err := a.get(auth.Public, "/api/v2/frequency-plans", &plans)
if err != nil {
return nil, err
}
return plans, nil
} | [
"func",
"(",
"a",
"*",
"Account",
")",
"FrequencyPlans",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"FrequencyPlan",
",",
"error",
")",
"{",
"var",
"plans",
"map",
"[",
"string",
"]",
"FrequencyPlan",
"\n",
"err",
":=",
"a",
".",
"get",
"(",
"auth",
... | // FrequencyPlans returns the frequency plans the account server supports | [
"FrequencyPlans",
"returns",
"the",
"frequency",
"plans",
"the",
"account",
"server",
"supports"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/account/frequency_plans.go#L9-L17 |
144,084 | TheThingsNetwork/go-account-lib | tokens/const_store.go | Get | func (s *constStore) Get(parent, scope string) (string, error) {
return s.token, nil
} | go | func (s *constStore) Get(parent, scope string) (string, error) {
return s.token, nil
} | [
"func",
"(",
"s",
"*",
"constStore",
")",
"Get",
"(",
"parent",
",",
"scope",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"s",
".",
"token",
",",
"nil",
"\n",
"}"
] | // Get always returns the initial token | [
"Get",
"always",
"returns",
"the",
"initial",
"token"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/tokens/const_store.go#L21-L23 |
144,085 | TheThingsNetwork/go-account-lib | errors/errors.go | StatusCode | func StatusCode(err error) int {
switch t := err.(type) {
case util.HTTPError:
return t.Code
case *util.HTTPError:
return t.Code
case *oauth.Error:
return t.Code
default:
return http.StatusInternalServerError
}
} | go | func StatusCode(err error) int {
switch t := err.(type) {
case util.HTTPError:
return t.Code
case *util.HTTPError:
return t.Code
case *oauth.Error:
return t.Code
default:
return http.StatusInternalServerError
}
} | [
"func",
"StatusCode",
"(",
"err",
"error",
")",
"int",
"{",
"switch",
"t",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"util",
".",
"HTTPError",
":",
"return",
"t",
".",
"Code",
"\n",
"case",
"*",
"util",
".",
"HTTPError",
":",
"return",
"t",
... | // StatusCode gets the status code from an error, defaulting to 500 | [
"StatusCode",
"gets",
"the",
"status",
"code",
"from",
"an",
"error",
"defaulting",
"to",
"500"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/errors/errors.go#L11-L22 |
144,086 | TheThingsNetwork/go-account-lib | claims/parse_access_token.go | FromToken | func FromToken(provider tokenkey.Provider, accessToken string) (*Claims, error) {
claims := &Claims{}
return claims, fromToken(provider, accessToken, claims)
} | go | func FromToken(provider tokenkey.Provider, accessToken string) (*Claims, error) {
claims := &Claims{}
return claims, fromToken(provider, accessToken, claims)
} | [
"func",
"FromToken",
"(",
"provider",
"tokenkey",
".",
"Provider",
",",
"accessToken",
"string",
")",
"(",
"*",
"Claims",
",",
"error",
")",
"{",
"claims",
":=",
"&",
"Claims",
"{",
"}",
"\n",
"return",
"claims",
",",
"fromToken",
"(",
"provider",
",",
... | // FromToken uses the tokenkey provider to parse and validate a token into its
// corresponding claims | [
"FromToken",
"uses",
"the",
"tokenkey",
"provider",
"to",
"parse",
"and",
"validate",
"a",
"token",
"into",
"its",
"corresponding",
"claims"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/claims/parse_access_token.go#L10-L13 |
144,087 | TheThingsNetwork/go-account-lib | claims/parse_access_token.go | FromTokenWithoutValidation | func FromTokenWithoutValidation(accessToken string) (*Claims, error) {
claims := &Claims{}
return claims, fromTokenWithoutValidation(accessToken, claims)
} | go | func FromTokenWithoutValidation(accessToken string) (*Claims, error) {
claims := &Claims{}
return claims, fromTokenWithoutValidation(accessToken, claims)
} | [
"func",
"FromTokenWithoutValidation",
"(",
"accessToken",
"string",
")",
"(",
"*",
"Claims",
",",
"error",
")",
"{",
"claims",
":=",
"&",
"Claims",
"{",
"}",
"\n",
"return",
"claims",
",",
"fromTokenWithoutValidation",
"(",
"accessToken",
",",
"claims",
")",
... | // FromTokenWithoutValidation parses a token into its corresponding claims,
// without checking the token signature | [
"FromTokenWithoutValidation",
"parses",
"a",
"token",
"into",
"its",
"corresponding",
"claims",
"without",
"checking",
"the",
"token",
"signature"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/claims/parse_access_token.go#L17-L20 |
144,088 | TheThingsNetwork/go-account-lib | tokens/dir_store.go | DirStore | func DirStore(dirname string) TokenStore {
return &dirStore{
cache: cache.FileCacheWithNameFn(dirname, filename),
}
} | go | func DirStore(dirname string) TokenStore {
return &dirStore{
cache: cache.FileCacheWithNameFn(dirname, filename),
}
} | [
"func",
"DirStore",
"(",
"dirname",
"string",
")",
"TokenStore",
"{",
"return",
"&",
"dirStore",
"{",
"cache",
":",
"cache",
".",
"FileCacheWithNameFn",
"(",
"dirname",
",",
"filename",
")",
",",
"}",
"\n",
"}"
] | // DirStore creates a filestore that stores tokens in the
// specified directory | [
"DirStore",
"creates",
"a",
"filestore",
"that",
"stores",
"tokens",
"in",
"the",
"specified",
"directory"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/tokens/dir_store.go#L21-L25 |
144,089 | TheThingsNetwork/go-account-lib | tokens/dir_store.go | FileStoreWithNameFn | func FileStoreWithNameFn(dirname string, nameFn func(string) string) TokenStore {
return &dirStore{
cache: cache.FileCacheWithNameFn(dirname, nameFn),
}
} | go | func FileStoreWithNameFn(dirname string, nameFn func(string) string) TokenStore {
return &dirStore{
cache: cache.FileCacheWithNameFn(dirname, nameFn),
}
} | [
"func",
"FileStoreWithNameFn",
"(",
"dirname",
"string",
",",
"nameFn",
"func",
"(",
"string",
")",
"string",
")",
"TokenStore",
"{",
"return",
"&",
"dirStore",
"{",
"cache",
":",
"cache",
".",
"FileCacheWithNameFn",
"(",
"dirname",
",",
"nameFn",
")",
",",
... | // FileStoreWithNameFn creates a filestore that stores tokens in the
// specified directory under with a custom filename | [
"FileStoreWithNameFn",
"creates",
"a",
"filestore",
"that",
"stores",
"tokens",
"in",
"the",
"specified",
"directory",
"under",
"with",
"a",
"custom",
"filename"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/tokens/dir_store.go#L29-L33 |
144,090 | TheThingsNetwork/go-account-lib | tokens/dir_store.go | DirStoreWithFormat | func DirStoreWithFormat(dirname, format string) TokenStore {
return &dirStore{
cache: cache.FileCacheWithFormat(dirname, format),
}
} | go | func DirStoreWithFormat(dirname, format string) TokenStore {
return &dirStore{
cache: cache.FileCacheWithFormat(dirname, format),
}
} | [
"func",
"DirStoreWithFormat",
"(",
"dirname",
",",
"format",
"string",
")",
"TokenStore",
"{",
"return",
"&",
"dirStore",
"{",
"cache",
":",
"cache",
".",
"FileCacheWithFormat",
"(",
"dirname",
",",
"format",
")",
",",
"}",
"\n",
"}"
] | // DirStoreWithFormat creates a filestore that stores tokens in the
// specified directory under with a custom filename | [
"DirStoreWithFormat",
"creates",
"a",
"filestore",
"that",
"stores",
"tokens",
"in",
"the",
"specified",
"directory",
"under",
"with",
"a",
"custom",
"filename"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/tokens/dir_store.go#L37-L41 |
144,091 | TheThingsNetwork/go-account-lib | tokens/dir_store.go | key | func (s *dirStore) key(parent, scope string) string {
data := scope + "." + parent
sum := md5.Sum([]byte(data))
return hex.EncodeToString(sum[:])
} | go | func (s *dirStore) key(parent, scope string) string {
data := scope + "." + parent
sum := md5.Sum([]byte(data))
return hex.EncodeToString(sum[:])
} | [
"func",
"(",
"s",
"*",
"dirStore",
")",
"key",
"(",
"parent",
",",
"scope",
"string",
")",
"string",
"{",
"data",
":=",
"scope",
"+",
"\"",
"\"",
"+",
"parent",
"\n",
"sum",
":=",
"md5",
".",
"Sum",
"(",
"[",
"]",
"byte",
"(",
"data",
")",
")",... | // key creates a key for storing a token and scope by md5 hashing
// the pair | [
"key",
"creates",
"a",
"key",
"for",
"storing",
"a",
"token",
"and",
"scope",
"by",
"md5",
"hashing",
"the",
"pair"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/tokens/dir_store.go#L45-L49 |
144,092 | TheThingsNetwork/go-account-lib | account/components.go | ListComponents | func (a *Account) ListComponents() ([]Component, error) {
components := make([]Component, 0)
err := a.get(a.auth, "/api/v2/components", &components)
return components, err
} | go | func (a *Account) ListComponents() ([]Component, error) {
components := make([]Component, 0)
err := a.get(a.auth, "/api/v2/components", &components)
return components, err
} | [
"func",
"(",
"a",
"*",
"Account",
")",
"ListComponents",
"(",
")",
"(",
"[",
"]",
"Component",
",",
"error",
")",
"{",
"components",
":=",
"make",
"(",
"[",
"]",
"Component",
",",
"0",
")",
"\n",
"err",
":=",
"a",
".",
"get",
"(",
"a",
".",
"au... | // ListComponents lists all of the users components | [
"ListComponents",
"lists",
"all",
"of",
"the",
"users",
"components"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/account/components.go#L42-L46 |
144,093 | TheThingsNetwork/go-account-lib | account/components.go | FindComponent | func (a *Account) FindComponent(typ, id string) (component Component, err error) {
p, err := plural(typ)
if err != nil {
return component, err
}
err = a.get(a.auth.WithScope(scope.Component(id)), fmt.Sprintf("/api/v2/components/%s/%s", p, id), &component)
return component, err
} | go | func (a *Account) FindComponent(typ, id string) (component Component, err error) {
p, err := plural(typ)
if err != nil {
return component, err
}
err = a.get(a.auth.WithScope(scope.Component(id)), fmt.Sprintf("/api/v2/components/%s/%s", p, id), &component)
return component, err
} | [
"func",
"(",
"a",
"*",
"Account",
")",
"FindComponent",
"(",
"typ",
",",
"id",
"string",
")",
"(",
"component",
"Component",
",",
"err",
"error",
")",
"{",
"p",
",",
"err",
":=",
"plural",
"(",
"typ",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"re... | // FindComponent finds a comonent of the specified type with the specified id | [
"FindComponent",
"finds",
"a",
"comonent",
"of",
"the",
"specified",
"type",
"with",
"the",
"specified",
"id"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/account/components.go#L49-L56 |
144,094 | TheThingsNetwork/go-account-lib | account/components.go | FindBroker | func (a *Account) FindBroker(id string) (component Component, err error) {
return a.FindComponent("broker", id)
} | go | func (a *Account) FindBroker(id string) (component Component, err error) {
return a.FindComponent("broker", id)
} | [
"func",
"(",
"a",
"*",
"Account",
")",
"FindBroker",
"(",
"id",
"string",
")",
"(",
"component",
"Component",
",",
"err",
"error",
")",
"{",
"return",
"a",
".",
"FindComponent",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}"
] | // FindBroker finds a broker with the specified id | [
"FindBroker",
"finds",
"a",
"broker",
"with",
"the",
"specified",
"id"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/account/components.go#L59-L61 |
144,095 | TheThingsNetwork/go-account-lib | account/components.go | CreateComponent | func (a *Account) CreateComponent(typ, id string) error {
p, err := plural(typ)
if err != nil {
return err
}
body := createComponentReq{
ID: id,
}
return a.post(a.auth, fmt.Sprintf("/api/v2/components/%s", p), body, nil)
} | go | func (a *Account) CreateComponent(typ, id string) error {
p, err := plural(typ)
if err != nil {
return err
}
body := createComponentReq{
ID: id,
}
return a.post(a.auth, fmt.Sprintf("/api/v2/components/%s", p), body, nil)
} | [
"func",
"(",
"a",
"*",
"Account",
")",
"CreateComponent",
"(",
"typ",
",",
"id",
"string",
")",
"error",
"{",
"p",
",",
"err",
":=",
"plural",
"(",
"typ",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"body",
":=",... | // CreateComponent creates a component with the specified type and id | [
"CreateComponent",
"creates",
"a",
"component",
"with",
"the",
"specified",
"type",
"and",
"id"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/account/components.go#L78-L88 |
144,096 | TheThingsNetwork/go-account-lib | account/components.go | ComponentToken | func (a *Account) ComponentToken(typ, id string) (token string, err error) {
p, err := plural(typ)
if err != nil {
return "", err
}
var res componentTokenRes
err = a.get(a.auth.WithScope(scope.Component(id)), fmt.Sprintf("/api/v2/components/%s/%s/token", p, id), &res)
return res.Token, err
} | go | func (a *Account) ComponentToken(typ, id string) (token string, err error) {
p, err := plural(typ)
if err != nil {
return "", err
}
var res componentTokenRes
err = a.get(a.auth.WithScope(scope.Component(id)), fmt.Sprintf("/api/v2/components/%s/%s/token", p, id), &res)
return res.Token, err
} | [
"func",
"(",
"a",
"*",
"Account",
")",
"ComponentToken",
"(",
"typ",
",",
"id",
"string",
")",
"(",
"token",
"string",
",",
"err",
"error",
")",
"{",
"p",
",",
"err",
":=",
"plural",
"(",
"typ",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",... | // ComponentToken fetches a token for the component with the given
// type and id | [
"ComponentToken",
"fetches",
"a",
"token",
"for",
"the",
"component",
"with",
"the",
"given",
"type",
"and",
"id"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/account/components.go#L112-L121 |
144,097 | TheThingsNetwork/go-account-lib | account/components.go | BrokerToken | func (a *Account) BrokerToken(id string) (token string, err error) {
return a.ComponentToken("broker", id)
} | go | func (a *Account) BrokerToken(id string) (token string, err error) {
return a.ComponentToken("broker", id)
} | [
"func",
"(",
"a",
"*",
"Account",
")",
"BrokerToken",
"(",
"id",
"string",
")",
"(",
"token",
"string",
",",
"err",
"error",
")",
"{",
"return",
"a",
".",
"ComponentToken",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}"
] | // BrokerToken gets the specified brokers token | [
"BrokerToken",
"gets",
"the",
"specified",
"brokers",
"token"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/account/components.go#L124-L126 |
144,098 | TheThingsNetwork/go-account-lib | account/components.go | GrantComponentRights | func (a *Account) GrantComponentRights(typ, componentID, username string, rights []types.Right) error {
p, err := plural(typ)
if err != nil {
return err
}
req := grantReq{
Rights: rights,
}
return a.put(a.auth.WithScope(scope.Component(componentID)), fmt.Sprintf("/api/v2/components/%s/%s/collaborators/%s", p... | go | func (a *Account) GrantComponentRights(typ, componentID, username string, rights []types.Right) error {
p, err := plural(typ)
if err != nil {
return err
}
req := grantReq{
Rights: rights,
}
return a.put(a.auth.WithScope(scope.Component(componentID)), fmt.Sprintf("/api/v2/components/%s/%s/collaborators/%s", p... | [
"func",
"(",
"a",
"*",
"Account",
")",
"GrantComponentRights",
"(",
"typ",
",",
"componentID",
",",
"username",
"string",
",",
"rights",
"[",
"]",
"types",
".",
"Right",
")",
"error",
"{",
"p",
",",
"err",
":=",
"plural",
"(",
"typ",
")",
"\n",
"if",... | // GrantComponentRights adds a collaborator to the component | [
"GrantComponentRights",
"adds",
"a",
"collaborator",
"to",
"the",
"component"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/account/components.go#L139-L149 |
144,099 | TheThingsNetwork/go-account-lib | account/components.go | RetractComponentRights | func (a *Account) RetractComponentRights(typ, componentID, username string) error {
p, err := plural(typ)
if err != nil {
return err
}
return a.del(a.auth.WithScope(scope.Component(componentID)), fmt.Sprintf("/api/v2/components/%s/%s/collaborators/%s", p, componentID, username))
} | go | func (a *Account) RetractComponentRights(typ, componentID, username string) error {
p, err := plural(typ)
if err != nil {
return err
}
return a.del(a.auth.WithScope(scope.Component(componentID)), fmt.Sprintf("/api/v2/components/%s/%s/collaborators/%s", p, componentID, username))
} | [
"func",
"(",
"a",
"*",
"Account",
")",
"RetractComponentRights",
"(",
"typ",
",",
"componentID",
",",
"username",
"string",
")",
"error",
"{",
"p",
",",
"err",
":=",
"plural",
"(",
"typ",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n... | // RetractComponentRights removes rights from a collaborator of the component | [
"RetractComponentRights",
"removes",
"rights",
"from",
"a",
"collaborator",
"of",
"the",
"component"
] | 3314753327942c0aed5a2a9233d4f001454c21a9 | https://github.com/TheThingsNetwork/go-account-lib/blob/3314753327942c0aed5a2a9233d4f001454c21a9/account/components.go#L152-L159 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.