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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
16,900 | denormal/go-gitignore | parser.go | undo | func (p *parser) undo(t *Token) {
// add this token to the list of previously read tokens
// - initialise the undo list if required
if p._undo == nil {
p._undo = make([]*Token, 0, 1)
}
p._undo = append(p._undo, t)
} | go | func (p *parser) undo(t *Token) {
// add this token to the list of previously read tokens
// - initialise the undo list if required
if p._undo == nil {
p._undo = make([]*Token, 0, 1)
}
p._undo = append(p._undo, t)
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"undo",
"(",
"t",
"*",
"Token",
")",
"{",
"// add this token to the list of previously read tokens",
"// - initialise the undo list if required",
"if",
"p",
".",
"_undo",
"==",
"nil",
"{",
"p",
".",
"_undo",
"=",
"make",
... | // undo returns the given Token t to the parser input stream to be retrieved
// again on a subsequent call to next. | [
"undo",
"returns",
"the",
"given",
"Token",
"t",
"to",
"the",
"parser",
"input",
"stream",
"to",
"be",
"retrieved",
"again",
"on",
"a",
"subsequent",
"call",
"to",
"next",
"."
] | ae8ad1d07817b3d3b49cabb21559a3f493a357a3 | https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/parser.go#L418-L425 |
16,901 | denormal/go-gitignore | parser.go | err | func (p *parser) err(e error) Error {
// convert the error to include the parser position
return NewError(e, p.Position())
} | go | func (p *parser) err(e error) Error {
// convert the error to include the parser position
return NewError(e, p.Position())
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"err",
"(",
"e",
"error",
")",
"Error",
"{",
"// convert the error to include the parser position",
"return",
"NewError",
"(",
"e",
",",
"p",
".",
"Position",
"(",
")",
")",
"\n",
"}"
] | // err returns an Error for the error e, capturing the current parser Position. | [
"err",
"returns",
"an",
"Error",
"for",
"the",
"error",
"e",
"capturing",
"the",
"current",
"parser",
"Position",
"."
] | ae8ad1d07817b3d3b49cabb21559a3f493a357a3 | https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/parser.go#L428-L431 |
16,902 | denormal/go-gitignore | parser.go | errors | func (p *parser) errors(e Error) bool {
// do we have an error handler?
if p._error == nil {
return true
}
// pass the error through to the error handler
// - if this returns false, parsing will stop
return p._error(e)
} | go | func (p *parser) errors(e Error) bool {
// do we have an error handler?
if p._error == nil {
return true
}
// pass the error through to the error handler
// - if this returns false, parsing will stop
return p._error(e)
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"errors",
"(",
"e",
"Error",
")",
"bool",
"{",
"// do we have an error handler?",
"if",
"p",
".",
"_error",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"// pass the error through to the error handler",
"// - ... | // errors returns the response from the parser error handler to the Error e. If
// no error handler has been configured for this parser, errors returns true. | [
"errors",
"returns",
"the",
"response",
"from",
"the",
"parser",
"error",
"handler",
"to",
"the",
"Error",
"e",
".",
"If",
"no",
"error",
"handler",
"has",
"been",
"configured",
"for",
"this",
"parser",
"errors",
"returns",
"true",
"."
] | ae8ad1d07817b3d3b49cabb21559a3f493a357a3 | https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/parser.go#L435-L444 |
16,903 | foomo/htpasswd | htpasswd.go | Bytes | func (hp HashedPasswords) Bytes() (passwordBytes []byte) {
passwordBytes = []byte{}
for name, hash := range hp {
passwordBytes = append(passwordBytes, []byte(name+PasswordSeparator+hash+LineSeparator)...)
}
return passwordBytes
} | go | func (hp HashedPasswords) Bytes() (passwordBytes []byte) {
passwordBytes = []byte{}
for name, hash := range hp {
passwordBytes = append(passwordBytes, []byte(name+PasswordSeparator+hash+LineSeparator)...)
}
return passwordBytes
} | [
"func",
"(",
"hp",
"HashedPasswords",
")",
"Bytes",
"(",
")",
"(",
"passwordBytes",
"[",
"]",
"byte",
")",
"{",
"passwordBytes",
"=",
"[",
"]",
"byte",
"{",
"}",
"\n",
"for",
"name",
",",
"hash",
":=",
"range",
"hp",
"{",
"passwordBytes",
"=",
"appen... | // Bytes bytes representation | [
"Bytes",
"bytes",
"representation"
] | cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e | https://github.com/foomo/htpasswd/blob/cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e/htpasswd.go#L40-L46 |
16,904 | foomo/htpasswd | htpasswd.go | WriteToFile | func (hp HashedPasswords) WriteToFile(file string) error {
return ioutil.WriteFile(file, hp.Bytes(), 0644)
} | go | func (hp HashedPasswords) WriteToFile(file string) error {
return ioutil.WriteFile(file, hp.Bytes(), 0644)
} | [
"func",
"(",
"hp",
"HashedPasswords",
")",
"WriteToFile",
"(",
"file",
"string",
")",
"error",
"{",
"return",
"ioutil",
".",
"WriteFile",
"(",
"file",
",",
"hp",
".",
"Bytes",
"(",
")",
",",
"0644",
")",
"\n",
"}"
] | // WriteToFile put them to a file will be overwritten or created | [
"WriteToFile",
"put",
"them",
"to",
"a",
"file",
"will",
"be",
"overwritten",
"or",
"created"
] | cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e | https://github.com/foomo/htpasswd/blob/cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e/htpasswd.go#L49-L51 |
16,905 | foomo/htpasswd | htpasswd.go | SetPassword | func (hp HashedPasswords) SetPassword(name, password string, hashAlgorithm HashAlgorithm) (err error) {
if len(password) == 0 {
return errors.New("passwords must not be empty, if you want to delete a user call RemoveUser")
}
hash := ""
prefix := ""
switch hashAlgorithm {
case HashBCrypt:
hash, err = hashBcrypt(password)
case HashSHA:
prefix = "{SHA}"
hash = hashSha(password)
}
if err != nil {
return err
}
hp[name] = prefix + hash
return nil
} | go | func (hp HashedPasswords) SetPassword(name, password string, hashAlgorithm HashAlgorithm) (err error) {
if len(password) == 0 {
return errors.New("passwords must not be empty, if you want to delete a user call RemoveUser")
}
hash := ""
prefix := ""
switch hashAlgorithm {
case HashBCrypt:
hash, err = hashBcrypt(password)
case HashSHA:
prefix = "{SHA}"
hash = hashSha(password)
}
if err != nil {
return err
}
hp[name] = prefix + hash
return nil
} | [
"func",
"(",
"hp",
"HashedPasswords",
")",
"SetPassword",
"(",
"name",
",",
"password",
"string",
",",
"hashAlgorithm",
"HashAlgorithm",
")",
"(",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"password",
")",
"==",
"0",
"{",
"return",
"errors",
".",
"New"... | // SetPassword set a password for a user with a hashing algo | [
"SetPassword",
"set",
"a",
"password",
"for",
"a",
"user",
"with",
"a",
"hashing",
"algo"
] | cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e | https://github.com/foomo/htpasswd/blob/cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e/htpasswd.go#L54-L72 |
16,906 | foomo/htpasswd | htpasswd.go | ParseHtpasswdFile | func ParseHtpasswdFile(file string) (passwords HashedPasswords, err error) {
htpasswdBytes, err := ioutil.ReadFile(file)
if err != nil {
return
}
if len(htpasswdBytes) > MaxHtpasswdFilesize {
err = errors.New("this file is too large, use a database instead")
return
}
return ParseHtpasswd(htpasswdBytes)
} | go | func ParseHtpasswdFile(file string) (passwords HashedPasswords, err error) {
htpasswdBytes, err := ioutil.ReadFile(file)
if err != nil {
return
}
if len(htpasswdBytes) > MaxHtpasswdFilesize {
err = errors.New("this file is too large, use a database instead")
return
}
return ParseHtpasswd(htpasswdBytes)
} | [
"func",
"ParseHtpasswdFile",
"(",
"file",
"string",
")",
"(",
"passwords",
"HashedPasswords",
",",
"err",
"error",
")",
"{",
"htpasswdBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\... | // ParseHtpasswdFile load a htpasswd file | [
"ParseHtpasswdFile",
"load",
"a",
"htpasswd",
"file"
] | cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e | https://github.com/foomo/htpasswd/blob/cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e/htpasswd.go#L75-L85 |
16,907 | foomo/htpasswd | htpasswd.go | ParseHtpasswd | func ParseHtpasswd(htpasswdBytes []byte) (passwords HashedPasswords, err error) {
lines := strings.Split(string(htpasswdBytes), LineSeparator)
passwords = make(map[string]string)
for lineNumber, line := range lines {
// scan lines
line = strings.Trim(line, " ")
if len(line) == 0 {
// skipping empty lines
continue
}
parts := strings.Split(line, PasswordSeparator)
if len(parts) != 2 {
err = errors.New(fmt.Sprintln("invalid line", lineNumber+1, "unexpected number of parts split by", PasswordSeparator, len(parts), "instead of 2 in\"", line, "\""))
return
}
for i, part := range parts {
parts[i] = strings.Trim(part, " ")
}
_, alreadyExists := passwords[parts[0]]
if alreadyExists {
err = errors.New("invalid htpasswords file - user " + parts[0] + " was already defined")
return
}
passwords[parts[0]] = parts[1]
}
return
} | go | func ParseHtpasswd(htpasswdBytes []byte) (passwords HashedPasswords, err error) {
lines := strings.Split(string(htpasswdBytes), LineSeparator)
passwords = make(map[string]string)
for lineNumber, line := range lines {
// scan lines
line = strings.Trim(line, " ")
if len(line) == 0 {
// skipping empty lines
continue
}
parts := strings.Split(line, PasswordSeparator)
if len(parts) != 2 {
err = errors.New(fmt.Sprintln("invalid line", lineNumber+1, "unexpected number of parts split by", PasswordSeparator, len(parts), "instead of 2 in\"", line, "\""))
return
}
for i, part := range parts {
parts[i] = strings.Trim(part, " ")
}
_, alreadyExists := passwords[parts[0]]
if alreadyExists {
err = errors.New("invalid htpasswords file - user " + parts[0] + " was already defined")
return
}
passwords[parts[0]] = parts[1]
}
return
} | [
"func",
"ParseHtpasswd",
"(",
"htpasswdBytes",
"[",
"]",
"byte",
")",
"(",
"passwords",
"HashedPasswords",
",",
"err",
"error",
")",
"{",
"lines",
":=",
"strings",
".",
"Split",
"(",
"string",
"(",
"htpasswdBytes",
")",
",",
"LineSeparator",
")",
"\n",
"pa... | // ParseHtpasswd parse htpasswd bytes | [
"ParseHtpasswd",
"parse",
"htpasswd",
"bytes"
] | cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e | https://github.com/foomo/htpasswd/blob/cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e/htpasswd.go#L88-L114 |
16,908 | foomo/htpasswd | htpasswd.go | SetHtpasswdHash | func SetHtpasswdHash(file, name, hash string) error {
passwords, err := ParseHtpasswdFile(file)
if err != nil {
return err
}
passwords[name] = hash
return passwords.WriteToFile(file)
} | go | func SetHtpasswdHash(file, name, hash string) error {
passwords, err := ParseHtpasswdFile(file)
if err != nil {
return err
}
passwords[name] = hash
return passwords.WriteToFile(file)
} | [
"func",
"SetHtpasswdHash",
"(",
"file",
",",
"name",
",",
"hash",
"string",
")",
"error",
"{",
"passwords",
",",
"err",
":=",
"ParseHtpasswdFile",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"passwords",
"["... | // SetHtpasswdHash set password hash for a user | [
"SetHtpasswdHash",
"set",
"password",
"hash",
"for",
"a",
"user"
] | cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e | https://github.com/foomo/htpasswd/blob/cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e/htpasswd.go#L117-L124 |
16,909 | foomo/htpasswd | htpasswd.go | RemoveUser | func RemoveUser(file, user string) error {
passwords, err := ParseHtpasswdFile(file)
if err != nil {
return err
}
_, ok := passwords[user]
if !ok {
return ErrNotExist
}
delete(passwords, user)
return passwords.WriteToFile(file)
} | go | func RemoveUser(file, user string) error {
passwords, err := ParseHtpasswdFile(file)
if err != nil {
return err
}
_, ok := passwords[user]
if !ok {
return ErrNotExist
}
delete(passwords, user)
return passwords.WriteToFile(file)
} | [
"func",
"RemoveUser",
"(",
"file",
",",
"user",
"string",
")",
"error",
"{",
"passwords",
",",
"err",
":=",
"ParseHtpasswdFile",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
",",
"ok",
":=",
"passwords... | // RemoveUser remove an existing user from a file, returns an error, if the user does not \
// exist in the file | [
"RemoveUser",
"remove",
"an",
"existing",
"user",
"from",
"a",
"file",
"returns",
"an",
"error",
"if",
"the",
"user",
"does",
"not",
"\\",
"exist",
"in",
"the",
"file"
] | cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e | https://github.com/foomo/htpasswd/blob/cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e/htpasswd.go#L128-L139 |
16,910 | foomo/htpasswd | htpasswd.go | SetPasswordHash | func SetPasswordHash(file, user, hash string) error {
if len(hash) == 0 {
return errors.New("you might want to rethink your hashing algorithm, it left you with an empty hash")
}
passwords, err := ParseHtpasswdFile(file)
if err != nil {
return err
}
passwords[user] = hash
return passwords.WriteToFile(file)
} | go | func SetPasswordHash(file, user, hash string) error {
if len(hash) == 0 {
return errors.New("you might want to rethink your hashing algorithm, it left you with an empty hash")
}
passwords, err := ParseHtpasswdFile(file)
if err != nil {
return err
}
passwords[user] = hash
return passwords.WriteToFile(file)
} | [
"func",
"SetPasswordHash",
"(",
"file",
",",
"user",
",",
"hash",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"hash",
")",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"passwords",
",",
"err",
":=",
"P... | // SetPasswordHash directly set a hash for a user in a file | [
"SetPasswordHash",
"directly",
"set",
"a",
"hash",
"for",
"a",
"user",
"in",
"a",
"file"
] | cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e | https://github.com/foomo/htpasswd/blob/cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e/htpasswd.go#L142-L152 |
16,911 | foomo/htpasswd | htpasswd.go | SetPassword | func SetPassword(file, name, password string, hashAlgorithm HashAlgorithm) error {
_, err := os.Stat(file)
passwords := HashedPasswords(map[string]string{})
if err == nil {
passwords, err = ParseHtpasswdFile(file)
if err != nil {
return err
}
}
err = passwords.SetPassword(name, password, hashAlgorithm)
if err != nil {
return err
}
return passwords.WriteToFile(file)
} | go | func SetPassword(file, name, password string, hashAlgorithm HashAlgorithm) error {
_, err := os.Stat(file)
passwords := HashedPasswords(map[string]string{})
if err == nil {
passwords, err = ParseHtpasswdFile(file)
if err != nil {
return err
}
}
err = passwords.SetPassword(name, password, hashAlgorithm)
if err != nil {
return err
}
return passwords.WriteToFile(file)
} | [
"func",
"SetPassword",
"(",
"file",
",",
"name",
",",
"password",
"string",
",",
"hashAlgorithm",
"HashAlgorithm",
")",
"error",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"file",
")",
"\n",
"passwords",
":=",
"HashedPasswords",
"(",
"map",
"[",... | // SetPassword set password for a user with a given hashing algorithm | [
"SetPassword",
"set",
"password",
"for",
"a",
"user",
"with",
"a",
"given",
"hashing",
"algorithm"
] | cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e | https://github.com/foomo/htpasswd/blob/cb63c4ac0e5029b961b3ac7dcc281ed2a9232e4e/htpasswd.go#L155-L169 |
16,912 | alexbrainman/sspi | schannel/buffer.go | copy | func (ib *inputBuffer) copy(d []byte) int {
// TODO: check all call sites, maybe this can be made more efficient
return copy(ib.data, d)
} | go | func (ib *inputBuffer) copy(d []byte) int {
// TODO: check all call sites, maybe this can be made more efficient
return copy(ib.data, d)
} | [
"func",
"(",
"ib",
"*",
"inputBuffer",
")",
"copy",
"(",
"d",
"[",
"]",
"byte",
")",
"int",
"{",
"// TODO: check all call sites, maybe this can be made more efficient",
"return",
"copy",
"(",
"ib",
".",
"data",
",",
"d",
")",
"\n",
"}"
] | // copy copies data d into buffer ib. copy grows destination if needed. | [
"copy",
"copies",
"data",
"d",
"into",
"buffer",
"ib",
".",
"copy",
"grows",
"destination",
"if",
"needed",
"."
] | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/schannel/buffer.go#L28-L31 |
16,913 | alexbrainman/sspi | schannel/buffer.go | indexOfSecBuffer | func indexOfSecBuffer(bs []sspi.SecBuffer, buftype uint32) int {
for i := range bs {
if bs[i].BufferType == buftype {
return i
}
}
return -1
} | go | func indexOfSecBuffer(bs []sspi.SecBuffer, buftype uint32) int {
for i := range bs {
if bs[i].BufferType == buftype {
return i
}
}
return -1
} | [
"func",
"indexOfSecBuffer",
"(",
"bs",
"[",
"]",
"sspi",
".",
"SecBuffer",
",",
"buftype",
"uint32",
")",
"int",
"{",
"for",
"i",
":=",
"range",
"bs",
"{",
"if",
"bs",
"[",
"i",
"]",
".",
"BufferType",
"==",
"buftype",
"{",
"return",
"i",
"\n",
"}"... | // indexOfSecBuffer searches buffers bs for buffer type buftype.
// It returns -1 if not found. | [
"indexOfSecBuffer",
"searches",
"buffers",
"bs",
"for",
"buffer",
"type",
"buftype",
".",
"It",
"returns",
"-",
"1",
"if",
"not",
"found",
"."
] | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/schannel/buffer.go#L71-L78 |
16,914 | alexbrainman/sspi | negotiate/negotiate.go | Release | func (c *ClientContext) Release() error {
if c == nil {
return nil
}
return c.sctxt.Release()
} | go | func (c *ClientContext) Release() error {
if c == nil {
return nil
}
return c.sctxt.Release()
} | [
"func",
"(",
"c",
"*",
"ClientContext",
")",
"Release",
"(",
")",
"error",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"c",
".",
"sctxt",
".",
"Release",
"(",
")",
"\n",
"}"
] | // Release free up resources associated with client context c. | [
"Release",
"free",
"up",
"resources",
"associated",
"with",
"client",
"context",
"c",
"."
] | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/negotiate/negotiate.go#L262-L267 |
16,915 | alexbrainman/sspi | negotiate/negotiate.go | Sizes | func (c *ClientContext) Sizes() (uint32, uint32, uint32, uint32, error) {
return c.sctxt.Sizes()
} | go | func (c *ClientContext) Sizes() (uint32, uint32, uint32, uint32, error) {
return c.sctxt.Sizes()
} | [
"func",
"(",
"c",
"*",
"ClientContext",
")",
"Sizes",
"(",
")",
"(",
"uint32",
",",
"uint32",
",",
"uint32",
",",
"uint32",
",",
"error",
")",
"{",
"return",
"c",
".",
"sctxt",
".",
"Sizes",
"(",
")",
"\n",
"}"
] | // Sizes queries the client context for the sizes used in per-message
// functions. It returns the maximum token size used in authentication
// exchanges, the maximum signature size, the preferred integral size of
// messages, the size of any security trailer, and any error. | [
"Sizes",
"queries",
"the",
"client",
"context",
"for",
"the",
"sizes",
"used",
"in",
"per",
"-",
"message",
"functions",
".",
"It",
"returns",
"the",
"maximum",
"token",
"size",
"used",
"in",
"authentication",
"exchanges",
"the",
"maximum",
"signature",
"size"... | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/negotiate/negotiate.go#L295-L297 |
16,916 | alexbrainman/sspi | negotiate/negotiate.go | MakeSignature | func (c *ClientContext) MakeSignature(msg []byte, qop, seqno uint32) ([]byte, error) {
return makeSignature(c.sctxt, msg, qop, seqno)
} | go | func (c *ClientContext) MakeSignature(msg []byte, qop, seqno uint32) ([]byte, error) {
return makeSignature(c.sctxt, msg, qop, seqno)
} | [
"func",
"(",
"c",
"*",
"ClientContext",
")",
"MakeSignature",
"(",
"msg",
"[",
"]",
"byte",
",",
"qop",
",",
"seqno",
"uint32",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"makeSignature",
"(",
"c",
".",
"sctxt",
",",
"msg",
",",
... | // MakeSignature uses the established client context to create a signature
// for the given message using the provided quality of protection flags and
// sequence number. It returns the signature token in addition to any error. | [
"MakeSignature",
"uses",
"the",
"established",
"client",
"context",
"to",
"create",
"a",
"signature",
"for",
"the",
"given",
"message",
"using",
"the",
"provided",
"quality",
"of",
"protection",
"flags",
"and",
"sequence",
"number",
".",
"It",
"returns",
"the",
... | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/negotiate/negotiate.go#L302-L304 |
16,917 | alexbrainman/sspi | negotiate/negotiate.go | NewServerContext | func NewServerContext(cred *sspi.Credentials, token []byte) (sc *ServerContext, authDone bool, outputToken []byte, err error) {
otoken := make([]byte, PackageInfo.MaxToken)
c := sspi.NewServerContext(cred, sspi.ASC_REQ_CONNECTION)
authDone, n, err2 := updateContext(c, otoken, token, nil)
if err2 != nil {
return nil, false, nil, err2
}
otoken = otoken[:n]
return &ServerContext{sctxt: c}, authDone, otoken, nil
} | go | func NewServerContext(cred *sspi.Credentials, token []byte) (sc *ServerContext, authDone bool, outputToken []byte, err error) {
otoken := make([]byte, PackageInfo.MaxToken)
c := sspi.NewServerContext(cred, sspi.ASC_REQ_CONNECTION)
authDone, n, err2 := updateContext(c, otoken, token, nil)
if err2 != nil {
return nil, false, nil, err2
}
otoken = otoken[:n]
return &ServerContext{sctxt: c}, authDone, otoken, nil
} | [
"func",
"NewServerContext",
"(",
"cred",
"*",
"sspi",
".",
"Credentials",
",",
"token",
"[",
"]",
"byte",
")",
"(",
"sc",
"*",
"ServerContext",
",",
"authDone",
"bool",
",",
"outputToken",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"otoken",
":="... | // NewServerContext creates new server context. It uses server
// credentials created by AcquireServerCredentials and token from
// the client to start server Negotiate negotiation sequence.
// It also returns new token to be sent to the client. | [
"NewServerContext",
"creates",
"new",
"server",
"context",
".",
"It",
"uses",
"server",
"credentials",
"created",
"by",
"AcquireServerCredentials",
"and",
"token",
"from",
"the",
"client",
"to",
"start",
"server",
"Negotiate",
"negotiation",
"sequence",
".",
"It",
... | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/negotiate/negotiate.go#L353-L362 |
16,918 | alexbrainman/sspi | negotiate/negotiate.go | Release | func (c *ServerContext) Release() error {
if c == nil {
return nil
}
return c.sctxt.Release()
} | go | func (c *ServerContext) Release() error {
if c == nil {
return nil
}
return c.sctxt.Release()
} | [
"func",
"(",
"c",
"*",
"ServerContext",
")",
"Release",
"(",
")",
"error",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"c",
".",
"sctxt",
".",
"Release",
"(",
")",
"\n",
"}"
] | // Release free up resources associated with server context c. | [
"Release",
"free",
"up",
"resources",
"associated",
"with",
"server",
"context",
"c",
"."
] | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/negotiate/negotiate.go#L365-L370 |
16,919 | alexbrainman/sspi | negotiate/negotiate.go | Update | func (c *ServerContext) Update(token []byte) (authCompleted bool, outputToken []byte, err error) {
otoken := make([]byte, PackageInfo.MaxToken)
authDone, n, err2 := updateContext(c.sctxt, otoken, token, nil)
if err2 != nil {
return false, nil, err2
}
if n == 0 && !authDone {
return false, nil, errors.New("negotiate token should not be empty")
}
otoken = otoken[:n]
return authDone, otoken, nil
} | go | func (c *ServerContext) Update(token []byte) (authCompleted bool, outputToken []byte, err error) {
otoken := make([]byte, PackageInfo.MaxToken)
authDone, n, err2 := updateContext(c.sctxt, otoken, token, nil)
if err2 != nil {
return false, nil, err2
}
if n == 0 && !authDone {
return false, nil, errors.New("negotiate token should not be empty")
}
otoken = otoken[:n]
return authDone, otoken, nil
} | [
"func",
"(",
"c",
"*",
"ServerContext",
")",
"Update",
"(",
"token",
"[",
"]",
"byte",
")",
"(",
"authCompleted",
"bool",
",",
"outputToken",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"otoken",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"Pack... | // Update advances server part of Negotiate negotiation c. It uses
// token received from the client and returns true if server part
// of authentication is complete. It also returns new token to be
// sent to the client. | [
"Update",
"advances",
"server",
"part",
"of",
"Negotiate",
"negotiation",
"c",
".",
"It",
"uses",
"token",
"received",
"from",
"the",
"client",
"and",
"returns",
"true",
"if",
"server",
"part",
"of",
"authentication",
"is",
"complete",
".",
"It",
"also",
"re... | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/negotiate/negotiate.go#L381-L392 |
16,920 | alexbrainman/sspi | negotiate/negotiate.go | GetUsername | func (c *ServerContext) GetUsername() (string, error) {
var ns _SecPkgContext_NativeNames
ret := sspi.QueryContextAttributes(c.sctxt.Handle, _SECPKG_ATTR_NATIVE_NAMES, (*byte)(unsafe.Pointer(&ns)))
if ret != sspi.SEC_E_OK {
return "", ret
}
sspi.FreeContextBuffer((*byte)(unsafe.Pointer(ns.ServerName)))
defer sspi.FreeContextBuffer((*byte)(unsafe.Pointer(ns.ClientName)))
return syscall.UTF16ToString((*[2 << 20]uint16)(unsafe.Pointer(ns.ClientName))[:]), nil
} | go | func (c *ServerContext) GetUsername() (string, error) {
var ns _SecPkgContext_NativeNames
ret := sspi.QueryContextAttributes(c.sctxt.Handle, _SECPKG_ATTR_NATIVE_NAMES, (*byte)(unsafe.Pointer(&ns)))
if ret != sspi.SEC_E_OK {
return "", ret
}
sspi.FreeContextBuffer((*byte)(unsafe.Pointer(ns.ServerName)))
defer sspi.FreeContextBuffer((*byte)(unsafe.Pointer(ns.ClientName)))
return syscall.UTF16ToString((*[2 << 20]uint16)(unsafe.Pointer(ns.ClientName))[:]), nil
} | [
"func",
"(",
"c",
"*",
"ServerContext",
")",
"GetUsername",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"ns",
"_SecPkgContext_NativeNames",
"\n",
"ret",
":=",
"sspi",
".",
"QueryContextAttributes",
"(",
"c",
".",
"sctxt",
".",
"Handle",
",",
... | // GetUsername returns the username corresponding to the authenticated client | [
"GetUsername",
"returns",
"the",
"username",
"corresponding",
"to",
"the",
"authenticated",
"client"
] | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/negotiate/negotiate.go#L402-L411 |
16,921 | alexbrainman/sspi | negotiate/negotiate.go | Sizes | func (c *ServerContext) Sizes() (uint32, uint32, uint32, uint32, error) {
return c.sctxt.Sizes()
} | go | func (c *ServerContext) Sizes() (uint32, uint32, uint32, uint32, error) {
return c.sctxt.Sizes()
} | [
"func",
"(",
"c",
"*",
"ServerContext",
")",
"Sizes",
"(",
")",
"(",
"uint32",
",",
"uint32",
",",
"uint32",
",",
"uint32",
",",
"error",
")",
"{",
"return",
"c",
".",
"sctxt",
".",
"Sizes",
"(",
")",
"\n",
"}"
] | // Sizes queries the server context for the sizes used in per-message
// functions. It returns the maximum token size used in authentication
// exchanges, the maximum signature size, the preferred integral size of
// messages, the size of any security trailer, and any error. | [
"Sizes",
"queries",
"the",
"server",
"context",
"for",
"the",
"sizes",
"used",
"in",
"per",
"-",
"message",
"functions",
".",
"It",
"returns",
"the",
"maximum",
"token",
"size",
"used",
"in",
"authentication",
"exchanges",
"the",
"maximum",
"signature",
"size"... | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/negotiate/negotiate.go#L429-L431 |
16,922 | alexbrainman/sspi | negotiate/negotiate.go | VerifySignature | func (c *ServerContext) VerifySignature(msg, token []byte, seqno uint32) (uint32, error) {
return verifySignature(c.sctxt, msg, token, seqno)
} | go | func (c *ServerContext) VerifySignature(msg, token []byte, seqno uint32) (uint32, error) {
return verifySignature(c.sctxt, msg, token, seqno)
} | [
"func",
"(",
"c",
"*",
"ServerContext",
")",
"VerifySignature",
"(",
"msg",
",",
"token",
"[",
"]",
"byte",
",",
"seqno",
"uint32",
")",
"(",
"uint32",
",",
"error",
")",
"{",
"return",
"verifySignature",
"(",
"c",
".",
"sctxt",
",",
"msg",
",",
"tok... | // VerifySignature uses the established server context and signature token
// to check that the provided message hasn't been tampered or received out
// of sequence. It returns any quality of protection flags and any error
// that occurred. | [
"VerifySignature",
"uses",
"the",
"established",
"server",
"context",
"and",
"signature",
"token",
"to",
"check",
"that",
"the",
"provided",
"message",
"hasn",
"t",
"been",
"tampered",
"or",
"received",
"out",
"of",
"sequence",
".",
"It",
"returns",
"any",
"qu... | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/negotiate/negotiate.go#L444-L446 |
16,923 | alexbrainman/sspi | negotiate/negotiate.go | DecryptMessage | func (c *ServerContext) DecryptMessage(msg []byte, seqno uint32) (uint32, []byte, error) {
return decryptMessage(c.sctxt, msg, seqno)
} | go | func (c *ServerContext) DecryptMessage(msg []byte, seqno uint32) (uint32, []byte, error) {
return decryptMessage(c.sctxt, msg, seqno)
} | [
"func",
"(",
"c",
"*",
"ServerContext",
")",
"DecryptMessage",
"(",
"msg",
"[",
"]",
"byte",
",",
"seqno",
"uint32",
")",
"(",
"uint32",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"decryptMessage",
"(",
"c",
".",
"sctxt",
",",
"msg",
... | // DecryptMessage uses the established server context to decrypt a message
// using the provided sequence number.
// It returns the quality of protection flag and the decrypted message in addition to any error. | [
"DecryptMessage",
"uses",
"the",
"established",
"server",
"context",
"to",
"decrypt",
"a",
"message",
"using",
"the",
"provided",
"sequence",
"number",
".",
"It",
"returns",
"the",
"quality",
"of",
"protection",
"flag",
"and",
"the",
"decrypted",
"message",
"in"... | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/negotiate/negotiate.go#L460-L462 |
16,924 | alexbrainman/sspi | ntlm/ntlm.go | NewClientContext | func NewClientContext(cred *sspi.Credentials) (*ClientContext, []byte, error) {
negotiate := make([]byte, PackageInfo.MaxToken)
c := sspi.NewClientContext(cred, sspi.ISC_REQ_CONNECTION)
authCompleted, n, err := updateContext(c, negotiate, nil)
if err != nil {
return nil, nil, err
}
if authCompleted {
c.Release()
return nil, nil, errors.New("ntlm authentication should not be completed yet")
}
if n == 0 {
c.Release()
return nil, nil, errors.New("ntlm token should not be empty")
}
negotiate = negotiate[:n]
return &ClientContext{sctxt: c}, negotiate, nil
} | go | func NewClientContext(cred *sspi.Credentials) (*ClientContext, []byte, error) {
negotiate := make([]byte, PackageInfo.MaxToken)
c := sspi.NewClientContext(cred, sspi.ISC_REQ_CONNECTION)
authCompleted, n, err := updateContext(c, negotiate, nil)
if err != nil {
return nil, nil, err
}
if authCompleted {
c.Release()
return nil, nil, errors.New("ntlm authentication should not be completed yet")
}
if n == 0 {
c.Release()
return nil, nil, errors.New("ntlm token should not be empty")
}
negotiate = negotiate[:n]
return &ClientContext{sctxt: c}, negotiate, nil
} | [
"func",
"NewClientContext",
"(",
"cred",
"*",
"sspi",
".",
"Credentials",
")",
"(",
"*",
"ClientContext",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"negotiate",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"PackageInfo",
".",
"MaxToken",
")",
"\n",
... | // NewClientContext creates new client context. It uses client
// credentials cred generated by AcquireCurrentUserCredentials or
// AcquireUserCredentials and, if successful, outputs negotiate
// message. Negotiate message needs to be sent to the server to
// start NTLM negotiation sequence. | [
"NewClientContext",
"creates",
"new",
"client",
"context",
".",
"It",
"uses",
"client",
"credentials",
"cred",
"generated",
"by",
"AcquireCurrentUserCredentials",
"or",
"AcquireUserCredentials",
"and",
"if",
"successful",
"outputs",
"negotiate",
"message",
".",
"Negotia... | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/ntlm/ntlm.go#L126-L143 |
16,925 | alexbrainman/sspi | ntlm/ntlm.go | Update | func (c *ClientContext) Update(challenge []byte) ([]byte, error) {
authenticate := make([]byte, PackageInfo.MaxToken)
authCompleted, n, err := updateContext(c.sctxt, authenticate, challenge)
if err != nil {
return nil, err
}
if !authCompleted {
return nil, errors.New("ntlm authentication should be completed now")
}
if n == 0 {
return nil, errors.New("ntlm token should not be empty")
}
authenticate = authenticate[:n]
return authenticate, nil
} | go | func (c *ClientContext) Update(challenge []byte) ([]byte, error) {
authenticate := make([]byte, PackageInfo.MaxToken)
authCompleted, n, err := updateContext(c.sctxt, authenticate, challenge)
if err != nil {
return nil, err
}
if !authCompleted {
return nil, errors.New("ntlm authentication should be completed now")
}
if n == 0 {
return nil, errors.New("ntlm token should not be empty")
}
authenticate = authenticate[:n]
return authenticate, nil
} | [
"func",
"(",
"c",
"*",
"ClientContext",
")",
"Update",
"(",
"challenge",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"authenticate",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"PackageInfo",
".",
"MaxToken",
")",
"\n",
"aut... | // Update completes client part of NTLM negotiation c. It uses
// challenge message received from the server, and generates
// authenticate message to be returned to the server. | [
"Update",
"completes",
"client",
"part",
"of",
"NTLM",
"negotiation",
"c",
".",
"It",
"uses",
"challenge",
"message",
"received",
"from",
"the",
"server",
"and",
"generates",
"authenticate",
"message",
"to",
"be",
"returned",
"to",
"the",
"server",
"."
] | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/ntlm/ntlm.go#L161-L175 |
16,926 | alexbrainman/sspi | ntlm/ntlm.go | NewServerContext | func NewServerContext(cred *sspi.Credentials, negotiate []byte) (*ServerContext, []byte, error) {
challenge := make([]byte, PackageInfo.MaxToken)
c := sspi.NewServerContext(cred, sspi.ASC_REQ_CONNECTION)
authCompleted, n, err := updateContext(c, challenge, negotiate)
if err != nil {
return nil, nil, err
}
if authCompleted {
c.Release()
return nil, nil, errors.New("ntlm authentication should not be completed yet")
}
if n == 0 {
c.Release()
return nil, nil, errors.New("ntlm token should not be empty")
}
challenge = challenge[:n]
return &ServerContext{sctxt: c}, challenge, nil
} | go | func NewServerContext(cred *sspi.Credentials, negotiate []byte) (*ServerContext, []byte, error) {
challenge := make([]byte, PackageInfo.MaxToken)
c := sspi.NewServerContext(cred, sspi.ASC_REQ_CONNECTION)
authCompleted, n, err := updateContext(c, challenge, negotiate)
if err != nil {
return nil, nil, err
}
if authCompleted {
c.Release()
return nil, nil, errors.New("ntlm authentication should not be completed yet")
}
if n == 0 {
c.Release()
return nil, nil, errors.New("ntlm token should not be empty")
}
challenge = challenge[:n]
return &ServerContext{sctxt: c}, challenge, nil
} | [
"func",
"NewServerContext",
"(",
"cred",
"*",
"sspi",
".",
"Credentials",
",",
"negotiate",
"[",
"]",
"byte",
")",
"(",
"*",
"ServerContext",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"challenge",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"Packa... | // NewServerContext creates new server context. It uses server
// credentials created by AcquireServerCredentials and client
// negotiate message and, if successful, outputs challenge message.
// Challenge message needs to be sent to the client to continue
// NTLM negotiation sequence. | [
"NewServerContext",
"creates",
"new",
"server",
"context",
".",
"It",
"uses",
"server",
"credentials",
"created",
"by",
"AcquireServerCredentials",
"and",
"client",
"negotiate",
"message",
"and",
"if",
"successful",
"outputs",
"challenge",
"message",
".",
"Challenge",... | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/ntlm/ntlm.go#L197-L214 |
16,927 | alexbrainman/sspi | ntlm/ntlm.go | Update | func (c *ServerContext) Update(authenticate []byte) error {
authCompleted, n, err := updateContext(c.sctxt, nil, authenticate)
if err != nil {
return err
}
if !authCompleted {
return errors.New("ntlm authentication should be completed now")
}
if n != 0 {
return errors.New("ntlm token should be empty now")
}
return nil
} | go | func (c *ServerContext) Update(authenticate []byte) error {
authCompleted, n, err := updateContext(c.sctxt, nil, authenticate)
if err != nil {
return err
}
if !authCompleted {
return errors.New("ntlm authentication should be completed now")
}
if n != 0 {
return errors.New("ntlm token should be empty now")
}
return nil
} | [
"func",
"(",
"c",
"*",
"ServerContext",
")",
"Update",
"(",
"authenticate",
"[",
"]",
"byte",
")",
"error",
"{",
"authCompleted",
",",
"n",
",",
"err",
":=",
"updateContext",
"(",
"c",
".",
"sctxt",
",",
"nil",
",",
"authenticate",
")",
"\n",
"if",
"... | // Update completes server part of NTLM negotiation c. It uses
// authenticate message received from the client. | [
"Update",
"completes",
"server",
"part",
"of",
"NTLM",
"negotiation",
"c",
".",
"It",
"uses",
"authenticate",
"message",
"received",
"from",
"the",
"client",
"."
] | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/ntlm/ntlm.go#L231-L243 |
16,928 | alexbrainman/sspi | sspi.go | AcquireCredentials | func AcquireCredentials(principal string, pkgname string, creduse uint32, authdata *byte) (*Credentials, error) {
var principalName *uint16
if principal != "" {
var err error
principalName, err = syscall.UTF16PtrFromString(principal)
if err != nil {
return nil, err
}
}
name, err := syscall.UTF16PtrFromString(pkgname)
if err != nil {
return nil, err
}
var c Credentials
ret := AcquireCredentialsHandle(principalName, name, creduse, nil, authdata, 0, 0, &c.Handle, &c.expiry)
if ret != SEC_E_OK {
return nil, ret
}
return &c, nil
} | go | func AcquireCredentials(principal string, pkgname string, creduse uint32, authdata *byte) (*Credentials, error) {
var principalName *uint16
if principal != "" {
var err error
principalName, err = syscall.UTF16PtrFromString(principal)
if err != nil {
return nil, err
}
}
name, err := syscall.UTF16PtrFromString(pkgname)
if err != nil {
return nil, err
}
var c Credentials
ret := AcquireCredentialsHandle(principalName, name, creduse, nil, authdata, 0, 0, &c.Handle, &c.expiry)
if ret != SEC_E_OK {
return nil, ret
}
return &c, nil
} | [
"func",
"AcquireCredentials",
"(",
"principal",
"string",
",",
"pkgname",
"string",
",",
"creduse",
"uint32",
",",
"authdata",
"*",
"byte",
")",
"(",
"*",
"Credentials",
",",
"error",
")",
"{",
"var",
"principalName",
"*",
"uint16",
"\n",
"if",
"principal",
... | // AcquireCredentials calls the windows AcquireCredentialsHandle function and
// returns Credentials containing a security handle that can be used for
// InitializeSecurityContext or AcceptSecurityContext operations.
// As a special case, passing an empty string as the principal parameter will
// pass a null string to the underlying function. | [
"AcquireCredentials",
"calls",
"the",
"windows",
"AcquireCredentialsHandle",
"function",
"and",
"returns",
"Credentials",
"containing",
"a",
"security",
"handle",
"that",
"can",
"be",
"used",
"for",
"InitializeSecurityContext",
"or",
"AcceptSecurityContext",
"operations",
... | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/sspi.go#L59-L78 |
16,929 | alexbrainman/sspi | sspi.go | verifySelectiveFlags | func verifySelectiveFlags(flags, establishedFlags uint32) (valid bool, missing, extra uint32) {
missing = flags&establishedFlags ^ flags
extra = flags | establishedFlags ^ flags
valid = missing == 0
return valid, missing, extra
} | go | func verifySelectiveFlags(flags, establishedFlags uint32) (valid bool, missing, extra uint32) {
missing = flags&establishedFlags ^ flags
extra = flags | establishedFlags ^ flags
valid = missing == 0
return valid, missing, extra
} | [
"func",
"verifySelectiveFlags",
"(",
"flags",
",",
"establishedFlags",
"uint32",
")",
"(",
"valid",
"bool",
",",
"missing",
",",
"extra",
"uint32",
")",
"{",
"missing",
"=",
"flags",
"&",
"establishedFlags",
"^",
"flags",
"\n",
"extra",
"=",
"flags",
"|",
... | // verifySelectiveFlags determines if all bits requested in flags are set in establishedFlags.
// missing represents the bits set in flags that are not set in establishedFlags.
// extra represents the bits set in establishedFlags that are not set in flags.
// valid is true and missing is zero when establishedFlags has all of the requested flags. | [
"verifySelectiveFlags",
"determines",
"if",
"all",
"bits",
"requested",
"in",
"flags",
"are",
"set",
"in",
"establishedFlags",
".",
"missing",
"represents",
"the",
"bits",
"set",
"in",
"flags",
"that",
"are",
"not",
"set",
"in",
"establishedFlags",
".",
"extra",... | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/sspi.go#L211-L216 |
16,930 | alexbrainman/sspi | sspi.go | NewSecBufferDesc | func NewSecBufferDesc(b []SecBuffer) *SecBufferDesc {
return &SecBufferDesc{
Version: SECBUFFER_VERSION,
BuffersCount: uint32(len(b)),
Buffers: &b[0],
}
} | go | func NewSecBufferDesc(b []SecBuffer) *SecBufferDesc {
return &SecBufferDesc{
Version: SECBUFFER_VERSION,
BuffersCount: uint32(len(b)),
Buffers: &b[0],
}
} | [
"func",
"NewSecBufferDesc",
"(",
"b",
"[",
"]",
"SecBuffer",
")",
"*",
"SecBufferDesc",
"{",
"return",
"&",
"SecBufferDesc",
"{",
"Version",
":",
"SECBUFFER_VERSION",
",",
"BuffersCount",
":",
"uint32",
"(",
"len",
"(",
"b",
")",
")",
",",
"Buffers",
":",
... | // NewSecBufferDesc returns an initialized SecBufferDesc describing the
// provided SecBuffer. | [
"NewSecBufferDesc",
"returns",
"an",
"initialized",
"SecBufferDesc",
"describing",
"the",
"provided",
"SecBuffer",
"."
] | e580b900e9f5657daa5473021296289be6da2661 | https://github.com/alexbrainman/sspi/blob/e580b900e9f5657daa5473021296289be6da2661/sspi.go#L220-L226 |
16,931 | coreos/go-tcmu | cmd_handler.go | EmulateModeSense | func EmulateModeSense(cmd *SCSICmd, wce bool) (SCSIResponse, error) {
pgs := &bytes.Buffer{}
outlen := int(cmd.XferLen())
page := cmd.GetCDB(2)
if page == 0x3f || page == 0x08 {
CachingModePage(pgs, wce)
}
scsiCmd := cmd.Command()
dsp := byte(0x10) // Support DPO/FUA
pgdata := pgs.Bytes()
var hdr []byte
if scsiCmd == scsi.ModeSense {
// MODE_SENSE_6
hdr = make([]byte, 4)
hdr[0] = byte(len(pgdata) + 3)
hdr[1] = 0x00 // Device type
hdr[2] = dsp
} else {
// MODE_SENSE_10
hdr = make([]byte, 8)
order := binary.BigEndian
order.PutUint16(hdr, uint16(len(pgdata)+6))
hdr[2] = 0x00 // Device type
hdr[3] = dsp
}
data := append(hdr, pgdata...)
if outlen < len(data) {
data = data[:outlen]
}
cmd.Write(data)
return cmd.Ok(), nil
} | go | func EmulateModeSense(cmd *SCSICmd, wce bool) (SCSIResponse, error) {
pgs := &bytes.Buffer{}
outlen := int(cmd.XferLen())
page := cmd.GetCDB(2)
if page == 0x3f || page == 0x08 {
CachingModePage(pgs, wce)
}
scsiCmd := cmd.Command()
dsp := byte(0x10) // Support DPO/FUA
pgdata := pgs.Bytes()
var hdr []byte
if scsiCmd == scsi.ModeSense {
// MODE_SENSE_6
hdr = make([]byte, 4)
hdr[0] = byte(len(pgdata) + 3)
hdr[1] = 0x00 // Device type
hdr[2] = dsp
} else {
// MODE_SENSE_10
hdr = make([]byte, 8)
order := binary.BigEndian
order.PutUint16(hdr, uint16(len(pgdata)+6))
hdr[2] = 0x00 // Device type
hdr[3] = dsp
}
data := append(hdr, pgdata...)
if outlen < len(data) {
data = data[:outlen]
}
cmd.Write(data)
return cmd.Ok(), nil
} | [
"func",
"EmulateModeSense",
"(",
"cmd",
"*",
"SCSICmd",
",",
"wce",
"bool",
")",
"(",
"SCSIResponse",
",",
"error",
")",
"{",
"pgs",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"outlen",
":=",
"int",
"(",
"cmd",
".",
"XferLen",
"(",
")",
")"... | // EmulateModeSense responds to a static Mode Sense command. `wce` enables or diables
// the SCSI "Write Cache Enabled" flag. | [
"EmulateModeSense",
"responds",
"to",
"a",
"static",
"Mode",
"Sense",
"command",
".",
"wce",
"enables",
"or",
"diables",
"the",
"SCSI",
"Write",
"Cache",
"Enabled",
"flag",
"."
] | 51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726 | https://github.com/coreos/go-tcmu/blob/51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726/cmd_handler.go#L234-L268 |
16,932 | coreos/go-tcmu | cmd_handler.go | EmulateModeSelect | func EmulateModeSelect(cmd *SCSICmd, wce bool) (SCSIResponse, error) {
selectTen := (cmd.GetCDB(0) == scsi.ModeSelect10)
page := cmd.GetCDB(2) & 0x3f
subpage := cmd.GetCDB(3)
allocLen := cmd.XferLen()
hdrLen := 4
if selectTen {
hdrLen = 8
}
inBuf := make([]byte, 512)
gotSense := false
if allocLen == 0 {
return cmd.Ok(), nil
}
n, err := cmd.Read(inBuf)
if err != nil {
return SCSIResponse{}, err
}
if n >= len(inBuf) {
return cmd.CheckCondition(scsi.SenseIllegalRequest, scsi.AscParameterListLengthError), nil
}
cdbone := cmd.GetCDB(1)
if cdbone&0x10 == 0 || cdbone&0x01 != 0 {
return cmd.IllegalRequest(), nil
}
pgs := &bytes.Buffer{}
// TODO(barakmich): select over handlers. Today we have one.
if page == 0x08 && subpage == 0 {
CachingModePage(pgs, wce)
gotSense = true
}
if !gotSense {
return cmd.IllegalRequest(), nil
}
b := pgs.Bytes()
if int(allocLen) < (hdrLen + len(b)) {
return cmd.CheckCondition(scsi.SenseIllegalRequest, scsi.AscParameterListLengthError), nil
}
/* Verify what was selected is identical to what sense returns, since we
don't support actually setting anything. */
if !bytes.Equal(inBuf[hdrLen:len(b)], b) {
log.Errorf("not equal for some reason: %#v %#v", inBuf[hdrLen:len(b)], b)
return cmd.CheckCondition(scsi.SenseIllegalRequest, scsi.AscInvalidFieldInParameterList), nil
}
return cmd.Ok(), nil
} | go | func EmulateModeSelect(cmd *SCSICmd, wce bool) (SCSIResponse, error) {
selectTen := (cmd.GetCDB(0) == scsi.ModeSelect10)
page := cmd.GetCDB(2) & 0x3f
subpage := cmd.GetCDB(3)
allocLen := cmd.XferLen()
hdrLen := 4
if selectTen {
hdrLen = 8
}
inBuf := make([]byte, 512)
gotSense := false
if allocLen == 0 {
return cmd.Ok(), nil
}
n, err := cmd.Read(inBuf)
if err != nil {
return SCSIResponse{}, err
}
if n >= len(inBuf) {
return cmd.CheckCondition(scsi.SenseIllegalRequest, scsi.AscParameterListLengthError), nil
}
cdbone := cmd.GetCDB(1)
if cdbone&0x10 == 0 || cdbone&0x01 != 0 {
return cmd.IllegalRequest(), nil
}
pgs := &bytes.Buffer{}
// TODO(barakmich): select over handlers. Today we have one.
if page == 0x08 && subpage == 0 {
CachingModePage(pgs, wce)
gotSense = true
}
if !gotSense {
return cmd.IllegalRequest(), nil
}
b := pgs.Bytes()
if int(allocLen) < (hdrLen + len(b)) {
return cmd.CheckCondition(scsi.SenseIllegalRequest, scsi.AscParameterListLengthError), nil
}
/* Verify what was selected is identical to what sense returns, since we
don't support actually setting anything. */
if !bytes.Equal(inBuf[hdrLen:len(b)], b) {
log.Errorf("not equal for some reason: %#v %#v", inBuf[hdrLen:len(b)], b)
return cmd.CheckCondition(scsi.SenseIllegalRequest, scsi.AscInvalidFieldInParameterList), nil
}
return cmd.Ok(), nil
} | [
"func",
"EmulateModeSelect",
"(",
"cmd",
"*",
"SCSICmd",
",",
"wce",
"bool",
")",
"(",
"SCSIResponse",
",",
"error",
")",
"{",
"selectTen",
":=",
"(",
"cmd",
".",
"GetCDB",
"(",
"0",
")",
"==",
"scsi",
".",
"ModeSelect10",
")",
"\n",
"page",
":=",
"c... | // EmulateModeSelect checks that the only mode selected is the static one returned from
// EmulateModeSense. `wce` should match the Write Cache Enabled of the EmulateModeSense call. | [
"EmulateModeSelect",
"checks",
"that",
"the",
"only",
"mode",
"selected",
"is",
"the",
"static",
"one",
"returned",
"from",
"EmulateModeSense",
".",
"wce",
"should",
"match",
"the",
"Write",
"Cache",
"Enabled",
"of",
"the",
"EmulateModeSense",
"call",
"."
] | 51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726 | https://github.com/coreos/go-tcmu/blob/51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726/cmd_handler.go#L272-L320 |
16,933 | coreos/go-tcmu | scsi_handler.go | CdbLen | func (c *SCSICmd) CdbLen() int {
opcode := c.cdb[0]
// See spc-4 4.2.5.1 operation code
//
if opcode <= 0x1f {
return 6
} else if opcode <= 0x5f {
return 10
} else if opcode == 0x7f {
return int(c.cdb[7]) + 8
} else if opcode >= 0x80 && opcode <= 0x9f {
return 16
} else if opcode >= 0xa0 && opcode <= 0xbf {
return 12
}
panic(fmt.Sprintf("what opcode is %x", opcode))
} | go | func (c *SCSICmd) CdbLen() int {
opcode := c.cdb[0]
// See spc-4 4.2.5.1 operation code
//
if opcode <= 0x1f {
return 6
} else if opcode <= 0x5f {
return 10
} else if opcode == 0x7f {
return int(c.cdb[7]) + 8
} else if opcode >= 0x80 && opcode <= 0x9f {
return 16
} else if opcode >= 0xa0 && opcode <= 0xbf {
return 12
}
panic(fmt.Sprintf("what opcode is %x", opcode))
} | [
"func",
"(",
"c",
"*",
"SCSICmd",
")",
"CdbLen",
"(",
")",
"int",
"{",
"opcode",
":=",
"c",
".",
"cdb",
"[",
"0",
"]",
"\n",
"// See spc-4 4.2.5.1 operation code",
"//",
"if",
"opcode",
"<=",
"0x1f",
"{",
"return",
"6",
"\n",
"}",
"else",
"if",
"opco... | // CdbLen returns the length of the command, in bytes. | [
"CdbLen",
"returns",
"the",
"length",
"of",
"the",
"command",
"in",
"bytes",
"."
] | 51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726 | https://github.com/coreos/go-tcmu/blob/51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726/scsi_handler.go#L36-L52 |
16,934 | coreos/go-tcmu | scsi_handler.go | LBA | func (c *SCSICmd) LBA() uint64 {
order := binary.BigEndian
switch c.CdbLen() {
case 6:
val6 := uint8(order.Uint16(c.cdb[2:4]))
if val6 == 0 {
return 256
}
return uint64(val6)
case 10:
return uint64(order.Uint32(c.cdb[2:6]))
case 12:
return uint64(order.Uint32(c.cdb[2:6]))
case 16:
return uint64(order.Uint64(c.cdb[2:10]))
default:
log.Errorf("What LBA has this length: %d", c.CdbLen())
panic("unusal scsi command length")
}
} | go | func (c *SCSICmd) LBA() uint64 {
order := binary.BigEndian
switch c.CdbLen() {
case 6:
val6 := uint8(order.Uint16(c.cdb[2:4]))
if val6 == 0 {
return 256
}
return uint64(val6)
case 10:
return uint64(order.Uint32(c.cdb[2:6]))
case 12:
return uint64(order.Uint32(c.cdb[2:6]))
case 16:
return uint64(order.Uint64(c.cdb[2:10]))
default:
log.Errorf("What LBA has this length: %d", c.CdbLen())
panic("unusal scsi command length")
}
} | [
"func",
"(",
"c",
"*",
"SCSICmd",
")",
"LBA",
"(",
")",
"uint64",
"{",
"order",
":=",
"binary",
".",
"BigEndian",
"\n\n",
"switch",
"c",
".",
"CdbLen",
"(",
")",
"{",
"case",
"6",
":",
"val6",
":=",
"uint8",
"(",
"order",
".",
"Uint16",
"(",
"c",... | // LBA returns the block address that this command wishes to access. | [
"LBA",
"returns",
"the",
"block",
"address",
"that",
"this",
"command",
"wishes",
"to",
"access",
"."
] | 51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726 | https://github.com/coreos/go-tcmu/blob/51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726/scsi_handler.go#L55-L75 |
16,935 | coreos/go-tcmu | scsi_handler.go | Read | func (c *SCSICmd) Read(b []byte) (n int, err error) {
toRead := len(b)
boff := 0
for toRead != 0 {
if c.vecoffset == len(c.vecs) {
return boff, io.EOF
}
read := copy(b[boff:], c.vecs[c.vecoffset][c.offset:])
boff += read
toRead -= read
c.offset += read
if c.offset == len(c.vecs[c.vecoffset]) {
c.vecoffset++
c.offset = 0
}
}
return boff, nil
} | go | func (c *SCSICmd) Read(b []byte) (n int, err error) {
toRead := len(b)
boff := 0
for toRead != 0 {
if c.vecoffset == len(c.vecs) {
return boff, io.EOF
}
read := copy(b[boff:], c.vecs[c.vecoffset][c.offset:])
boff += read
toRead -= read
c.offset += read
if c.offset == len(c.vecs[c.vecoffset]) {
c.vecoffset++
c.offset = 0
}
}
return boff, nil
} | [
"func",
"(",
"c",
"*",
"SCSICmd",
")",
"Read",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"toRead",
":=",
"len",
"(",
"b",
")",
"\n",
"boff",
":=",
"0",
"\n",
"for",
"toRead",
"!=",
"0",
"{",
"if",
"c",... | // Read, for a SCSICmd, is a io.Reader from the data buffer attached to this SCSI command.
// If there's data to be written to the virtual device, this is the way to access it. | [
"Read",
"for",
"a",
"SCSICmd",
"is",
"a",
"io",
".",
"Reader",
"from",
"the",
"data",
"buffer",
"attached",
"to",
"this",
"SCSI",
"command",
".",
"If",
"there",
"s",
"data",
"to",
"be",
"written",
"to",
"the",
"virtual",
"device",
"this",
"is",
"the",
... | 51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726 | https://github.com/coreos/go-tcmu/blob/51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726/scsi_handler.go#L118-L135 |
16,936 | coreos/go-tcmu | scsi_handler.go | Ok | func (c *SCSICmd) Ok() SCSIResponse {
return SCSIResponse{
id: c.id,
status: scsi.SamStatGood,
}
} | go | func (c *SCSICmd) Ok() SCSIResponse {
return SCSIResponse{
id: c.id,
status: scsi.SamStatGood,
}
} | [
"func",
"(",
"c",
"*",
"SCSICmd",
")",
"Ok",
"(",
")",
"SCSIResponse",
"{",
"return",
"SCSIResponse",
"{",
"id",
":",
"c",
".",
"id",
",",
"status",
":",
"scsi",
".",
"SamStatGood",
",",
"}",
"\n",
"}"
] | // Ok creates a SCSIResponse to this command with SAM_STAT_GOOD, the common case for commands that succeed. | [
"Ok",
"creates",
"a",
"SCSIResponse",
"to",
"this",
"command",
"with",
"SAM_STAT_GOOD",
"the",
"common",
"case",
"for",
"commands",
"that",
"succeed",
"."
] | 51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726 | https://github.com/coreos/go-tcmu/blob/51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726/scsi_handler.go#L143-L148 |
16,937 | coreos/go-tcmu | scsi_handler.go | RespondSenseData | func (c *SCSICmd) RespondSenseData(status byte, sense []byte) SCSIResponse {
return SCSIResponse{
id: c.id,
status: status,
senseBuffer: sense,
}
} | go | func (c *SCSICmd) RespondSenseData(status byte, sense []byte) SCSIResponse {
return SCSIResponse{
id: c.id,
status: status,
senseBuffer: sense,
}
} | [
"func",
"(",
"c",
"*",
"SCSICmd",
")",
"RespondSenseData",
"(",
"status",
"byte",
",",
"sense",
"[",
"]",
"byte",
")",
"SCSIResponse",
"{",
"return",
"SCSIResponse",
"{",
"id",
":",
"c",
".",
"id",
",",
"status",
":",
"status",
",",
"senseBuffer",
":",... | // RespondSenseData returns a SCSIResponse with the given status byte set and takes a byte array representing the SCSI sense data to be written. | [
"RespondSenseData",
"returns",
"a",
"SCSIResponse",
"with",
"the",
"given",
"status",
"byte",
"set",
"and",
"takes",
"a",
"byte",
"array",
"representing",
"the",
"SCSI",
"sense",
"data",
"to",
"be",
"written",
"."
] | 51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726 | https://github.com/coreos/go-tcmu/blob/51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726/scsi_handler.go#L164-L170 |
16,938 | coreos/go-tcmu | scsi_handler.go | NotHandled | func (c *SCSICmd) NotHandled() SCSIResponse {
buf := make([]byte, tcmuSenseBufferSize)
buf[0] = 0x70 /* fixed, current */
buf[2] = 0x5 /* illegal request */
buf[7] = 0xa
buf[12] = 0x20 /* ASC: invalid command operation code */
buf[13] = 0x0 /* ASCQ: (none) */
return SCSIResponse{
id: c.id,
status: scsi.SamStatCheckCondition,
senseBuffer: buf,
}
} | go | func (c *SCSICmd) NotHandled() SCSIResponse {
buf := make([]byte, tcmuSenseBufferSize)
buf[0] = 0x70 /* fixed, current */
buf[2] = 0x5 /* illegal request */
buf[7] = 0xa
buf[12] = 0x20 /* ASC: invalid command operation code */
buf[13] = 0x0 /* ASCQ: (none) */
return SCSIResponse{
id: c.id,
status: scsi.SamStatCheckCondition,
senseBuffer: buf,
}
} | [
"func",
"(",
"c",
"*",
"SCSICmd",
")",
"NotHandled",
"(",
")",
"SCSIResponse",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"tcmuSenseBufferSize",
")",
"\n",
"buf",
"[",
"0",
"]",
"=",
"0x70",
"/* fixed, current */",
"\n",
"buf",
"[",
"2",
"... | // NotHandled creates a response and sense data that tells the kernel this device does not emulate this command. | [
"NotHandled",
"creates",
"a",
"response",
"and",
"sense",
"data",
"that",
"tells",
"the",
"kernel",
"this",
"device",
"does",
"not",
"emulate",
"this",
"command",
"."
] | 51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726 | https://github.com/coreos/go-tcmu/blob/51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726/scsi_handler.go#L173-L186 |
16,939 | coreos/go-tcmu | scsi_handler.go | CheckCondition | func (c *SCSICmd) CheckCondition(key byte, asc uint16) SCSIResponse {
buf := make([]byte, tcmuSenseBufferSize)
buf[0] = 0x70 /* fixed, current */
buf[2] = key
buf[7] = 0xa
buf[12] = byte(uint8((asc >> 8) & 0xff))
buf[13] = byte(uint8(asc & 0xff))
return SCSIResponse{
id: c.id,
status: scsi.SamStatCheckCondition,
senseBuffer: buf,
}
} | go | func (c *SCSICmd) CheckCondition(key byte, asc uint16) SCSIResponse {
buf := make([]byte, tcmuSenseBufferSize)
buf[0] = 0x70 /* fixed, current */
buf[2] = key
buf[7] = 0xa
buf[12] = byte(uint8((asc >> 8) & 0xff))
buf[13] = byte(uint8(asc & 0xff))
return SCSIResponse{
id: c.id,
status: scsi.SamStatCheckCondition,
senseBuffer: buf,
}
} | [
"func",
"(",
"c",
"*",
"SCSICmd",
")",
"CheckCondition",
"(",
"key",
"byte",
",",
"asc",
"uint16",
")",
"SCSIResponse",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"tcmuSenseBufferSize",
")",
"\n",
"buf",
"[",
"0",
"]",
"=",
"0x70",
"/* fix... | // CheckCondition returns a response providing extra sense data. Takes a Sense Key and an Additional Sense Code. | [
"CheckCondition",
"returns",
"a",
"response",
"providing",
"extra",
"sense",
"data",
".",
"Takes",
"a",
"Sense",
"Key",
"and",
"an",
"Additional",
"Sense",
"Code",
"."
] | 51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726 | https://github.com/coreos/go-tcmu/blob/51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726/scsi_handler.go#L189-L201 |
16,940 | coreos/go-tcmu | scsi_handler.go | MediumError | func (c *SCSICmd) MediumError() SCSIResponse {
return c.CheckCondition(scsi.SenseMediumError, scsi.AscReadError)
} | go | func (c *SCSICmd) MediumError() SCSIResponse {
return c.CheckCondition(scsi.SenseMediumError, scsi.AscReadError)
} | [
"func",
"(",
"c",
"*",
"SCSICmd",
")",
"MediumError",
"(",
")",
"SCSIResponse",
"{",
"return",
"c",
".",
"CheckCondition",
"(",
"scsi",
".",
"SenseMediumError",
",",
"scsi",
".",
"AscReadError",
")",
"\n",
"}"
] | // MediumError is a preset response for a read error condition from the device | [
"MediumError",
"is",
"a",
"preset",
"response",
"for",
"a",
"read",
"error",
"condition",
"from",
"the",
"device"
] | 51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726 | https://github.com/coreos/go-tcmu/blob/51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726/scsi_handler.go#L204-L206 |
16,941 | coreos/go-tcmu | scsi_handler.go | IllegalRequest | func (c *SCSICmd) IllegalRequest() SCSIResponse {
return c.CheckCondition(scsi.SenseIllegalRequest, scsi.AscInvalidFieldInCdb)
} | go | func (c *SCSICmd) IllegalRequest() SCSIResponse {
return c.CheckCondition(scsi.SenseIllegalRequest, scsi.AscInvalidFieldInCdb)
} | [
"func",
"(",
"c",
"*",
"SCSICmd",
")",
"IllegalRequest",
"(",
")",
"SCSIResponse",
"{",
"return",
"c",
".",
"CheckCondition",
"(",
"scsi",
".",
"SenseIllegalRequest",
",",
"scsi",
".",
"AscInvalidFieldInCdb",
")",
"\n",
"}"
] | // IllegalRequest is a preset response for a request that is malformed or unexpected. | [
"IllegalRequest",
"is",
"a",
"preset",
"response",
"for",
"a",
"request",
"that",
"is",
"malformed",
"or",
"unexpected",
"."
] | 51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726 | https://github.com/coreos/go-tcmu/blob/51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726/scsi_handler.go#L209-L211 |
16,942 | coreos/go-tcmu | scsi_handler.go | TargetFailure | func (c *SCSICmd) TargetFailure() SCSIResponse {
return c.CheckCondition(scsi.SenseHardwareError, scsi.AscInternalTargetFailure)
} | go | func (c *SCSICmd) TargetFailure() SCSIResponse {
return c.CheckCondition(scsi.SenseHardwareError, scsi.AscInternalTargetFailure)
} | [
"func",
"(",
"c",
"*",
"SCSICmd",
")",
"TargetFailure",
"(",
")",
"SCSIResponse",
"{",
"return",
"c",
".",
"CheckCondition",
"(",
"scsi",
".",
"SenseHardwareError",
",",
"scsi",
".",
"AscInternalTargetFailure",
")",
"\n",
"}"
] | // TargetFailure is a preset response for returning a hardware error. | [
"TargetFailure",
"is",
"a",
"preset",
"response",
"for",
"returning",
"a",
"hardware",
"error",
"."
] | 51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726 | https://github.com/coreos/go-tcmu/blob/51bcb4f0f3a2dc05fb66b23069e58ee2ab08c726/scsi_handler.go#L214-L216 |
16,943 | hsanjuan/go-libp2p-http | p2phttp.go | ProtocolOption | func ProtocolOption(p protocol.ID) Option {
return func(o *options) {
o.Protocol = p
}
} | go | func ProtocolOption(p protocol.ID) Option {
return func(o *options) {
o.Protocol = p
}
} | [
"func",
"ProtocolOption",
"(",
"p",
"protocol",
".",
"ID",
")",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"options",
")",
"{",
"o",
".",
"Protocol",
"=",
"p",
"\n",
"}",
"\n",
"}"
] | // ProtocolOption sets the Protocol Tag associated to the libp2p roundtripper. | [
"ProtocolOption",
"sets",
"the",
"Protocol",
"Tag",
"associated",
"to",
"the",
"libp2p",
"roundtripper",
"."
] | f53827a3f0ba3acaa10f64cc9c425021c8ebfc34 | https://github.com/hsanjuan/go-libp2p-http/blob/f53827a3f0ba3acaa10f64cc9c425021c8ebfc34/p2phttp.go#L73-L77 |
16,944 | hsanjuan/go-libp2p-http | p2phttp.go | Close | func (rb *respBody) Close() error {
rb.conn.Close()
return rb.ReadCloser.Close()
} | go | func (rb *respBody) Close() error {
rb.conn.Close()
return rb.ReadCloser.Close()
} | [
"func",
"(",
"rb",
"*",
"respBody",
")",
"Close",
"(",
")",
"error",
"{",
"rb",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"return",
"rb",
".",
"ReadCloser",
".",
"Close",
"(",
")",
"\n",
"}"
] | // Closes the response's body and the connection. | [
"Closes",
"the",
"response",
"s",
"body",
"and",
"the",
"connection",
"."
] | f53827a3f0ba3acaa10f64cc9c425021c8ebfc34 | https://github.com/hsanjuan/go-libp2p-http/blob/f53827a3f0ba3acaa10f64cc9c425021c8ebfc34/p2phttp.go#L115-L118 |
16,945 | muesli/crunchy | crunchy.go | NewValidatorWithOpts | func NewValidatorWithOpts(options Options) *Validator {
if options.MinLength <= 0 {
options.MinLength = 8
}
if options.MinDiff <= 0 {
options.MinDiff = 5
}
if options.MinDist < 0 {
options.MinDist = 3
}
return &Validator{
options: options,
words: make(map[string]struct{}),
hashedWords: make(map[string]string),
}
} | go | func NewValidatorWithOpts(options Options) *Validator {
if options.MinLength <= 0 {
options.MinLength = 8
}
if options.MinDiff <= 0 {
options.MinDiff = 5
}
if options.MinDist < 0 {
options.MinDist = 3
}
return &Validator{
options: options,
words: make(map[string]struct{}),
hashedWords: make(map[string]string),
}
} | [
"func",
"NewValidatorWithOpts",
"(",
"options",
"Options",
")",
"*",
"Validator",
"{",
"if",
"options",
".",
"MinLength",
"<=",
"0",
"{",
"options",
".",
"MinLength",
"=",
"8",
"\n",
"}",
"\n",
"if",
"options",
".",
"MinDiff",
"<=",
"0",
"{",
"options",
... | // NewValidatorWithOpts returns a new password validator with custom settings | [
"NewValidatorWithOpts",
"returns",
"a",
"new",
"password",
"validator",
"with",
"custom",
"settings"
] | ee5032c9b35b57a43c16bfbab8196051a5bcb1d9 | https://github.com/muesli/crunchy/blob/ee5032c9b35b57a43c16bfbab8196051a5bcb1d9/crunchy.go#L54-L70 |
16,946 | muesli/crunchy | crunchy.go | Check | func (v *Validator) Check(password string) error {
if strings.TrimSpace(password) == "" {
return ErrEmpty
}
if len(password) < v.options.MinLength {
return ErrTooShort
}
if countUniqueChars(password) < v.options.MinDiff {
return ErrTooFewChars
}
// Inspired by cracklib
maxrepeat := 3.0 + (0.09 * float64(len(password)))
if countSystematicChars(password) > int(maxrepeat) {
return ErrTooSystematic
}
return v.foundInDictionaries(password)
} | go | func (v *Validator) Check(password string) error {
if strings.TrimSpace(password) == "" {
return ErrEmpty
}
if len(password) < v.options.MinLength {
return ErrTooShort
}
if countUniqueChars(password) < v.options.MinDiff {
return ErrTooFewChars
}
// Inspired by cracklib
maxrepeat := 3.0 + (0.09 * float64(len(password)))
if countSystematicChars(password) > int(maxrepeat) {
return ErrTooSystematic
}
return v.foundInDictionaries(password)
} | [
"func",
"(",
"v",
"*",
"Validator",
")",
"Check",
"(",
"password",
"string",
")",
"error",
"{",
"if",
"strings",
".",
"TrimSpace",
"(",
"password",
")",
"==",
"\"",
"\"",
"{",
"return",
"ErrEmpty",
"\n",
"}",
"\n",
"if",
"len",
"(",
"password",
")",
... | // Check validates a password for common flaws
// It returns nil if the password is considered acceptable. | [
"Check",
"validates",
"a",
"password",
"for",
"common",
"flaws",
"It",
"returns",
"nil",
"if",
"the",
"password",
"is",
"considered",
"acceptable",
"."
] | ee5032c9b35b57a43c16bfbab8196051a5bcb1d9 | https://github.com/muesli/crunchy/blob/ee5032c9b35b57a43c16bfbab8196051a5bcb1d9/crunchy.go#L151-L169 |
16,947 | muesli/crunchy | stringutils.go | countUniqueChars | func countUniqueChars(s string) int {
m := make(map[rune]struct{})
for _, c := range s {
c = unicode.ToLower(c)
if _, ok := m[c]; !ok {
m[c] = struct{}{}
}
}
return len(m)
} | go | func countUniqueChars(s string) int {
m := make(map[rune]struct{})
for _, c := range s {
c = unicode.ToLower(c)
if _, ok := m[c]; !ok {
m[c] = struct{}{}
}
}
return len(m)
} | [
"func",
"countUniqueChars",
"(",
"s",
"string",
")",
"int",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"rune",
"]",
"struct",
"{",
"}",
")",
"\n\n",
"for",
"_",
",",
"c",
":=",
"range",
"s",
"{",
"c",
"=",
"unicode",
".",
"ToLower",
"(",
"c",
")"... | // countUniqueChars returns the amount of unique runes in a string | [
"countUniqueChars",
"returns",
"the",
"amount",
"of",
"unique",
"runes",
"in",
"a",
"string"
] | ee5032c9b35b57a43c16bfbab8196051a5bcb1d9 | https://github.com/muesli/crunchy/blob/ee5032c9b35b57a43c16bfbab8196051a5bcb1d9/stringutils.go#L19-L30 |
16,948 | muesli/crunchy | stringutils.go | reverse | func reverse(s string) string {
var rs []rune
for len(s) > 0 {
r, size := utf8.DecodeLastRuneInString(s)
s = s[:len(s)-size]
rs = append(rs, r)
}
return string(rs)
} | go | func reverse(s string) string {
var rs []rune
for len(s) > 0 {
r, size := utf8.DecodeLastRuneInString(s)
s = s[:len(s)-size]
rs = append(rs, r)
}
return string(rs)
} | [
"func",
"reverse",
"(",
"s",
"string",
")",
"string",
"{",
"var",
"rs",
"[",
"]",
"rune",
"\n",
"for",
"len",
"(",
"s",
")",
">",
"0",
"{",
"r",
",",
"size",
":=",
"utf8",
".",
"DecodeLastRuneInString",
"(",
"s",
")",
"\n",
"s",
"=",
"s",
"[",
... | // reverse returns the reversed form of a string | [
"reverse",
"returns",
"the",
"reversed",
"form",
"of",
"a",
"string"
] | ee5032c9b35b57a43c16bfbab8196051a5bcb1d9 | https://github.com/muesli/crunchy/blob/ee5032c9b35b57a43c16bfbab8196051a5bcb1d9/stringutils.go#L50-L60 |
16,949 | muesli/crunchy | stringutils.go | hashsum | func hashsum(s string, hasher hash.Hash) string {
hasher.Reset()
hasher.Write([]byte(s))
return hex.EncodeToString(hasher.Sum(nil))
} | go | func hashsum(s string, hasher hash.Hash) string {
hasher.Reset()
hasher.Write([]byte(s))
return hex.EncodeToString(hasher.Sum(nil))
} | [
"func",
"hashsum",
"(",
"s",
"string",
",",
"hasher",
"hash",
".",
"Hash",
")",
"string",
"{",
"hasher",
".",
"Reset",
"(",
")",
"\n",
"hasher",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"s",
")",
")",
"\n",
"return",
"hex",
".",
"EncodeToString",
... | // hashsum returns the hashed sum of a string | [
"hashsum",
"returns",
"the",
"hashed",
"sum",
"of",
"a",
"string"
] | ee5032c9b35b57a43c16bfbab8196051a5bcb1d9 | https://github.com/muesli/crunchy/blob/ee5032c9b35b57a43c16bfbab8196051a5bcb1d9/stringutils.go#L68-L72 |
16,950 | stampzilla/gozwave | serialrecorder/serialrecorder.go | New | func New(port string, baud int) *serialRecorder {
return &serialRecorder{
port: port,
baud: baud,
Logger: os.Stdout,
writeBuffer: make(chan *Row, 100),
}
} | go | func New(port string, baud int) *serialRecorder {
return &serialRecorder{
port: port,
baud: baud,
Logger: os.Stdout,
writeBuffer: make(chan *Row, 100),
}
} | [
"func",
"New",
"(",
"port",
"string",
",",
"baud",
"int",
")",
"*",
"serialRecorder",
"{",
"return",
"&",
"serialRecorder",
"{",
"port",
":",
"port",
",",
"baud",
":",
"baud",
",",
"Logger",
":",
"os",
".",
"Stdout",
",",
"writeBuffer",
":",
"make",
... | // New returns a new serialRecorder that implements PortOpener for serial port that will record and output each write and read to stdout | [
"New",
"returns",
"a",
"new",
"serialRecorder",
"that",
"implements",
"PortOpener",
"for",
"serial",
"port",
"that",
"will",
"record",
"and",
"output",
"each",
"write",
"and",
"read",
"to",
"stdout"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/serialrecorder/serialrecorder.go#L30-L37 |
16,951 | stampzilla/gozwave | commands/raw.go | Encode | func (r Raw) Encode() []byte {
return append([]byte{
0x13, // SendData // TODO: use functions.SendData somehow without import cycle
byte(r.node), // Node id
byte(len(r.data) + 1), // Length
}, r.data...)
} | go | func (r Raw) Encode() []byte {
return append([]byte{
0x13, // SendData // TODO: use functions.SendData somehow without import cycle
byte(r.node), // Node id
byte(len(r.data) + 1), // Length
}, r.data...)
} | [
"func",
"(",
"r",
"Raw",
")",
"Encode",
"(",
")",
"[",
"]",
"byte",
"{",
"return",
"append",
"(",
"[",
"]",
"byte",
"{",
"0x13",
",",
"// SendData // TODO: use functions.SendData somehow without import cycle",
"byte",
"(",
"r",
".",
"node",
")",
",",
"// Nod... | // Encode make sure we implement the Encodable interface | [
"Encode",
"make",
"sure",
"we",
"implement",
"the",
"Encodable",
"interface"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/commands/raw.go#L15-L22 |
16,952 | stampzilla/gozwave | serialapi/message.go | Decode | func Decode(data []byte) (length int, msg *Message, err error) {
// SOF 0x01 1 Start Of Frame
// ACK 0x06 6 Message Ack
// NAK 0x15 21 Message NAK
// CAN 0x18 24 Cancel - Resend request
switch data[0] {
case 0x01: // SOF
if len(data) < 2 {
return 2, nil, nil
}
length := int(data[1])
if len(data) < length+2 { // Make shure we have the full message
return length + 2, nil, nil
}
checksum := data[length+1]
checksumData := append(data[1:length+1], byte(0x00))
if checksum != GenerateChecksum(checksumData) {
return -1, nil, fmt.Errorf("Invalid checksum, is 0x%x should be 0x%x, (len=%d)", checksum, GenerateChecksum(checksumData), length)
}
msg, err := NewMessage(data)
return length + 2, msg, err
case 0x06, 0x15, 0x18: // ACK, NAC, CAN
msg, err := NewMessage(data)
if err != nil {
logrus.Error(err)
}
return 1, msg, nil
}
return -1, nil, nil // Not a valid start char
} | go | func Decode(data []byte) (length int, msg *Message, err error) {
// SOF 0x01 1 Start Of Frame
// ACK 0x06 6 Message Ack
// NAK 0x15 21 Message NAK
// CAN 0x18 24 Cancel - Resend request
switch data[0] {
case 0x01: // SOF
if len(data) < 2 {
return 2, nil, nil
}
length := int(data[1])
if len(data) < length+2 { // Make shure we have the full message
return length + 2, nil, nil
}
checksum := data[length+1]
checksumData := append(data[1:length+1], byte(0x00))
if checksum != GenerateChecksum(checksumData) {
return -1, nil, fmt.Errorf("Invalid checksum, is 0x%x should be 0x%x, (len=%d)", checksum, GenerateChecksum(checksumData), length)
}
msg, err := NewMessage(data)
return length + 2, msg, err
case 0x06, 0x15, 0x18: // ACK, NAC, CAN
msg, err := NewMessage(data)
if err != nil {
logrus.Error(err)
}
return 1, msg, nil
}
return -1, nil, nil // Not a valid start char
} | [
"func",
"Decode",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"length",
"int",
",",
"msg",
"*",
"Message",
",",
"err",
"error",
")",
"{",
"// SOF\t0x01\t1\tStart Of Frame",
"// ACK\t0x06\t6\tMessage Ack",
"// NAK\t0x15\t21\tMessage NAK",
"// CAN\t0x18\t24\tCancel - Resend ... | // Decode decodes serialapi raw data | [
"Decode",
"decodes",
"serialapi",
"raw",
"data"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/serialapi/message.go#L36-L70 |
16,953 | stampzilla/gozwave | serialapi/message.go | GenerateChecksum | func GenerateChecksum(data []byte) byte {
var offset int
ret := data[offset]
for i := offset + 1; i < len(data)-1; i++ {
// Xor bytes
ret ^= data[i]
}
// Not result
ret = (byte)(^ret)
return ret
} | go | func GenerateChecksum(data []byte) byte {
var offset int
ret := data[offset]
for i := offset + 1; i < len(data)-1; i++ {
// Xor bytes
ret ^= data[i]
}
// Not result
ret = (byte)(^ret)
return ret
} | [
"func",
"GenerateChecksum",
"(",
"data",
"[",
"]",
"byte",
")",
"byte",
"{",
"var",
"offset",
"int",
"\n",
"ret",
":=",
"data",
"[",
"offset",
"]",
"\n",
"for",
"i",
":=",
"offset",
"+",
"1",
";",
"i",
"<",
"len",
"(",
"data",
")",
"-",
"1",
";... | // GenerateChecksum calculates the checksum for a serialapi message | [
"GenerateChecksum",
"calculates",
"the",
"checksum",
"for",
"a",
"serialapi",
"message"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/serialapi/message.go#L73-L83 |
16,954 | stampzilla/gozwave | serialapi/message.go | CompileMessage | func CompileMessage(data []byte) []byte {
// Compile message
msg := append([]byte{0x00, 0x00}, data...)
msg = append(msg, 0x00)
// Add length
msg[0] = byte(len(msg) - 1)
// Add checksum
msg[len(msg)-1] = GenerateChecksum(msg)
// Add header
msg = append([]byte{0x01}, msg...)
return msg
} | go | func CompileMessage(data []byte) []byte {
// Compile message
msg := append([]byte{0x00, 0x00}, data...)
msg = append(msg, 0x00)
// Add length
msg[0] = byte(len(msg) - 1)
// Add checksum
msg[len(msg)-1] = GenerateChecksum(msg)
// Add header
msg = append([]byte{0x01}, msg...)
return msg
} | [
"func",
"CompileMessage",
"(",
"data",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"// Compile message",
"msg",
":=",
"append",
"(",
"[",
"]",
"byte",
"{",
"0x00",
",",
"0x00",
"}",
",",
"data",
"...",
")",
"\n",
"msg",
"=",
"append",
"(",
"msg",... | // CompileMessage is used to calculate length and checksum for messages that are going to be sent to the controller | [
"CompileMessage",
"is",
"used",
"to",
"calculate",
"length",
"and",
"checksum",
"for",
"messages",
"that",
"are",
"going",
"to",
"be",
"sent",
"to",
"the",
"controller"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/serialapi/message.go#L86-L101 |
16,955 | stampzilla/gozwave | serialapi/message.go | NewMessage | func NewMessage(data []byte) (*Message, error) {
message := &Message{}
message.startByte = data[0]
if len(data) <= 1 {
return message, nil
}
message.Length = data[1]
message.MessageType = data[2]
message.Function = ZWaveFunction(data[3])
var err error
switch message.Function {
case ApplicationCommandHandler:
message.NodeID = data[5]
message.Data, err = NewApplicationCommandHandler(data[7 : 7+data[6]])
case DiscoveryNodes:
message.Data, err = NewDiscoverdNodes(data[7 : 7+data[6]])
case GetNodeProtocolInfo:
message.Data, err = NewGetNodeProtocolInfo(data[4:])
default:
err = fmt.Errorf("Dropping message function='%s' with data %x (not implemented)", message.Function, data[4:])
}
if err != nil {
return nil, err
}
logrus.Debugf("Message: %+v Message data: %+v", message, message.Data)
return message, err
// 1 FrameHeader (type of message)
// 1 Message length
// 1 Request (00) or Response (01)
// 1 Function
//
// 1 (Node ID)
// 1 (Command - length)
// - (Command)
// - (Transmit options)
// - (Callback id)
// 1 Checksum
// Type
//Request = 0x00,
//Response = 0x01,
//GetVersion = 0x15,
//MemoryGetId = 0x20,
//ClockSet = 0x30
// Transmit options
//Ack = 0x01,
//LowPower = 0x02,
//AutoRoute = 0x04,
//ForceRoute = 0x08
} | go | func NewMessage(data []byte) (*Message, error) {
message := &Message{}
message.startByte = data[0]
if len(data) <= 1 {
return message, nil
}
message.Length = data[1]
message.MessageType = data[2]
message.Function = ZWaveFunction(data[3])
var err error
switch message.Function {
case ApplicationCommandHandler:
message.NodeID = data[5]
message.Data, err = NewApplicationCommandHandler(data[7 : 7+data[6]])
case DiscoveryNodes:
message.Data, err = NewDiscoverdNodes(data[7 : 7+data[6]])
case GetNodeProtocolInfo:
message.Data, err = NewGetNodeProtocolInfo(data[4:])
default:
err = fmt.Errorf("Dropping message function='%s' with data %x (not implemented)", message.Function, data[4:])
}
if err != nil {
return nil, err
}
logrus.Debugf("Message: %+v Message data: %+v", message, message.Data)
return message, err
// 1 FrameHeader (type of message)
// 1 Message length
// 1 Request (00) or Response (01)
// 1 Function
//
// 1 (Node ID)
// 1 (Command - length)
// - (Command)
// - (Transmit options)
// - (Callback id)
// 1 Checksum
// Type
//Request = 0x00,
//Response = 0x01,
//GetVersion = 0x15,
//MemoryGetId = 0x20,
//ClockSet = 0x30
// Transmit options
//Ack = 0x01,
//LowPower = 0x02,
//AutoRoute = 0x04,
//ForceRoute = 0x08
} | [
"func",
"NewMessage",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"Message",
",",
"error",
")",
"{",
"message",
":=",
"&",
"Message",
"{",
"}",
"\n",
"message",
".",
"startByte",
"=",
"data",
"[",
"0",
"]",
"\n",
"if",
"len",
"(",
"data",
")",
... | // NewMessage tries to decode a binary message from the controller in to a message struct | [
"NewMessage",
"tries",
"to",
"decode",
"a",
"binary",
"message",
"from",
"the",
"controller",
"in",
"to",
"a",
"message",
"struct"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/serialapi/message.go#L104-L162 |
16,956 | stampzilla/gozwave | serialapi/application_command_handler.go | NewApplicationCommandHandler | func NewApplicationCommandHandler(data []byte) (*FuncApplicationCommandHandler, error) {
f := &FuncApplicationCommandHandler{}
f.Command = commands.ZWaveCommand(data[0])
f.Class = data[1]
var err error
f.Report, err = reports.New(f.Command, f.Class, data[2:])
if err != nil {
return nil, err
}
if report, ok := f.Report.(reports.Report); ok && report != nil {
report.SetNode(f.Node)
}
return f, nil
} | go | func NewApplicationCommandHandler(data []byte) (*FuncApplicationCommandHandler, error) {
f := &FuncApplicationCommandHandler{}
f.Command = commands.ZWaveCommand(data[0])
f.Class = data[1]
var err error
f.Report, err = reports.New(f.Command, f.Class, data[2:])
if err != nil {
return nil, err
}
if report, ok := f.Report.(reports.Report); ok && report != nil {
report.SetNode(f.Node)
}
return f, nil
} | [
"func",
"NewApplicationCommandHandler",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"FuncApplicationCommandHandler",
",",
"error",
")",
"{",
"f",
":=",
"&",
"FuncApplicationCommandHandler",
"{",
"}",
"\n\n",
"f",
".",
"Command",
"=",
"commands",
".",
"ZWaveC... | // NewApplicationCommandHandler decodes and creates a funcApplicationCommandHandler. This is the most common message from the controller. Its sent everytime a report are received from the zwave network. | [
"NewApplicationCommandHandler",
"decodes",
"and",
"creates",
"a",
"funcApplicationCommandHandler",
".",
"This",
"is",
"the",
"most",
"common",
"message",
"from",
"the",
"controller",
".",
"Its",
"sent",
"everytime",
"a",
"report",
"are",
"received",
"from",
"the",
... | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/serialapi/application_command_handler.go#L17-L34 |
16,957 | stampzilla/gozwave | commands/reports/alarm.go | NewAlarm | func NewAlarm(data []byte) (*Alarm, error) {
a := &Alarm{data: data}
if len(data) < 2 {
return nil, fmt.Errorf("To short, expected at least 2 byte")
}
a.Type = data[0]
a.Level = data[1]
if len(data) >= 6 {
a.SensorSourceID = data[2]
a.Status = data[3]
a.SensorType = data[4]
a.Event = data[5]
}
// Version 2
if len(data) >= 9 {
}
return a, nil
} | go | func NewAlarm(data []byte) (*Alarm, error) {
a := &Alarm{data: data}
if len(data) < 2 {
return nil, fmt.Errorf("To short, expected at least 2 byte")
}
a.Type = data[0]
a.Level = data[1]
if len(data) >= 6 {
a.SensorSourceID = data[2]
a.Status = data[3]
a.SensorType = data[4]
a.Event = data[5]
}
// Version 2
if len(data) >= 9 {
}
return a, nil
} | [
"func",
"NewAlarm",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"Alarm",
",",
"error",
")",
"{",
"a",
":=",
"&",
"Alarm",
"{",
"data",
":",
"data",
"}",
"\n\n",
"if",
"len",
"(",
"data",
")",
"<",
"2",
"{",
"return",
"nil",
",",
"fmt",
".",... | // NewAlarm creates a new alarm report. | [
"NewAlarm",
"creates",
"a",
"new",
"alarm",
"report",
"."
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/commands/reports/alarm.go#L19-L41 |
16,958 | stampzilla/gozwave | commands/reports/report.go | New | func New(c commands.ZWaveCommand, class byte, data []byte) (Report, error) {
switch c {
case commands.Alarm:
switch class {
case 0x05: // Report
return NewAlarm(data)
}
case commands.ManufacturerSpecific:
switch class {
case 0x05: // Report
return NewManufacturerSpecific(data)
}
case commands.MultiInstance:
switch class {
case 0x08: // MultiChannelCmd_EndPointReport
return NewMultiChannelEndpoints(data)
}
case commands.SensorMultiLevel:
switch class {
case 0x05: // Report
return NewSensorMultiLevel(data)
}
case commands.SwitchBinary:
switch class {
case 0x03: // Report
switch len(data) {
case 1:
return NewSwitchBinaryV1(data)
case 3:
return NewSwitchBinaryV2(data)
}
}
case commands.SwitchMultilevel:
switch class {
case 0x03: // Report
switch len(data) {
case 1:
return NewSwitchMultilevelV1(data)
// V2 reports is same as V1
// V3 reports is depreciated and is not recomended to implement by sigma designs
case 3:
return NewSwitchMultilevelV4(data)
}
}
case commands.WakeUp:
return NewWakeUp()
}
return nil, fmt.Errorf("Unknown command (%x - %s) / command class (%x)", byte(c), c, class)
} | go | func New(c commands.ZWaveCommand, class byte, data []byte) (Report, error) {
switch c {
case commands.Alarm:
switch class {
case 0x05: // Report
return NewAlarm(data)
}
case commands.ManufacturerSpecific:
switch class {
case 0x05: // Report
return NewManufacturerSpecific(data)
}
case commands.MultiInstance:
switch class {
case 0x08: // MultiChannelCmd_EndPointReport
return NewMultiChannelEndpoints(data)
}
case commands.SensorMultiLevel:
switch class {
case 0x05: // Report
return NewSensorMultiLevel(data)
}
case commands.SwitchBinary:
switch class {
case 0x03: // Report
switch len(data) {
case 1:
return NewSwitchBinaryV1(data)
case 3:
return NewSwitchBinaryV2(data)
}
}
case commands.SwitchMultilevel:
switch class {
case 0x03: // Report
switch len(data) {
case 1:
return NewSwitchMultilevelV1(data)
// V2 reports is same as V1
// V3 reports is depreciated and is not recomended to implement by sigma designs
case 3:
return NewSwitchMultilevelV4(data)
}
}
case commands.WakeUp:
return NewWakeUp()
}
return nil, fmt.Errorf("Unknown command (%x - %s) / command class (%x)", byte(c), c, class)
} | [
"func",
"New",
"(",
"c",
"commands",
".",
"ZWaveCommand",
",",
"class",
"byte",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"Report",
",",
"error",
")",
"{",
"switch",
"c",
"{",
"case",
"commands",
".",
"Alarm",
":",
"switch",
"class",
"{",
"case",
"0... | // New creates a new report based on command, command class and data | [
"New",
"creates",
"a",
"new",
"report",
"based",
"on",
"command",
"command",
"class",
"and",
"data"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/commands/reports/report.go#L28-L77 |
16,959 | stampzilla/gozwave | serialapi/get_node_protocolinfo.go | NewGetNodeProtocolInfo | func NewGetNodeProtocolInfo(data []byte) (*FuncGetNodeProtocolInfo, error) {
pi := &FuncGetNodeProtocolInfo{}
if len(data) < 6 {
return nil, fmt.Errorf("wrong length, should be at least 6 bytes got len %d data: %x", len(data), data)
}
// Capabilities
pi.Listening = data[0]&0x80 != 0
pi.Routing = data[0]&0x40 != 0
pi.Version = data[0]&0x07 + 1
pi.MaxBaud = 9600
if data[0]&0x38 == 0x10 {
pi.MaxBaud = 40000
}
// Security
pi.Flirs = data[1]&0x60 != 0
pi.Beaming = data[1]&0x10 != 0
pi.Security = data[1]&0x01 != 0
// data[2] - reserved
pi.Basic = data[3]
pi.Generic = data[4]
pi.Specific = data[5]
return pi, nil
} | go | func NewGetNodeProtocolInfo(data []byte) (*FuncGetNodeProtocolInfo, error) {
pi := &FuncGetNodeProtocolInfo{}
if len(data) < 6 {
return nil, fmt.Errorf("wrong length, should be at least 6 bytes got len %d data: %x", len(data), data)
}
// Capabilities
pi.Listening = data[0]&0x80 != 0
pi.Routing = data[0]&0x40 != 0
pi.Version = data[0]&0x07 + 1
pi.MaxBaud = 9600
if data[0]&0x38 == 0x10 {
pi.MaxBaud = 40000
}
// Security
pi.Flirs = data[1]&0x60 != 0
pi.Beaming = data[1]&0x10 != 0
pi.Security = data[1]&0x01 != 0
// data[2] - reserved
pi.Basic = data[3]
pi.Generic = data[4]
pi.Specific = data[5]
return pi, nil
} | [
"func",
"NewGetNodeProtocolInfo",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"FuncGetNodeProtocolInfo",
",",
"error",
")",
"{",
"pi",
":=",
"&",
"FuncGetNodeProtocolInfo",
"{",
"}",
"\n\n",
"if",
"len",
"(",
"data",
")",
"<",
"6",
"{",
"return",
"nil"... | // NewGetNodeProtocolInfo decodes and cretes a funcGetNodeProtocolInfo. It is sent from the controller and contanins all basic information that the controller knows about a node. | [
"NewGetNodeProtocolInfo",
"decodes",
"and",
"cretes",
"a",
"funcGetNodeProtocolInfo",
".",
"It",
"is",
"sent",
"from",
"the",
"controller",
"and",
"contanins",
"all",
"basic",
"information",
"that",
"the",
"controller",
"knows",
"about",
"a",
"node",
"."
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/serialapi/get_node_protocolinfo.go#L22-L51 |
16,960 | stampzilla/gozwave | commands/reports/manufacturer_specific.go | NewManufacturerSpecific | func NewManufacturerSpecific(data []byte) (*ManufacturerSpecific, error) {
if len(data) != 6 {
return nil, fmt.Errorf("Failed to decode ManufacturerSpecific: Wrong length")
}
type aliasCmdManufacturerSpecific struct {
Manufacturer uint16
Type uint16
ID uint16
}
ms := &aliasCmdManufacturerSpecific{}
buf := bytes.NewReader(data)
err := binary.Read(buf, binary.BigEndian, ms)
ret := &ManufacturerSpecific{}
ret.Manufacturer = fmt.Sprintf("%04x", ms.Manufacturer)
ret.Type = fmt.Sprintf("%04x", ms.Type)
ret.ID = fmt.Sprintf("%04x", ms.ID)
return ret, err
} | go | func NewManufacturerSpecific(data []byte) (*ManufacturerSpecific, error) {
if len(data) != 6 {
return nil, fmt.Errorf("Failed to decode ManufacturerSpecific: Wrong length")
}
type aliasCmdManufacturerSpecific struct {
Manufacturer uint16
Type uint16
ID uint16
}
ms := &aliasCmdManufacturerSpecific{}
buf := bytes.NewReader(data)
err := binary.Read(buf, binary.BigEndian, ms)
ret := &ManufacturerSpecific{}
ret.Manufacturer = fmt.Sprintf("%04x", ms.Manufacturer)
ret.Type = fmt.Sprintf("%04x", ms.Type)
ret.ID = fmt.Sprintf("%04x", ms.ID)
return ret, err
} | [
"func",
"NewManufacturerSpecific",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"ManufacturerSpecific",
",",
"error",
")",
"{",
"if",
"len",
"(",
"data",
")",
"!=",
"6",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
... | // NewManufacturerSpecific decodes and returns a manufacureSpecific report. | [
"NewManufacturerSpecific",
"decodes",
"and",
"returns",
"a",
"manufacureSpecific",
"report",
"."
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/commands/reports/manufacturer_specific.go#L18-L41 |
16,961 | stampzilla/gozwave | database/commandclasses.go | GetMandatoryCommandClasses | func GetMandatoryCommandClasses(generic, specific byte) []*CommandClass {
for k, v := range definitions {
if k.Generic == generic && k.Specific == specific {
return v
}
}
return nil
} | go | func GetMandatoryCommandClasses(generic, specific byte) []*CommandClass {
for k, v := range definitions {
if k.Generic == generic && k.Specific == specific {
return v
}
}
return nil
} | [
"func",
"GetMandatoryCommandClasses",
"(",
"generic",
",",
"specific",
"byte",
")",
"[",
"]",
"*",
"CommandClass",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"definitions",
"{",
"if",
"k",
".",
"Generic",
"==",
"generic",
"&&",
"k",
".",
"Specific",
"==",... | // GetMandatoryCommandClasses generates a list of mandatory commandclasses | [
"GetMandatoryCommandClasses",
"generates",
"a",
"list",
"of",
"mandatory",
"commandclasses"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/database/commandclasses.go#L4-L11 |
16,962 | stampzilla/gozwave | commands/reports/switch_binary.go | NewSwitchBinaryV1 | func NewSwitchBinaryV1(data []byte) (*SwitchBinaryV1, error) {
if len(data) != 1 {
return nil, fmt.Errorf("Wrong length, expected 1 byte got %d", len(data))
}
return &SwitchBinaryV1{
CurrentValue: data[0] == 0xFF && data[0] != 0xFE,
Valid: data[0] != 0xFE,
data: data,
}, nil
} | go | func NewSwitchBinaryV1(data []byte) (*SwitchBinaryV1, error) {
if len(data) != 1 {
return nil, fmt.Errorf("Wrong length, expected 1 byte got %d", len(data))
}
return &SwitchBinaryV1{
CurrentValue: data[0] == 0xFF && data[0] != 0xFE,
Valid: data[0] != 0xFE,
data: data,
}, nil
} | [
"func",
"NewSwitchBinaryV1",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"SwitchBinaryV1",
",",
"error",
")",
"{",
"if",
"len",
"(",
"data",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"dat... | // NewSwitchBinaryV1 creates a new SwitchBinary report that contains the switch status from a
// zwave node | [
"NewSwitchBinaryV1",
"creates",
"a",
"new",
"SwitchBinary",
"report",
"that",
"contains",
"the",
"switch",
"status",
"from",
"a",
"zwave",
"node"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/commands/reports/switch_binary.go#L23-L33 |
16,963 | stampzilla/gozwave | commands/reports/switch_binary.go | NewSwitchBinaryV2 | func NewSwitchBinaryV2(data []byte) (*SwitchBinaryV2, error) {
if len(data) != 3 {
return nil, fmt.Errorf("Wrong length, expected 3 byte got %d", len(data))
}
return &SwitchBinaryV2{
CurrentValue: data[0] != 0x00,
TargetValue: data[1] != 0x00,
Duration: commands.Duration(data[2]),
data: data,
}, nil
} | go | func NewSwitchBinaryV2(data []byte) (*SwitchBinaryV2, error) {
if len(data) != 3 {
return nil, fmt.Errorf("Wrong length, expected 3 byte got %d", len(data))
}
return &SwitchBinaryV2{
CurrentValue: data[0] != 0x00,
TargetValue: data[1] != 0x00,
Duration: commands.Duration(data[2]),
data: data,
}, nil
} | [
"func",
"NewSwitchBinaryV2",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"SwitchBinaryV2",
",",
"error",
")",
"{",
"if",
"len",
"(",
"data",
")",
"!=",
"3",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"dat... | // NewSwitchBinaryV2 creates a new switchBinary report that contains the switch status from a
// zwave node | [
"NewSwitchBinaryV2",
"creates",
"a",
"new",
"switchBinary",
"report",
"that",
"contains",
"the",
"switch",
"status",
"from",
"a",
"zwave",
"node"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/commands/reports/switch_binary.go#L54-L65 |
16,964 | stampzilla/gozwave | commands/reports/switch_multilevel.go | NewSwitchMultilevelV1 | func NewSwitchMultilevelV1(data []byte) (*SwitchMultilevelV1, error) {
if len(data) != 1 {
return nil, fmt.Errorf("Wrong length, expected 1 byte got %d", len(data))
}
return &SwitchMultilevelV1{
CurrentValue: math.Min(float64(data[0]), 100),
Valid: data[0] != 0xFE,
data: data,
}, nil
} | go | func NewSwitchMultilevelV1(data []byte) (*SwitchMultilevelV1, error) {
if len(data) != 1 {
return nil, fmt.Errorf("Wrong length, expected 1 byte got %d", len(data))
}
return &SwitchMultilevelV1{
CurrentValue: math.Min(float64(data[0]), 100),
Valid: data[0] != 0xFE,
data: data,
}, nil
} | [
"func",
"NewSwitchMultilevelV1",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"SwitchMultilevelV1",
",",
"error",
")",
"{",
"if",
"len",
"(",
"data",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"("... | // NewSwitchMultilevelV1 creates a new SwitchMultilevelV1 report from binary data sent from a
// zwave node | [
"NewSwitchMultilevelV1",
"creates",
"a",
"new",
"SwitchMultilevelV1",
"report",
"from",
"binary",
"data",
"sent",
"from",
"a",
"zwave",
"node"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/commands/reports/switch_multilevel.go#L22-L32 |
16,965 | stampzilla/gozwave | commands/reports/switch_multilevel.go | NewSwitchMultilevelV4 | func NewSwitchMultilevelV4(data []byte) (*SwitchMultilevelV4, error) {
if len(data) != 3 {
return nil, fmt.Errorf("Wrong length, expected 3 byte got %d", len(data))
}
return &SwitchMultilevelV4{
CurrentValue: math.Min(float64(data[0]), 100),
TargetValue: math.Min(float64(data[1]), 100),
Duration: commands.Duration(data[2]),
Valid: data[0] != 0xFE,
TargetValid: data[1] != 0xFE,
data: data,
}, nil
} | go | func NewSwitchMultilevelV4(data []byte) (*SwitchMultilevelV4, error) {
if len(data) != 3 {
return nil, fmt.Errorf("Wrong length, expected 3 byte got %d", len(data))
}
return &SwitchMultilevelV4{
CurrentValue: math.Min(float64(data[0]), 100),
TargetValue: math.Min(float64(data[1]), 100),
Duration: commands.Duration(data[2]),
Valid: data[0] != 0xFE,
TargetValid: data[1] != 0xFE,
data: data,
}, nil
} | [
"func",
"NewSwitchMultilevelV4",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"SwitchMultilevelV4",
",",
"error",
")",
"{",
"if",
"len",
"(",
"data",
")",
"!=",
"3",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"("... | // NewSwitchMultilevelV4 creates a new SwitchMultilevelV1 report from binary data sent from a
// zwave node | [
"NewSwitchMultilevelV4",
"creates",
"a",
"new",
"SwitchMultilevelV1",
"report",
"from",
"binary",
"data",
"sent",
"from",
"a",
"zwave",
"node"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/commands/reports/switch_multilevel.go#L56-L69 |
16,966 | stampzilla/gozwave | commands/duration.go | Duration | func (d Duration) Duration() (time.Duration, error) {
switch {
case byte(d) == 0x00:
return time.Duration(0), nil
case byte(d) <= 0x7F:
return time.Duration(d) * time.Second, nil
case d <= 0xFD:
return time.Duration(d-0x7F) * time.Minute, nil
}
return time.Duration(0), fmt.Errorf("Factory default duration")
} | go | func (d Duration) Duration() (time.Duration, error) {
switch {
case byte(d) == 0x00:
return time.Duration(0), nil
case byte(d) <= 0x7F:
return time.Duration(d) * time.Second, nil
case d <= 0xFD:
return time.Duration(d-0x7F) * time.Minute, nil
}
return time.Duration(0), fmt.Errorf("Factory default duration")
} | [
"func",
"(",
"d",
"Duration",
")",
"Duration",
"(",
")",
"(",
"time",
".",
"Duration",
",",
"error",
")",
"{",
"switch",
"{",
"case",
"byte",
"(",
"d",
")",
"==",
"0x00",
":",
"return",
"time",
".",
"Duration",
"(",
"0",
")",
",",
"nil",
"\n",
... | // Duration converts zwave duration type into time.Duration | [
"Duration",
"converts",
"zwave",
"duration",
"type",
"into",
"time",
".",
"Duration"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/commands/duration.go#L12-L22 |
16,967 | stampzilla/gozwave | serialapi/discovery_nodes.go | NewDiscoverdNodes | func NewDiscoverdNodes(data []byte) (*DiscoverdNodes, error) {
f := &DiscoverdNodes{
data: data,
}
if len(data) < 6 {
return nil, fmt.Errorf("wrong length, should be at least 6 bytes got %d", len(data))
}
for index, bits := range data {
f.ActiveNodes[index*8+0] = bits&0x01 != 0
f.ActiveNodes[index*8+1] = bits&0x02 != 0
f.ActiveNodes[index*8+2] = bits&0x04 != 0
f.ActiveNodes[index*8+3] = bits&0x08 != 0
f.ActiveNodes[index*8+4] = bits&0x10 != 0
f.ActiveNodes[index*8+5] = bits&0x20 != 0
f.ActiveNodes[index*8+6] = bits&0x40 != 0
f.ActiveNodes[index*8+7] = bits&0x80 != 0
}
return f, nil
} | go | func NewDiscoverdNodes(data []byte) (*DiscoverdNodes, error) {
f := &DiscoverdNodes{
data: data,
}
if len(data) < 6 {
return nil, fmt.Errorf("wrong length, should be at least 6 bytes got %d", len(data))
}
for index, bits := range data {
f.ActiveNodes[index*8+0] = bits&0x01 != 0
f.ActiveNodes[index*8+1] = bits&0x02 != 0
f.ActiveNodes[index*8+2] = bits&0x04 != 0
f.ActiveNodes[index*8+3] = bits&0x08 != 0
f.ActiveNodes[index*8+4] = bits&0x10 != 0
f.ActiveNodes[index*8+5] = bits&0x20 != 0
f.ActiveNodes[index*8+6] = bits&0x40 != 0
f.ActiveNodes[index*8+7] = bits&0x80 != 0
}
return f, nil
} | [
"func",
"NewDiscoverdNodes",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"DiscoverdNodes",
",",
"error",
")",
"{",
"f",
":=",
"&",
"DiscoverdNodes",
"{",
"data",
":",
"data",
",",
"}",
"\n\n",
"if",
"len",
"(",
"data",
")",
"<",
"6",
"{",
"return... | // NewDiscoverdNodes decodes and creates a discoveryNode message. This message is received from the controller and contains a list of all available nodes in the network | [
"NewDiscoverdNodes",
"decodes",
"and",
"creates",
"a",
"discoveryNode",
"message",
".",
"This",
"message",
"is",
"received",
"from",
"the",
"controller",
"and",
"contains",
"a",
"list",
"of",
"all",
"available",
"nodes",
"in",
"the",
"network"
] | 576012815e010355bd3374a4f6af2d544ccab079 | https://github.com/stampzilla/gozwave/blob/576012815e010355bd3374a4f6af2d544ccab079/serialapi/discovery_nodes.go#L12-L34 |
16,968 | mitchellh/prefixedio | reader.go | NewReader | func NewReader(r io.Reader) (*Reader, error) {
if r == nil {
return nil, errors.New("Reader must not be nil")
}
return &Reader{r: r}, nil
} | go | func NewReader(r io.Reader) (*Reader, error) {
if r == nil {
return nil, errors.New("Reader must not be nil")
}
return &Reader{r: r}, nil
} | [
"func",
"NewReader",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"Reader",
",",
"error",
")",
"{",
"if",
"r",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"Reader",
"{",... | // NewReader creates a new Reader with the given io.Reader. | [
"NewReader",
"creates",
"a",
"new",
"Reader",
"with",
"the",
"given",
"io",
".",
"Reader",
"."
] | 5733675afd5162de652b410d2244d82b00a38a79 | https://github.com/mitchellh/prefixedio/blob/5733675afd5162de652b410d2244d82b00a38a79/reader.go#L39-L45 |
16,969 | mitchellh/prefixedio | reader.go | read | func (r *Reader) read() {
var err error
var lastPrefix string
buf := bufio.NewReader(r.r)
// Listen for bytes in a goroutine. We do this so that if we're blocking
// we can flush the bytes we have after some configured time. There is
// probably a way to make this a lot faster but this works for now.
byteCh := make(chan byte)
doneCh := make(chan error)
go func() {
defer close(doneCh)
for {
b, err := buf.ReadByte()
if err != nil {
doneCh <- err
return
}
byteCh <- b
}
}()
// Figure out the timeout we wait until we flush if we see no data
ft := r.FlushTimeout
if ft == 0 {
ft = 100 * time.Millisecond
}
lineBuf := make([]byte, 0, 80)
for {
line := lineBuf[0:0]
for {
brk := false
select {
case b := <-byteCh:
line = append(line, b)
brk = b == '\n'
case err = <-doneCh:
brk = true
case <-time.After(ft):
brk = true
}
if brk {
break
}
}
// If an error occurred and its not an EOF, then report that
// error to all pipes and exit.
if err != nil && err != io.EOF {
break
}
// Go through each prefix and write if the line matches.
// If no lines match, the data is lost.
var prefix string
r.l.Lock()
for p, _ := range r.prefixes {
if p == "" {
continue
}
if bytes.HasPrefix(line, []byte(p)) {
prefix = p
line = line[len(p):]
break
}
}
if prefix == "" {
prefix = lastPrefix
}
pw, ok := r.prefixes[prefix]
if ok {
lastPrefix = prefix
// Make sure we write all the data before we exit.
n := 0
for n < len(line) {
ni, err := pw.Write(line[n:])
if err != nil {
break
}
n += ni
}
}
r.l.Unlock()
if err == io.EOF {
break
}
}
r.l.Lock()
defer r.l.Unlock()
// Mark us done so that we don't create anymore readers
r.done = true
// All previous writers should be closed so that the readers
// properly return an EOF (or another error if we had one)
for _, pw := range r.prefixes {
if err != nil && err != io.EOF {
pw.CloseWithError(err)
} else {
pw.Close()
}
}
} | go | func (r *Reader) read() {
var err error
var lastPrefix string
buf := bufio.NewReader(r.r)
// Listen for bytes in a goroutine. We do this so that if we're blocking
// we can flush the bytes we have after some configured time. There is
// probably a way to make this a lot faster but this works for now.
byteCh := make(chan byte)
doneCh := make(chan error)
go func() {
defer close(doneCh)
for {
b, err := buf.ReadByte()
if err != nil {
doneCh <- err
return
}
byteCh <- b
}
}()
// Figure out the timeout we wait until we flush if we see no data
ft := r.FlushTimeout
if ft == 0 {
ft = 100 * time.Millisecond
}
lineBuf := make([]byte, 0, 80)
for {
line := lineBuf[0:0]
for {
brk := false
select {
case b := <-byteCh:
line = append(line, b)
brk = b == '\n'
case err = <-doneCh:
brk = true
case <-time.After(ft):
brk = true
}
if brk {
break
}
}
// If an error occurred and its not an EOF, then report that
// error to all pipes and exit.
if err != nil && err != io.EOF {
break
}
// Go through each prefix and write if the line matches.
// If no lines match, the data is lost.
var prefix string
r.l.Lock()
for p, _ := range r.prefixes {
if p == "" {
continue
}
if bytes.HasPrefix(line, []byte(p)) {
prefix = p
line = line[len(p):]
break
}
}
if prefix == "" {
prefix = lastPrefix
}
pw, ok := r.prefixes[prefix]
if ok {
lastPrefix = prefix
// Make sure we write all the data before we exit.
n := 0
for n < len(line) {
ni, err := pw.Write(line[n:])
if err != nil {
break
}
n += ni
}
}
r.l.Unlock()
if err == io.EOF {
break
}
}
r.l.Lock()
defer r.l.Unlock()
// Mark us done so that we don't create anymore readers
r.done = true
// All previous writers should be closed so that the readers
// properly return an EOF (or another error if we had one)
for _, pw := range r.prefixes {
if err != nil && err != io.EOF {
pw.CloseWithError(err)
} else {
pw.Close()
}
}
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"read",
"(",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"lastPrefix",
"string",
"\n",
"buf",
":=",
"bufio",
".",
"NewReader",
"(",
"r",
".",
"r",
")",
"\n\n",
"// Listen for bytes in a goroutine. We do this so that if... | // read runs in a goroutine and performs a read on the reader,
// dispatching lines to prefixes where necessary. | [
"read",
"runs",
"in",
"a",
"goroutine",
"and",
"performs",
"a",
"read",
"on",
"the",
"reader",
"dispatching",
"lines",
"to",
"prefixes",
"where",
"necessary",
"."
] | 5733675afd5162de652b410d2244d82b00a38a79 | https://github.com/mitchellh/prefixedio/blob/5733675afd5162de652b410d2244d82b00a38a79/reader.go#L97-L210 |
16,970 | spacemonkeygo/spacelog | setup/setup.go | MustSetupWithFacility | func MustSetupWithFacility(procname string, facility spacelog.SyslogPriority) {
err := SetupWithFacility(procname, facility)
if err != nil {
panic(err)
}
} | go | func MustSetupWithFacility(procname string, facility spacelog.SyslogPriority) {
err := SetupWithFacility(procname, facility)
if err != nil {
panic(err)
}
} | [
"func",
"MustSetupWithFacility",
"(",
"procname",
"string",
",",
"facility",
"spacelog",
".",
"SyslogPriority",
")",
"{",
"err",
":=",
"SetupWithFacility",
"(",
"procname",
",",
"facility",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
... | // MustSetupWithFacility is deprecated and will be removed soon. Please
// configure facility through the facility flag option. | [
"MustSetupWithFacility",
"is",
"deprecated",
"and",
"will",
"be",
"removed",
"soon",
".",
"Please",
"configure",
"facility",
"through",
"the",
"facility",
"flag",
"option",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/setup/setup.go#L66-L71 |
16,971 | spacemonkeygo/spacelog | setup/setup.go | SetupWithFacility | func SetupWithFacility(procname string,
facility spacelog.SyslogPriority) error {
config_copy := config
config_copy.Facility = int(facility)
return spacelog.Setup(procname, config_copy)
} | go | func SetupWithFacility(procname string,
facility spacelog.SyslogPriority) error {
config_copy := config
config_copy.Facility = int(facility)
return spacelog.Setup(procname, config_copy)
} | [
"func",
"SetupWithFacility",
"(",
"procname",
"string",
",",
"facility",
"spacelog",
".",
"SyslogPriority",
")",
"error",
"{",
"config_copy",
":=",
"config",
"\n",
"config_copy",
".",
"Facility",
"=",
"int",
"(",
"facility",
")",
"\n",
"return",
"spacelog",
".... | // SetupWithFacility is deprecated and will be removed soon. Please
// configure facility through the facility flag option. | [
"SetupWithFacility",
"is",
"deprecated",
"and",
"will",
"be",
"removed",
"soon",
".",
"Please",
"configure",
"facility",
"through",
"the",
"facility",
"flag",
"option",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/setup/setup.go#L75-L80 |
16,972 | spacemonkeygo/spacelog | text.go | NewTextHandler | func NewTextHandler(t *template.Template, output TextOutput) *TextHandler {
return &TextHandler{template: t, output: output}
} | go | func NewTextHandler(t *template.Template, output TextOutput) *TextHandler {
return &TextHandler{template: t, output: output}
} | [
"func",
"NewTextHandler",
"(",
"t",
"*",
"template",
".",
"Template",
",",
"output",
"TextOutput",
")",
"*",
"TextHandler",
"{",
"return",
"&",
"TextHandler",
"{",
"template",
":",
"t",
",",
"output",
":",
"output",
"}",
"\n",
"}"
] | // NewTextHandler creates a Handler that creates LogEvents, passes them to
// the given template, and passes the result to output | [
"NewTextHandler",
"creates",
"a",
"Handler",
"that",
"creates",
"LogEvents",
"passes",
"them",
"to",
"the",
"given",
"template",
"and",
"passes",
"the",
"result",
"to",
"output"
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/text.go#L39-L41 |
16,973 | spacemonkeygo/spacelog | text.go | Log | func (h *TextHandler) Log(logger_name string, level LogLevel, msg string,
calldepth int) {
h.mtx.RLock()
output, template := h.output, h.template
h.mtx.RUnlock()
event := LogEvent{
LoggerName: logger_name,
Level: level,
Message: strings.TrimRight(msg, "\n\r"),
Timestamp: time.Now()}
if calldepth >= 0 {
_, event.Filepath, event.Line, _ = runtime.Caller(calldepth + 1)
}
var buf bytes.Buffer
err := template.Execute(&buf, &event)
if err != nil {
output.Output(level, []byte(
fmt.Sprintf("log format template failed: %s", err)))
return
}
output.Output(level, buf.Bytes())
} | go | func (h *TextHandler) Log(logger_name string, level LogLevel, msg string,
calldepth int) {
h.mtx.RLock()
output, template := h.output, h.template
h.mtx.RUnlock()
event := LogEvent{
LoggerName: logger_name,
Level: level,
Message: strings.TrimRight(msg, "\n\r"),
Timestamp: time.Now()}
if calldepth >= 0 {
_, event.Filepath, event.Line, _ = runtime.Caller(calldepth + 1)
}
var buf bytes.Buffer
err := template.Execute(&buf, &event)
if err != nil {
output.Output(level, []byte(
fmt.Sprintf("log format template failed: %s", err)))
return
}
output.Output(level, buf.Bytes())
} | [
"func",
"(",
"h",
"*",
"TextHandler",
")",
"Log",
"(",
"logger_name",
"string",
",",
"level",
"LogLevel",
",",
"msg",
"string",
",",
"calldepth",
"int",
")",
"{",
"h",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"output",
",",
"template",
":=",
"h",
... | // Log makes a LogEvent, formats it with the configured template, then passes
// the output to configured output sink | [
"Log",
"makes",
"a",
"LogEvent",
"formats",
"it",
"with",
"the",
"configured",
"template",
"then",
"passes",
"the",
"output",
"to",
"configured",
"output",
"sink"
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/text.go#L45-L66 |
16,974 | spacemonkeygo/spacelog | text.go | SetTextTemplate | func (h *TextHandler) SetTextTemplate(t *template.Template) {
h.mtx.Lock()
defer h.mtx.Unlock()
h.template = t
} | go | func (h *TextHandler) SetTextTemplate(t *template.Template) {
h.mtx.Lock()
defer h.mtx.Unlock()
h.template = t
} | [
"func",
"(",
"h",
"*",
"TextHandler",
")",
"SetTextTemplate",
"(",
"t",
"*",
"template",
".",
"Template",
")",
"{",
"h",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"h",
".",
"template",
"=",
... | // SetTextTemplate changes the TextHandler's text formatting template | [
"SetTextTemplate",
"changes",
"the",
"TextHandler",
"s",
"text",
"formatting",
"template"
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/text.go#L69-L73 |
16,975 | spacemonkeygo/spacelog | text.go | SetTextOutput | func (h *TextHandler) SetTextOutput(output TextOutput) {
h.mtx.Lock()
defer h.mtx.Unlock()
h.output = output
} | go | func (h *TextHandler) SetTextOutput(output TextOutput) {
h.mtx.Lock()
defer h.mtx.Unlock()
h.output = output
} | [
"func",
"(",
"h",
"*",
"TextHandler",
")",
"SetTextOutput",
"(",
"output",
"TextOutput",
")",
"{",
"h",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"h",
".",
"output",
"=",
"output",
"\n",
"}"... | // SetTextOutput changes the TextHandler's TextOutput sink | [
"SetTextOutput",
"changes",
"the",
"TextHandler",
"s",
"TextOutput",
"sink"
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/text.go#L76-L80 |
16,976 | spacemonkeygo/spacelog | templates.go | ColorizeLevel | func ColorizeLevel(level LogLevel) string {
switch level.Match() {
case Critical, Error:
return TermColors{}.Red()
case Warning:
return TermColors{}.Magenta()
case Notice:
return TermColors{}.Yellow()
case Info, Debug, Trace:
return TermColors{}.Green()
}
return ""
} | go | func ColorizeLevel(level LogLevel) string {
switch level.Match() {
case Critical, Error:
return TermColors{}.Red()
case Warning:
return TermColors{}.Magenta()
case Notice:
return TermColors{}.Yellow()
case Info, Debug, Trace:
return TermColors{}.Green()
}
return ""
} | [
"func",
"ColorizeLevel",
"(",
"level",
"LogLevel",
")",
"string",
"{",
"switch",
"level",
".",
"Match",
"(",
")",
"{",
"case",
"Critical",
",",
"Error",
":",
"return",
"TermColors",
"{",
"}",
".",
"Red",
"(",
")",
"\n",
"case",
"Warning",
":",
"return"... | // ColorizeLevel returns a TermColor byte sequence for the appropriate color
// for the level. If you'd like to configure your own color choices, you can
// make your own template with its own function map to your own colorize
// function. | [
"ColorizeLevel",
"returns",
"a",
"TermColor",
"byte",
"sequence",
"for",
"the",
"appropriate",
"color",
"for",
"the",
"level",
".",
"If",
"you",
"d",
"like",
"to",
"configure",
"your",
"own",
"color",
"choices",
"you",
"can",
"make",
"your",
"own",
"template... | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/templates.go#L25-L37 |
16,977 | spacemonkeygo/spacelog | event.go | LevelJustified | func (l *LogEvent) LevelJustified() (rv string) {
rv = l.Level.String()
if len(rv) < 5 {
rv += strings.Repeat(" ", 5-len(rv))
}
return rv
} | go | func (l *LogEvent) LevelJustified() (rv string) {
rv = l.Level.String()
if len(rv) < 5 {
rv += strings.Repeat(" ", 5-len(rv))
}
return rv
} | [
"func",
"(",
"l",
"*",
"LogEvent",
")",
"LevelJustified",
"(",
")",
"(",
"rv",
"string",
")",
"{",
"rv",
"=",
"l",
".",
"Level",
".",
"String",
"(",
")",
"\n",
"if",
"len",
"(",
"rv",
")",
"<",
"5",
"{",
"rv",
"+=",
"strings",
".",
"Repeat",
... | // LevelJustified returns the log level in string form justified so that all
// log levels take the same text width. | [
"LevelJustified",
"returns",
"the",
"log",
"level",
"in",
"string",
"form",
"justified",
"so",
"that",
"all",
"log",
"levels",
"take",
"the",
"same",
"text",
"width",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/event.go#L69-L75 |
16,978 | spacemonkeygo/spacelog | level.go | String | func (l LogLevel) String() string {
switch l.Match() {
case Critical:
return "CRIT"
case Error:
return "ERR"
case Warning:
return "WARN"
case Notice:
return "NOTE"
case Info:
return "INFO"
case Debug:
return "DEBUG"
case Trace:
return "TRACE"
default:
return "UNSET"
}
} | go | func (l LogLevel) String() string {
switch l.Match() {
case Critical:
return "CRIT"
case Error:
return "ERR"
case Warning:
return "WARN"
case Notice:
return "NOTE"
case Info:
return "INFO"
case Debug:
return "DEBUG"
case Trace:
return "TRACE"
default:
return "UNSET"
}
} | [
"func",
"(",
"l",
"LogLevel",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"l",
".",
"Match",
"(",
")",
"{",
"case",
"Critical",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Error",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Warning",
":",
"return... | // String returns the log level name in short form | [
"String",
"returns",
"the",
"log",
"level",
"name",
"in",
"short",
"form"
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/level.go#L40-L59 |
16,979 | spacemonkeygo/spacelog | level.go | LevelFromString | func LevelFromString(str string) (LogLevel, error) {
switch strings.ToLower(str) {
case "crit", "critical":
return Critical, nil
case "err", "error":
return Error, nil
case "warn", "warning":
return Warning, nil
case "note", "notice":
return Notice, nil
case "info":
return Info, nil
case "debug":
return Debug, nil
case "trace":
return Trace, nil
}
val, err := strconv.ParseInt(str, 10, 32)
if err == nil {
return LogLevel(val), nil
}
return 0, fmt.Errorf("Invalid log level: %s", str)
} | go | func LevelFromString(str string) (LogLevel, error) {
switch strings.ToLower(str) {
case "crit", "critical":
return Critical, nil
case "err", "error":
return Error, nil
case "warn", "warning":
return Warning, nil
case "note", "notice":
return Notice, nil
case "info":
return Info, nil
case "debug":
return Debug, nil
case "trace":
return Trace, nil
}
val, err := strconv.ParseInt(str, 10, 32)
if err == nil {
return LogLevel(val), nil
}
return 0, fmt.Errorf("Invalid log level: %s", str)
} | [
"func",
"LevelFromString",
"(",
"str",
"string",
")",
"(",
"LogLevel",
",",
"error",
")",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"str",
")",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"Critical",
",",
"nil",
"\n",
"case",
"\"",
... | // LevelFromString will convert a named log level to its corresponding value
// type, or error if both the name was unknown and an integer value was unable
// to be parsed. | [
"LevelFromString",
"will",
"convert",
"a",
"named",
"log",
"level",
"to",
"its",
"corresponding",
"value",
"type",
"or",
"error",
"if",
"both",
"the",
"name",
"was",
"unknown",
"and",
"an",
"integer",
"value",
"was",
"unable",
"to",
"be",
"parsed",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/level.go#L114-L136 |
16,980 | spacemonkeygo/spacelog | setup.go | MustSetup | func MustSetup(procname string, config SetupConfig) {
err := Setup(procname, config)
if err != nil {
panic(err)
}
} | go | func MustSetup(procname string, config SetupConfig) {
err := Setup(procname, config)
if err != nil {
panic(err)
}
} | [
"func",
"MustSetup",
"(",
"procname",
"string",
",",
"config",
"SetupConfig",
")",
"{",
"err",
":=",
"Setup",
"(",
"procname",
",",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // MustSetup is the same as Setup, but panics instead of returning an error | [
"MustSetup",
"is",
"the",
"same",
"as",
"Setup",
"but",
"panics",
"instead",
"of",
"returning",
"an",
"error"
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/setup.go#L61-L66 |
16,981 | spacemonkeygo/spacelog | capture.go | CaptureOutputToFile | func CaptureOutputToFile(path string) error {
fh, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return err
}
defer fh.Close()
return CaptureOutputToFd(int(fh.Fd()))
} | go | func CaptureOutputToFile(path string) error {
fh, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return err
}
defer fh.Close()
return CaptureOutputToFd(int(fh.Fd()))
} | [
"func",
"CaptureOutputToFile",
"(",
"path",
"string",
")",
"error",
"{",
"fh",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"path",
",",
"os",
".",
"O_RDWR",
"|",
"os",
".",
"O_CREATE",
",",
"0644",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retur... | // CaptureOutputToFile opens a filehandle using the given path, then calls
// CaptureOutputToFd on the associated filehandle. | [
"CaptureOutputToFile",
"opens",
"a",
"filehandle",
"using",
"the",
"given",
"path",
"then",
"calls",
"CaptureOutputToFd",
"on",
"the",
"associated",
"filehandle",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/capture.go#L25-L32 |
16,982 | spacemonkeygo/spacelog | capture.go | CaptureOutputToProcess | func CaptureOutputToProcess(command string, args ...string) error {
cmd := exec.Command(command, args...)
out, err := cmd.StdinPipe()
if err != nil {
return err
}
defer out.Close()
type fder interface {
Fd() uintptr
}
out_fder, ok := out.(fder)
if !ok {
return fmt.Errorf("unable to get underlying pipe")
}
err = CaptureOutputToFd(int(out_fder.Fd()))
if err != nil {
return err
}
err = cmd.Start()
if err != nil {
return err
}
go func() {
err := cmd.Wait()
if err != nil {
panic(fmt.Errorf("captured output process died! %s", err))
}
}()
return nil
} | go | func CaptureOutputToProcess(command string, args ...string) error {
cmd := exec.Command(command, args...)
out, err := cmd.StdinPipe()
if err != nil {
return err
}
defer out.Close()
type fder interface {
Fd() uintptr
}
out_fder, ok := out.(fder)
if !ok {
return fmt.Errorf("unable to get underlying pipe")
}
err = CaptureOutputToFd(int(out_fder.Fd()))
if err != nil {
return err
}
err = cmd.Start()
if err != nil {
return err
}
go func() {
err := cmd.Wait()
if err != nil {
panic(fmt.Errorf("captured output process died! %s", err))
}
}()
return nil
} | [
"func",
"CaptureOutputToProcess",
"(",
"command",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"command",
",",
"args",
"...",
")",
"\n",
"out",
",",
"err",
":=",
"cmd",
".",
"StdinPipe",
"(",
")",... | // CaptureOutputToProcess starts a process and using CaptureOutputToFd,
// redirects stdout and stderr to the subprocess' stdin.
// CaptureOutputToProcess expects the subcommand to last the lifetime of the
// process, and if the subprocess dies, will panic. | [
"CaptureOutputToProcess",
"starts",
"a",
"process",
"and",
"using",
"CaptureOutputToFd",
"redirects",
"stdout",
"and",
"stderr",
"to",
"the",
"subprocess",
"stdin",
".",
"CaptureOutputToProcess",
"expects",
"the",
"subcommand",
"to",
"last",
"the",
"lifetime",
"of",
... | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/capture.go#L38-L67 |
16,983 | spacemonkeygo/spacelog | convenience.go | Trace | func (l *Logger) Trace(v ...interface{}) {
if l.getLevel() <= Trace {
l.getHandler().Log(l.name, Trace, fmt.Sprint(v...), 1)
}
} | go | func (l *Logger) Trace(v ...interface{}) {
if l.getLevel() <= Trace {
l.getHandler().Log(l.name, Trace, fmt.Sprint(v...), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Trace",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Trace",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
"name",
",",
"Trace",
",",... | // Trace logs a collection of values if the logger's level is trace or even
// more permissive. | [
"Trace",
"logs",
"a",
"collection",
"of",
"values",
"if",
"the",
"logger",
"s",
"level",
"is",
"trace",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L24-L28 |
16,984 | spacemonkeygo/spacelog | convenience.go | Tracef | func (l *Logger) Tracef(format string, v ...interface{}) {
if l.getLevel() <= Trace {
l.getHandler().Log(l.name, Trace, fmt.Sprintf(format, v...), 1)
}
} | go | func (l *Logger) Tracef(format string, v ...interface{}) {
if l.getLevel() <= Trace {
l.getHandler().Log(l.name, Trace, fmt.Sprintf(format, v...), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Tracef",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Trace",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
... | // Tracef logs a format string with values if the logger's level is trace or
// even more permissive. | [
"Tracef",
"logs",
"a",
"format",
"string",
"with",
"values",
"if",
"the",
"logger",
"s",
"level",
"is",
"trace",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L32-L36 |
16,985 | spacemonkeygo/spacelog | convenience.go | Tracee | func (l *Logger) Tracee(err error) {
if l.getLevel() <= Trace && err != nil {
l.getHandler().Log(l.name, Trace, err.Error(), 1)
}
} | go | func (l *Logger) Tracee(err error) {
if l.getLevel() <= Trace && err != nil {
l.getHandler().Log(l.name, Trace, err.Error(), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Tracee",
"(",
"err",
"error",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Trace",
"&&",
"err",
"!=",
"nil",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
"name",
",",
"Trac... | // Tracee logs an error value if the error is not nil and the logger's level
// is trace or even more permissive. | [
"Tracee",
"logs",
"an",
"error",
"value",
"if",
"the",
"error",
"is",
"not",
"nil",
"and",
"the",
"logger",
"s",
"level",
"is",
"trace",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L40-L44 |
16,986 | spacemonkeygo/spacelog | convenience.go | Debug | func (l *Logger) Debug(v ...interface{}) {
if l.getLevel() <= Debug {
l.getHandler().Log(l.name, Debug, fmt.Sprint(v...), 1)
}
} | go | func (l *Logger) Debug(v ...interface{}) {
if l.getLevel() <= Debug {
l.getHandler().Log(l.name, Debug, fmt.Sprint(v...), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Debug",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Debug",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
"name",
",",
"Debug",
",",... | // Debug logs a collection of values if the logger's level is debug or even
// more permissive. | [
"Debug",
"logs",
"a",
"collection",
"of",
"values",
"if",
"the",
"logger",
"s",
"level",
"is",
"debug",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L54-L58 |
16,987 | spacemonkeygo/spacelog | convenience.go | Debugf | func (l *Logger) Debugf(format string, v ...interface{}) {
if l.getLevel() <= Debug {
l.getHandler().Log(l.name, Debug, fmt.Sprintf(format, v...), 1)
}
} | go | func (l *Logger) Debugf(format string, v ...interface{}) {
if l.getLevel() <= Debug {
l.getHandler().Log(l.name, Debug, fmt.Sprintf(format, v...), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Debugf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Debug",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
... | // Debugf logs a format string with values if the logger's level is debug or
// even more permissive. | [
"Debugf",
"logs",
"a",
"format",
"string",
"with",
"values",
"if",
"the",
"logger",
"s",
"level",
"is",
"debug",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L62-L66 |
16,988 | spacemonkeygo/spacelog | convenience.go | Debuge | func (l *Logger) Debuge(err error) {
if l.getLevel() <= Debug && err != nil {
l.getHandler().Log(l.name, Debug, err.Error(), 1)
}
} | go | func (l *Logger) Debuge(err error) {
if l.getLevel() <= Debug && err != nil {
l.getHandler().Log(l.name, Debug, err.Error(), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Debuge",
"(",
"err",
"error",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Debug",
"&&",
"err",
"!=",
"nil",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
"name",
",",
"Debu... | // Debuge logs an error value if the error is not nil and the logger's level
// is debug or even more permissive. | [
"Debuge",
"logs",
"an",
"error",
"value",
"if",
"the",
"error",
"is",
"not",
"nil",
"and",
"the",
"logger",
"s",
"level",
"is",
"debug",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L70-L74 |
16,989 | spacemonkeygo/spacelog | convenience.go | Info | func (l *Logger) Info(v ...interface{}) {
if l.getLevel() <= Info {
l.getHandler().Log(l.name, Info, fmt.Sprint(v...), 1)
}
} | go | func (l *Logger) Info(v ...interface{}) {
if l.getLevel() <= Info {
l.getHandler().Log(l.name, Info, fmt.Sprint(v...), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Info",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Info",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
"name",
",",
"Info",
",",
... | // Info logs a collection of values if the logger's level is info or even
// more permissive. | [
"Info",
"logs",
"a",
"collection",
"of",
"values",
"if",
"the",
"logger",
"s",
"level",
"is",
"info",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L84-L88 |
16,990 | spacemonkeygo/spacelog | convenience.go | Infof | func (l *Logger) Infof(format string, v ...interface{}) {
if l.getLevel() <= Info {
l.getHandler().Log(l.name, Info, fmt.Sprintf(format, v...), 1)
}
} | go | func (l *Logger) Infof(format string, v ...interface{}) {
if l.getLevel() <= Info {
l.getHandler().Log(l.name, Info, fmt.Sprintf(format, v...), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Infof",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Info",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
"n... | // Infof logs a format string with values if the logger's level is info or
// even more permissive. | [
"Infof",
"logs",
"a",
"format",
"string",
"with",
"values",
"if",
"the",
"logger",
"s",
"level",
"is",
"info",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L92-L96 |
16,991 | spacemonkeygo/spacelog | convenience.go | Infoe | func (l *Logger) Infoe(err error) {
if l.getLevel() <= Info && err != nil {
l.getHandler().Log(l.name, Info, err.Error(), 1)
}
} | go | func (l *Logger) Infoe(err error) {
if l.getLevel() <= Info && err != nil {
l.getHandler().Log(l.name, Info, err.Error(), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Infoe",
"(",
"err",
"error",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Info",
"&&",
"err",
"!=",
"nil",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
"name",
",",
"Info",... | // Infoe logs an error value if the error is not nil and the logger's level
// is info or even more permissive. | [
"Infoe",
"logs",
"an",
"error",
"value",
"if",
"the",
"error",
"is",
"not",
"nil",
"and",
"the",
"logger",
"s",
"level",
"is",
"info",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L100-L104 |
16,992 | spacemonkeygo/spacelog | convenience.go | Notice | func (l *Logger) Notice(v ...interface{}) {
if l.getLevel() <= Notice {
l.getHandler().Log(l.name, Notice, fmt.Sprint(v...), 1)
}
} | go | func (l *Logger) Notice(v ...interface{}) {
if l.getLevel() <= Notice {
l.getHandler().Log(l.name, Notice, fmt.Sprint(v...), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Notice",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Notice",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
"name",
",",
"Notice",
"... | // Notice logs a collection of values if the logger's level is notice or even
// more permissive. | [
"Notice",
"logs",
"a",
"collection",
"of",
"values",
"if",
"the",
"logger",
"s",
"level",
"is",
"notice",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L114-L118 |
16,993 | spacemonkeygo/spacelog | convenience.go | Noticef | func (l *Logger) Noticef(format string, v ...interface{}) {
if l.getLevel() <= Notice {
l.getHandler().Log(l.name, Notice, fmt.Sprintf(format, v...), 1)
}
} | go | func (l *Logger) Noticef(format string, v ...interface{}) {
if l.getLevel() <= Notice {
l.getHandler().Log(l.name, Notice, fmt.Sprintf(format, v...), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Noticef",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Notice",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
... | // Noticef logs a format string with values if the logger's level is notice or
// even more permissive. | [
"Noticef",
"logs",
"a",
"format",
"string",
"with",
"values",
"if",
"the",
"logger",
"s",
"level",
"is",
"notice",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L122-L126 |
16,994 | spacemonkeygo/spacelog | convenience.go | Noticee | func (l *Logger) Noticee(err error) {
if l.getLevel() <= Notice && err != nil {
l.getHandler().Log(l.name, Notice, err.Error(), 1)
}
} | go | func (l *Logger) Noticee(err error) {
if l.getLevel() <= Notice && err != nil {
l.getHandler().Log(l.name, Notice, err.Error(), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Noticee",
"(",
"err",
"error",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Notice",
"&&",
"err",
"!=",
"nil",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
"name",
",",
"No... | // Noticee logs an error value if the error is not nil and the logger's level
// is notice or even more permissive. | [
"Noticee",
"logs",
"an",
"error",
"value",
"if",
"the",
"error",
"is",
"not",
"nil",
"and",
"the",
"logger",
"s",
"level",
"is",
"notice",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L130-L134 |
16,995 | spacemonkeygo/spacelog | convenience.go | Warn | func (l *Logger) Warn(v ...interface{}) {
if l.getLevel() <= Warning {
l.getHandler().Log(l.name, Warning, fmt.Sprint(v...), 1)
}
} | go | func (l *Logger) Warn(v ...interface{}) {
if l.getLevel() <= Warning {
l.getHandler().Log(l.name, Warning, fmt.Sprint(v...), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Warn",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Warning",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
"name",
",",
"Warning",
"... | // Warn logs a collection of values if the logger's level is warning or even
// more permissive. | [
"Warn",
"logs",
"a",
"collection",
"of",
"values",
"if",
"the",
"logger",
"s",
"level",
"is",
"warning",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L144-L148 |
16,996 | spacemonkeygo/spacelog | convenience.go | Warnf | func (l *Logger) Warnf(format string, v ...interface{}) {
if l.getLevel() <= Warning {
l.getHandler().Log(l.name, Warning, fmt.Sprintf(format, v...), 1)
}
} | go | func (l *Logger) Warnf(format string, v ...interface{}) {
if l.getLevel() <= Warning {
l.getHandler().Log(l.name, Warning, fmt.Sprintf(format, v...), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Warnf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Warning",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
... | // Warnf logs a format string with values if the logger's level is warning or
// even more permissive. | [
"Warnf",
"logs",
"a",
"format",
"string",
"with",
"values",
"if",
"the",
"logger",
"s",
"level",
"is",
"warning",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L152-L156 |
16,997 | spacemonkeygo/spacelog | convenience.go | Warne | func (l *Logger) Warne(err error) {
if l.getLevel() <= Warning && err != nil {
l.getHandler().Log(l.name, Warning, err.Error(), 1)
}
} | go | func (l *Logger) Warne(err error) {
if l.getLevel() <= Warning && err != nil {
l.getHandler().Log(l.name, Warning, err.Error(), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Warne",
"(",
"err",
"error",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Warning",
"&&",
"err",
"!=",
"nil",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
"name",
",",
"War... | // Warne logs an error value if the error is not nil and the logger's level
// is warning or even more permissive. | [
"Warne",
"logs",
"an",
"error",
"value",
"if",
"the",
"error",
"is",
"not",
"nil",
"and",
"the",
"logger",
"s",
"level",
"is",
"warning",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L160-L164 |
16,998 | spacemonkeygo/spacelog | convenience.go | Error | func (l *Logger) Error(v ...interface{}) {
if l.getLevel() <= Error {
l.getHandler().Log(l.name, Error, fmt.Sprint(v...), 1)
}
} | go | func (l *Logger) Error(v ...interface{}) {
if l.getLevel() <= Error {
l.getHandler().Log(l.name, Error, fmt.Sprint(v...), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Error",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Error",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
"name",
",",
"Error",
",",... | // Error logs a collection of values if the logger's level is error or even
// more permissive. | [
"Error",
"logs",
"a",
"collection",
"of",
"values",
"if",
"the",
"logger",
"s",
"level",
"is",
"error",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L174-L178 |
16,999 | spacemonkeygo/spacelog | convenience.go | Errorf | func (l *Logger) Errorf(format string, v ...interface{}) {
if l.getLevel() <= Error {
l.getHandler().Log(l.name, Error, fmt.Sprintf(format, v...), 1)
}
} | go | func (l *Logger) Errorf(format string, v ...interface{}) {
if l.getLevel() <= Error {
l.getHandler().Log(l.name, Error, fmt.Sprintf(format, v...), 1)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Errorf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"getLevel",
"(",
")",
"<=",
"Error",
"{",
"l",
".",
"getHandler",
"(",
")",
".",
"Log",
"(",
"l",
".",
... | // Errorf logs a format string with values if the logger's level is error or
// even more permissive. | [
"Errorf",
"logs",
"a",
"format",
"string",
"with",
"values",
"if",
"the",
"logger",
"s",
"level",
"is",
"error",
"or",
"even",
"more",
"permissive",
"."
] | 2296661a0572a51438413369004fa931c2641923 | https://github.com/spacemonkeygo/spacelog/blob/2296661a0572a51438413369004fa931c2641923/convenience.go#L182-L186 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.