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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
149,000 | golangplus/bytes | slice.go | ReadFrom | func (s *Slice) ReadFrom(r io.Reader) (n int64, err error) {
const buf_SIZE = 32 * 1024
buf := make([]byte, buf_SIZE)
for {
nRead, err := r.Read(buf)
if nRead == 0 {
if err != io.EOF {
return n, err
}
break
}
n += int64(nRead)
*s = append(*s, buf[:nRead]...)
if err == io.EOF {
break
}
... | go | func (s *Slice) ReadFrom(r io.Reader) (n int64, err error) {
const buf_SIZE = 32 * 1024
buf := make([]byte, buf_SIZE)
for {
nRead, err := r.Read(buf)
if nRead == 0 {
if err != io.EOF {
return n, err
}
break
}
n += int64(nRead)
*s = append(*s, buf[:nRead]...)
if err == io.EOF {
break
}
... | [
"func",
"(",
"s",
"*",
"Slice",
")",
"ReadFrom",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"n",
"int64",
",",
"err",
"error",
")",
"{",
"const",
"buf_SIZE",
"=",
"32",
"*",
"1024",
"\n",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"buf_SIZE... | // ReadFrom implements the io.ReaderFrom interface. | [
"ReadFrom",
"implements",
"the",
"io",
".",
"ReaderFrom",
"interface",
"."
] | 45c989fe545070ef7c9003cf1998bb195c61731a | https://github.com/golangplus/bytes/blob/45c989fe545070ef7c9003cf1998bb195c61731a/slice.go#L118-L141 |
149,001 | golangplus/bytes | slice.go | ReadRune | func (s *Slice) ReadRune() (r rune, size int, err error) {
if !utf8.FullRune(*s) {
return utf8.RuneError, 0, io.ErrUnexpectedEOF
}
r, size = utf8.DecodeRune(*s)
*s = (*s)[size:]
return r, size, err
} | go | func (s *Slice) ReadRune() (r rune, size int, err error) {
if !utf8.FullRune(*s) {
return utf8.RuneError, 0, io.ErrUnexpectedEOF
}
r, size = utf8.DecodeRune(*s)
*s = (*s)[size:]
return r, size, err
} | [
"func",
"(",
"s",
"*",
"Slice",
")",
"ReadRune",
"(",
")",
"(",
"r",
"rune",
",",
"size",
"int",
",",
"err",
"error",
")",
"{",
"if",
"!",
"utf8",
".",
"FullRune",
"(",
"*",
"s",
")",
"{",
"return",
"utf8",
".",
"RuneError",
",",
"0",
",",
"i... | // ReadRune implements the io.RuneReader interface. | [
"ReadRune",
"implements",
"the",
"io",
".",
"RuneReader",
"interface",
"."
] | 45c989fe545070ef7c9003cf1998bb195c61731a | https://github.com/golangplus/bytes/blob/45c989fe545070ef7c9003cf1998bb195c61731a/slice.go#L150-L158 |
149,002 | golangplus/bytes | slice.go | WriteRune | func (s *Slice) WriteRune(r rune) (size int, err error) {
if r < utf8.RuneSelf {
*s = append(*s, byte(r))
return 1, nil
}
l := utf8.RuneLen(r)
if l < 0 {
return 0, ErrInvalidRune
}
*s = append(*s, emptySlices[l]...)
utf8.EncodeRune((*s)[len(*s)-l:], r)
return l, nil
} | go | func (s *Slice) WriteRune(r rune) (size int, err error) {
if r < utf8.RuneSelf {
*s = append(*s, byte(r))
return 1, nil
}
l := utf8.RuneLen(r)
if l < 0 {
return 0, ErrInvalidRune
}
*s = append(*s, emptySlices[l]...)
utf8.EncodeRune((*s)[len(*s)-l:], r)
return l, nil
} | [
"func",
"(",
"s",
"*",
"Slice",
")",
"WriteRune",
"(",
"r",
"rune",
")",
"(",
"size",
"int",
",",
"err",
"error",
")",
"{",
"if",
"r",
"<",
"utf8",
".",
"RuneSelf",
"{",
"*",
"s",
"=",
"append",
"(",
"*",
"s",
",",
"byte",
"(",
"r",
")",
")... | // WriteRune writes a single Unicode code point, returning the number of bytes
// written and any error. | [
"WriteRune",
"writes",
"a",
"single",
"Unicode",
"code",
"point",
"returning",
"the",
"number",
"of",
"bytes",
"written",
"and",
"any",
"error",
"."
] | 45c989fe545070ef7c9003cf1998bb195c61731a | https://github.com/golangplus/bytes/blob/45c989fe545070ef7c9003cf1998bb195c61731a/slice.go#L173-L187 |
149,003 | golangplus/bytes | slice.go | WriteString | func (s *Slice) WriteString(str string) (size int, err error) {
*s = append(*s, str...)
return len(str), nil
} | go | func (s *Slice) WriteString(str string) (size int, err error) {
*s = append(*s, str...)
return len(str), nil
} | [
"func",
"(",
"s",
"*",
"Slice",
")",
"WriteString",
"(",
"str",
"string",
")",
"(",
"size",
"int",
",",
"err",
"error",
")",
"{",
"*",
"s",
"=",
"append",
"(",
"*",
"s",
",",
"str",
"...",
")",
"\n",
"return",
"len",
"(",
"str",
")",
",",
"ni... | // WriteString appends the contents of str to the slice, growing the slice as
// needed. The return value n is the length of str; err is always nil. | [
"WriteString",
"appends",
"the",
"contents",
"of",
"str",
"to",
"the",
"slice",
"growing",
"the",
"slice",
"as",
"needed",
".",
"The",
"return",
"value",
"n",
"is",
"the",
"length",
"of",
"str",
";",
"err",
"is",
"always",
"nil",
"."
] | 45c989fe545070ef7c9003cf1998bb195c61731a | https://github.com/golangplus/bytes/blob/45c989fe545070ef7c9003cf1998bb195c61731a/slice.go#L191-L194 |
149,004 | golangplus/bytes | slice.go | WriteItoa | func (s *Slice) WriteItoa(i int64, base int) (size int, err error) {
l := len(*s)
*s = strconv.AppendInt([]byte(*s), i, base)
return len(*s) - l, nil
} | go | func (s *Slice) WriteItoa(i int64, base int) (size int, err error) {
l := len(*s)
*s = strconv.AppendInt([]byte(*s), i, base)
return len(*s) - l, nil
} | [
"func",
"(",
"s",
"*",
"Slice",
")",
"WriteItoa",
"(",
"i",
"int64",
",",
"base",
"int",
")",
"(",
"size",
"int",
",",
"err",
"error",
")",
"{",
"l",
":=",
"len",
"(",
"*",
"s",
")",
"\n",
"*",
"s",
"=",
"strconv",
".",
"AppendInt",
"(",
"[",... | // WriteItoa converts i into text of the specified base and write to s. | [
"WriteItoa",
"converts",
"i",
"into",
"text",
"of",
"the",
"specified",
"base",
"and",
"write",
"to",
"s",
"."
] | 45c989fe545070ef7c9003cf1998bb195c61731a | https://github.com/golangplus/bytes/blob/45c989fe545070ef7c9003cf1998bb195c61731a/slice.go#L197-L201 |
149,005 | dmotylev/goproperties | properties.go | Load | func Load(file string) (Properties, error) {
p := make(Properties)
f, err := os.Open(file)
if err != nil {
return p, err
}
defer f.Close()
if err := p.Load(f); err != nil {
return p, err
}
return p, nil
} | go | func Load(file string) (Properties, error) {
p := make(Properties)
f, err := os.Open(file)
if err != nil {
return p, err
}
defer f.Close()
if err := p.Load(f); err != nil {
return p, err
}
return p, nil
} | [
"func",
"Load",
"(",
"file",
"string",
")",
"(",
"Properties",
",",
"error",
")",
"{",
"p",
":=",
"make",
"(",
"Properties",
")",
"\n",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"... | // Creates an instance of Properties and try to fill it with data from file.
// It's safe to ignore error as method always return pointer to the created
// instance and close any opened resources. | [
"Creates",
"an",
"instance",
"of",
"Properties",
"and",
"try",
"to",
"fill",
"it",
"with",
"data",
"from",
"file",
".",
"It",
"s",
"safe",
"to",
"ignore",
"error",
"as",
"method",
"always",
"return",
"pointer",
"to",
"the",
"created",
"instance",
"and",
... | 7cbffbaada472bc302cbaca51c1d5ed2682eb509 | https://github.com/dmotylev/goproperties/blob/7cbffbaada472bc302cbaca51c1d5ed2682eb509/properties.go#L92-L103 |
149,006 | dmotylev/goproperties | properties.go | Bool | func (p Properties) Bool(key string, def bool) bool {
if v, found := p[key]; found {
if b, err := strconv.ParseBool(v); err == nil {
return b
}
}
return def
} | go | func (p Properties) Bool(key string, def bool) bool {
if v, found := p[key]; found {
if b, err := strconv.ParseBool(v); err == nil {
return b
}
}
return def
} | [
"func",
"(",
"p",
"Properties",
")",
"Bool",
"(",
"key",
"string",
",",
"def",
"bool",
")",
"bool",
"{",
"if",
"v",
",",
"found",
":=",
"p",
"[",
"key",
"]",
";",
"found",
"{",
"if",
"b",
",",
"err",
":=",
"strconv",
".",
"ParseBool",
"(",
"v",... | // Uses strconv to convert key's value to bool. Returns def if
// conversion failed or key does not exist. | [
"Uses",
"strconv",
"to",
"convert",
"key",
"s",
"value",
"to",
"bool",
".",
"Returns",
"def",
"if",
"conversion",
"failed",
"or",
"key",
"does",
"not",
"exist",
"."
] | 7cbffbaada472bc302cbaca51c1d5ed2682eb509 | https://github.com/dmotylev/goproperties/blob/7cbffbaada472bc302cbaca51c1d5ed2682eb509/properties.go#L107-L114 |
149,007 | dmotylev/goproperties | properties.go | Float | func (p Properties) Float(key string, def float64) float64 {
if v, found := p[key]; found {
if b, err := strconv.ParseFloat(v, 64); err == nil {
return b
}
}
return def
} | go | func (p Properties) Float(key string, def float64) float64 {
if v, found := p[key]; found {
if b, err := strconv.ParseFloat(v, 64); err == nil {
return b
}
}
return def
} | [
"func",
"(",
"p",
"Properties",
")",
"Float",
"(",
"key",
"string",
",",
"def",
"float64",
")",
"float64",
"{",
"if",
"v",
",",
"found",
":=",
"p",
"[",
"key",
"]",
";",
"found",
"{",
"if",
"b",
",",
"err",
":=",
"strconv",
".",
"ParseFloat",
"("... | // Uses strconv to convert key's value to float64. Returns def if
// conversion failed or key does not exist. | [
"Uses",
"strconv",
"to",
"convert",
"key",
"s",
"value",
"to",
"float64",
".",
"Returns",
"def",
"if",
"conversion",
"failed",
"or",
"key",
"does",
"not",
"exist",
"."
] | 7cbffbaada472bc302cbaca51c1d5ed2682eb509 | https://github.com/dmotylev/goproperties/blob/7cbffbaada472bc302cbaca51c1d5ed2682eb509/properties.go#L118-L125 |
149,008 | dmotylev/goproperties | properties.go | String | func (p Properties) String(key string, def string) string {
if v, found := p[key]; found {
return v
}
return def
} | go | func (p Properties) String(key string, def string) string {
if v, found := p[key]; found {
return v
}
return def
} | [
"func",
"(",
"p",
"Properties",
")",
"String",
"(",
"key",
"string",
",",
"def",
"string",
")",
"string",
"{",
"if",
"v",
",",
"found",
":=",
"p",
"[",
"key",
"]",
";",
"found",
"{",
"return",
"v",
"\n",
"}",
"\n",
"return",
"def",
"\n",
"}"
] | // Returns def if key does not exist. | [
"Returns",
"def",
"if",
"key",
"does",
"not",
"exist",
"."
] | 7cbffbaada472bc302cbaca51c1d5ed2682eb509 | https://github.com/dmotylev/goproperties/blob/7cbffbaada472bc302cbaca51c1d5ed2682eb509/properties.go#L150-L155 |
149,009 | dmotylev/goproperties | properties.go | decodeString | func decodeString(in string) (string, error) {
out := make([]byte, len(in))
o := 0
for i := 0; i < len(in); {
if in[i] == '\\' {
i++
switch in[i] {
case 'u':
i++
utf8rune := 0
for j := 0; j < 4; j++ {
switch {
case in[i] >= '0' && in[i] <= '9':
utf8rune = (utf8rune << 4) + int(... | go | func decodeString(in string) (string, error) {
out := make([]byte, len(in))
o := 0
for i := 0; i < len(in); {
if in[i] == '\\' {
i++
switch in[i] {
case 'u':
i++
utf8rune := 0
for j := 0; j < 4; j++ {
switch {
case in[i] >= '0' && in[i] <= '9':
utf8rune = (utf8rune << 4) + int(... | [
"func",
"decodeString",
"(",
"in",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"out",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"in",
")",
")",
"\n",
"o",
":=",
"0",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"... | // Decodes \t,\n,\r,\f and \uXXXX characters in string | [
"Decodes",
"\\",
"t",
"\\",
"n",
"\\",
"r",
"\\",
"f",
"and",
"\\",
"uXXXX",
"characters",
"in",
"string"
] | 7cbffbaada472bc302cbaca51c1d5ed2682eb509 | https://github.com/dmotylev/goproperties/blob/7cbffbaada472bc302cbaca51c1d5ed2682eb509/properties.go#L225-L290 |
149,010 | dmotylev/goproperties | properties.go | readLine | func (lr *lineReader) readLine() (line string, e error) {
if lr.exhausted {
return "", io.EOF
}
nextCharIndex := 0
char := byte(0)
skipLF := false
skipWhiteSpace := true
appendedLineBegin := false
isNewLine := true
isCommentLine := false
precedingBackslash := false
for {
if lr.offset >= lr.limit {
l... | go | func (lr *lineReader) readLine() (line string, e error) {
if lr.exhausted {
return "", io.EOF
}
nextCharIndex := 0
char := byte(0)
skipLF := false
skipWhiteSpace := true
appendedLineBegin := false
isNewLine := true
isCommentLine := false
precedingBackslash := false
for {
if lr.offset >= lr.limit {
l... | [
"func",
"(",
"lr",
"*",
"lineReader",
")",
"readLine",
"(",
")",
"(",
"line",
"string",
",",
"e",
"error",
")",
"{",
"if",
"lr",
".",
"exhausted",
"{",
"return",
"\"",
"\"",
",",
"io",
".",
"EOF",
"\n",
"}",
"\n",
"nextCharIndex",
":=",
"0",
"\n"... | // Returns the "logical line" from given reader | [
"Returns",
"the",
"logical",
"line",
"from",
"given",
"reader"
] | 7cbffbaada472bc302cbaca51c1d5ed2682eb509 | https://github.com/dmotylev/goproperties/blob/7cbffbaada472bc302cbaca51c1d5ed2682eb509/properties.go#L316-L420 |
149,011 | Songmu/wrapcommander | wrapcommander.go | IsInvoked | func IsInvoked(err error) bool {
if err == nil {
return true
}
_, ok := err.(*exec.ExitError)
return ok
} | go | func IsInvoked(err error) bool {
if err == nil {
return true
}
_, ok := err.(*exec.ExitError)
return ok
} | [
"func",
"IsInvoked",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"exec",
".",
"ExitError",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // IsInvoked returns a boolean indicating whether the error is known to report
// that the command is invoked or not. | [
"IsInvoked",
"returns",
"a",
"boolean",
"indicating",
"whether",
"the",
"error",
"is",
"known",
"to",
"report",
"that",
"the",
"command",
"is",
"invoked",
"or",
"not",
"."
] | 40b2529744055e6263ee1cb6c84bda109537ebb4 | https://github.com/Songmu/wrapcommander/blob/40b2529744055e6263ee1cb6c84bda109537ebb4/wrapcommander.go#L45-L51 |
149,012 | Songmu/wrapcommander | wrapcommander.go | ErrorToWaitStatus | func ErrorToWaitStatus(err error) (syscall.WaitStatus, bool) {
if e, ok := err.(*exec.ExitError); ok {
st, ok := e.Sys().(syscall.WaitStatus)
return st, ok
}
var zero syscall.WaitStatus
return zero, false
} | go | func ErrorToWaitStatus(err error) (syscall.WaitStatus, bool) {
if e, ok := err.(*exec.ExitError); ok {
st, ok := e.Sys().(syscall.WaitStatus)
return st, ok
}
var zero syscall.WaitStatus
return zero, false
} | [
"func",
"ErrorToWaitStatus",
"(",
"err",
"error",
")",
"(",
"syscall",
".",
"WaitStatus",
",",
"bool",
")",
"{",
"if",
"e",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"exec",
".",
"ExitError",
")",
";",
"ok",
"{",
"st",
",",
"ok",
":=",
"e",
".",
"... | // ErrorToWaitStatus try to convert error into syscall.WaitStatus | [
"ErrorToWaitStatus",
"try",
"to",
"convert",
"error",
"into",
"syscall",
".",
"WaitStatus"
] | 40b2529744055e6263ee1cb6c84bda109537ebb4 | https://github.com/Songmu/wrapcommander/blob/40b2529744055e6263ee1cb6c84bda109537ebb4/wrapcommander.go#L54-L61 |
149,013 | Songmu/wrapcommander | wrapcommander.go | ResolveExitCode | func ResolveExitCode(err error) int {
if err == nil {
return ExitNormal
}
if !IsInvoked(err) {
switch {
case IsPermission(err), IsExecFormatError(err):
return ExitCommandNotInvoked
case IsNotExist(err), IsNotFoundInPATH(err):
return ExitCommandNotFound
default:
return ExitUnknownErr
}
}
if sta... | go | func ResolveExitCode(err error) int {
if err == nil {
return ExitNormal
}
if !IsInvoked(err) {
switch {
case IsPermission(err), IsExecFormatError(err):
return ExitCommandNotInvoked
case IsNotExist(err), IsNotFoundInPATH(err):
return ExitCommandNotFound
default:
return ExitUnknownErr
}
}
if sta... | [
"func",
"ResolveExitCode",
"(",
"err",
"error",
")",
"int",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"ExitNormal",
"\n",
"}",
"\n",
"if",
"!",
"IsInvoked",
"(",
"err",
")",
"{",
"switch",
"{",
"case",
"IsPermission",
"(",
"err",
")",
",",
"IsExe... | // ResolveExitCode retruns a int as command exit code from an error. | [
"ResolveExitCode",
"retruns",
"a",
"int",
"as",
"command",
"exit",
"code",
"from",
"an",
"error",
"."
] | 40b2529744055e6263ee1cb6c84bda109537ebb4 | https://github.com/Songmu/wrapcommander/blob/40b2529744055e6263ee1cb6c84bda109537ebb4/wrapcommander.go#L69-L87 |
149,014 | Songmu/wrapcommander | wrapcommander.go | SeparateArgs | func SeparateArgs(args []string) ([]string, []string) {
optsArgs := []string{}
cmdArgs := []string{}
for i, v := range args {
if v == "--" && i+1 < len(args) {
cmdArgs = args[i+1:]
break
}
optsArgs = append(optsArgs, v)
}
if len(cmdArgs) <= 0 {
cmdArgs, optsArgs = optsArgs, []string{}
}
return opts... | go | func SeparateArgs(args []string) ([]string, []string) {
optsArgs := []string{}
cmdArgs := []string{}
for i, v := range args {
if v == "--" && i+1 < len(args) {
cmdArgs = args[i+1:]
break
}
optsArgs = append(optsArgs, v)
}
if len(cmdArgs) <= 0 {
cmdArgs, optsArgs = optsArgs, []string{}
}
return opts... | [
"func",
"SeparateArgs",
"(",
"args",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"string",
",",
"[",
"]",
"string",
")",
"{",
"optsArgs",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"cmdArgs",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"i",
","... | // SeparateArgs separates command line arguments for wrapper command. | [
"SeparateArgs",
"separates",
"command",
"line",
"arguments",
"for",
"wrapper",
"command",
"."
] | 40b2529744055e6263ee1cb6c84bda109537ebb4 | https://github.com/Songmu/wrapcommander/blob/40b2529744055e6263ee1cb6c84bda109537ebb4/wrapcommander.go#L90-L104 |
149,015 | Financial-Times/neo-utils-go | neoutils/neoutils.go | Check | func Check(cr CypherRunner) error {
var results []struct {
node interface{}
}
query := &neoism.CypherQuery{
Statement: `MATCH (n) RETURN id(n) LIMIT 1`,
Result: &results,
}
err := cr.CypherBatch([]*neoism.CypherQuery{query})
if err != nil {
return err
}
return nil
} | go | func Check(cr CypherRunner) error {
var results []struct {
node interface{}
}
query := &neoism.CypherQuery{
Statement: `MATCH (n) RETURN id(n) LIMIT 1`,
Result: &results,
}
err := cr.CypherBatch([]*neoism.CypherQuery{query})
if err != nil {
return err
}
return nil
} | [
"func",
"Check",
"(",
"cr",
"CypherRunner",
")",
"error",
"{",
"var",
"results",
"[",
"]",
"struct",
"{",
"node",
"interface",
"{",
"}",
"\n",
"}",
"\n\n",
"query",
":=",
"&",
"neoism",
".",
"CypherQuery",
"{",
"Statement",
":",
"`MATCH (n) RETURN id(n) LI... | // Check will use the supplied CypherRunner to check connectivity to Neo4j | [
"Check",
"will",
"use",
"the",
"supplied",
"CypherRunner",
"to",
"check",
"connectivity",
"to",
"Neo4j"
] | 7fc6c3f7b78f6e11f15d0613716048ed1e5e6d66 | https://github.com/Financial-Times/neo-utils-go/blob/7fc6c3f7b78f6e11f15d0613716048ed1e5e6d66/neoutils/neoutils.go#L17-L33 |
149,016 | Financial-Times/neo-utils-go | neoutils/neoutils.go | EnsureIndexes | func EnsureIndexes(im IndexManager, indexes map[string]string) error {
for label, propertyName := range indexes {
err := ensureIndex(im, label, propertyName)
if err != nil { // stop as soon as something goes wrong
return err
}
}
return nil
} | go | func EnsureIndexes(im IndexManager, indexes map[string]string) error {
for label, propertyName := range indexes {
err := ensureIndex(im, label, propertyName)
if err != nil { // stop as soon as something goes wrong
return err
}
}
return nil
} | [
"func",
"EnsureIndexes",
"(",
"im",
"IndexManager",
",",
"indexes",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"for",
"label",
",",
"propertyName",
":=",
"range",
"indexes",
"{",
"err",
":=",
"ensureIndex",
"(",
"im",
",",
"label",
",",
"pro... | // EnsureIndexes will, for a map of labels and properties, check whether an index exists for a given property on a given label, and if missing will create one | [
"EnsureIndexes",
"will",
"for",
"a",
"map",
"of",
"labels",
"and",
"properties",
"check",
"whether",
"an",
"index",
"exists",
"for",
"a",
"given",
"property",
"on",
"a",
"given",
"label",
"and",
"if",
"missing",
"will",
"create",
"one"
] | 7fc6c3f7b78f6e11f15d0613716048ed1e5e6d66 | https://github.com/Financial-Times/neo-utils-go/blob/7fc6c3f7b78f6e11f15d0613716048ed1e5e6d66/neoutils/neoutils.go#L67-L75 |
149,017 | Financial-Times/neo-utils-go | neoutils/neoutils.go | EnsureConstraints | func EnsureConstraints(im IndexManager, indexes map[string]string) error {
for label, propertyName := range indexes {
err := ensureConstraint(im, label, propertyName)
if err != nil { // stop as soon as something goes wrong
return err
}
}
return nil
} | go | func EnsureConstraints(im IndexManager, indexes map[string]string) error {
for label, propertyName := range indexes {
err := ensureConstraint(im, label, propertyName)
if err != nil { // stop as soon as something goes wrong
return err
}
}
return nil
} | [
"func",
"EnsureConstraints",
"(",
"im",
"IndexManager",
",",
"indexes",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"for",
"label",
",",
"propertyName",
":=",
"range",
"indexes",
"{",
"err",
":=",
"ensureConstraint",
"(",
"im",
",",
"label",
",... | // EnsureConstraints will, for a map of labels and properties, check whether a constraint exists for a given property on a given label, and
// if missing will create one. Creating the unique constraint ensures an index automatically. | [
"EnsureConstraints",
"will",
"for",
"a",
"map",
"of",
"labels",
"and",
"properties",
"check",
"whether",
"a",
"constraint",
"exists",
"for",
"a",
"given",
"property",
"on",
"a",
"given",
"label",
"and",
"if",
"missing",
"will",
"create",
"one",
".",
"Creatin... | 7fc6c3f7b78f6e11f15d0613716048ed1e5e6d66 | https://github.com/Financial-Times/neo-utils-go/blob/7fc6c3f7b78f6e11f15d0613716048ed1e5e6d66/neoutils/neoutils.go#L79-L87 |
149,018 | Financial-Times/neo-utils-go | neoutils/error.go | NewConstraintViolationError | func NewConstraintViolationError(message string, err *neoism.NeoError) error {
if err == nil {
return nil
}
return &ConstraintViolationError{message, err}
} | go | func NewConstraintViolationError(message string, err *neoism.NeoError) error {
if err == nil {
return nil
}
return &ConstraintViolationError{message, err}
} | [
"func",
"NewConstraintViolationError",
"(",
"message",
"string",
",",
"err",
"*",
"neoism",
".",
"NeoError",
")",
"error",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"ConstraintViolationError",
"{",
"message",
",",
... | // NewConstraintViolationError returns, as an error, a new NewConstraintViolationError
// with the given message and error details.
// As a convenience, if err is nil, NewSyscallError returns nil. | [
"NewConstraintViolationError",
"returns",
"as",
"an",
"error",
"a",
"new",
"NewConstraintViolationError",
"with",
"the",
"given",
"message",
"and",
"error",
"details",
".",
"As",
"a",
"convenience",
"if",
"err",
"is",
"nil",
"NewSyscallError",
"returns",
"nil",
".... | 7fc6c3f7b78f6e11f15d0613716048ed1e5e6d66 | https://github.com/Financial-Times/neo-utils-go/blob/7fc6c3f7b78f6e11f15d0613716048ed1e5e6d66/neoutils/error.go#L21-L26 |
149,019 | Songmu/wrapcommander | exitstatus.go | ResolveExitStatus | func ResolveExitStatus(err error) *ExitStatus {
es := &ExitStatus{
invoked: true,
err: err,
exitCode: -1,
}
if es.err == nil {
es.exitCode = 0
return es
}
eerr, ok := es.err.(*exec.ExitError)
es.invoked = ok
if !es.invoked {
switch {
case os.IsPermission(err), IsExecFormatError(err):
es.e... | go | func ResolveExitStatus(err error) *ExitStatus {
es := &ExitStatus{
invoked: true,
err: err,
exitCode: -1,
}
if es.err == nil {
es.exitCode = 0
return es
}
eerr, ok := es.err.(*exec.ExitError)
es.invoked = ok
if !es.invoked {
switch {
case os.IsPermission(err), IsExecFormatError(err):
es.e... | [
"func",
"ResolveExitStatus",
"(",
"err",
"error",
")",
"*",
"ExitStatus",
"{",
"es",
":=",
"&",
"ExitStatus",
"{",
"invoked",
":",
"true",
",",
"err",
":",
"err",
",",
"exitCode",
":",
"-",
"1",
",",
"}",
"\n",
"if",
"es",
".",
"err",
"==",
"nil",
... | // ResolveExitStatus resolve ExitStatus from command error | [
"ResolveExitStatus",
"resolve",
"ExitStatus",
"from",
"command",
"error"
] | 40b2529744055e6263ee1cb6c84bda109537ebb4 | https://github.com/Songmu/wrapcommander/blob/40b2529744055e6263ee1cb6c84bda109537ebb4/exitstatus.go#L44-L78 |
149,020 | joyent/gosign | auth/auth.go | NewAuth | func NewAuth(user, privateKey, algorithm string) (*Auth, error) {
block, _ := pem.Decode([]byte(privateKey))
if block == nil {
return nil, fmt.Errorf("invalid private key data: %s", privateKey)
}
rsakey, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
return nil, fmt.Errorf("An error occurred whi... | go | func NewAuth(user, privateKey, algorithm string) (*Auth, error) {
block, _ := pem.Decode([]byte(privateKey))
if block == nil {
return nil, fmt.Errorf("invalid private key data: %s", privateKey)
}
rsakey, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
return nil, fmt.Errorf("An error occurred whi... | [
"func",
"NewAuth",
"(",
"user",
",",
"privateKey",
",",
"algorithm",
"string",
")",
"(",
"*",
"Auth",
",",
"error",
")",
"{",
"block",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"[",
"]",
"byte",
"(",
"privateKey",
")",
")",
"\n",
"if",
"block",
... | // NewAuth creates a new Auth. | [
"NewAuth",
"creates",
"a",
"new",
"Auth",
"."
] | 9abcee278795b82b36858cdfc857c8a0e7de797c | https://github.com/joyent/gosign/blob/9abcee278795b82b36858cdfc857c8a0e7de797c/auth/auth.go#L54-L64 |
149,021 | joyent/gosign | auth/auth.go | CreateAuthorizationHeader | func CreateAuthorizationHeader(headers http.Header, credentials *Credentials, isMantaRequest bool) (string, error) {
if isMantaRequest {
signature, err := GetSignature(credentials.UserAuthentication, "date: "+headers.Get("Date"))
if err != nil {
return "", err
}
return fmt.Sprintf(MantaSignature, credential... | go | func CreateAuthorizationHeader(headers http.Header, credentials *Credentials, isMantaRequest bool) (string, error) {
if isMantaRequest {
signature, err := GetSignature(credentials.UserAuthentication, "date: "+headers.Get("Date"))
if err != nil {
return "", err
}
return fmt.Sprintf(MantaSignature, credential... | [
"func",
"CreateAuthorizationHeader",
"(",
"headers",
"http",
".",
"Header",
",",
"credentials",
"*",
"Credentials",
",",
"isMantaRequest",
"bool",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"isMantaRequest",
"{",
"signature",
",",
"err",
":=",
"GetSigna... | // The CreateAuthorizationHeader returns the Authorization header for the give request. | [
"The",
"CreateAuthorizationHeader",
"returns",
"the",
"Authorization",
"header",
"for",
"the",
"give",
"request",
"."
] | 9abcee278795b82b36858cdfc857c8a0e7de797c | https://github.com/joyent/gosign/blob/9abcee278795b82b36858cdfc857c8a0e7de797c/auth/auth.go#L67-L82 |
149,022 | joyent/gosign | auth/auth.go | getHashFunction | func getHashFunction(algorithm string) (hashFunc crypto.Hash) {
switch strings.ToLower(algorithm) {
case "rsa-sha1":
hashFunc = crypto.SHA1
case "rsa-sha224", "rsa-sha256":
hashFunc = crypto.SHA256
case "rsa-sha384", "rsa-sha512":
hashFunc = crypto.SHA512
default:
hashFunc = crypto.SHA256
}
return
} | go | func getHashFunction(algorithm string) (hashFunc crypto.Hash) {
switch strings.ToLower(algorithm) {
case "rsa-sha1":
hashFunc = crypto.SHA1
case "rsa-sha224", "rsa-sha256":
hashFunc = crypto.SHA256
case "rsa-sha384", "rsa-sha512":
hashFunc = crypto.SHA512
default:
hashFunc = crypto.SHA256
}
return
} | [
"func",
"getHashFunction",
"(",
"algorithm",
"string",
")",
"(",
"hashFunc",
"crypto",
".",
"Hash",
")",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"algorithm",
")",
"{",
"case",
"\"",
"\"",
":",
"hashFunc",
"=",
"crypto",
".",
"SHA1",
"\n",
"case",
... | // Helper method to get the Hash function based on the algorithm | [
"Helper",
"method",
"to",
"get",
"the",
"Hash",
"function",
"based",
"on",
"the",
"algorithm"
] | 9abcee278795b82b36858cdfc857c8a0e7de797c | https://github.com/joyent/gosign/blob/9abcee278795b82b36858cdfc857c8a0e7de797c/auth/auth.go#L102-L114 |
149,023 | vova616/xxhash | xxhash.go | Write | func (self *XXHash) Write(data []byte) (nn int, err error) {
if data == nil {
return 0, errors.New("Data cannot be nil.")
}
l := len(data)
if l > 1<<30 {
return 0, errors.New("Cannot add more than 1 Gigabytes at once.")
}
self.feed(data)
return len(data), nil
} | go | func (self *XXHash) Write(data []byte) (nn int, err error) {
if data == nil {
return 0, errors.New("Data cannot be nil.")
}
l := len(data)
if l > 1<<30 {
return 0, errors.New("Cannot add more than 1 Gigabytes at once.")
}
self.feed(data)
return len(data), nil
} | [
"func",
"(",
"self",
"*",
"XXHash",
")",
"Write",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"nn",
"int",
",",
"err",
"error",
")",
"{",
"if",
"data",
"==",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
... | // Write adds more data to the running hash.
// Length of data MUST BE less than 1 Gigabytes. | [
"Write",
"adds",
"more",
"data",
"to",
"the",
"running",
"hash",
".",
"Length",
"of",
"data",
"MUST",
"BE",
"less",
"than",
"1",
"Gigabytes",
"."
] | f0a9a8b74d487f9563a527daf3bd6b4fbd3f5d00 | https://github.com/vova616/xxhash/blob/f0a9a8b74d487f9563a527daf3bd6b4fbd3f5d00/xxhash.go#L167-L177 |
149,024 | ethantkoenig/rupture | metadata.go | ReadIndexMetadata | func ReadIndexMetadata(path string) (*IndexMetadata, error) {
meta := &IndexMetadata{}
metaPath := indexMetadataPath(path)
if _, err := os.Stat(metaPath); os.IsNotExist(err) {
return meta, nil
} else if err != nil {
return nil, err
}
return meta, readJSON(metaPath, meta)
} | go | func ReadIndexMetadata(path string) (*IndexMetadata, error) {
meta := &IndexMetadata{}
metaPath := indexMetadataPath(path)
if _, err := os.Stat(metaPath); os.IsNotExist(err) {
return meta, nil
} else if err != nil {
return nil, err
}
return meta, readJSON(metaPath, meta)
} | [
"func",
"ReadIndexMetadata",
"(",
"path",
"string",
")",
"(",
"*",
"IndexMetadata",
",",
"error",
")",
"{",
"meta",
":=",
"&",
"IndexMetadata",
"{",
"}",
"\n",
"metaPath",
":=",
"indexMetadataPath",
"(",
"path",
")",
"\n",
"if",
"_",
",",
"err",
":=",
... | // ReadIndexMetadata returns the metadata for the index at the specified path.
// If no such index metadata exists, an empty metadata and a nil error are
// returned. | [
"ReadIndexMetadata",
"returns",
"the",
"metadata",
"for",
"the",
"index",
"at",
"the",
"specified",
"path",
".",
"If",
"no",
"such",
"index",
"metadata",
"exists",
"an",
"empty",
"metadata",
"and",
"a",
"nil",
"error",
"are",
"returned",
"."
] | c3b3b810dc77dda7b29a8b43c7761d8cfaa387d0 | https://github.com/ethantkoenig/rupture/blob/c3b3b810dc77dda7b29a8b43c7761d8cfaa387d0/metadata.go#L54-L63 |
149,025 | ethantkoenig/rupture | metadata.go | WriteIndexMetadata | func WriteIndexMetadata(path string, meta *IndexMetadata) error {
return writeJSON(indexMetadataPath(path), meta)
} | go | func WriteIndexMetadata(path string, meta *IndexMetadata) error {
return writeJSON(indexMetadataPath(path), meta)
} | [
"func",
"WriteIndexMetadata",
"(",
"path",
"string",
",",
"meta",
"*",
"IndexMetadata",
")",
"error",
"{",
"return",
"writeJSON",
"(",
"indexMetadataPath",
"(",
"path",
")",
",",
"meta",
")",
"\n",
"}"
] | // WriteIndexMetadata writes metadata for the index at the specified path. | [
"WriteIndexMetadata",
"writes",
"metadata",
"for",
"the",
"index",
"at",
"the",
"specified",
"path",
"."
] | c3b3b810dc77dda7b29a8b43c7761d8cfaa387d0 | https://github.com/ethantkoenig/rupture/blob/c3b3b810dc77dda7b29a8b43c7761d8cfaa387d0/metadata.go#L66-L68 |
149,026 | ethantkoenig/rupture | flushing_batch.go | NewFlushingBatch | func NewFlushingBatch(index bleve.Index, maxBatchSize int) FlushingBatch {
return newFlushingBatch(index, maxBatchSize)
} | go | func NewFlushingBatch(index bleve.Index, maxBatchSize int) FlushingBatch {
return newFlushingBatch(index, maxBatchSize)
} | [
"func",
"NewFlushingBatch",
"(",
"index",
"bleve",
".",
"Index",
",",
"maxBatchSize",
"int",
")",
"FlushingBatch",
"{",
"return",
"newFlushingBatch",
"(",
"index",
",",
"maxBatchSize",
")",
"\n",
"}"
] | // NewFlushingBatch creates a new flushing batch for the specified index. Once
// the number of operations in the batch reaches the specified limit, the batch
// automatically flushes its operations to the index. | [
"NewFlushingBatch",
"creates",
"a",
"new",
"flushing",
"batch",
"for",
"the",
"specified",
"index",
".",
"Once",
"the",
"number",
"of",
"operations",
"in",
"the",
"batch",
"reaches",
"the",
"specified",
"limit",
"the",
"batch",
"automatically",
"flushes",
"its",... | c3b3b810dc77dda7b29a8b43c7761d8cfaa387d0 | https://github.com/ethantkoenig/rupture/blob/c3b3b810dc77dda7b29a8b43c7761d8cfaa387d0/flushing_batch.go#L37-L39 |
149,027 | charlievieth/fs | fs.go | NewFile | func NewFile(fd uintptr, name string) *os.File {
return newfile(fd, name)
} | go | func NewFile(fd uintptr, name string) *os.File {
return newfile(fd, name)
} | [
"func",
"NewFile",
"(",
"fd",
"uintptr",
",",
"name",
"string",
")",
"*",
"os",
".",
"File",
"{",
"return",
"newfile",
"(",
"fd",
",",
"name",
")",
"\n",
"}"
] | // NewFile returns a new File with the given file descriptor and name. | [
"NewFile",
"returns",
"a",
"new",
"File",
"with",
"the",
"given",
"file",
"descriptor",
"and",
"name",
"."
] | 7dc373669fa10ddf827c37c595dee30a2f001be9 | https://github.com/charlievieth/fs/blob/7dc373669fa10ddf827c37c595dee30a2f001be9/fs.go#L145-L147 |
149,028 | ethantkoenig/rupture | sharded_index.go | NewShardedIndex | func NewShardedIndex(path string, mapping mapping.IndexMapping, numShards int) (ShardedIndex, error) {
if numShards <= 0 {
return nil, fmt.Errorf("Invalid number of shards: %d", numShards)
}
err := writeJSON(shardedIndexMetadataPath(path), &shardedIndexMetadata{NumShards: numShards})
if err != nil {
return nil,... | go | func NewShardedIndex(path string, mapping mapping.IndexMapping, numShards int) (ShardedIndex, error) {
if numShards <= 0 {
return nil, fmt.Errorf("Invalid number of shards: %d", numShards)
}
err := writeJSON(shardedIndexMetadataPath(path), &shardedIndexMetadata{NumShards: numShards})
if err != nil {
return nil,... | [
"func",
"NewShardedIndex",
"(",
"path",
"string",
",",
"mapping",
"mapping",
".",
"IndexMapping",
",",
"numShards",
"int",
")",
"(",
"ShardedIndex",
",",
"error",
")",
"{",
"if",
"numShards",
"<=",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(... | // NewShardedIndex creates a sharded index at the specified path, with the
// specified mapping and number of shards. | [
"NewShardedIndex",
"creates",
"a",
"sharded",
"index",
"at",
"the",
"specified",
"path",
"with",
"the",
"specified",
"mapping",
"and",
"number",
"of",
"shards",
"."
] | c3b3b810dc77dda7b29a8b43c7761d8cfaa387d0 | https://github.com/ethantkoenig/rupture/blob/c3b3b810dc77dda7b29a8b43c7761d8cfaa387d0/sharded_index.go#L43-L63 |
149,029 | ethantkoenig/rupture | sharded_index.go | OpenShardedIndex | func OpenShardedIndex(path string) (ShardedIndex, error) {
var meta shardedIndexMetadata
var err error
if err = readJSON(shardedIndexMetadataPath(path), &meta); err != nil {
return nil, err
}
s := &shardedIndex{
indices: make([]bleve.Index, meta.NumShards),
}
for i := 0; i < meta.NumShards; i++ {
s.indice... | go | func OpenShardedIndex(path string) (ShardedIndex, error) {
var meta shardedIndexMetadata
var err error
if err = readJSON(shardedIndexMetadataPath(path), &meta); err != nil {
return nil, err
}
s := &shardedIndex{
indices: make([]bleve.Index, meta.NumShards),
}
for i := 0; i < meta.NumShards; i++ {
s.indice... | [
"func",
"OpenShardedIndex",
"(",
"path",
"string",
")",
"(",
"ShardedIndex",
",",
"error",
")",
"{",
"var",
"meta",
"shardedIndexMetadata",
"\n",
"var",
"err",
"error",
"\n",
"if",
"err",
"=",
"readJSON",
"(",
"shardedIndexMetadataPath",
"(",
"path",
")",
",... | // OpenShardedIndex opens a sharded index at the specified path. | [
"OpenShardedIndex",
"opens",
"a",
"sharded",
"index",
"at",
"the",
"specified",
"path",
"."
] | c3b3b810dc77dda7b29a8b43c7761d8cfaa387d0 | https://github.com/ethantkoenig/rupture/blob/c3b3b810dc77dda7b29a8b43c7761d8cfaa387d0/sharded_index.go#L66-L84 |
149,030 | ethantkoenig/rupture | sharded_index.go | NewShardedFlushingBatch | func NewShardedFlushingBatch(index ShardedIndex, maxBatchSize int) FlushingBatch {
indices := index.shards()
b := &shardedIndexFlushingBatch{
batches: make([]*singleIndexFlushingBatch, len(indices)),
}
for i, index := range indices {
b.batches[i] = newFlushingBatch(index, maxBatchSize)
}
return b
} | go | func NewShardedFlushingBatch(index ShardedIndex, maxBatchSize int) FlushingBatch {
indices := index.shards()
b := &shardedIndexFlushingBatch{
batches: make([]*singleIndexFlushingBatch, len(indices)),
}
for i, index := range indices {
b.batches[i] = newFlushingBatch(index, maxBatchSize)
}
return b
} | [
"func",
"NewShardedFlushingBatch",
"(",
"index",
"ShardedIndex",
",",
"maxBatchSize",
"int",
")",
"FlushingBatch",
"{",
"indices",
":=",
"index",
".",
"shards",
"(",
")",
"\n",
"b",
":=",
"&",
"shardedIndexFlushingBatch",
"{",
"batches",
":",
"make",
"(",
"[",... | // NewShardedFlushingBatch creates a flushing batch with the specified batch
// size for the specified sharded index. | [
"NewShardedFlushingBatch",
"creates",
"a",
"flushing",
"batch",
"with",
"the",
"specified",
"batch",
"size",
"for",
"the",
"specified",
"sharded",
"index",
"."
] | c3b3b810dc77dda7b29a8b43c7761d8cfaa387d0 | https://github.com/ethantkoenig/rupture/blob/c3b3b810dc77dda7b29a8b43c7761d8cfaa387d0/sharded_index.go#L120-L129 |
149,031 | timewasted/go-accept-headers | accept.go | Negotiate | func Negotiate(header string, ctypes ...string) (string, error) {
a := Parse(header)
return a.Negotiate(ctypes...)
} | go | func Negotiate(header string, ctypes ...string) (string, error) {
a := Parse(header)
return a.Negotiate(ctypes...)
} | [
"func",
"Negotiate",
"(",
"header",
"string",
",",
"ctypes",
"...",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"a",
":=",
"Parse",
"(",
"header",
")",
"\n",
"return",
"a",
".",
"Negotiate",
"(",
"ctypes",
"...",
")",
"\n",
"}"
] | // Negotiate returns a type that is accepted by both the header declaration,
// and the list of types provided. If no common types are found, an empty
// string is returned. | [
"Negotiate",
"returns",
"a",
"type",
"that",
"is",
"accepted",
"by",
"both",
"the",
"header",
"declaration",
"and",
"the",
"list",
"of",
"types",
"provided",
".",
"If",
"no",
"common",
"types",
"are",
"found",
"an",
"empty",
"string",
"is",
"returned",
"."... | c78f304b1b09181c0a2de98d15f5279514413f7b | https://github.com/timewasted/go-accept-headers/blob/c78f304b1b09181c0a2de98d15f5279514413f7b/accept.go#L90-L93 |
149,032 | timewasted/go-accept-headers | accept.go | Negotiate | func (accept AcceptSlice) Negotiate(ctypes ...string) (string, error) {
if len(ctypes) == 0 {
return "", nil
}
typeSubtypes := make([][]string, 0, len(ctypes))
for _, v := range ctypes {
_, ts, err := parseMediaRange(v)
if err != nil {
return "", err
}
if ts[0] == "*" && ts[1] == "*" {
return v, ni... | go | func (accept AcceptSlice) Negotiate(ctypes ...string) (string, error) {
if len(ctypes) == 0 {
return "", nil
}
typeSubtypes := make([][]string, 0, len(ctypes))
for _, v := range ctypes {
_, ts, err := parseMediaRange(v)
if err != nil {
return "", err
}
if ts[0] == "*" && ts[1] == "*" {
return v, ni... | [
"func",
"(",
"accept",
"AcceptSlice",
")",
"Negotiate",
"(",
"ctypes",
"...",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"len",
"(",
"ctypes",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n\n",
"typeSubtypes",
... | // Negotiate returns a type that is accepted by both the AcceptSlice, and the
// list of types provided. If no common types are found, an empty string is
// returned. | [
"Negotiate",
"returns",
"a",
"type",
"that",
"is",
"accepted",
"by",
"both",
"the",
"AcceptSlice",
"and",
"the",
"list",
"of",
"types",
"provided",
".",
"If",
"no",
"common",
"types",
"are",
"found",
"an",
"empty",
"string",
"is",
"returned",
"."
] | c78f304b1b09181c0a2de98d15f5279514413f7b | https://github.com/timewasted/go-accept-headers/blob/c78f304b1b09181c0a2de98d15f5279514413f7b/accept.go#L98-L125 |
149,033 | timewasted/go-accept-headers | accept.go | Accepts | func (accept AcceptSlice) Accepts(ctype string) bool {
t, err := accept.Negotiate(ctype)
if t == "" || err != nil {
return false
}
return true
} | go | func (accept AcceptSlice) Accepts(ctype string) bool {
t, err := accept.Negotiate(ctype)
if t == "" || err != nil {
return false
}
return true
} | [
"func",
"(",
"accept",
"AcceptSlice",
")",
"Accepts",
"(",
"ctype",
"string",
")",
"bool",
"{",
"t",
",",
"err",
":=",
"accept",
".",
"Negotiate",
"(",
"ctype",
")",
"\n",
"if",
"t",
"==",
"\"",
"\"",
"||",
"err",
"!=",
"nil",
"{",
"return",
"false... | // Accepts returns true if the provided type is accepted. | [
"Accepts",
"returns",
"true",
"if",
"the",
"provided",
"type",
"is",
"accepted",
"."
] | c78f304b1b09181c0a2de98d15f5279514413f7b | https://github.com/timewasted/go-accept-headers/blob/c78f304b1b09181c0a2de98d15f5279514413f7b/accept.go#L128-L134 |
149,034 | sec51/cryptoengine | message.go | encryptedMessageFromBytes | func encryptedMessageFromBytes(data []byte) (EncryptedMessage, error) {
var err error
var lengthData [8]byte
var nonceData [nonceSize]byte
minimumDataSize := 8 + nonceSize
m := EncryptedMessage{}
// check if the data is smaller than 36 which is the minimum
if data == nil {
return m, MessageParsingError
}
... | go | func encryptedMessageFromBytes(data []byte) (EncryptedMessage, error) {
var err error
var lengthData [8]byte
var nonceData [nonceSize]byte
minimumDataSize := 8 + nonceSize
m := EncryptedMessage{}
// check if the data is smaller than 36 which is the minimum
if data == nil {
return m, MessageParsingError
}
... | [
"func",
"encryptedMessageFromBytes",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"EncryptedMessage",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"lengthData",
"[",
"8",
"]",
"byte",
"\n",
"var",
"nonceData",
"[",
"nonceSize",
"]",
"byte",
"\... | // Parse the bytes coming from the network and extract
// |length| => 8
// |nonce| => nonce size
// |message| => message | [
"Parse",
"the",
"bytes",
"coming",
"from",
"the",
"network",
"and",
"extract",
"|length|",
"=",
">",
"8",
"|nonce|",
"=",
">",
"nonce",
"size",
"|message|",
"=",
">",
"message"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/message.go#L68-L104 |
149,035 | sec51/cryptoengine | message.go | messageFromBytes | func messageFromBytes(data []byte) (*message, error) {
var err error
var versionData [4]byte
var typeData [4]byte
minimumDataSize := 4 + 4
m := new(message)
// check if the data is smaller than 36 which is the minimum
if data == nil {
return nil, MessageParsingError
}
if len(data) < minimumDataSize+1 {
... | go | func messageFromBytes(data []byte) (*message, error) {
var err error
var versionData [4]byte
var typeData [4]byte
minimumDataSize := 4 + 4
m := new(message)
// check if the data is smaller than 36 which is the minimum
if data == nil {
return nil, MessageParsingError
}
if len(data) < minimumDataSize+1 {
... | [
"func",
"messageFromBytes",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"message",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"versionData",
"[",
"4",
"]",
"byte",
"\n",
"var",
"typeData",
"[",
"4",
"]",
"byte",
"\n",
"minimumDataS... | // This function separates the associated data once decrypted | [
"This",
"function",
"separates",
"the",
"associated",
"data",
"once",
"decrypted"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/message.go#L107-L142 |
149,036 | sec51/cryptoengine | file_utils.go | init | func init() {
if os.Getenv("SEC51_KEYPATH") != "" {
keyPath = os.Getenv("SEC51_KEYPATH")
} else {
keyPath = "keys"
}
keysFolderPrefixFormat = filepath.Join(keyPath, "%s")
testKeysFolderPrefixFormat = filepath.Join(testKeyPath, "%s")
if err := createBaseKeyFolder(keyPath); err != nil {
log.Println(err)
}
} | go | func init() {
if os.Getenv("SEC51_KEYPATH") != "" {
keyPath = os.Getenv("SEC51_KEYPATH")
} else {
keyPath = "keys"
}
keysFolderPrefixFormat = filepath.Join(keyPath, "%s")
testKeysFolderPrefixFormat = filepath.Join(testKeyPath, "%s")
if err := createBaseKeyFolder(keyPath); err != nil {
log.Println(err)
}
} | [
"func",
"init",
"(",
")",
"{",
"if",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"!=",
"\"",
"\"",
"{",
"keyPath",
"=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"keyPath",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"keysFold... | // create the keys folder if it does not exist, with the proper permission | [
"create",
"the",
"keys",
"folder",
"if",
"it",
"does",
"not",
"exist",
"with",
"the",
"proper",
"permission"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/file_utils.go#L23-L35 |
149,037 | sec51/cryptoengine | file_utils.go | keyFileExists | func keyFileExists(filename string) bool {
_, err := os.Stat(fmt.Sprintf(keysFolderPrefixFormat, filename))
return err == nil
} | go | func keyFileExists(filename string) bool {
_, err := os.Stat(fmt.Sprintf(keysFolderPrefixFormat, filename))
return err == nil
} | [
"func",
"keyFileExists",
"(",
"filename",
"string",
")",
"bool",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"fmt",
".",
"Sprintf",
"(",
"keysFolderPrefixFormat",
",",
"filename",
")",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // Check if a key file exists | [
"Check",
"if",
"a",
"key",
"file",
"exists"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/file_utils.go#L44-L47 |
149,038 | sec51/cryptoengine | file_utils.go | readKey | func readKey(filename, pathFormat string) ([keySize]byte, error) {
var data32 [keySize]byte
// read the data back
data, err := readFile(fmt.Sprintf(pathFormat, filename))
if err != nil {
return data32, err
}
// decode from hex
dst := make([]byte, len(data))
_, err = hex.Decode(dst, data) //.StdEncoding.Decod... | go | func readKey(filename, pathFormat string) ([keySize]byte, error) {
var data32 [keySize]byte
// read the data back
data, err := readFile(fmt.Sprintf(pathFormat, filename))
if err != nil {
return data32, err
}
// decode from hex
dst := make([]byte, len(data))
_, err = hex.Decode(dst, data) //.StdEncoding.Decod... | [
"func",
"readKey",
"(",
"filename",
",",
"pathFormat",
"string",
")",
"(",
"[",
"keySize",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"data32",
"[",
"keySize",
"]",
"byte",
"\n\n",
"// read the data back",
"data",
",",
"err",
":=",
"readFile",
"(",
"fmt... | // Read the key file into a 32 byte array | [
"Read",
"the",
"key",
"file",
"into",
"a",
"32",
"byte",
"array"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/file_utils.go#L75-L92 |
149,039 | sec51/cryptoengine | file_utils.go | writeKey | func writeKey(filename, pathFormat string, data []byte) error {
dst := make([]byte, hex.EncodedLen(len(data))) //StdEncoding.EncodedLen(len(data)))
hex.Encode(dst, data) // StdEncoding.Encode(dst, data)
filePath := fmt.Sprintf(pathFormat, filename)
return writeFile(filePath, dst)
} | go | func writeKey(filename, pathFormat string, data []byte) error {
dst := make([]byte, hex.EncodedLen(len(data))) //StdEncoding.EncodedLen(len(data)))
hex.Encode(dst, data) // StdEncoding.Encode(dst, data)
filePath := fmt.Sprintf(pathFormat, filename)
return writeFile(filePath, dst)
} | [
"func",
"writeKey",
"(",
"filename",
",",
"pathFormat",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"dst",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"hex",
".",
"EncodedLen",
"(",
"len",
"(",
"data",
")",
")",
")",
"//StdEncoding.Enco... | // Write the key file hex encoded | [
"Write",
"the",
"key",
"file",
"hex",
"encoded"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/file_utils.go#L95-L100 |
149,040 | sec51/cryptoengine | file_utils.go | deleteFile | func deleteFile(filename string) error {
if fileExists(filename) {
return os.Remove(filename)
}
return nil
} | go | func deleteFile(filename string) error {
if fileExists(filename) {
return os.Remove(filename)
}
return nil
} | [
"func",
"deleteFile",
"(",
"filename",
"string",
")",
"error",
"{",
"if",
"fileExists",
"(",
"filename",
")",
"{",
"return",
"os",
".",
"Remove",
"(",
"filename",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Check if the file or directory exists and then deletes it | [
"Check",
"if",
"the",
"file",
"or",
"directory",
"exists",
"and",
"then",
"deletes",
"it"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/file_utils.go#L103-L108 |
149,041 | sec51/cryptoengine | verification_engine.go | NewVerificationEngine | func NewVerificationEngine(context string) (VerificationEngine, error) {
engine := VerificationEngine{}
if context == "" {
return engine, errors.New("Context cannot be empty when initializing the Verification Engine")
}
// try to load the public key and if it succeed, then return both the keys
publicFile := f... | go | func NewVerificationEngine(context string) (VerificationEngine, error) {
engine := VerificationEngine{}
if context == "" {
return engine, errors.New("Context cannot be empty when initializing the Verification Engine")
}
// try to load the public key and if it succeed, then return both the keys
publicFile := f... | [
"func",
"NewVerificationEngine",
"(",
"context",
"string",
")",
"(",
"VerificationEngine",
",",
"error",
")",
"{",
"engine",
":=",
"VerificationEngine",
"{",
"}",
"\n\n",
"if",
"context",
"==",
"\"",
"\"",
"{",
"return",
"engine",
",",
"errors",
".",
"New",
... | // This function instantiate the verification engine by leveraging the context
// Basically if a public key of a peer is available locally then it's locaded here | [
"This",
"function",
"instantiate",
"the",
"verification",
"engine",
"by",
"leveraging",
"the",
"context",
"Basically",
"if",
"a",
"public",
"key",
"of",
"a",
"peer",
"is",
"available",
"locally",
"then",
"it",
"s",
"locaded",
"here"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/verification_engine.go#L18-L44 |
149,042 | square/go-sq-metrics | metrics.go | NewMetrics | func NewMetrics(metricsURL, metricsPrefix string, client *http.Client, interval time.Duration, registry metrics.Registry, logger *log.Logger) *SquareMetrics {
hostname, err := os.Hostname()
if err != nil {
panic(err)
}
metrics := &SquareMetrics{
Registry: registry,
url: metricsURL,
prefix: metricsPr... | go | func NewMetrics(metricsURL, metricsPrefix string, client *http.Client, interval time.Duration, registry metrics.Registry, logger *log.Logger) *SquareMetrics {
hostname, err := os.Hostname()
if err != nil {
panic(err)
}
metrics := &SquareMetrics{
Registry: registry,
url: metricsURL,
prefix: metricsPr... | [
"func",
"NewMetrics",
"(",
"metricsURL",
",",
"metricsPrefix",
"string",
",",
"client",
"*",
"http",
".",
"Client",
",",
"interval",
"time",
".",
"Duration",
",",
"registry",
"metrics",
".",
"Registry",
",",
"logger",
"*",
"log",
".",
"Logger",
")",
"*",
... | // NewMetrics is the entry point for this code | [
"NewMetrics",
"is",
"the",
"entry",
"point",
"for",
"this",
"code"
] | ae72f332d0d940cfe1d965eb65d1df79e755b2e4 | https://github.com/square/go-sq-metrics/blob/ae72f332d0d940cfe1d965eb65d1df79e755b2e4/metrics.go#L53-L77 |
149,043 | square/go-sq-metrics | metrics.go | AddGauge | func (mb *SquareMetrics) AddGauge(name string, callback func() int64) {
mb.mutex.Lock()
defer mb.mutex.Unlock()
mb.gauges = append(mb.gauges, gaugeWithCallback{metrics.GetOrRegisterGauge(name, mb.Registry), callback})
} | go | func (mb *SquareMetrics) AddGauge(name string, callback func() int64) {
mb.mutex.Lock()
defer mb.mutex.Unlock()
mb.gauges = append(mb.gauges, gaugeWithCallback{metrics.GetOrRegisterGauge(name, mb.Registry), callback})
} | [
"func",
"(",
"mb",
"*",
"SquareMetrics",
")",
"AddGauge",
"(",
"name",
"string",
",",
"callback",
"func",
"(",
")",
"int64",
")",
"{",
"mb",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mb",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"m... | // AddGauge installs a callback for a gauge with the given name. The callback
// will be called every metrics collection interval, and should provide an
// updated value for the gauge. | [
"AddGauge",
"installs",
"a",
"callback",
"for",
"a",
"gauge",
"with",
"the",
"given",
"name",
".",
"The",
"callback",
"will",
"be",
"called",
"every",
"metrics",
"collection",
"interval",
"and",
"should",
"provide",
"an",
"updated",
"value",
"for",
"the",
"g... | ae72f332d0d940cfe1d965eb65d1df79e755b2e4 | https://github.com/square/go-sq-metrics/blob/ae72f332d0d940cfe1d965eb65d1df79e755b2e4/metrics.go#L82-L86 |
149,044 | square/go-sq-metrics | metrics.go | publishMetrics | func (mb *SquareMetrics) publishMetrics() {
for range time.Tick(mb.interval) {
err := mb.postMetrics()
if err != nil && err != io.EOF {
mb.logger.Printf("error reporting metrics: %s", err)
}
}
} | go | func (mb *SquareMetrics) publishMetrics() {
for range time.Tick(mb.interval) {
err := mb.postMetrics()
if err != nil && err != io.EOF {
mb.logger.Printf("error reporting metrics: %s", err)
}
}
} | [
"func",
"(",
"mb",
"*",
"SquareMetrics",
")",
"publishMetrics",
"(",
")",
"{",
"for",
"range",
"time",
".",
"Tick",
"(",
"mb",
".",
"interval",
")",
"{",
"err",
":=",
"mb",
".",
"postMetrics",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
... | // Publish metrics to bridge | [
"Publish",
"metrics",
"to",
"bridge"
] | ae72f332d0d940cfe1d965eb65d1df79e755b2e4 | https://github.com/square/go-sq-metrics/blob/ae72f332d0d940cfe1d965eb65d1df79e755b2e4/metrics.go#L98-L105 |
149,045 | square/go-sq-metrics | metrics.go | collectMetrics | func (mb *SquareMetrics) collectMetrics() {
var mem runtime.MemStats
update := func(name string, value uint64) {
metrics.GetOrRegisterGauge(name, mb.Registry).Update(int64(value))
}
updateFloat := func(name string, value float64) {
metrics.GetOrRegisterGaugeFloat64(name, mb.Registry).Update(value)
}
sample... | go | func (mb *SquareMetrics) collectMetrics() {
var mem runtime.MemStats
update := func(name string, value uint64) {
metrics.GetOrRegisterGauge(name, mb.Registry).Update(int64(value))
}
updateFloat := func(name string, value float64) {
metrics.GetOrRegisterGaugeFloat64(name, mb.Registry).Update(value)
}
sample... | [
"func",
"(",
"mb",
"*",
"SquareMetrics",
")",
"collectMetrics",
"(",
")",
"{",
"var",
"mem",
"runtime",
".",
"MemStats",
"\n\n",
"update",
":=",
"func",
"(",
"name",
"string",
",",
"value",
"uint64",
")",
"{",
"metrics",
".",
"GetOrRegisterGauge",
"(",
"... | // Collect memory usage metrics | [
"Collect",
"memory",
"usage",
"metrics"
] | ae72f332d0d940cfe1d965eb65d1df79e755b2e4 | https://github.com/square/go-sq-metrics/blob/ae72f332d0d940cfe1d965eb65d1df79e755b2e4/metrics.go#L108-L161 |
149,046 | qor/filebox | controller.go | Download | func (filebox *Filebox) Download(w http.ResponseWriter, req *http.Request) {
var (
currentUser qor.CurrentUser
filePath = strings.TrimPrefix(req.URL.Path, filebox.prefix)
context = &admin.Context{Context: &qor.Context{Request: req, Writer: w}}
)
if auth := filebox.Auth; auth != nil {
currentUser = au... | go | func (filebox *Filebox) Download(w http.ResponseWriter, req *http.Request) {
var (
currentUser qor.CurrentUser
filePath = strings.TrimPrefix(req.URL.Path, filebox.prefix)
context = &admin.Context{Context: &qor.Context{Request: req, Writer: w}}
)
if auth := filebox.Auth; auth != nil {
currentUser = au... | [
"func",
"(",
"filebox",
"*",
"Filebox",
")",
"Download",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"var",
"(",
"currentUser",
"qor",
".",
"CurrentUser",
"\n",
"filePath",
"=",
"strings",
".",
"TrimPrefix"... | // Download is a handler will return a specific file | [
"Download",
"is",
"a",
"handler",
"will",
"return",
"a",
"specific",
"file"
] | e1210ba127af94fd8babd644550e322a4ff3fa02 | https://github.com/qor/filebox/blob/e1210ba127af94fd8babd644550e322a4ff3fa02/controller.go#L15-L40 |
149,047 | sec51/cryptoengine | hkdf.go | deriveNonce | func deriveNonce(masterKey [keySize]byte, salt [keySize]byte, context string, counterValue string) ([nonceSize]byte, error) {
var data24 [nonceSize]byte
// Underlying hash function to use
hash := sha256.New
// Create the key derivation function
hkdf := hkdf.New(hash, masterKey[:], salt[:], []byte(context+counterV... | go | func deriveNonce(masterKey [keySize]byte, salt [keySize]byte, context string, counterValue string) ([nonceSize]byte, error) {
var data24 [nonceSize]byte
// Underlying hash function to use
hash := sha256.New
// Create the key derivation function
hkdf := hkdf.New(hash, masterKey[:], salt[:], []byte(context+counterV... | [
"func",
"deriveNonce",
"(",
"masterKey",
"[",
"keySize",
"]",
"byte",
",",
"salt",
"[",
"keySize",
"]",
"byte",
",",
"context",
"string",
",",
"counterValue",
"string",
")",
"(",
"[",
"nonceSize",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"data24",
"... | // IMPORTANT !!!
// If someone changes the hash function, then the salt needs to have the exactly same lenght!
// So be careful when touching this. | [
"IMPORTANT",
"!!!",
"If",
"someone",
"changes",
"the",
"hash",
"function",
"then",
"the",
"salt",
"needs",
"to",
"have",
"the",
"exactly",
"same",
"lenght!",
"So",
"be",
"careful",
"when",
"touching",
"this",
"."
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/hkdf.go#L13-L33 |
149,048 | jbowles/nlpt-cld2 | cld2nlpt.go | DetectLanguage | func DetectLanguage(buffer_length int, text, format string) (lang Language, err error) {
c_buffer := C.int(buffer_length)
c_string := C.CString(text)
var c_char = C.CString("")
defer C.free(unsafe.Pointer(c_char))
defer C.free(unsafe.Pointer(c_string))
var lang_result C.Language = C.CLD2_DetectLanguage(c_string... | go | func DetectLanguage(buffer_length int, text, format string) (lang Language, err error) {
c_buffer := C.int(buffer_length)
c_string := C.CString(text)
var c_char = C.CString("")
defer C.free(unsafe.Pointer(c_char))
defer C.free(unsafe.Pointer(c_string))
var lang_result C.Language = C.CLD2_DetectLanguage(c_string... | [
"func",
"DetectLanguage",
"(",
"buffer_length",
"int",
",",
"text",
",",
"format",
"string",
")",
"(",
"lang",
"Language",
",",
"err",
"error",
")",
"{",
"c_buffer",
":=",
"C",
".",
"int",
"(",
"buffer_length",
")",
"\n",
"c_string",
":=",
"C",
".",
"C... | // DetectLanguage uses nlpt_wrapper.h and returns a format of the output.
// cld2 defualts languages to ENGLISH, and so any unreliability returns default; which can yeild wrong results, expecially for small data sets.
// By default it defines plain text as true and reliable as true. This means it will not strip out HTM... | [
"DetectLanguage",
"uses",
"nlpt_wrapper",
".",
"h",
"and",
"returns",
"a",
"format",
"of",
"the",
"output",
".",
"cld2",
"defualts",
"languages",
"to",
"ENGLISH",
"and",
"so",
"any",
"unreliability",
"returns",
"default",
";",
"which",
"can",
"yeild",
"wrong",... | 115fa4a4a0376ad04ee112459fdd441ba033944b | https://github.com/jbowles/nlpt-cld2/blob/115fa4a4a0376ad04ee112459fdd441ba033944b/cld2nlpt.go#L118-L150 |
149,049 | sec51/cryptoengine | crypto_engine.go | generateSalt | func generateSalt() ([keySize]byte, error) {
var data32 [keySize]byte
data := make([]byte, keySize)
_, err := rand.Read(data)
if err != nil {
return data32, err
}
total := copy(data32[:], data)
if total != keySize {
return data32, SaltGenerationError
}
return data32, nil
} | go | func generateSalt() ([keySize]byte, error) {
var data32 [keySize]byte
data := make([]byte, keySize)
_, err := rand.Read(data)
if err != nil {
return data32, err
}
total := copy(data32[:], data)
if total != keySize {
return data32, SaltGenerationError
}
return data32, nil
} | [
"func",
"generateSalt",
"(",
")",
"(",
"[",
"keySize",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"data32",
"[",
"keySize",
"]",
"byte",
"\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"keySize",
")",
"\n",
"_",
",",
"err",
":=",
"rand",... | // this function reads nonceSize random data | [
"this",
"function",
"reads",
"nonceSize",
"random",
"data"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/crypto_engine.go#L125-L137 |
149,050 | sec51/cryptoengine | crypto_engine.go | generateSecretKey | func generateSecretKey() ([keySize]byte, error) {
var data32 [keySize]byte
data := make([]byte, keySize)
_, err := rand.Read(data)
if err != nil {
return data32, err
}
total := copy(data32[:], data[:keySize])
if total != keySize {
return data32, KeyGenerationError
}
return data32, nil
} | go | func generateSecretKey() ([keySize]byte, error) {
var data32 [keySize]byte
data := make([]byte, keySize)
_, err := rand.Read(data)
if err != nil {
return data32, err
}
total := copy(data32[:], data[:keySize])
if total != keySize {
return data32, KeyGenerationError
}
return data32, nil
} | [
"func",
"generateSecretKey",
"(",
")",
"(",
"[",
"keySize",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"data32",
"[",
"keySize",
"]",
"byte",
"\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"keySize",
")",
"\n",
"_",
",",
"err",
":=",
"r... | // this function reads keySize random data | [
"this",
"function",
"reads",
"keySize",
"random",
"data"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/crypto_engine.go#L140-L152 |
149,051 | sec51/cryptoengine | crypto_engine.go | loadSecretKey | func loadSecretKey(id string) ([keySize]byte, error) {
var key [keySize]byte
keyFile := fmt.Sprintf(secretSuffixFormat, id)
if keyFileExists(keyFile) {
return readKey(keyFile, keysFolderPrefixFormat)
}
// generate the random salt
key, err := generateSecretKey()
if err != nil {
return key, err
}
// writ... | go | func loadSecretKey(id string) ([keySize]byte, error) {
var key [keySize]byte
keyFile := fmt.Sprintf(secretSuffixFormat, id)
if keyFileExists(keyFile) {
return readKey(keyFile, keysFolderPrefixFormat)
}
// generate the random salt
key, err := generateSecretKey()
if err != nil {
return key, err
}
// writ... | [
"func",
"loadSecretKey",
"(",
"id",
"string",
")",
"(",
"[",
"keySize",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"key",
"[",
"keySize",
"]",
"byte",
"\n\n",
"keyFile",
":=",
"fmt",
".",
"Sprintf",
"(",
"secretSuffixFormat",
",",
"id",
")",
"\n",
"... | // load the key random bytes from the id_secret.key
// if the file does not exist, create a new one | [
"load",
"the",
"key",
"random",
"bytes",
"from",
"the",
"id_secret",
".",
"key",
"if",
"the",
"file",
"does",
"not",
"exist",
"create",
"a",
"new",
"one"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/crypto_engine.go#L184-L206 |
149,052 | sec51/cryptoengine | crypto_engine.go | loadNonceKey | func loadNonceKey(id string) ([keySize]byte, error) {
var nonceKey [keySize]byte
nonceFile := fmt.Sprintf(nonceSuffixFormat, id)
if keyFileExists(nonceFile) {
return readKey(nonceFile, keysFolderPrefixFormat)
}
// generate the random salt
nonceKey, err := generateSecretKey()
if err != nil {
return nonceKe... | go | func loadNonceKey(id string) ([keySize]byte, error) {
var nonceKey [keySize]byte
nonceFile := fmt.Sprintf(nonceSuffixFormat, id)
if keyFileExists(nonceFile) {
return readKey(nonceFile, keysFolderPrefixFormat)
}
// generate the random salt
nonceKey, err := generateSecretKey()
if err != nil {
return nonceKe... | [
"func",
"loadNonceKey",
"(",
"id",
"string",
")",
"(",
"[",
"keySize",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"nonceKey",
"[",
"keySize",
"]",
"byte",
"\n\n",
"nonceFile",
":=",
"fmt",
".",
"Sprintf",
"(",
"nonceSuffixFormat",
",",
"id",
")",
"\n"... | // load the nonce key random bytes from the id_nonce.key
// if the file does not exist, create a new one | [
"load",
"the",
"nonce",
"key",
"random",
"bytes",
"from",
"the",
"id_nonce",
".",
"key",
"if",
"the",
"file",
"does",
"not",
"exist",
"create",
"a",
"new",
"one"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/crypto_engine.go#L210-L232 |
149,053 | sec51/cryptoengine | crypto_engine.go | loadKeyPairs | func loadKeyPairs(id string) ([keySize]byte, [keySize]byte, error) {
var private [keySize]byte
var public [keySize]byte
var err error
// try to load the private key
privateFile := fmt.Sprintf(privateSuffixFormat, id)
if keyFileExists(privateFile) {
if private, err = readKey(privateFile, keysFolderPrefixFormat... | go | func loadKeyPairs(id string) ([keySize]byte, [keySize]byte, error) {
var private [keySize]byte
var public [keySize]byte
var err error
// try to load the private key
privateFile := fmt.Sprintf(privateSuffixFormat, id)
if keyFileExists(privateFile) {
if private, err = readKey(privateFile, keysFolderPrefixFormat... | [
"func",
"loadKeyPairs",
"(",
"id",
"string",
")",
"(",
"[",
"keySize",
"]",
"byte",
",",
"[",
"keySize",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"private",
"[",
"keySize",
"]",
"byte",
"\n",
"var",
"public",
"[",
"keySize",
"]",
"byte",
"\n",
"... | // load the key pair, public and private keys, the id_public.key, id_private.key
// if the files do not exist, create them
// Returns the publicKey, privateKey, error | [
"load",
"the",
"key",
"pair",
"public",
"and",
"private",
"keys",
"the",
"id_public",
".",
"key",
"id_private",
".",
"key",
"if",
"the",
"files",
"do",
"not",
"exist",
"create",
"them",
"Returns",
"the",
"publicKey",
"privateKey",
"error"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/crypto_engine.go#L237-L292 |
149,054 | sec51/cryptoengine | crypto_engine.go | NewEncryptedMessage | func (engine *CryptoEngine) NewEncryptedMessage(msg message) (EncryptedMessage, error) {
m := EncryptedMessage{}
// derive nonce
nonce, err := deriveNonce(engine.nonceKey, engine.salt, engine.context, engine.fetchAndIncrement())
if err != nil {
return m, err
}
m.nonce = nonce
encryptedData := secretbox.Sea... | go | func (engine *CryptoEngine) NewEncryptedMessage(msg message) (EncryptedMessage, error) {
m := EncryptedMessage{}
// derive nonce
nonce, err := deriveNonce(engine.nonceKey, engine.salt, engine.context, engine.fetchAndIncrement())
if err != nil {
return m, err
}
m.nonce = nonce
encryptedData := secretbox.Sea... | [
"func",
"(",
"engine",
"*",
"CryptoEngine",
")",
"NewEncryptedMessage",
"(",
"msg",
"message",
")",
"(",
"EncryptedMessage",
",",
"error",
")",
"{",
"m",
":=",
"EncryptedMessage",
"{",
"}",
"\n\n",
"// derive nonce",
"nonce",
",",
"err",
":=",
"deriveNonce",
... | // This method accepts a message , then encrypts its Version+Type+Text using a symmetric key | [
"This",
"method",
"accepts",
"a",
"message",
"then",
"encrypts",
"its",
"Version",
"+",
"Type",
"+",
"Text",
"using",
"a",
"symmetric",
"key"
] | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/crypto_engine.go#L334-L356 |
149,055 | sec51/cryptoengine | crypto_engine.go | NewEncryptedMessageWithPubKey | func (engine *CryptoEngine) NewEncryptedMessageWithPubKey(msg message, verificationEngine VerificationEngine) (EncryptedMessage, error) {
encryptedMessage := EncryptedMessage{}
// get the peer public key
peerPublicKey := verificationEngine.PublicKey()
// check the size of the peerPublicKey
if len(peerPublicKey)... | go | func (engine *CryptoEngine) NewEncryptedMessageWithPubKey(msg message, verificationEngine VerificationEngine) (EncryptedMessage, error) {
encryptedMessage := EncryptedMessage{}
// get the peer public key
peerPublicKey := verificationEngine.PublicKey()
// check the size of the peerPublicKey
if len(peerPublicKey)... | [
"func",
"(",
"engine",
"*",
"CryptoEngine",
")",
"NewEncryptedMessageWithPubKey",
"(",
"msg",
"message",
",",
"verificationEngine",
"VerificationEngine",
")",
"(",
"EncryptedMessage",
",",
"error",
")",
"{",
"encryptedMessage",
":=",
"EncryptedMessage",
"{",
"}",
"\... | // This method accepts the message as byte slice and the public key of the receiver of the messae,
// then encrypts it using the asymmetric key public key.
// If the public key is not privisioned and does not have the required length of 32 bytes it raises an exception. | [
"This",
"method",
"accepts",
"the",
"message",
"as",
"byte",
"slice",
"and",
"the",
"public",
"key",
"of",
"the",
"receiver",
"of",
"the",
"messae",
"then",
"encrypts",
"it",
"using",
"the",
"asymmetric",
"key",
"public",
"key",
".",
"If",
"the",
"public",... | 2306d105a49ec564d9d376570a1881d557fc4a82 | https://github.com/sec51/cryptoengine/blob/2306d105a49ec564d9d376570a1881d557fc4a82/crypto_engine.go#L361-L431 |
149,056 | qor/filebox | filebox.go | ServeHTTP | func (filebox *Filebox) ServeHTTP(w http.ResponseWriter, req *http.Request) {
filebox.Download(w, req)
} | go | func (filebox *Filebox) ServeHTTP(w http.ResponseWriter, req *http.Request) {
filebox.Download(w, req)
} | [
"func",
"(",
"filebox",
"*",
"Filebox",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"filebox",
".",
"Download",
"(",
"w",
",",
"req",
")",
"\n",
"}"
] | // ServeHTTP is a implement for http server interface | [
"ServeHTTP",
"is",
"a",
"implement",
"for",
"http",
"server",
"interface"
] | e1210ba127af94fd8babd644550e322a4ff3fa02 | https://github.com/qor/filebox/blob/e1210ba127af94fd8babd644550e322a4ff3fa02/filebox.go#L39-L41 |
149,057 | qor/filebox | filebox.go | MountTo | func (filebox *Filebox) MountTo(mountTo string, mux *http.ServeMux) {
filebox.prefix = "/" + strings.Trim(mountTo, "/")
mux.Handle(filebox.prefix+"/", filebox)
} | go | func (filebox *Filebox) MountTo(mountTo string, mux *http.ServeMux) {
filebox.prefix = "/" + strings.Trim(mountTo, "/")
mux.Handle(filebox.prefix+"/", filebox)
} | [
"func",
"(",
"filebox",
"*",
"Filebox",
")",
"MountTo",
"(",
"mountTo",
"string",
",",
"mux",
"*",
"http",
".",
"ServeMux",
")",
"{",
"filebox",
".",
"prefix",
"=",
"\"",
"\"",
"+",
"strings",
".",
"Trim",
"(",
"mountTo",
",",
"\"",
"\"",
")",
"\n"... | // MountTo will mount to mux to route `mountto` | [
"MountTo",
"will",
"mount",
"to",
"mux",
"to",
"route",
"mountto"
] | e1210ba127af94fd8babd644550e322a4ff3fa02 | https://github.com/qor/filebox/blob/e1210ba127af94fd8babd644550e322a4ff3fa02/filebox.go#L49-L52 |
149,058 | qor/filebox | filebox.go | AccessFile | func (filebox *Filebox) AccessFile(filePath string, roles ...string) *File {
file := &File{FilePath: filepath.Join(filebox.BaseDir, filePath), Roles: roles, Filebox: filebox}
file.Dir = filebox.AccessDir(filepath.Dir(filePath), roles...)
return file
} | go | func (filebox *Filebox) AccessFile(filePath string, roles ...string) *File {
file := &File{FilePath: filepath.Join(filebox.BaseDir, filePath), Roles: roles, Filebox: filebox}
file.Dir = filebox.AccessDir(filepath.Dir(filePath), roles...)
return file
} | [
"func",
"(",
"filebox",
"*",
"Filebox",
")",
"AccessFile",
"(",
"filePath",
"string",
",",
"roles",
"...",
"string",
")",
"*",
"File",
"{",
"file",
":=",
"&",
"File",
"{",
"FilePath",
":",
"filepath",
".",
"Join",
"(",
"filebox",
".",
"BaseDir",
",",
... | // AccessFile will return a specific File object | [
"AccessFile",
"will",
"return",
"a",
"specific",
"File",
"object"
] | e1210ba127af94fd8babd644550e322a4ff3fa02 | https://github.com/qor/filebox/blob/e1210ba127af94fd8babd644550e322a4ff3fa02/filebox.go#L60-L64 |
149,059 | qor/filebox | filebox.go | Read | func (f *File) Read() (io.ReadSeeker, error) {
if f.HasPermission(roles.Read) {
return os.Open(f.FilePath)
}
return nil, roles.ErrPermissionDenied
} | go | func (f *File) Read() (io.ReadSeeker, error) {
if f.HasPermission(roles.Read) {
return os.Open(f.FilePath)
}
return nil, roles.ErrPermissionDenied
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Read",
"(",
")",
"(",
"io",
".",
"ReadSeeker",
",",
"error",
")",
"{",
"if",
"f",
".",
"HasPermission",
"(",
"roles",
".",
"Read",
")",
"{",
"return",
"os",
".",
"Open",
"(",
"f",
".",
"FilePath",
")",
"\n",... | // Read will get a io reader for a specific file | [
"Read",
"will",
"get",
"a",
"io",
"reader",
"for",
"a",
"specific",
"file"
] | e1210ba127af94fd8babd644550e322a4ff3fa02 | https://github.com/qor/filebox/blob/e1210ba127af94fd8babd644550e322a4ff3fa02/filebox.go#L67-L72 |
149,060 | qor/filebox | filebox.go | Write | func (f *File) Write(reader io.Reader) (err error) {
if f.HasPermission(roles.Update) {
var dst *os.File
if _, err = os.Stat(f.FilePath); os.IsNotExist(err) {
err = os.MkdirAll(filepath.Dir(f.FilePath), os.ModePerm)
}
if err == nil {
if dst, err = os.Create(f.FilePath); err == nil {
_, err = io.Copy... | go | func (f *File) Write(reader io.Reader) (err error) {
if f.HasPermission(roles.Update) {
var dst *os.File
if _, err = os.Stat(f.FilePath); os.IsNotExist(err) {
err = os.MkdirAll(filepath.Dir(f.FilePath), os.ModePerm)
}
if err == nil {
if dst, err = os.Create(f.FilePath); err == nil {
_, err = io.Copy... | [
"func",
"(",
"f",
"*",
"File",
")",
"Write",
"(",
"reader",
"io",
".",
"Reader",
")",
"(",
"err",
"error",
")",
"{",
"if",
"f",
".",
"HasPermission",
"(",
"roles",
".",
"Update",
")",
"{",
"var",
"dst",
"*",
"os",
".",
"File",
"\n",
"if",
"_",
... | // Write used to store reader's content to a file | [
"Write",
"used",
"to",
"store",
"reader",
"s",
"content",
"to",
"a",
"file"
] | e1210ba127af94fd8babd644550e322a4ff3fa02 | https://github.com/qor/filebox/blob/e1210ba127af94fd8babd644550e322a4ff3fa02/filebox.go#L75-L90 |
149,061 | qor/filebox | filebox.go | SetPermission | func (f *File) SetPermission(permission *roles.Permission) (err error) {
jsonVal, err := json.Marshal(permission)
if err == nil {
err = ioutil.WriteFile(f.metaFilePath(), jsonVal, 0644)
}
return err
} | go | func (f *File) SetPermission(permission *roles.Permission) (err error) {
jsonVal, err := json.Marshal(permission)
if err == nil {
err = ioutil.WriteFile(f.metaFilePath(), jsonVal, 0644)
}
return err
} | [
"func",
"(",
"f",
"*",
"File",
")",
"SetPermission",
"(",
"permission",
"*",
"roles",
".",
"Permission",
")",
"(",
"err",
"error",
")",
"{",
"jsonVal",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"permission",
")",
"\n",
"if",
"err",
"==",
"nil",
... | // SetPermission used to set a Permission to file | [
"SetPermission",
"used",
"to",
"set",
"a",
"Permission",
"to",
"file"
] | e1210ba127af94fd8babd644550e322a4ff3fa02 | https://github.com/qor/filebox/blob/e1210ba127af94fd8babd644550e322a4ff3fa02/filebox.go#L93-L99 |
149,062 | qor/filebox | filebox.go | HasPermission | func (f *File) HasPermission(mode roles.PermissionMode) bool {
if _, err := os.Stat(f.metaFilePath()); !os.IsNotExist(err) {
return hasPermission(f.metaFilePath(), mode, f.Roles)
}
return f.Dir.HasPermission(mode)
} | go | func (f *File) HasPermission(mode roles.PermissionMode) bool {
if _, err := os.Stat(f.metaFilePath()); !os.IsNotExist(err) {
return hasPermission(f.metaFilePath(), mode, f.Roles)
}
return f.Dir.HasPermission(mode)
} | [
"func",
"(",
"f",
"*",
"File",
")",
"HasPermission",
"(",
"mode",
"roles",
".",
"PermissionMode",
")",
"bool",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"f",
".",
"metaFilePath",
"(",
")",
")",
";",
"!",
"os",
".",
"IsNotExist",
"... | // HasPermission used to check current user whether have permission to access file | [
"HasPermission",
"used",
"to",
"check",
"current",
"user",
"whether",
"have",
"permission",
"to",
"access",
"file"
] | e1210ba127af94fd8babd644550e322a4ff3fa02 | https://github.com/qor/filebox/blob/e1210ba127af94fd8babd644550e322a4ff3fa02/filebox.go#L102-L107 |
149,063 | qor/filebox | filebox.go | AccessDir | func (filebox *Filebox) AccessDir(dirPath string, roles ...string) *Dir {
return &Dir{DirPath: filepath.Join(filebox.BaseDir, dirPath), Roles: roles, Filebox: filebox}
} | go | func (filebox *Filebox) AccessDir(dirPath string, roles ...string) *Dir {
return &Dir{DirPath: filepath.Join(filebox.BaseDir, dirPath), Roles: roles, Filebox: filebox}
} | [
"func",
"(",
"filebox",
"*",
"Filebox",
")",
"AccessDir",
"(",
"dirPath",
"string",
",",
"roles",
"...",
"string",
")",
"*",
"Dir",
"{",
"return",
"&",
"Dir",
"{",
"DirPath",
":",
"filepath",
".",
"Join",
"(",
"filebox",
".",
"BaseDir",
",",
"dirPath",... | // AccessDir will return a specific Dir object | [
"AccessDir",
"will",
"return",
"a",
"specific",
"Dir",
"object"
] | e1210ba127af94fd8babd644550e322a4ff3fa02 | https://github.com/qor/filebox/blob/e1210ba127af94fd8babd644550e322a4ff3fa02/filebox.go#L116-L118 |
149,064 | qor/filebox | filebox.go | WriteFile | func (dir *Dir) WriteFile(fileName string, reader io.Reader) (file *File, err error) {
if err = dir.createIfNoExist(); err == nil {
relativeDir := strings.TrimPrefix(dir.DirPath, dir.Filebox.BaseDir)
file = dir.Filebox.AccessFile(filepath.Join(relativeDir, fileName), dir.Roles...)
err = file.Write(reader)
}
re... | go | func (dir *Dir) WriteFile(fileName string, reader io.Reader) (file *File, err error) {
if err = dir.createIfNoExist(); err == nil {
relativeDir := strings.TrimPrefix(dir.DirPath, dir.Filebox.BaseDir)
file = dir.Filebox.AccessFile(filepath.Join(relativeDir, fileName), dir.Roles...)
err = file.Write(reader)
}
re... | [
"func",
"(",
"dir",
"*",
"Dir",
")",
"WriteFile",
"(",
"fileName",
"string",
",",
"reader",
"io",
".",
"Reader",
")",
"(",
"file",
"*",
"File",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"dir",
".",
"createIfNoExist",
"(",
")",
";",
"err",
... | // WriteFile writes data to a file named by filename. If the file does not exist, WriteFile will create a new file | [
"WriteFile",
"writes",
"data",
"to",
"a",
"file",
"named",
"by",
"filename",
".",
"If",
"the",
"file",
"does",
"not",
"exist",
"WriteFile",
"will",
"create",
"a",
"new",
"file"
] | e1210ba127af94fd8babd644550e322a4ff3fa02 | https://github.com/qor/filebox/blob/e1210ba127af94fd8babd644550e322a4ff3fa02/filebox.go#L121-L128 |
149,065 | qor/filebox | filebox.go | SetPermission | func (dir *Dir) SetPermission(permission *roles.Permission) (err error) {
err = dir.createIfNoExist()
jsonVal, err := json.Marshal(permission)
if err == nil {
err = ioutil.WriteFile(dir.metaDirPath(), jsonVal, 0644)
}
return err
} | go | func (dir *Dir) SetPermission(permission *roles.Permission) (err error) {
err = dir.createIfNoExist()
jsonVal, err := json.Marshal(permission)
if err == nil {
err = ioutil.WriteFile(dir.metaDirPath(), jsonVal, 0644)
}
return err
} | [
"func",
"(",
"dir",
"*",
"Dir",
")",
"SetPermission",
"(",
"permission",
"*",
"roles",
".",
"Permission",
")",
"(",
"err",
"error",
")",
"{",
"err",
"=",
"dir",
".",
"createIfNoExist",
"(",
")",
"\n",
"jsonVal",
",",
"err",
":=",
"json",
".",
"Marsha... | // SetPermission used to set a Permission to directory | [
"SetPermission",
"used",
"to",
"set",
"a",
"Permission",
"to",
"directory"
] | e1210ba127af94fd8babd644550e322a4ff3fa02 | https://github.com/qor/filebox/blob/e1210ba127af94fd8babd644550e322a4ff3fa02/filebox.go#L131-L138 |
149,066 | qor/filebox | filebox.go | HasPermission | func (dir *Dir) HasPermission(mode roles.PermissionMode) bool {
return hasPermission(dir.metaDirPath(), mode, dir.Roles)
} | go | func (dir *Dir) HasPermission(mode roles.PermissionMode) bool {
return hasPermission(dir.metaDirPath(), mode, dir.Roles)
} | [
"func",
"(",
"dir",
"*",
"Dir",
")",
"HasPermission",
"(",
"mode",
"roles",
".",
"PermissionMode",
")",
"bool",
"{",
"return",
"hasPermission",
"(",
"dir",
".",
"metaDirPath",
"(",
")",
",",
"mode",
",",
"dir",
".",
"Roles",
")",
"\n",
"}"
] | // HasPermission used to check current user whether have permission to access directory | [
"HasPermission",
"used",
"to",
"check",
"current",
"user",
"whether",
"have",
"permission",
"to",
"access",
"directory"
] | e1210ba127af94fd8babd644550e322a4ff3fa02 | https://github.com/qor/filebox/blob/e1210ba127af94fd8babd644550e322a4ff3fa02/filebox.go#L141-L143 |
149,067 | nabeken/aws-go-s3 | bucket/option/list.go | ListDelimiter | func ListDelimiter(delim string) ListObjectsInput {
return func(req *s3.ListObjectsInput) {
req.Delimiter = aws.String(delim)
}
} | go | func ListDelimiter(delim string) ListObjectsInput {
return func(req *s3.ListObjectsInput) {
req.Delimiter = aws.String(delim)
}
} | [
"func",
"ListDelimiter",
"(",
"delim",
"string",
")",
"ListObjectsInput",
"{",
"return",
"func",
"(",
"req",
"*",
"s3",
".",
"ListObjectsInput",
")",
"{",
"req",
".",
"Delimiter",
"=",
"aws",
".",
"String",
"(",
"delim",
")",
"\n",
"}",
"\n",
"}"
] | // ListDelimiter returns a ListObjectsInput that changes a delimiter in
// s3.ListObjectsInput. | [
"ListDelimiter",
"returns",
"a",
"ListObjectsInput",
"that",
"changes",
"a",
"delimiter",
"in",
"s3",
".",
"ListObjectsInput",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/option/list.go#L14-L18 |
149,068 | nabeken/aws-go-s3 | bucket/option/list.go | ListEncodingType | func ListEncodingType(typ string) ListObjectsInput {
return func(req *s3.ListObjectsInput) {
req.EncodingType = aws.String(typ)
}
} | go | func ListEncodingType(typ string) ListObjectsInput {
return func(req *s3.ListObjectsInput) {
req.EncodingType = aws.String(typ)
}
} | [
"func",
"ListEncodingType",
"(",
"typ",
"string",
")",
"ListObjectsInput",
"{",
"return",
"func",
"(",
"req",
"*",
"s3",
".",
"ListObjectsInput",
")",
"{",
"req",
".",
"EncodingType",
"=",
"aws",
".",
"String",
"(",
"typ",
")",
"\n",
"}",
"\n",
"}"
] | // ListEncodingType returns a ListObjectsInput that changes a EncodingType in
// s3.ListObjectsInput. | [
"ListEncodingType",
"returns",
"a",
"ListObjectsInput",
"that",
"changes",
"a",
"EncodingType",
"in",
"s3",
".",
"ListObjectsInput",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/option/list.go#L22-L26 |
149,069 | nabeken/aws-go-s3 | bucket/option/list.go | ListMarker | func ListMarker(marker string) ListObjectsInput {
return func(req *s3.ListObjectsInput) {
req.Marker = aws.String(marker)
}
} | go | func ListMarker(marker string) ListObjectsInput {
return func(req *s3.ListObjectsInput) {
req.Marker = aws.String(marker)
}
} | [
"func",
"ListMarker",
"(",
"marker",
"string",
")",
"ListObjectsInput",
"{",
"return",
"func",
"(",
"req",
"*",
"s3",
".",
"ListObjectsInput",
")",
"{",
"req",
".",
"Marker",
"=",
"aws",
".",
"String",
"(",
"marker",
")",
"\n",
"}",
"\n",
"}"
] | // ListMarker returns a ListObjectsInput that changes a Marker in
// s3.ListObjectsInput. | [
"ListMarker",
"returns",
"a",
"ListObjectsInput",
"that",
"changes",
"a",
"Marker",
"in",
"s3",
".",
"ListObjectsInput",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/option/list.go#L30-L34 |
149,070 | nabeken/aws-go-s3 | bucket/option/copy.go | CopySSEKMSKeyID | func CopySSEKMSKeyID(keyID string) CopyObjectInput {
return func(req *s3.CopyObjectInput) {
req.SSEKMSKeyId = aws.String(keyID)
req.ServerSideEncryption = aws.String("aws:kms")
}
} | go | func CopySSEKMSKeyID(keyID string) CopyObjectInput {
return func(req *s3.CopyObjectInput) {
req.SSEKMSKeyId = aws.String(keyID)
req.ServerSideEncryption = aws.String("aws:kms")
}
} | [
"func",
"CopySSEKMSKeyID",
"(",
"keyID",
"string",
")",
"CopyObjectInput",
"{",
"return",
"func",
"(",
"req",
"*",
"s3",
".",
"CopyObjectInput",
")",
"{",
"req",
".",
"SSEKMSKeyId",
"=",
"aws",
".",
"String",
"(",
"keyID",
")",
"\n",
"req",
".",
"ServerS... | // CopySSEKMSKeyID returns a CopyObjectInput that changes a SSE-KMS Key ID. | [
"CopySSEKMSKeyID",
"returns",
"a",
"CopyObjectInput",
"that",
"changes",
"a",
"SSE",
"-",
"KMS",
"Key",
"ID",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/option/copy.go#L13-L18 |
149,071 | nabeken/aws-go-s3 | bucket/option/put.go | SSEKMSKeyID | func SSEKMSKeyID(keyID string) PutObjectInput {
return func(req *s3.PutObjectInput) {
req.SSEKMSKeyId = aws.String(keyID)
req.ServerSideEncryption = aws.String("aws:kms")
}
} | go | func SSEKMSKeyID(keyID string) PutObjectInput {
return func(req *s3.PutObjectInput) {
req.SSEKMSKeyId = aws.String(keyID)
req.ServerSideEncryption = aws.String("aws:kms")
}
} | [
"func",
"SSEKMSKeyID",
"(",
"keyID",
"string",
")",
"PutObjectInput",
"{",
"return",
"func",
"(",
"req",
"*",
"s3",
".",
"PutObjectInput",
")",
"{",
"req",
".",
"SSEKMSKeyId",
"=",
"aws",
".",
"String",
"(",
"keyID",
")",
"\n",
"req",
".",
"ServerSideEnc... | // SSEKMSKeyID returns a PutObjectInput that changes a SSE-KMS Key ID. | [
"SSEKMSKeyID",
"returns",
"a",
"PutObjectInput",
"that",
"changes",
"a",
"SSE",
"-",
"KMS",
"Key",
"ID",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/option/put.go#L13-L18 |
149,072 | nabeken/aws-go-s3 | bucket/option/put.go | ACLPrivate | func ACLPrivate() PutObjectInput {
return func(req *s3.PutObjectInput) {
req.ACL = aws.String(s3.ObjectCannedACLPrivate)
}
} | go | func ACLPrivate() PutObjectInput {
return func(req *s3.PutObjectInput) {
req.ACL = aws.String(s3.ObjectCannedACLPrivate)
}
} | [
"func",
"ACLPrivate",
"(",
")",
"PutObjectInput",
"{",
"return",
"func",
"(",
"req",
"*",
"s3",
".",
"PutObjectInput",
")",
"{",
"req",
".",
"ACL",
"=",
"aws",
".",
"String",
"(",
"s3",
".",
"ObjectCannedACLPrivate",
")",
"\n",
"}",
"\n",
"}"
] | // ACLPrivate returns a PutObjectInput that set ACL private. | [
"ACLPrivate",
"returns",
"a",
"PutObjectInput",
"that",
"set",
"ACL",
"private",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/option/put.go#L21-L25 |
149,073 | nabeken/aws-go-s3 | bucket/option/put.go | ACLPublicRead | func ACLPublicRead() PutObjectInput {
return func(req *s3.PutObjectInput) {
req.ACL = aws.String(s3.ObjectCannedACLPublicRead)
}
} | go | func ACLPublicRead() PutObjectInput {
return func(req *s3.PutObjectInput) {
req.ACL = aws.String(s3.ObjectCannedACLPublicRead)
}
} | [
"func",
"ACLPublicRead",
"(",
")",
"PutObjectInput",
"{",
"return",
"func",
"(",
"req",
"*",
"s3",
".",
"PutObjectInput",
")",
"{",
"req",
".",
"ACL",
"=",
"aws",
".",
"String",
"(",
"s3",
".",
"ObjectCannedACLPublicRead",
")",
"\n",
"}",
"\n",
"}"
] | // ACLPublicRead returns a PutObjectInput that set ACL public-read. | [
"ACLPublicRead",
"returns",
"a",
"PutObjectInput",
"that",
"set",
"ACL",
"public",
"-",
"read",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/option/put.go#L28-L32 |
149,074 | nabeken/aws-go-s3 | bucket/option/put.go | ContentType | func ContentType(ct string) PutObjectInput {
return func(req *s3.PutObjectInput) {
req.ContentType = aws.String(ct)
}
} | go | func ContentType(ct string) PutObjectInput {
return func(req *s3.PutObjectInput) {
req.ContentType = aws.String(ct)
}
} | [
"func",
"ContentType",
"(",
"ct",
"string",
")",
"PutObjectInput",
"{",
"return",
"func",
"(",
"req",
"*",
"s3",
".",
"PutObjectInput",
")",
"{",
"req",
".",
"ContentType",
"=",
"aws",
".",
"String",
"(",
"ct",
")",
"\n",
"}",
"\n",
"}"
] | // ContentType returns a PutObjectInput that set Content-Type. | [
"ContentType",
"returns",
"a",
"PutObjectInput",
"that",
"set",
"Content",
"-",
"Type",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/option/put.go#L35-L39 |
149,075 | nabeken/aws-go-s3 | bucket/option/put.go | ContentLength | func ContentLength(length int64) PutObjectInput {
return func(req *s3.PutObjectInput) {
req.ContentLength = aws.Int64(length)
}
} | go | func ContentLength(length int64) PutObjectInput {
return func(req *s3.PutObjectInput) {
req.ContentLength = aws.Int64(length)
}
} | [
"func",
"ContentLength",
"(",
"length",
"int64",
")",
"PutObjectInput",
"{",
"return",
"func",
"(",
"req",
"*",
"s3",
".",
"PutObjectInput",
")",
"{",
"req",
".",
"ContentLength",
"=",
"aws",
".",
"Int64",
"(",
"length",
")",
"\n",
"}",
"\n",
"}"
] | // ContentLength returns a PutObjectInput that set Content-Length. | [
"ContentLength",
"returns",
"a",
"PutObjectInput",
"that",
"set",
"Content",
"-",
"Length",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/option/put.go#L42-L46 |
149,076 | nabeken/aws-go-s3 | ioutils/ioutils.go | Close | func (f *FileReadSeeker) Close() error {
if err := f.file.Close(); err != nil {
return err
}
return os.Remove(f.file.Name())
} | go | func (f *FileReadSeeker) Close() error {
if err := f.file.Close(); err != nil {
return err
}
return os.Remove(f.file.Name())
} | [
"func",
"(",
"f",
"*",
"FileReadSeeker",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"f",
".",
"file",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"os",
".",
"Remove",
"(",
"f... | // Close closes underlying tempfile and remove it. | [
"Close",
"closes",
"underlying",
"tempfile",
"and",
"remove",
"it",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/ioutils/ioutils.go#L17-L23 |
149,077 | nabeken/aws-go-s3 | ioutils/ioutils.go | Read | func (f *FileReadSeeker) Read(p []byte) (int, error) {
return f.file.Read(p)
} | go | func (f *FileReadSeeker) Read(p []byte) (int, error) {
return f.file.Read(p)
} | [
"func",
"(",
"f",
"*",
"FileReadSeeker",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"f",
".",
"file",
".",
"Read",
"(",
"p",
")",
"\n",
"}"
] | // Read implements io.Reader with underlying tempfile. | [
"Read",
"implements",
"io",
".",
"Reader",
"with",
"underlying",
"tempfile",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/ioutils/ioutils.go#L26-L28 |
149,078 | nabeken/aws-go-s3 | ioutils/ioutils.go | Seek | func (f *FileReadSeeker) Seek(offset int64, whence int) (int64, error) {
return f.file.Seek(offset, whence)
} | go | func (f *FileReadSeeker) Seek(offset int64, whence int) (int64, error) {
return f.file.Seek(offset, whence)
} | [
"func",
"(",
"f",
"*",
"FileReadSeeker",
")",
"Seek",
"(",
"offset",
"int64",
",",
"whence",
"int",
")",
"(",
"int64",
",",
"error",
")",
"{",
"return",
"f",
".",
"file",
".",
"Seek",
"(",
"offset",
",",
"whence",
")",
"\n",
"}"
] | // Seek implements io.Seeker with underlying tempfile. | [
"Seek",
"implements",
"io",
".",
"Seeker",
"with",
"underlying",
"tempfile",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/ioutils/ioutils.go#L31-L33 |
149,079 | nabeken/aws-go-s3 | ioutils/ioutils.go | NewFileReadSeeker | func NewFileReadSeeker(r io.Reader) (*FileReadSeeker, error) {
f, err := ioutil.TempFile("", "")
if err != nil {
return nil, err
}
if _, err := io.Copy(f, r); err != nil {
return nil, err
}
if _, err := f.Seek(0, 0); err != nil {
return nil, err
}
return &FileReadSeeker{
file: f,
}, nil
} | go | func NewFileReadSeeker(r io.Reader) (*FileReadSeeker, error) {
f, err := ioutil.TempFile("", "")
if err != nil {
return nil, err
}
if _, err := io.Copy(f, r); err != nil {
return nil, err
}
if _, err := f.Seek(0, 0); err != nil {
return nil, err
}
return &FileReadSeeker{
file: f,
}, nil
} | [
"func",
"NewFileReadSeeker",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"FileReadSeeker",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"ioutil",
".",
"TempFile",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"re... | // NewFileReadSeeker returns FileReadSeeker with reading data from r.
// If you want to reuse it, you must rewind. | [
"NewFileReadSeeker",
"returns",
"FileReadSeeker",
"with",
"reading",
"data",
"from",
"r",
".",
"If",
"you",
"want",
"to",
"reuse",
"it",
"you",
"must",
"rewind",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/ioutils/ioutils.go#L37-L54 |
149,080 | DexterLB/mpvipc | mpvipc.go | NewConnection | func NewConnection(socketName string) *Connection {
return &Connection{
socketName: socketName,
lock: &sync.Mutex{},
waitingRequests: make(map[uint]chan *commandResult),
eventListeners: make(map[uint]chan<- *Event),
closeWaiters: make(map[uint]chan struct{}),
}
} | go | func NewConnection(socketName string) *Connection {
return &Connection{
socketName: socketName,
lock: &sync.Mutex{},
waitingRequests: make(map[uint]chan *commandResult),
eventListeners: make(map[uint]chan<- *Event),
closeWaiters: make(map[uint]chan struct{}),
}
} | [
"func",
"NewConnection",
"(",
"socketName",
"string",
")",
"*",
"Connection",
"{",
"return",
"&",
"Connection",
"{",
"socketName",
":",
"socketName",
",",
"lock",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"waitingRequests",
":",
"make",
"(",
"map",
... | // NewConnection returns a Connection associated with the given unix socket | [
"NewConnection",
"returns",
"a",
"Connection",
"associated",
"with",
"the",
"given",
"unix",
"socket"
] | 2a226fa01bbda228d7cd2d589e3e88f15ba16620 | https://github.com/DexterLB/mpvipc/blob/2a226fa01bbda228d7cd2d589e3e88f15ba16620/mpvipc.go#L58-L66 |
149,081 | nabeken/aws-go-s3 | bucket/bucket.go | New | func New(s s3iface.S3API, name string) *Bucket {
return &Bucket{
S3: s,
Name: aws.String(name),
}
} | go | func New(s s3iface.S3API, name string) *Bucket {
return &Bucket{
S3: s,
Name: aws.String(name),
}
} | [
"func",
"New",
"(",
"s",
"s3iface",
".",
"S3API",
",",
"name",
"string",
")",
"*",
"Bucket",
"{",
"return",
"&",
"Bucket",
"{",
"S3",
":",
"s",
",",
"Name",
":",
"aws",
".",
"String",
"(",
"name",
")",
",",
"}",
"\n",
"}"
] | // New returns Bucket instance with bucket name name. | [
"New",
"returns",
"Bucket",
"instance",
"with",
"bucket",
"name",
"name",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/bucket.go#L23-L28 |
149,082 | nabeken/aws-go-s3 | bucket/bucket.go | GetObject | func (b *Bucket) GetObject(key string, opts ...option.GetObjectInput) (*s3.GetObjectOutput, error) {
req := &s3.GetObjectInput{
Bucket: b.Name,
Key: aws.String(key),
}
for _, f := range opts {
f(req)
}
return b.S3.GetObject(req)
} | go | func (b *Bucket) GetObject(key string, opts ...option.GetObjectInput) (*s3.GetObjectOutput, error) {
req := &s3.GetObjectInput{
Bucket: b.Name,
Key: aws.String(key),
}
for _, f := range opts {
f(req)
}
return b.S3.GetObject(req)
} | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"GetObject",
"(",
"key",
"string",
",",
"opts",
"...",
"option",
".",
"GetObjectInput",
")",
"(",
"*",
"s3",
".",
"GetObjectOutput",
",",
"error",
")",
"{",
"req",
":=",
"&",
"s3",
".",
"GetObjectInput",
"{",
"Bu... | // GetObject returns the s3.GetObjectOutput. | [
"GetObject",
"returns",
"the",
"s3",
".",
"GetObjectOutput",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/bucket.go#L31-L42 |
149,083 | nabeken/aws-go-s3 | bucket/bucket.go | GetObjectReader | func (b *Bucket) GetObjectReader(key string, opts ...option.GetObjectInput) (io.ReadCloser, error) {
resp, err := b.GetObject(key, opts...)
if err != nil {
return nil, err
}
return resp.Body, nil
} | go | func (b *Bucket) GetObjectReader(key string, opts ...option.GetObjectInput) (io.ReadCloser, error) {
resp, err := b.GetObject(key, opts...)
if err != nil {
return nil, err
}
return resp.Body, nil
} | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"GetObjectReader",
"(",
"key",
"string",
",",
"opts",
"...",
"option",
".",
"GetObjectInput",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"b",
".",
"GetObject",
"(",
"key"... | // GetObjectReader returns a reader assosiated with body. A caller of this MUST close the reader when it finishes reading. | [
"GetObjectReader",
"returns",
"a",
"reader",
"assosiated",
"with",
"body",
".",
"A",
"caller",
"of",
"this",
"MUST",
"close",
"the",
"reader",
"when",
"it",
"finishes",
"reading",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/bucket.go#L45-L52 |
149,084 | nabeken/aws-go-s3 | bucket/bucket.go | HeadObject | func (b *Bucket) HeadObject(key string, opts ...option.HeadObjectInput) (*s3.HeadObjectOutput, error) {
req := &s3.HeadObjectInput{
Bucket: b.Name,
Key: aws.String(key),
}
for _, f := range opts {
f(req)
}
return b.S3.HeadObject(req)
} | go | func (b *Bucket) HeadObject(key string, opts ...option.HeadObjectInput) (*s3.HeadObjectOutput, error) {
req := &s3.HeadObjectInput{
Bucket: b.Name,
Key: aws.String(key),
}
for _, f := range opts {
f(req)
}
return b.S3.HeadObject(req)
} | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"HeadObject",
"(",
"key",
"string",
",",
"opts",
"...",
"option",
".",
"HeadObjectInput",
")",
"(",
"*",
"s3",
".",
"HeadObjectOutput",
",",
"error",
")",
"{",
"req",
":=",
"&",
"s3",
".",
"HeadObjectInput",
"{",
... | // HeadObject retrieves an object metadata for key. | [
"HeadObject",
"retrieves",
"an",
"object",
"metadata",
"for",
"key",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/bucket.go#L69-L80 |
149,085 | nabeken/aws-go-s3 | bucket/bucket.go | ExistsObject | func (b *Bucket) ExistsObject(key string, opts ...option.HeadObjectInput) (bool, error) {
_, err := b.HeadObject(key, opts...)
if err == nil {
return true, nil
}
if s3err, ok := err.(awserr.RequestFailure); ok && s3err.StatusCode() == http.StatusNotFound {
// actually key does not exist
return false, nil
}
... | go | func (b *Bucket) ExistsObject(key string, opts ...option.HeadObjectInput) (bool, error) {
_, err := b.HeadObject(key, opts...)
if err == nil {
return true, nil
}
if s3err, ok := err.(awserr.RequestFailure); ok && s3err.StatusCode() == http.StatusNotFound {
// actually key does not exist
return false, nil
}
... | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"ExistsObject",
"(",
"key",
"string",
",",
"opts",
"...",
"option",
".",
"HeadObjectInput",
")",
"(",
"bool",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"b",
".",
"HeadObject",
"(",
"key",
",",
"opts",
"...... | // ExistsObject returns true if key does not exist on bucket. | [
"ExistsObject",
"returns",
"true",
"if",
"key",
"does",
"not",
"exist",
"on",
"bucket",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/bucket.go#L83-L96 |
149,086 | nabeken/aws-go-s3 | bucket/bucket.go | PutObject | func (b *Bucket) PutObject(key string, rs io.ReadSeeker, opts ...option.PutObjectInput) (*s3.PutObjectOutput, error) {
req := &s3.PutObjectInput{
Bucket: b.Name,
Key: aws.String(key),
Body: rs,
}
for _, f := range opts {
f(req)
}
return b.S3.PutObject(req)
} | go | func (b *Bucket) PutObject(key string, rs io.ReadSeeker, opts ...option.PutObjectInput) (*s3.PutObjectOutput, error) {
req := &s3.PutObjectInput{
Bucket: b.Name,
Key: aws.String(key),
Body: rs,
}
for _, f := range opts {
f(req)
}
return b.S3.PutObject(req)
} | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"PutObject",
"(",
"key",
"string",
",",
"rs",
"io",
".",
"ReadSeeker",
",",
"opts",
"...",
"option",
".",
"PutObjectInput",
")",
"(",
"*",
"s3",
".",
"PutObjectOutput",
",",
"error",
")",
"{",
"req",
":=",
"&",
... | // PutObject puts an object with reading data from reader. | [
"PutObject",
"puts",
"an",
"object",
"with",
"reading",
"data",
"from",
"reader",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/bucket.go#L99-L111 |
149,087 | nabeken/aws-go-s3 | bucket/bucket.go | DeleteObject | func (b *Bucket) DeleteObject(key string) (*s3.DeleteObjectOutput, error) {
req := &s3.DeleteObjectInput{
Bucket: b.Name,
Key: aws.String(key),
}
return b.S3.DeleteObject(req)
} | go | func (b *Bucket) DeleteObject(key string) (*s3.DeleteObjectOutput, error) {
req := &s3.DeleteObjectInput{
Bucket: b.Name,
Key: aws.String(key),
}
return b.S3.DeleteObject(req)
} | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"DeleteObject",
"(",
"key",
"string",
")",
"(",
"*",
"s3",
".",
"DeleteObjectOutput",
",",
"error",
")",
"{",
"req",
":=",
"&",
"s3",
".",
"DeleteObjectInput",
"{",
"Bucket",
":",
"b",
".",
"Name",
",",
"Key",
... | // DeleteObject deletes an object for key. | [
"DeleteObject",
"deletes",
"an",
"object",
"for",
"key",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/bucket.go#L114-L121 |
149,088 | nabeken/aws-go-s3 | bucket/bucket.go | ListObjects | func (b *Bucket) ListObjects(prefix string, opts ...option.ListObjectsInput) (*s3.ListObjectsOutput, error) {
req := &s3.ListObjectsInput{
Bucket: b.Name,
Prefix: aws.String(prefix),
}
for _, f := range opts {
f(req)
}
return b.S3.ListObjects(req)
} | go | func (b *Bucket) ListObjects(prefix string, opts ...option.ListObjectsInput) (*s3.ListObjectsOutput, error) {
req := &s3.ListObjectsInput{
Bucket: b.Name,
Prefix: aws.String(prefix),
}
for _, f := range opts {
f(req)
}
return b.S3.ListObjects(req)
} | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"ListObjects",
"(",
"prefix",
"string",
",",
"opts",
"...",
"option",
".",
"ListObjectsInput",
")",
"(",
"*",
"s3",
".",
"ListObjectsOutput",
",",
"error",
")",
"{",
"req",
":=",
"&",
"s3",
".",
"ListObjectsInput",
... | // ListObjects lists objects that has prefix. | [
"ListObjects",
"lists",
"objects",
"that",
"has",
"prefix",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/bucket.go#L124-L135 |
149,089 | nabeken/aws-go-s3 | bucket/bucket.go | CopyObject | func (b *Bucket) CopyObject(dest, src string, opts ...option.CopyObjectInput) (*s3.CopyObjectOutput, error) {
req := &s3.CopyObjectInput{
Bucket: b.Name,
Key: aws.String(dest),
CopySource: aws.String(aws.StringValue(b.Name) + "/" + url.QueryEscape(src)),
}
for _, f := range opts {
f(req)
}
ret... | go | func (b *Bucket) CopyObject(dest, src string, opts ...option.CopyObjectInput) (*s3.CopyObjectOutput, error) {
req := &s3.CopyObjectInput{
Bucket: b.Name,
Key: aws.String(dest),
CopySource: aws.String(aws.StringValue(b.Name) + "/" + url.QueryEscape(src)),
}
for _, f := range opts {
f(req)
}
ret... | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"CopyObject",
"(",
"dest",
",",
"src",
"string",
",",
"opts",
"...",
"option",
".",
"CopyObjectInput",
")",
"(",
"*",
"s3",
".",
"CopyObjectOutput",
",",
"error",
")",
"{",
"req",
":=",
"&",
"s3",
".",
"CopyObjec... | // CopyObject copies an object within the bucket. | [
"CopyObject",
"copies",
"an",
"object",
"within",
"the",
"bucket",
"."
] | af8508734d09dbb1ee3a628945ac8c1039120d46 | https://github.com/nabeken/aws-go-s3/blob/af8508734d09dbb1ee3a628945ac8c1039120d46/bucket/bucket.go#L138-L150 |
149,090 | brankas/autocertdns | godop/godop.go | New | func New(opts ...Option) (*Client, error) {
var err error
c := &Client{
logf: func(string, ...interface{}) {},
}
// apply opts
for _, o := range opts {
err = o(c)
if err != nil {
return nil, err
}
}
// ensure errf is set
if c.errf == nil {
c.errf = func(s string, v ...interface{}) {
c.logf("E... | go | func New(opts ...Option) (*Client, error) {
var err error
c := &Client{
logf: func(string, ...interface{}) {},
}
// apply opts
for _, o := range opts {
err = o(c)
if err != nil {
return nil, err
}
}
// ensure errf is set
if c.errf == nil {
c.errf = func(s string, v ...interface{}) {
c.logf("E... | [
"func",
"New",
"(",
"opts",
"...",
"Option",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"c",
":=",
"&",
"Client",
"{",
"logf",
":",
"func",
"(",
"string",
",",
"...",
"interface",
"{",
"}",
")",
"{",
"}",
",... | // New wraps a godo.Client with a Client that can also handle DNS provisioning
// requests for use with the autocertdns.Manager. | [
"New",
"wraps",
"a",
"godo",
".",
"Client",
"with",
"a",
"Client",
"that",
"can",
"also",
"handle",
"DNS",
"provisioning",
"requests",
"for",
"use",
"with",
"the",
"autocertdns",
".",
"Manager",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/godop/godop.go#L28-L55 |
149,091 | brankas/autocertdns | autocertdns.go | log | func (m *Manager) log(s string, v ...interface{}) {
if m.Logf != nil {
m.Logf(s, v...)
}
} | go | func (m *Manager) log(s string, v ...interface{}) {
if m.Logf != nil {
m.Logf(s, v...)
}
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"log",
"(",
"s",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"m",
".",
"Logf",
"!=",
"nil",
"{",
"m",
".",
"Logf",
"(",
"s",
",",
"v",
"...",
")",
"\n",
"}",
"\n",
"}"
] | // log logs s, v via Manager.Logf. | [
"log",
"logs",
"s",
"v",
"via",
"Manager",
".",
"Logf",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/autocertdns.go#L142-L146 |
149,092 | brankas/autocertdns | autocertdns.go | cachedKey | func (m *Manager) cachedKey(filename string) (*ecdsa.PrivateKey, error) {
keyfile := filepath.Join(m.CacheDir, filename)
// try to load cached credentials
store, err := pemutil.LoadFile(keyfile)
if err != nil && os.IsNotExist(err) {
store, err = pemutil.GenerateECKeySet(elliptic.P256())
if err != nil {
retu... | go | func (m *Manager) cachedKey(filename string) (*ecdsa.PrivateKey, error) {
keyfile := filepath.Join(m.CacheDir, filename)
// try to load cached credentials
store, err := pemutil.LoadFile(keyfile)
if err != nil && os.IsNotExist(err) {
store, err = pemutil.GenerateECKeySet(elliptic.P256())
if err != nil {
retu... | [
"func",
"(",
"m",
"*",
"Manager",
")",
"cachedKey",
"(",
"filename",
"string",
")",
"(",
"*",
"ecdsa",
".",
"PrivateKey",
",",
"error",
")",
"{",
"keyfile",
":=",
"filepath",
".",
"Join",
"(",
"m",
".",
"CacheDir",
",",
"filename",
")",
"\n\n",
"// t... | // cachedKey retrieves a private key from disk, generating a new elliptic.P256
// key if the file is not on disk. | [
"cachedKey",
"retrieves",
"a",
"private",
"key",
"from",
"disk",
"generating",
"a",
"new",
"elliptic",
".",
"P256",
"key",
"if",
"the",
"file",
"is",
"not",
"on",
"disk",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/autocertdns.go#L371-L400 |
149,093 | brankas/autocertdns | autocertdns.go | cachedCert | func (m *Manager) cachedCert(domain string) (crypto.Signer, time.Time, error) {
certPath := filepath.Join(m.CacheDir, domain+certSuffix)
store, err := pemutil.LoadFile(certPath)
if err != nil && !os.IsNotExist(err) {
return nil, time.Time{}, err
}
cert, ok := store.Certificate()
if !ok {
return nil, time.Tim... | go | func (m *Manager) cachedCert(domain string) (crypto.Signer, time.Time, error) {
certPath := filepath.Join(m.CacheDir, domain+certSuffix)
store, err := pemutil.LoadFile(certPath)
if err != nil && !os.IsNotExist(err) {
return nil, time.Time{}, err
}
cert, ok := store.Certificate()
if !ok {
return nil, time.Tim... | [
"func",
"(",
"m",
"*",
"Manager",
")",
"cachedCert",
"(",
"domain",
"string",
")",
"(",
"crypto",
".",
"Signer",
",",
"time",
".",
"Time",
",",
"error",
")",
"{",
"certPath",
":=",
"filepath",
".",
"Join",
"(",
"m",
".",
"CacheDir",
",",
"domain",
... | // cachedCert retrieves the certificate on disk for domain, and extracting the
// expiry date. | [
"cachedCert",
"retrieves",
"the",
"certificate",
"on",
"disk",
"for",
"domain",
"and",
"extracting",
"the",
"expiry",
"date",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/autocertdns.go#L404-L420 |
149,094 | brankas/autocertdns | autocertdns.go | afterRenew | func (m *Manager) afterRenew() <-chan time.Time {
m.rw.RLock()
exp := m.nextExpiry
m.rw.RUnlock()
return time.After(exp.Sub(time.Now()))
} | go | func (m *Manager) afterRenew() <-chan time.Time {
m.rw.RLock()
exp := m.nextExpiry
m.rw.RUnlock()
return time.After(exp.Sub(time.Now()))
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"afterRenew",
"(",
")",
"<-",
"chan",
"time",
".",
"Time",
"{",
"m",
".",
"rw",
".",
"RLock",
"(",
")",
"\n",
"exp",
":=",
"m",
".",
"nextExpiry",
"\n",
"m",
".",
"rw",
".",
"RUnlock",
"(",
")",
"\n\n",
... | // afterRenew returns a channel that will be closed after the passing the
// Manager's next expiration date. | [
"afterRenew",
"returns",
"a",
"channel",
"that",
"will",
"be",
"closed",
"after",
"the",
"passing",
"the",
"Manager",
"s",
"next",
"expiration",
"date",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/autocertdns.go#L424-L430 |
149,095 | brankas/autocertdns | autocertdns.go | GetCertificate | func (m *Manager) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error) {
m.rw.RLock()
defer m.rw.RUnlock()
return m.cert, nil
} | go | func (m *Manager) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error) {
m.rw.RLock()
defer m.rw.RUnlock()
return m.cert, nil
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"GetCertificate",
"(",
"hello",
"*",
"tls",
".",
"ClientHelloInfo",
")",
"(",
"*",
"tls",
".",
"Certificate",
",",
"error",
")",
"{",
"m",
".",
"rw",
".",
"RLock",
"(",
")",
"\n",
"defer",
"m",
".",
"rw",
".... | // GetCertificate returns the current certificate. | [
"GetCertificate",
"returns",
"the",
"current",
"certificate",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/autocertdns.go#L463-L468 |
149,096 | brankas/autocertdns | godop/opts.go | Domain | func Domain(domain string) Option {
return func(c *Client) error {
c.domain = domain
return nil
}
} | go | func Domain(domain string) Option {
return func(c *Client) error {
c.domain = domain
return nil
}
} | [
"func",
"Domain",
"(",
"domain",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"domain",
"=",
"domain",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Domain is a Client option to set the domain. | [
"Domain",
"is",
"a",
"Client",
"option",
"to",
"set",
"the",
"domain",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/godop/opts.go#L16-L21 |
149,097 | brankas/autocertdns | godop/opts.go | GodoClient | func GodoClient(client *godo.Client) Option {
return func(c *Client) error {
c.client = client
return nil
}
} | go | func GodoClient(client *godo.Client) Option {
return func(c *Client) error {
c.client = client
return nil
}
} | [
"func",
"GodoClient",
"(",
"client",
"*",
"godo",
".",
"Client",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"client",
"=",
"client",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // GodoClient is a Client option to pass an already created godo client. | [
"GodoClient",
"is",
"a",
"Client",
"option",
"to",
"pass",
"an",
"already",
"created",
"godo",
"client",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/godop/opts.go#L24-L29 |
149,098 | brankas/autocertdns | godop/opts.go | GodoClientToken | func GodoClientToken(ctxt context.Context, token string) Option {
return func(c *Client) error {
return GodoClient(godo.NewClient(oauth2.NewClient(
ctxt,
oauth2.StaticTokenSource(
&oauth2.Token{
AccessToken: token,
},
),
)))(c)
}
} | go | func GodoClientToken(ctxt context.Context, token string) Option {
return func(c *Client) error {
return GodoClient(godo.NewClient(oauth2.NewClient(
ctxt,
oauth2.StaticTokenSource(
&oauth2.Token{
AccessToken: token,
},
),
)))(c)
}
} | [
"func",
"GodoClientToken",
"(",
"ctxt",
"context",
".",
"Context",
",",
"token",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"return",
"GodoClient",
"(",
"godo",
".",
"NewClient",
"(",
"oauth2",
".",
"NewCl... | // GodoClientToken is a Client option to pass only the godo client token, and a
// new godo client will be created. | [
"GodoClientToken",
"is",
"a",
"Client",
"option",
"to",
"pass",
"only",
"the",
"godo",
"client",
"token",
"and",
"a",
"new",
"godo",
"client",
"will",
"be",
"created",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/godop/opts.go#L33-L44 |
149,099 | brankas/autocertdns | godop/opts.go | GodoClientTokenFile | func GodoClientTokenFile(ctxt context.Context, filename string) Option {
return func(c *Client) error {
tok, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
return GodoClientToken(ctxt, string(bytes.TrimSpace(tok)))(c)
}
} | go | func GodoClientTokenFile(ctxt context.Context, filename string) Option {
return func(c *Client) error {
tok, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
return GodoClientToken(ctxt, string(bytes.TrimSpace(tok)))(c)
}
} | [
"func",
"GodoClientTokenFile",
"(",
"ctxt",
"context",
".",
"Context",
",",
"filename",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"tok",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filename",
")",
... | // GodoClientTokenFile is a Client option to create a new godo client using a
// token stored in a file on disk. | [
"GodoClientTokenFile",
"is",
"a",
"Client",
"option",
"to",
"create",
"a",
"new",
"godo",
"client",
"using",
"a",
"token",
"stored",
"in",
"a",
"file",
"on",
"disk",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/godop/opts.go#L48-L57 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.