repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6
values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
ikawaha/kagome.ipadic | internal/dic/index.go | WriteTo | func (idx IndexTable) WriteTo(w io.Writer) (n int64, err error) {
n, err = idx.Da.WriteTo(w)
var b bytes.Buffer
enc := gob.NewEncoder(&b)
if err = enc.Encode(idx.Dup); err != nil {
return
}
x, err := b.WriteTo(w)
if err != nil {
return
}
n += x
return
} | go | func (idx IndexTable) WriteTo(w io.Writer) (n int64, err error) {
n, err = idx.Da.WriteTo(w)
var b bytes.Buffer
enc := gob.NewEncoder(&b)
if err = enc.Encode(idx.Dup); err != nil {
return
}
x, err := b.WriteTo(w)
if err != nil {
return
}
n += x
return
} | [
"func",
"(",
"idx",
"IndexTable",
")",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"n",
"int64",
",",
"err",
"error",
")",
"{",
"n",
",",
"err",
"=",
"idx",
".",
"Da",
".",
"WriteTo",
"(",
"w",
")",
"\n",
"var",
"b",
"bytes",
".",
"Bu... | // WriteTo saves a index table. | [
"WriteTo",
"saves",
"a",
"index",
"table",
"."
] | fe03f87a0c7c32945d956fcfc934c3e11d5eb182 | https://github.com/ikawaha/kagome.ipadic/blob/fe03f87a0c7c32945d956fcfc934c3e11d5eb182/internal/dic/index.go#L105-L118 | test |
ikawaha/kagome.ipadic | internal/dic/index.go | ReadIndexTable | func ReadIndexTable(r io.Reader) (IndexTable, error) {
idx := IndexTable{}
d, err := da.Read(r)
if err != nil {
return idx, fmt.Errorf("read index error, %v", err)
}
idx.Da = d
dec := gob.NewDecoder(r)
if e := dec.Decode(&idx.Dup); e != nil {
return idx, fmt.Errorf("read index dup table error, %v", e)
}
... | go | func ReadIndexTable(r io.Reader) (IndexTable, error) {
idx := IndexTable{}
d, err := da.Read(r)
if err != nil {
return idx, fmt.Errorf("read index error, %v", err)
}
idx.Da = d
dec := gob.NewDecoder(r)
if e := dec.Decode(&idx.Dup); e != nil {
return idx, fmt.Errorf("read index dup table error, %v", e)
}
... | [
"func",
"ReadIndexTable",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"IndexTable",
",",
"error",
")",
"{",
"idx",
":=",
"IndexTable",
"{",
"}",
"\n",
"d",
",",
"err",
":=",
"da",
".",
"Read",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r... | // ReadIndexTable loads a index table. | [
"ReadIndexTable",
"loads",
"a",
"index",
"table",
"."
] | fe03f87a0c7c32945d956fcfc934c3e11d5eb182 | https://github.com/ikawaha/kagome.ipadic/blob/fe03f87a0c7c32945d956fcfc934c3e11d5eb182/internal/dic/index.go#L121-L135 | test |
qor/action_bar | action_bar.go | New | func New(admin *admin.Admin) *ActionBar {
bar := &ActionBar{Admin: admin}
ctr := &controller{ActionBar: bar}
admin.GetRouter().Get("/action_bar/switch_mode", ctr.SwitchMode)
admin.GetRouter().Get("/action_bar/inline_edit", ctr.InlineEdit)
return bar
} | go | func New(admin *admin.Admin) *ActionBar {
bar := &ActionBar{Admin: admin}
ctr := &controller{ActionBar: bar}
admin.GetRouter().Get("/action_bar/switch_mode", ctr.SwitchMode)
admin.GetRouter().Get("/action_bar/inline_edit", ctr.InlineEdit)
return bar
} | [
"func",
"New",
"(",
"admin",
"*",
"admin",
".",
"Admin",
")",
"*",
"ActionBar",
"{",
"bar",
":=",
"&",
"ActionBar",
"{",
"Admin",
":",
"admin",
"}",
"\n",
"ctr",
":=",
"&",
"controller",
"{",
"ActionBar",
":",
"bar",
"}",
"\n",
"admin",
".",
"GetRo... | // New will create an ActionBar object | [
"New",
"will",
"create",
"an",
"ActionBar",
"object"
] | 136e5e2c5b8c50976dc39edddf523fcaab0a73b8 | https://github.com/qor/action_bar/blob/136e5e2c5b8c50976dc39edddf523fcaab0a73b8/action_bar.go#L24-L30 | test |
qor/action_bar | action_bar.go | RegisterAction | func (bar *ActionBar) RegisterAction(action ActionInterface) {
bar.GlobalActions = append(bar.GlobalActions, action)
bar.actions = bar.GlobalActions
} | go | func (bar *ActionBar) RegisterAction(action ActionInterface) {
bar.GlobalActions = append(bar.GlobalActions, action)
bar.actions = bar.GlobalActions
} | [
"func",
"(",
"bar",
"*",
"ActionBar",
")",
"RegisterAction",
"(",
"action",
"ActionInterface",
")",
"{",
"bar",
".",
"GlobalActions",
"=",
"append",
"(",
"bar",
".",
"GlobalActions",
",",
"action",
")",
"\n",
"bar",
".",
"actions",
"=",
"bar",
".",
"Glob... | // RegisterAction register global action | [
"RegisterAction",
"register",
"global",
"action"
] | 136e5e2c5b8c50976dc39edddf523fcaab0a73b8 | https://github.com/qor/action_bar/blob/136e5e2c5b8c50976dc39edddf523fcaab0a73b8/action_bar.go#L33-L36 | test |
qor/action_bar | action_bar.go | Actions | func (bar *ActionBar) Actions(actions ...ActionInterface) *ActionBar {
newBar := &ActionBar{Admin: bar.Admin, actions: bar.GlobalActions}
newBar.actions = append(newBar.actions, actions...)
return newBar
} | go | func (bar *ActionBar) Actions(actions ...ActionInterface) *ActionBar {
newBar := &ActionBar{Admin: bar.Admin, actions: bar.GlobalActions}
newBar.actions = append(newBar.actions, actions...)
return newBar
} | [
"func",
"(",
"bar",
"*",
"ActionBar",
")",
"Actions",
"(",
"actions",
"...",
"ActionInterface",
")",
"*",
"ActionBar",
"{",
"newBar",
":=",
"&",
"ActionBar",
"{",
"Admin",
":",
"bar",
".",
"Admin",
",",
"actions",
":",
"bar",
".",
"GlobalActions",
"}",
... | // Actions register actions | [
"Actions",
"register",
"actions"
] | 136e5e2c5b8c50976dc39edddf523fcaab0a73b8 | https://github.com/qor/action_bar/blob/136e5e2c5b8c50976dc39edddf523fcaab0a73b8/action_bar.go#L39-L43 | test |
qor/action_bar | action_bar.go | Render | func (bar *ActionBar) Render(w http.ResponseWriter, r *http.Request) template.HTML {
var (
actions, inlineActions []ActionInterface
context = bar.Admin.NewContext(w, r)
)
for _, action := range bar.actions {
if action.InlineAction() {
inlineActions = append(inlineActions, action)
} else {
... | go | func (bar *ActionBar) Render(w http.ResponseWriter, r *http.Request) template.HTML {
var (
actions, inlineActions []ActionInterface
context = bar.Admin.NewContext(w, r)
)
for _, action := range bar.actions {
if action.InlineAction() {
inlineActions = append(inlineActions, action)
} else {
... | [
"func",
"(",
"bar",
"*",
"ActionBar",
")",
"Render",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"template",
".",
"HTML",
"{",
"var",
"(",
"actions",
",",
"inlineActions",
"[",
"]",
"ActionInterface",
"\n",
"con... | // Render will return the HTML of the bar, used this function to render the bar in frontend page's template or layout | [
"Render",
"will",
"return",
"the",
"HTML",
"of",
"the",
"bar",
"used",
"this",
"function",
"to",
"render",
"the",
"bar",
"in",
"frontend",
"page",
"s",
"template",
"or",
"layout"
] | 136e5e2c5b8c50976dc39edddf523fcaab0a73b8 | https://github.com/qor/action_bar/blob/136e5e2c5b8c50976dc39edddf523fcaab0a73b8/action_bar.go#L46-L68 | test |
qor/action_bar | action_bar.go | FuncMap | func (bar *ActionBar) FuncMap(w http.ResponseWriter, r *http.Request) template.FuncMap {
funcMap := template.FuncMap{}
funcMap["render_edit_button"] = func(value interface{}, resources ...*admin.Resource) template.HTML {
return bar.RenderEditButtonWithResource(w, r, value, resources...)
}
return funcMap
} | go | func (bar *ActionBar) FuncMap(w http.ResponseWriter, r *http.Request) template.FuncMap {
funcMap := template.FuncMap{}
funcMap["render_edit_button"] = func(value interface{}, resources ...*admin.Resource) template.HTML {
return bar.RenderEditButtonWithResource(w, r, value, resources...)
}
return funcMap
} | [
"func",
"(",
"bar",
"*",
"ActionBar",
")",
"FuncMap",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"template",
".",
"FuncMap",
"{",
"funcMap",
":=",
"template",
".",
"FuncMap",
"{",
"}",
"\n",
"funcMap",
"[",
"... | // FuncMap will return helper to render inline edit button | [
"FuncMap",
"will",
"return",
"helper",
"to",
"render",
"inline",
"edit",
"button"
] | 136e5e2c5b8c50976dc39edddf523fcaab0a73b8 | https://github.com/qor/action_bar/blob/136e5e2c5b8c50976dc39edddf523fcaab0a73b8/action_bar.go#L71-L79 | test |
qor/action_bar | action_bar.go | EditMode | func (bar *ActionBar) EditMode(w http.ResponseWriter, r *http.Request) bool {
return isEditMode(bar.Admin.NewContext(w, r))
} | go | func (bar *ActionBar) EditMode(w http.ResponseWriter, r *http.Request) bool {
return isEditMode(bar.Admin.NewContext(w, r))
} | [
"func",
"(",
"bar",
"*",
"ActionBar",
")",
"EditMode",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"bool",
"{",
"return",
"isEditMode",
"(",
"bar",
".",
"Admin",
".",
"NewContext",
"(",
"w",
",",
"r",
")",
"... | // EditMode return whether current mode is `Preview` or `Edit` | [
"EditMode",
"return",
"whether",
"current",
"mode",
"is",
"Preview",
"or",
"Edit"
] | 136e5e2c5b8c50976dc39edddf523fcaab0a73b8 | https://github.com/qor/action_bar/blob/136e5e2c5b8c50976dc39edddf523fcaab0a73b8/action_bar.go#L82-L84 | test |
qor/action_bar | controller.go | SwitchMode | func (controller) SwitchMode(context *admin.Context) {
utils.SetCookie(http.Cookie{Name: "qor-action-bar", Value: context.Request.URL.Query().Get("checked")}, context.Context)
referrer := context.Request.Referer()
if referrer == "" {
referrer = "/"
}
http.Redirect(context.Writer, context.Request, referrer, htt... | go | func (controller) SwitchMode(context *admin.Context) {
utils.SetCookie(http.Cookie{Name: "qor-action-bar", Value: context.Request.URL.Query().Get("checked")}, context.Context)
referrer := context.Request.Referer()
if referrer == "" {
referrer = "/"
}
http.Redirect(context.Writer, context.Request, referrer, htt... | [
"func",
"(",
"controller",
")",
"SwitchMode",
"(",
"context",
"*",
"admin",
".",
"Context",
")",
"{",
"utils",
".",
"SetCookie",
"(",
"http",
".",
"Cookie",
"{",
"Name",
":",
"\"qor-action-bar\"",
",",
"Value",
":",
"context",
".",
"Request",
".",
"URL",... | // SwitchMode is handle to store switch status in cookie | [
"SwitchMode",
"is",
"handle",
"to",
"store",
"switch",
"status",
"in",
"cookie"
] | 136e5e2c5b8c50976dc39edddf523fcaab0a73b8 | https://github.com/qor/action_bar/blob/136e5e2c5b8c50976dc39edddf523fcaab0a73b8/controller.go#L15-L24 | test |
qor/action_bar | controller.go | InlineEdit | func (controller) InlineEdit(context *admin.Context) {
context.Writer.Write([]byte(context.Render("action_bar/inline_edit")))
} | go | func (controller) InlineEdit(context *admin.Context) {
context.Writer.Write([]byte(context.Render("action_bar/inline_edit")))
} | [
"func",
"(",
"controller",
")",
"InlineEdit",
"(",
"context",
"*",
"admin",
".",
"Context",
")",
"{",
"context",
".",
"Writer",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"context",
".",
"Render",
"(",
"\"action_bar/inline_edit\"",
")",
")",
")",
"\n",
... | // InlineEdit using to make inline edit resource shown as slideout | [
"InlineEdit",
"using",
"to",
"make",
"inline",
"edit",
"resource",
"shown",
"as",
"slideout"
] | 136e5e2c5b8c50976dc39edddf523fcaab0a73b8 | https://github.com/qor/action_bar/blob/136e5e2c5b8c50976dc39edddf523fcaab0a73b8/controller.go#L27-L29 | test |
fhs/go-netrc | netrc/netrc.go | Error | func (e *Error) Error() string {
return fmt.Sprintf("%s:%d: %s", e.Filename, e.LineNum, e.Msg)
} | go | func (e *Error) Error() string {
return fmt.Sprintf("%s:%d: %s", e.Filename, e.LineNum, e.Msg)
} | [
"func",
"(",
"e",
"*",
"Error",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%s:%d: %s\"",
",",
"e",
".",
"Filename",
",",
"e",
".",
"LineNum",
",",
"e",
".",
"Msg",
")",
"\n",
"}"
] | // Error returns a string representation of error e. | [
"Error",
"returns",
"a",
"string",
"representation",
"of",
"error",
"e",
"."
] | 4ffed54ee5c32ebfb1b8c7c72fc90bb08dc3ff43 | https://github.com/fhs/go-netrc/blob/4ffed54ee5c32ebfb1b8c7c72fc90bb08dc3ff43/netrc/netrc.go#L80-L82 | test |
fhs/go-netrc | netrc/netrc.go | ParseFile | func ParseFile(filename string) ([]*Machine, Macros, error) {
// TODO(fhs): Check if file is readable by anyone besides the user if there is password in it.
fd, err := os.Open(filename)
if err != nil {
return nil, nil, err
}
defer fd.Close()
return parse(fd, &filePos{filename, 1})
} | go | func ParseFile(filename string) ([]*Machine, Macros, error) {
// TODO(fhs): Check if file is readable by anyone besides the user if there is password in it.
fd, err := os.Open(filename)
if err != nil {
return nil, nil, err
}
defer fd.Close()
return parse(fd, &filePos{filename, 1})
} | [
"func",
"ParseFile",
"(",
"filename",
"string",
")",
"(",
"[",
"]",
"*",
"Machine",
",",
"Macros",
",",
"error",
")",
"{",
"fd",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",... | // ParseFile parses the netrc file identified by filename and returns the set of
// machine information and macros defined in it. The ``default'' machine,
// which is intended to be used when no machine name matches, is identified
// by an empty machine name. There can be only one ``default'' machine.
//
// If there is... | [
"ParseFile",
"parses",
"the",
"netrc",
"file",
"identified",
"by",
"filename",
"and",
"returns",
"the",
"set",
"of",
"machine",
"information",
"and",
"macros",
"defined",
"in",
"it",
".",
"The",
"default",
"machine",
"which",
"is",
"intended",
"to",
"be",
"u... | 4ffed54ee5c32ebfb1b8c7c72fc90bb08dc3ff43 | https://github.com/fhs/go-netrc/blob/4ffed54ee5c32ebfb1b8c7c72fc90bb08dc3ff43/netrc/netrc.go#L228-L236 | test |
fhs/go-netrc | netrc/netrc.go | FindMachine | func FindMachine(filename, name string) (*Machine, error) {
mach, _, err := ParseFile(filename)
if err != nil {
return nil, err
}
var def *Machine
for _, m := range mach {
if m.Name == name {
return m, nil
}
if m.Name == "" {
def = m
}
}
if def == nil {
return nil, errors.New("no machine found"... | go | func FindMachine(filename, name string) (*Machine, error) {
mach, _, err := ParseFile(filename)
if err != nil {
return nil, err
}
var def *Machine
for _, m := range mach {
if m.Name == name {
return m, nil
}
if m.Name == "" {
def = m
}
}
if def == nil {
return nil, errors.New("no machine found"... | [
"func",
"FindMachine",
"(",
"filename",
",",
"name",
"string",
")",
"(",
"*",
"Machine",
",",
"error",
")",
"{",
"mach",
",",
"_",
",",
"err",
":=",
"ParseFile",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err"... | // FindMachine parses the netrc file identified by filename and returns
// the Machine named by name. If no Machine with name name is found, the
// ``default'' machine is returned. | [
"FindMachine",
"parses",
"the",
"netrc",
"file",
"identified",
"by",
"filename",
"and",
"returns",
"the",
"Machine",
"named",
"by",
"name",
".",
"If",
"no",
"Machine",
"with",
"name",
"name",
"is",
"found",
"the",
"default",
"machine",
"is",
"returned",
"."
... | 4ffed54ee5c32ebfb1b8c7c72fc90bb08dc3ff43 | https://github.com/fhs/go-netrc/blob/4ffed54ee5c32ebfb1b8c7c72fc90bb08dc3ff43/netrc/netrc.go#L241-L259 | test |
codemodus/kace | kace.go | New | func New(initialisms map[string]bool) (*Kace, error) {
ci := initialisms
if ci == nil {
ci = map[string]bool{}
}
ci = sanitizeCI(ci)
t, err := ktrie.NewKTrie(ci)
if err != nil {
return nil, fmt.Errorf("kace: cannot create trie: %s", err)
}
k := &Kace{
t: t,
}
return k, nil
} | go | func New(initialisms map[string]bool) (*Kace, error) {
ci := initialisms
if ci == nil {
ci = map[string]bool{}
}
ci = sanitizeCI(ci)
t, err := ktrie.NewKTrie(ci)
if err != nil {
return nil, fmt.Errorf("kace: cannot create trie: %s", err)
}
k := &Kace{
t: t,
}
return k, nil
} | [
"func",
"New",
"(",
"initialisms",
"map",
"[",
"string",
"]",
"bool",
")",
"(",
"*",
"Kace",
",",
"error",
")",
"{",
"ci",
":=",
"initialisms",
"\n",
"if",
"ci",
"==",
"nil",
"{",
"ci",
"=",
"map",
"[",
"string",
"]",
"bool",
"{",
"}",
"\n",
"}... | // New returns a pointer to an instance of kace loaded with a common
// initialsms trie based on the provided map. Before conversion to a
// trie, the provided map keys are all upper cased. | [
"New",
"returns",
"a",
"pointer",
"to",
"an",
"instance",
"of",
"kace",
"loaded",
"with",
"a",
"common",
"initialsms",
"trie",
"based",
"on",
"the",
"provided",
"map",
".",
"Before",
"conversion",
"to",
"a",
"trie",
"the",
"provided",
"map",
"keys",
"are",... | e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8 | https://github.com/codemodus/kace/blob/e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8/kace.go#L69-L87 | test |
codemodus/kace | kace.go | Camel | func (k *Kace) Camel(s string) string {
return camelCase(k.t, s, false)
} | go | func (k *Kace) Camel(s string) string {
return camelCase(k.t, s, false)
} | [
"func",
"(",
"k",
"*",
"Kace",
")",
"Camel",
"(",
"s",
"string",
")",
"string",
"{",
"return",
"camelCase",
"(",
"k",
".",
"t",
",",
"s",
",",
"false",
")",
"\n",
"}"
] | // Camel returns a camelCased string. | [
"Camel",
"returns",
"a",
"camelCased",
"string",
"."
] | e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8 | https://github.com/codemodus/kace/blob/e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8/kace.go#L90-L92 | test |
codemodus/kace | kace.go | Pascal | func (k *Kace) Pascal(s string) string {
return camelCase(k.t, s, true)
} | go | func (k *Kace) Pascal(s string) string {
return camelCase(k.t, s, true)
} | [
"func",
"(",
"k",
"*",
"Kace",
")",
"Pascal",
"(",
"s",
"string",
")",
"string",
"{",
"return",
"camelCase",
"(",
"k",
".",
"t",
",",
"s",
",",
"true",
")",
"\n",
"}"
] | // Pascal returns a PascalCased string. | [
"Pascal",
"returns",
"a",
"PascalCased",
"string",
"."
] | e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8 | https://github.com/codemodus/kace/blob/e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8/kace.go#L95-L97 | test |
codemodus/kace | kace.go | Snake | func (k *Kace) Snake(s string) string {
return delimitedCase(s, snakeDelim, false)
} | go | func (k *Kace) Snake(s string) string {
return delimitedCase(s, snakeDelim, false)
} | [
"func",
"(",
"k",
"*",
"Kace",
")",
"Snake",
"(",
"s",
"string",
")",
"string",
"{",
"return",
"delimitedCase",
"(",
"s",
",",
"snakeDelim",
",",
"false",
")",
"\n",
"}"
] | // Snake returns a snake_cased string with all lowercase letters. | [
"Snake",
"returns",
"a",
"snake_cased",
"string",
"with",
"all",
"lowercase",
"letters",
"."
] | e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8 | https://github.com/codemodus/kace/blob/e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8/kace.go#L100-L102 | test |
codemodus/kace | kace.go | SnakeUpper | func (k *Kace) SnakeUpper(s string) string {
return delimitedCase(s, snakeDelim, true)
} | go | func (k *Kace) SnakeUpper(s string) string {
return delimitedCase(s, snakeDelim, true)
} | [
"func",
"(",
"k",
"*",
"Kace",
")",
"SnakeUpper",
"(",
"s",
"string",
")",
"string",
"{",
"return",
"delimitedCase",
"(",
"s",
",",
"snakeDelim",
",",
"true",
")",
"\n",
"}"
] | // SnakeUpper returns a SNAKE_CASED string with all upper case letters. | [
"SnakeUpper",
"returns",
"a",
"SNAKE_CASED",
"string",
"with",
"all",
"upper",
"case",
"letters",
"."
] | e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8 | https://github.com/codemodus/kace/blob/e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8/kace.go#L105-L107 | test |
codemodus/kace | kace.go | Kebab | func (k *Kace) Kebab(s string) string {
return delimitedCase(s, kebabDelim, false)
} | go | func (k *Kace) Kebab(s string) string {
return delimitedCase(s, kebabDelim, false)
} | [
"func",
"(",
"k",
"*",
"Kace",
")",
"Kebab",
"(",
"s",
"string",
")",
"string",
"{",
"return",
"delimitedCase",
"(",
"s",
",",
"kebabDelim",
",",
"false",
")",
"\n",
"}"
] | // Kebab returns a kebab-cased string with all lowercase letters. | [
"Kebab",
"returns",
"a",
"kebab",
"-",
"cased",
"string",
"with",
"all",
"lowercase",
"letters",
"."
] | e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8 | https://github.com/codemodus/kace/blob/e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8/kace.go#L110-L112 | test |
codemodus/kace | kace.go | KebabUpper | func (k *Kace) KebabUpper(s string) string {
return delimitedCase(s, kebabDelim, true)
} | go | func (k *Kace) KebabUpper(s string) string {
return delimitedCase(s, kebabDelim, true)
} | [
"func",
"(",
"k",
"*",
"Kace",
")",
"KebabUpper",
"(",
"s",
"string",
")",
"string",
"{",
"return",
"delimitedCase",
"(",
"s",
",",
"kebabDelim",
",",
"true",
")",
"\n",
"}"
] | // KebabUpper returns a KEBAB-CASED string with all upper case letters. | [
"KebabUpper",
"returns",
"a",
"KEBAB",
"-",
"CASED",
"string",
"with",
"all",
"upper",
"case",
"letters",
"."
] | e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8 | https://github.com/codemodus/kace/blob/e3ecf78ee2a5e58652cb2be34d3159ad9c89acf8/kace.go#L115-L117 | test |
gravitational/roundtrip | sanitize.go | isPathSafe | func isPathSafe(s string) error {
u, err := url.Parse(s)
if err != nil {
return err
}
e, err := url.PathUnescape(u.Path)
if err != nil {
return err
}
if strings.Contains(e, "..") {
return fmt.Errorf(errorMessage)
}
if !whitelistPattern.MatchString(e) {
return fmt.Errorf(errorMessage)
}
return nil... | go | func isPathSafe(s string) error {
u, err := url.Parse(s)
if err != nil {
return err
}
e, err := url.PathUnescape(u.Path)
if err != nil {
return err
}
if strings.Contains(e, "..") {
return fmt.Errorf(errorMessage)
}
if !whitelistPattern.MatchString(e) {
return fmt.Errorf(errorMessage)
}
return nil... | [
"func",
"isPathSafe",
"(",
"s",
"string",
")",
"error",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"e",
",",
"err",
":=",
"url",
".",
"PathUnescape",
"(... | // isPathSafe checks if the passed in path conforms to a whitelist. | [
"isPathSafe",
"checks",
"if",
"the",
"passed",
"in",
"path",
"conforms",
"to",
"a",
"whitelist",
"."
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/sanitize.go#L33-L53 | test |
gravitational/roundtrip | tracer.go | Start | func (t *WriterTracer) Start(r *http.Request) {
t.StartTime = time.Now().UTC()
t.Request.URL = r.URL.String()
t.Request.Method = r.Method
} | go | func (t *WriterTracer) Start(r *http.Request) {
t.StartTime = time.Now().UTC()
t.Request.URL = r.URL.String()
t.Request.Method = r.Method
} | [
"func",
"(",
"t",
"*",
"WriterTracer",
")",
"Start",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"t",
".",
"StartTime",
"=",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
"\n",
"t",
".",
"Request",
".",
"URL",
"=",
"r",
".",
"URL",... | // Start is called on start of a request | [
"Start",
"is",
"called",
"on",
"start",
"of",
"a",
"request"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/tracer.go#L78-L82 | test |
gravitational/roundtrip | creds.go | ParseAuthHeaders | func ParseAuthHeaders(r *http.Request) (*AuthCreds, error) {
// according to the doc below oauth 2.0 bearer access token can
// come with query parameter
// http://self-issued.info/docs/draft-ietf-oauth-v2-bearer.html#query-param
// we are going to support this
if r.URL.Query().Get(AccessTokenQueryParam) != "" {
... | go | func ParseAuthHeaders(r *http.Request) (*AuthCreds, error) {
// according to the doc below oauth 2.0 bearer access token can
// come with query parameter
// http://self-issued.info/docs/draft-ietf-oauth-v2-bearer.html#query-param
// we are going to support this
if r.URL.Query().Get(AccessTokenQueryParam) != "" {
... | [
"func",
"ParseAuthHeaders",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"AuthCreds",
",",
"error",
")",
"{",
"if",
"r",
".",
"URL",
".",
"Query",
"(",
")",
".",
"Get",
"(",
"AccessTokenQueryParam",
")",
"!=",
"\"\"",
"{",
"return",
"&",
"... | // ParseAuthHeaders parses authentication headers from HTTP request
// it currently detects Bearer and Basic auth types | [
"ParseAuthHeaders",
"parses",
"authentication",
"headers",
"from",
"HTTP",
"request",
"it",
"currently",
"detects",
"Bearer",
"and",
"Basic",
"auth",
"types"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/creds.go#L44-L94 | test |
gravitational/roundtrip | client.go | Tracer | func Tracer(newTracer NewTracer) ClientParam {
return func(c *Client) error {
c.newTracer = newTracer
return nil
}
} | go | func Tracer(newTracer NewTracer) ClientParam {
return func(c *Client) error {
c.newTracer = newTracer
return nil
}
} | [
"func",
"Tracer",
"(",
"newTracer",
"NewTracer",
")",
"ClientParam",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"newTracer",
"=",
"newTracer",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Tracer sets a request tracer constructor | [
"Tracer",
"sets",
"a",
"request",
"tracer",
"constructor"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/client.go#L57-L62 | test |
gravitational/roundtrip | client.go | HTTPClient | func HTTPClient(h *http.Client) ClientParam {
return func(c *Client) error {
c.client = h
return nil
}
} | go | func HTTPClient(h *http.Client) ClientParam {
return func(c *Client) error {
c.client = h
return nil
}
} | [
"func",
"HTTPClient",
"(",
"h",
"*",
"http",
".",
"Client",
")",
"ClientParam",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"client",
"=",
"h",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // HTTPClient is a functional parameter that sets the internal
// HTTPClient of the roundtrip client wrapper | [
"HTTPClient",
"is",
"a",
"functional",
"parameter",
"that",
"sets",
"the",
"internal",
"HTTPClient",
"of",
"the",
"roundtrip",
"client",
"wrapper"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/client.go#L66-L71 | test |
gravitational/roundtrip | client.go | BasicAuth | func BasicAuth(username, password string) ClientParam {
return func(c *Client) error {
c.auth = &basicAuth{username: username, password: password}
return nil
}
} | go | func BasicAuth(username, password string) ClientParam {
return func(c *Client) error {
c.auth = &basicAuth{username: username, password: password}
return nil
}
} | [
"func",
"BasicAuth",
"(",
"username",
",",
"password",
"string",
")",
"ClientParam",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"auth",
"=",
"&",
"basicAuth",
"{",
"username",
":",
"username",
",",
"password",
":",
"pa... | // BasicAuth sets username and password for HTTP client | [
"BasicAuth",
"sets",
"username",
"and",
"password",
"for",
"HTTP",
"client"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/client.go#L74-L79 | test |
gravitational/roundtrip | client.go | BearerAuth | func BearerAuth(token string) ClientParam {
return func(c *Client) error {
c.auth = &bearerAuth{token: token}
return nil
}
} | go | func BearerAuth(token string) ClientParam {
return func(c *Client) error {
c.auth = &bearerAuth{token: token}
return nil
}
} | [
"func",
"BearerAuth",
"(",
"token",
"string",
")",
"ClientParam",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"auth",
"=",
"&",
"bearerAuth",
"{",
"token",
":",
"token",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
... | // BearerAuth sets token for HTTP client | [
"BearerAuth",
"sets",
"token",
"for",
"HTTP",
"client"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/client.go#L82-L87 | test |
gravitational/roundtrip | client.go | CookieJar | func CookieJar(jar http.CookieJar) ClientParam {
return func(c *Client) error {
c.jar = jar
return nil
}
} | go | func CookieJar(jar http.CookieJar) ClientParam {
return func(c *Client) error {
c.jar = jar
return nil
}
} | [
"func",
"CookieJar",
"(",
"jar",
"http",
".",
"CookieJar",
")",
"ClientParam",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"jar",
"=",
"jar",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // CookieJar sets HTTP cookie jar for this client | [
"CookieJar",
"sets",
"HTTP",
"cookie",
"jar",
"for",
"this",
"client"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/client.go#L90-L95 | test |
gravitational/roundtrip | client.go | SanitizerEnabled | func SanitizerEnabled(sanitizerEnabled bool) ClientParam {
return func(c *Client) error {
c.sanitizerEnabled = sanitizerEnabled
return nil
}
} | go | func SanitizerEnabled(sanitizerEnabled bool) ClientParam {
return func(c *Client) error {
c.sanitizerEnabled = sanitizerEnabled
return nil
}
} | [
"func",
"SanitizerEnabled",
"(",
"sanitizerEnabled",
"bool",
")",
"ClientParam",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"sanitizerEnabled",
"=",
"sanitizerEnabled",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // SanitizerEnabled will enable the input sanitizer which passes the URL
// path through a strict whitelist. | [
"SanitizerEnabled",
"will",
"enable",
"the",
"input",
"sanitizer",
"which",
"passes",
"the",
"URL",
"path",
"through",
"a",
"strict",
"whitelist",
"."
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/client.go#L99-L104 | test |
gravitational/roundtrip | client.go | OpenFile | func (c *Client) OpenFile(ctx context.Context, endpoint string, params url.Values) (ReadSeekCloser, error) {
// If the sanitizer is enabled, make sure the requested path is safe.
if c.sanitizerEnabled {
err := isPathSafe(endpoint)
if err != nil {
return nil, err
}
}
u, err := url.Parse(endpoint)
if err !... | go | func (c *Client) OpenFile(ctx context.Context, endpoint string, params url.Values) (ReadSeekCloser, error) {
// If the sanitizer is enabled, make sure the requested path is safe.
if c.sanitizerEnabled {
err := isPathSafe(endpoint)
if err != nil {
return nil, err
}
}
u, err := url.Parse(endpoint)
if err !... | [
"func",
"(",
"c",
"*",
"Client",
")",
"OpenFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"endpoint",
"string",
",",
"params",
"url",
".",
"Values",
")",
"(",
"ReadSeekCloser",
",",
"error",
")",
"{",
"if",
"c",
".",
"sanitizerEnabled",
"{",
"err",... | // OpenFile opens file using HTTP protocol and uses `Range` headers
// to seek to various positions in the file, this means that server
// has to support the flags `Range` and `Content-Range` | [
"OpenFile",
"opens",
"file",
"using",
"HTTP",
"protocol",
"and",
"uses",
"Range",
"headers",
"to",
"seek",
"to",
"various",
"positions",
"in",
"the",
"file",
"this",
"means",
"that",
"server",
"has",
"to",
"support",
"the",
"flags",
"Range",
"and",
"Content"... | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/client.go#L429-L445 | test |
gravitational/roundtrip | client.go | RoundTrip | func (c *Client) RoundTrip(fn RoundTripFn) (*Response, error) {
re, err := fn()
if err != nil {
return nil, err
}
defer re.Body.Close()
buf := &bytes.Buffer{}
_, err = io.Copy(buf, re.Body)
if err != nil {
return nil, err
}
return &Response{
code: re.StatusCode,
headers: re.Header,
body: buf,
... | go | func (c *Client) RoundTrip(fn RoundTripFn) (*Response, error) {
re, err := fn()
if err != nil {
return nil, err
}
defer re.Body.Close()
buf := &bytes.Buffer{}
_, err = io.Copy(buf, re.Body)
if err != nil {
return nil, err
}
return &Response{
code: re.StatusCode,
headers: re.Header,
body: buf,
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"RoundTrip",
"(",
"fn",
"RoundTripFn",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"re",
",",
"err",
":=",
"fn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",... | // RoundTrip collects response and error assuming fn has done
// HTTP roundtrip | [
"RoundTrip",
"collects",
"response",
"and",
"error",
"assuming",
"fn",
"has",
"done",
"HTTP",
"roundtrip"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/client.go#L453-L470 | test |
gravitational/roundtrip | client.go | SetAuthHeader | func (c *Client) SetAuthHeader(h http.Header) {
if c.auth != nil {
h.Set("Authorization", c.auth.String())
}
} | go | func (c *Client) SetAuthHeader(h http.Header) {
if c.auth != nil {
h.Set("Authorization", c.auth.String())
}
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetAuthHeader",
"(",
"h",
"http",
".",
"Header",
")",
"{",
"if",
"c",
".",
"auth",
"!=",
"nil",
"{",
"h",
".",
"Set",
"(",
"\"Authorization\"",
",",
"c",
".",
"auth",
".",
"String",
"(",
")",
")",
"\n",
"}... | // SetAuthHeader sets client's authorization headers if client
// was configured to work with authorization | [
"SetAuthHeader",
"sets",
"client",
"s",
"authorization",
"headers",
"if",
"client",
"was",
"configured",
"to",
"work",
"with",
"authorization"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/client.go#L474-L478 | test |
gravitational/roundtrip | client.go | FileName | func (r *FileResponse) FileName() string {
value := r.headers.Get("Content-Disposition")
if len(value) == 0 {
return ""
}
_, params, err := mime.ParseMediaType(value)
if err != nil {
return ""
}
return params["filename"]
} | go | func (r *FileResponse) FileName() string {
value := r.headers.Get("Content-Disposition")
if len(value) == 0 {
return ""
}
_, params, err := mime.ParseMediaType(value)
if err != nil {
return ""
}
return params["filename"]
} | [
"func",
"(",
"r",
"*",
"FileResponse",
")",
"FileName",
"(",
")",
"string",
"{",
"value",
":=",
"r",
".",
"headers",
".",
"Get",
"(",
"\"Content-Disposition\"",
")",
"\n",
"if",
"len",
"(",
"value",
")",
"==",
"0",
"{",
"return",
"\"\"",
"\n",
"}",
... | // FileName returns HTTP file name | [
"FileName",
"returns",
"HTTP",
"file",
"name"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/client.go#L555-L565 | test |
gravitational/roundtrip | client.go | newBuffersFromFiles | func newBuffersFromFiles(files []File) []fileBuffer {
buffers := make([]fileBuffer, 0, len(files))
for _, file := range files {
buffers = append(buffers, newFileBuffer(file))
}
return buffers
} | go | func newBuffersFromFiles(files []File) []fileBuffer {
buffers := make([]fileBuffer, 0, len(files))
for _, file := range files {
buffers = append(buffers, newFileBuffer(file))
}
return buffers
} | [
"func",
"newBuffersFromFiles",
"(",
"files",
"[",
"]",
"File",
")",
"[",
"]",
"fileBuffer",
"{",
"buffers",
":=",
"make",
"(",
"[",
"]",
"fileBuffer",
",",
"0",
",",
"len",
"(",
"files",
")",
")",
"\n",
"for",
"_",
",",
"file",
":=",
"range",
"file... | // newBuffersFromFiles wraps the specified files with a reader
// that caches data into a memory buffer | [
"newBuffersFromFiles",
"wraps",
"the",
"specified",
"files",
"with",
"a",
"reader",
"that",
"caches",
"data",
"into",
"a",
"memory",
"buffer"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/client.go#L631-L637 | test |
gravitational/roundtrip | client.go | newFileBuffer | func newFileBuffer(file File) fileBuffer {
buf := &bytes.Buffer{}
return fileBuffer{
Reader: io.TeeReader(file.Reader, buf),
File: file,
cache: buf,
}
} | go | func newFileBuffer(file File) fileBuffer {
buf := &bytes.Buffer{}
return fileBuffer{
Reader: io.TeeReader(file.Reader, buf),
File: file,
cache: buf,
}
} | [
"func",
"newFileBuffer",
"(",
"file",
"File",
")",
"fileBuffer",
"{",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"return",
"fileBuffer",
"{",
"Reader",
":",
"io",
".",
"TeeReader",
"(",
"file",
".",
"Reader",
",",
"buf",
")",
",",
"Fil... | // newFileBuffer creates a buffer for reading from the specified File file | [
"newFileBuffer",
"creates",
"a",
"buffer",
"for",
"reading",
"from",
"the",
"specified",
"File",
"file"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/client.go#L640-L647 | test |
gravitational/roundtrip | client.go | rewind | func (r *fileBuffer) rewind() {
r.Reader = io.MultiReader(r.cache, r.File.Reader)
} | go | func (r *fileBuffer) rewind() {
r.Reader = io.MultiReader(r.cache, r.File.Reader)
} | [
"func",
"(",
"r",
"*",
"fileBuffer",
")",
"rewind",
"(",
")",
"{",
"r",
".",
"Reader",
"=",
"io",
".",
"MultiReader",
"(",
"r",
".",
"cache",
",",
"r",
".",
"File",
".",
"Reader",
")",
"\n",
"}"
] | // rewind resets this fileBuffer to read from the beginning | [
"rewind",
"resets",
"this",
"fileBuffer",
"to",
"read",
"from",
"the",
"beginning"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/client.go#L659-L661 | test |
gravitational/roundtrip | errors.go | ConvertResponse | func ConvertResponse(re *Response, err error) (*Response, error) {
if err != nil {
if uerr, ok := err.(*url.Error); ok && uerr != nil && uerr.Err != nil {
return nil, trace.Wrap(uerr.Err)
}
return nil, trace.Wrap(err)
}
return re, trace.ReadError(re.Code(), re.Bytes())
} | go | func ConvertResponse(re *Response, err error) (*Response, error) {
if err != nil {
if uerr, ok := err.(*url.Error); ok && uerr != nil && uerr.Err != nil {
return nil, trace.Wrap(uerr.Err)
}
return nil, trace.Wrap(err)
}
return re, trace.ReadError(re.Code(), re.Bytes())
} | [
"func",
"ConvertResponse",
"(",
"re",
"*",
"Response",
",",
"err",
"error",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"if",
"uerr",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"url",
".",
"Error",
")",
";",
"o... | // ConvertResponse converts http error to internal error type
// based on HTTP response code and HTTP body contents | [
"ConvertResponse",
"converts",
"http",
"error",
"to",
"internal",
"error",
"type",
"based",
"on",
"HTTP",
"response",
"code",
"and",
"HTTP",
"body",
"contents"
] | e1e0cd6b05a6bb1791b262e63160038828fd7b3a | https://github.com/gravitational/roundtrip/blob/e1e0cd6b05a6bb1791b262e63160038828fd7b3a/errors.go#L62-L70 | test |
coryb/figtree | gen-rawoption.go | Set | func (o *BoolOption) Set(s string) error {
err := convertString(s, &o.Value)
if err != nil {
return err
}
o.Source = "override"
o.Defined = true
return nil
} | go | func (o *BoolOption) Set(s string) error {
err := convertString(s, &o.Value)
if err != nil {
return err
}
o.Source = "override"
o.Defined = true
return nil
} | [
"func",
"(",
"o",
"*",
"BoolOption",
")",
"Set",
"(",
"s",
"string",
")",
"error",
"{",
"err",
":=",
"convertString",
"(",
"s",
",",
"&",
"o",
".",
"Value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"o",
".",
... | // This is useful with kingpin option parser | [
"This",
"is",
"useful",
"with",
"kingpin",
"option",
"parser"
] | e5fa026ccd54e0a6a99b6d81f73bfcc8e6fe6a6b | https://github.com/coryb/figtree/blob/e5fa026ccd54e0a6a99b6d81f73bfcc8e6fe6a6b/gen-rawoption.go#L43-L51 | test |
coryb/figtree | gen-rawoption.go | WriteAnswer | func (o *BoolOption) WriteAnswer(name string, value interface{}) error {
if v, ok := value.(bool); ok {
o.Value = v
o.Defined = true
o.Source = "prompt"
return nil
}
return fmt.Errorf("Got %T expected %T type: %v", value, o.Value, value)
} | go | func (o *BoolOption) WriteAnswer(name string, value interface{}) error {
if v, ok := value.(bool); ok {
o.Value = v
o.Defined = true
o.Source = "prompt"
return nil
}
return fmt.Errorf("Got %T expected %T type: %v", value, o.Value, value)
} | [
"func",
"(",
"o",
"*",
"BoolOption",
")",
"WriteAnswer",
"(",
"name",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"v",
",",
"ok",
":=",
"value",
".",
"(",
"bool",
")",
";",
"ok",
"{",
"o",
".",
"Value",
"=",
"v",
"\n... | // This is useful with survey prompting library | [
"This",
"is",
"useful",
"with",
"survey",
"prompting",
"library"
] | e5fa026ccd54e0a6a99b6d81f73bfcc8e6fe6a6b | https://github.com/coryb/figtree/blob/e5fa026ccd54e0a6a99b6d81f73bfcc8e6fe6a6b/gen-rawoption.go#L54-L62 | test |
coryb/figtree | gen-rawoption.go | String | func (o BoolOption) String() string {
if StringifyValue {
return fmt.Sprintf("%v", o.Value)
}
return fmt.Sprintf("{Source:%s Defined:%t Value:%v}", o.Source, o.Defined, o.Value)
} | go | func (o BoolOption) String() string {
if StringifyValue {
return fmt.Sprintf("%v", o.Value)
}
return fmt.Sprintf("{Source:%s Defined:%t Value:%v}", o.Source, o.Defined, o.Value)
} | [
"func",
"(",
"o",
"BoolOption",
")",
"String",
"(",
")",
"string",
"{",
"if",
"StringifyValue",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%v\"",
",",
"o",
".",
"Value",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"{Source:%s Defin... | // String is required for kingpin to generate usage with this datatype | [
"String",
"is",
"required",
"for",
"kingpin",
"to",
"generate",
"usage",
"with",
"this",
"datatype"
] | e5fa026ccd54e0a6a99b6d81f73bfcc8e6fe6a6b | https://github.com/coryb/figtree/blob/e5fa026ccd54e0a6a99b6d81f73bfcc8e6fe6a6b/gen-rawoption.go#L124-L129 | test |
stvp/pager | pager.go | TriggerIncidentKey | func TriggerIncidentKey(description string, key string) (incidentKey string, err error) {
return trigger(description, key, map[string]interface{}{})
} | go | func TriggerIncidentKey(description string, key string) (incidentKey string, err error) {
return trigger(description, key, map[string]interface{}{})
} | [
"func",
"TriggerIncidentKey",
"(",
"description",
"string",
",",
"key",
"string",
")",
"(",
"incidentKey",
"string",
",",
"err",
"error",
")",
"{",
"return",
"trigger",
"(",
"description",
",",
"key",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
... | // TriggerIncidentKey triggers an incident using the default client with a
// given incident key only if that incident has been resolved or if that
// incident doesn't exist yet. | [
"TriggerIncidentKey",
"triggers",
"an",
"incident",
"using",
"the",
"default",
"client",
"with",
"a",
"given",
"incident",
"key",
"only",
"if",
"that",
"incident",
"has",
"been",
"resolved",
"or",
"if",
"that",
"incident",
"doesn",
"t",
"exist",
"yet",
"."
] | 17442a04891b757880b72d926848df3e3af06c15 | https://github.com/stvp/pager/blob/17442a04891b757880b72d926848df3e3af06c15/pager.go#L42-L44 | test |
stvp/pager | pager.go | TriggerWithDetails | func TriggerWithDetails(description string, details map[string]interface{}) (incidentKey string, err error) {
return trigger(description, "", details)
} | go | func TriggerWithDetails(description string, details map[string]interface{}) (incidentKey string, err error) {
return trigger(description, "", details)
} | [
"func",
"TriggerWithDetails",
"(",
"description",
"string",
",",
"details",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"incidentKey",
"string",
",",
"err",
"error",
")",
"{",
"return",
"trigger",
"(",
"description",
",",
"\"\"",
",",
"deta... | // TriggerWithDetails triggers an incident using the default client with a
// description string and a key-value map that will be saved as the incident's
// "details". | [
"TriggerWithDetails",
"triggers",
"an",
"incident",
"using",
"the",
"default",
"client",
"with",
"a",
"description",
"string",
"and",
"a",
"key",
"-",
"value",
"map",
"that",
"will",
"be",
"saved",
"as",
"the",
"incident",
"s",
"details",
"."
] | 17442a04891b757880b72d926848df3e3af06c15 | https://github.com/stvp/pager/blob/17442a04891b757880b72d926848df3e3af06c15/pager.go#L49-L51 | test |
stvp/pager | pager.go | TriggerIncidentKeyWithDetails | func TriggerIncidentKeyWithDetails(description string, key string, details map[string]interface{}) (incidentKey string, err error) {
return trigger(description, key, details)
} | go | func TriggerIncidentKeyWithDetails(description string, key string, details map[string]interface{}) (incidentKey string, err error) {
return trigger(description, key, details)
} | [
"func",
"TriggerIncidentKeyWithDetails",
"(",
"description",
"string",
",",
"key",
"string",
",",
"details",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"incidentKey",
"string",
",",
"err",
"error",
")",
"{",
"return",
"trigger",
"(",
"descri... | // TriggerIncidentKeyWithDetails triggers an incident using the default client
// with a given incident key only if that incident has been resolved or if that
// incident doesn't exist yet. | [
"TriggerIncidentKeyWithDetails",
"triggers",
"an",
"incident",
"using",
"the",
"default",
"client",
"with",
"a",
"given",
"incident",
"key",
"only",
"if",
"that",
"incident",
"has",
"been",
"resolved",
"or",
"if",
"that",
"incident",
"doesn",
"t",
"exist",
"yet"... | 17442a04891b757880b72d926848df3e3af06c15 | https://github.com/stvp/pager/blob/17442a04891b757880b72d926848df3e3af06c15/pager.go#L56-L58 | test |
coryb/figtree | figtree.go | Merge | func Merge(dst, src interface{}) {
m := NewMerger()
m.mergeStructs(reflect.ValueOf(dst), reflect.ValueOf(src))
} | go | func Merge(dst, src interface{}) {
m := NewMerger()
m.mergeStructs(reflect.ValueOf(dst), reflect.ValueOf(src))
} | [
"func",
"Merge",
"(",
"dst",
",",
"src",
"interface",
"{",
"}",
")",
"{",
"m",
":=",
"NewMerger",
"(",
")",
"\n",
"m",
".",
"mergeStructs",
"(",
"reflect",
".",
"ValueOf",
"(",
"dst",
")",
",",
"reflect",
".",
"ValueOf",
"(",
"src",
")",
")",
"\n... | // Merge will attempt to merge the data from src into dst. They shoud be either both maps or both structs.
// The structs do not need to have the same structure, but any field name that exists in both
// structs will must be the same type. | [
"Merge",
"will",
"attempt",
"to",
"merge",
"the",
"data",
"from",
"src",
"into",
"dst",
".",
"They",
"shoud",
"be",
"either",
"both",
"maps",
"or",
"both",
"structs",
".",
"The",
"structs",
"do",
"not",
"need",
"to",
"have",
"the",
"same",
"structure",
... | e5fa026ccd54e0a6a99b6d81f73bfcc8e6fe6a6b | https://github.com/coryb/figtree/blob/e5fa026ccd54e0a6a99b6d81f73bfcc8e6fe6a6b/figtree.go#L321-L324 | test |
coryb/figtree | figtree.go | setSource | func (m *Merger) setSource(v reflect.Value) {
if v.Kind() == reflect.Ptr {
v = v.Elem()
}
switch v.Kind() {
case reflect.Map:
for _, key := range v.MapKeys() {
keyval := v.MapIndex(key)
if keyval.Kind() == reflect.Struct && keyval.FieldByName("Source").IsValid() {
// map values are immutable, so we ne... | go | func (m *Merger) setSource(v reflect.Value) {
if v.Kind() == reflect.Ptr {
v = v.Elem()
}
switch v.Kind() {
case reflect.Map:
for _, key := range v.MapKeys() {
keyval := v.MapIndex(key)
if keyval.Kind() == reflect.Struct && keyval.FieldByName("Source").IsValid() {
// map values are immutable, so we ne... | [
"func",
"(",
"m",
"*",
"Merger",
")",
"setSource",
"(",
"v",
"reflect",
".",
"Value",
")",
"{",
"if",
"v",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"v",
"=",
"v",
".",
"Elem",
"(",
")",
"\n",
"}",
"\n",
"switch",
"v",
".",
"... | // recursively set the Source attribute of the Options | [
"recursively",
"set",
"the",
"Source",
"attribute",
"of",
"the",
"Options"
] | e5fa026ccd54e0a6a99b6d81f73bfcc8e6fe6a6b | https://github.com/coryb/figtree/blob/e5fa026ccd54e0a6a99b6d81f73bfcc8e6fe6a6b/figtree.go#L547-L589 | test |
coryb/figtree | convert.go | convertString | func convertString(src string, dst interface{}) (err error) {
switch v := dst.(type) {
case *bool:
*v, err = strconv.ParseBool(src)
case *string:
*v = src
case *int:
var tmp int64
// this is a cheat, we only know int is at least 32 bits
// but we have to make a compromise here
tmp, err = strconv.ParseIn... | go | func convertString(src string, dst interface{}) (err error) {
switch v := dst.(type) {
case *bool:
*v, err = strconv.ParseBool(src)
case *string:
*v = src
case *int:
var tmp int64
// this is a cheat, we only know int is at least 32 bits
// but we have to make a compromise here
tmp, err = strconv.ParseIn... | [
"func",
"convertString",
"(",
"src",
"string",
",",
"dst",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"switch",
"v",
":=",
"dst",
".",
"(",
"type",
")",
"{",
"case",
"*",
"bool",
":",
"*",
"v",
",",
"err",
"=",
"strconv",
".",
"... | // dst must be a pointer type | [
"dst",
"must",
"be",
"a",
"pointer",
"type"
] | e5fa026ccd54e0a6a99b6d81f73bfcc8e6fe6a6b | https://github.com/coryb/figtree/blob/e5fa026ccd54e0a6a99b6d81f73bfcc8e6fe6a6b/convert.go#L9-L91 | test |
shogo82148/txmanager | txmanager.go | Do | func Do(d DB, f func(t Tx) error) error {
t, err := d.TxBegin()
if err != nil {
return err
}
defer t.TxFinish()
err = f(t)
if err != nil {
return err
}
return t.TxCommit()
} | go | func Do(d DB, f func(t Tx) error) error {
t, err := d.TxBegin()
if err != nil {
return err
}
defer t.TxFinish()
err = f(t)
if err != nil {
return err
}
return t.TxCommit()
} | [
"func",
"Do",
"(",
"d",
"DB",
",",
"f",
"func",
"(",
"t",
"Tx",
")",
"error",
")",
"error",
"{",
"t",
",",
"err",
":=",
"d",
".",
"TxBegin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"t",
".",... | // Do executes the function in a transaction. | [
"Do",
"executes",
"the",
"function",
"in",
"a",
"transaction",
"."
] | 5c0985a3720f2c462fe54ce430cae4ccfaf49d31 | https://github.com/shogo82148/txmanager/blob/5c0985a3720f2c462fe54ce430cae4ccfaf49d31/txmanager.go#L180-L191 | test |
nicholasjackson/bench | util/newfile.go | NewFile | func NewFile(filename string) io.Writer {
if err, _ := os.Open(filename); err != nil {
os.Remove(filename)
}
file, _ := os.Create(filename)
return file
} | go | func NewFile(filename string) io.Writer {
if err, _ := os.Open(filename); err != nil {
os.Remove(filename)
}
file, _ := os.Create(filename)
return file
} | [
"func",
"NewFile",
"(",
"filename",
"string",
")",
"io",
".",
"Writer",
"{",
"if",
"err",
",",
"_",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
";",
"err",
"!=",
"nil",
"{",
"os",
".",
"Remove",
"(",
"filename",
")",
"\n",
"}",
"\n",
"file",
... | // NewFile is a convenience function which creates and opens a file | [
"NewFile",
"is",
"a",
"convenience",
"function",
"which",
"creates",
"and",
"opens",
"a",
"file"
] | 2df9635f0ad020b2e82616b0fd87130aaa1ee12e | https://github.com/nicholasjackson/bench/blob/2df9635f0ad020b2e82616b0fd87130aaa1ee12e/util/newfile.go#L9-L17 | test |
nicholasjackson/bench | internal.go | internalRun | func (b *Bench) internalRun(showProgress bool) results.ResultSet {
startTime := time.Now()
endTime := startTime.Add(b.duration)
sem := semaphore.NewSemaphore(b.threads, b.rampUp) // create a new semaphore with an initiall capacity or 0
out := make(chan results.Result)
resultsChan := make(chan []results.Result)
... | go | func (b *Bench) internalRun(showProgress bool) results.ResultSet {
startTime := time.Now()
endTime := startTime.Add(b.duration)
sem := semaphore.NewSemaphore(b.threads, b.rampUp) // create a new semaphore with an initiall capacity or 0
out := make(chan results.Result)
resultsChan := make(chan []results.Result)
... | [
"func",
"(",
"b",
"*",
"Bench",
")",
"internalRun",
"(",
"showProgress",
"bool",
")",
"results",
".",
"ResultSet",
"{",
"startTime",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"endTime",
":=",
"startTime",
".",
"Add",
"(",
"b",
".",
"duration",
")",
"... | // RunBenchmarks executes the benchmarks based upon the given criteria
//
// Returns a resultset | [
"RunBenchmarks",
"executes",
"the",
"benchmarks",
"based",
"upon",
"the",
"given",
"criteria",
"Returns",
"a",
"resultset"
] | 2df9635f0ad020b2e82616b0fd87130aaa1ee12e | https://github.com/nicholasjackson/bench/blob/2df9635f0ad020b2e82616b0fd87130aaa1ee12e/internal.go#L16-L48 | test |
nicholasjackson/bench | results/summary.go | String | func (r Row) String() string {
rStr := fmt.Sprintf("Start Time: %v\n", r.StartTime.UTC())
rStr = fmt.Sprintf("%vElapsed Time: %v\n", rStr, r.ElapsedTime)
rStr = fmt.Sprintf("%vThreads: %v\n", rStr, r.Threads)
rStr = fmt.Sprintf("%vTotal Requests: %v\n", rStr, r.TotalRequests)
rStr = fmt.Sprintf("%vAvg Request Tim... | go | func (r Row) String() string {
rStr := fmt.Sprintf("Start Time: %v\n", r.StartTime.UTC())
rStr = fmt.Sprintf("%vElapsed Time: %v\n", rStr, r.ElapsedTime)
rStr = fmt.Sprintf("%vThreads: %v\n", rStr, r.Threads)
rStr = fmt.Sprintf("%vTotal Requests: %v\n", rStr, r.TotalRequests)
rStr = fmt.Sprintf("%vAvg Request Tim... | [
"func",
"(",
"r",
"Row",
")",
"String",
"(",
")",
"string",
"{",
"rStr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"Start Time: %v\\n\"",
",",
"\\n",
")",
"\n",
"r",
".",
"StartTime",
".",
"UTC",
"(",
")",
"\n",
"rStr",
"=",
"fmt",
".",
"Sprintf",
"(",
... | // String implements String from the Stringer interface and
// allows results to be serialized to a sting | [
"String",
"implements",
"String",
"from",
"the",
"Stringer",
"interface",
"and",
"allows",
"results",
"to",
"be",
"serialized",
"to",
"a",
"sting"
] | 2df9635f0ad020b2e82616b0fd87130aaa1ee12e | https://github.com/nicholasjackson/bench/blob/2df9635f0ad020b2e82616b0fd87130aaa1ee12e/results/summary.go#L24-L34 | test |
nicholasjackson/bench | results/summary.go | Tabulate | func (t *TabularResults) Tabulate(results []ResultSet) []Row {
var rows []Row
startTime := time.Unix(0, 0)
for _, bucket := range results {
if len(bucket) > 0 {
var elapsedTime time.Duration
if startTime == time.Unix(0, 0) {
startTime = bucket[0].Timestamp
}
elapsedTime = bucket[0].Timestamp.S... | go | func (t *TabularResults) Tabulate(results []ResultSet) []Row {
var rows []Row
startTime := time.Unix(0, 0)
for _, bucket := range results {
if len(bucket) > 0 {
var elapsedTime time.Duration
if startTime == time.Unix(0, 0) {
startTime = bucket[0].Timestamp
}
elapsedTime = bucket[0].Timestamp.S... | [
"func",
"(",
"t",
"*",
"TabularResults",
")",
"Tabulate",
"(",
"results",
"[",
"]",
"ResultSet",
")",
"[",
"]",
"Row",
"{",
"var",
"rows",
"[",
"]",
"Row",
"\n",
"startTime",
":=",
"time",
".",
"Unix",
"(",
"0",
",",
"0",
")",
"\n",
"for",
"_",
... | // Tabulate transforms the ResultsSets and returns a slice of Row | [
"Tabulate",
"transforms",
"the",
"ResultsSets",
"and",
"returns",
"a",
"slice",
"of",
"Row"
] | 2df9635f0ad020b2e82616b0fd87130aaa1ee12e | https://github.com/nicholasjackson/bench/blob/2df9635f0ad020b2e82616b0fd87130aaa1ee12e/results/summary.go#L41-L102 | test |
nicholasjackson/bench | example/main.go | AmazonRequest | func AmazonRequest() error {
resp, err := http.Get("http://www.amazon.co.uk/")
defer func(response *http.Response) {
if response != nil && response.Body != nil {
response.Body.Close()
}
}(resp)
if err != nil || resp.StatusCode != 200 {
return err
}
return nil
} | go | func AmazonRequest() error {
resp, err := http.Get("http://www.amazon.co.uk/")
defer func(response *http.Response) {
if response != nil && response.Body != nil {
response.Body.Close()
}
}(resp)
if err != nil || resp.StatusCode != 200 {
return err
}
return nil
} | [
"func",
"AmazonRequest",
"(",
")",
"error",
"{",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"\"http://www.amazon.co.uk/\"",
")",
"\n",
"defer",
"func",
"(",
"response",
"*",
"http",
".",
"Response",
")",
"{",
"if",
"response",
"!=",
"nil",
"&&",
... | // AmazonRequest is an example to benchmark a call to googles homepage | [
"AmazonRequest",
"is",
"an",
"example",
"to",
"benchmark",
"a",
"call",
"to",
"googles",
"homepage"
] | 2df9635f0ad020b2e82616b0fd87130aaa1ee12e | https://github.com/nicholasjackson/bench/blob/2df9635f0ad020b2e82616b0fd87130aaa1ee12e/example/main.go#L27-L41 | test |
nicholasjackson/bench | output/tablewriter.go | WriteTabularData | func WriteTabularData(interval time.Duration, r results.ResultSet, w io.Writer) {
set := r.Reduce(interval)
t := results.TabularResults{}
rows := t.Tabulate(set)
for _, row := range rows {
w.Write([]byte(row.String()))
w.Write([]byte("\n"))
}
} | go | func WriteTabularData(interval time.Duration, r results.ResultSet, w io.Writer) {
set := r.Reduce(interval)
t := results.TabularResults{}
rows := t.Tabulate(set)
for _, row := range rows {
w.Write([]byte(row.String()))
w.Write([]byte("\n"))
}
} | [
"func",
"WriteTabularData",
"(",
"interval",
"time",
".",
"Duration",
",",
"r",
"results",
".",
"ResultSet",
",",
"w",
"io",
".",
"Writer",
")",
"{",
"set",
":=",
"r",
".",
"Reduce",
"(",
"interval",
")",
"\n",
"t",
":=",
"results",
".",
"TabularResult... | // WriteTabularData writes the given results to the given output stream | [
"WriteTabularData",
"writes",
"the",
"given",
"results",
"to",
"the",
"given",
"output",
"stream"
] | 2df9635f0ad020b2e82616b0fd87130aaa1ee12e | https://github.com/nicholasjackson/bench/blob/2df9635f0ad020b2e82616b0fd87130aaa1ee12e/output/tablewriter.go#L11-L21 | test |
nicholasjackson/bench | results/results.go | Reduce | func (r ResultSet) Reduce(interval time.Duration) []ResultSet {
sort.Sort(r)
start := r[0].Timestamp
end := r[len(r)-1].Timestamp
// create the buckets
bucketCount := getBucketCount(start, end, interval)
buckets := make([]ResultSet, bucketCount)
for _, result := range r {
currentBucket := getBucketNumber(r... | go | func (r ResultSet) Reduce(interval time.Duration) []ResultSet {
sort.Sort(r)
start := r[0].Timestamp
end := r[len(r)-1].Timestamp
// create the buckets
bucketCount := getBucketCount(start, end, interval)
buckets := make([]ResultSet, bucketCount)
for _, result := range r {
currentBucket := getBucketNumber(r... | [
"func",
"(",
"r",
"ResultSet",
")",
"Reduce",
"(",
"interval",
"time",
".",
"Duration",
")",
"[",
"]",
"ResultSet",
"{",
"sort",
".",
"Sort",
"(",
"r",
")",
"\n",
"start",
":=",
"r",
"[",
"0",
"]",
".",
"Timestamp",
"\n",
"end",
":=",
"r",
"[",
... | // Reduce reduces the ResultSet into buckets defined by the given interval | [
"Reduce",
"reduces",
"the",
"ResultSet",
"into",
"buckets",
"defined",
"by",
"the",
"given",
"interval"
] | 2df9635f0ad020b2e82616b0fd87130aaa1ee12e | https://github.com/nicholasjackson/bench/blob/2df9635f0ad020b2e82616b0fd87130aaa1ee12e/results/results.go#L33-L50 | test |
nicholasjackson/bench | semaphore/semaphore.go | NewSemaphore | func NewSemaphore(capacity int, rampUp time.Duration) *Semaphore {
s := Semaphore{
lockDone: make(chan struct{}),
lockLock: make(chan struct{}),
rampUp: rampUp,
}
// if the rampup time is less than 1 then return immediately
if rampUp < 1 {
s.s = make(chan struct{}, capacity)
} else {
s.s = make(chan s... | go | func NewSemaphore(capacity int, rampUp time.Duration) *Semaphore {
s := Semaphore{
lockDone: make(chan struct{}),
lockLock: make(chan struct{}),
rampUp: rampUp,
}
// if the rampup time is less than 1 then return immediately
if rampUp < 1 {
s.s = make(chan struct{}, capacity)
} else {
s.s = make(chan s... | [
"func",
"NewSemaphore",
"(",
"capacity",
"int",
",",
"rampUp",
"time",
".",
"Duration",
")",
"*",
"Semaphore",
"{",
"s",
":=",
"Semaphore",
"{",
"lockDone",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"lockLock",
":",
"make",
"(",
"chan",
... | // NewSemaphore is used to create a new semaphore, initalised with a capacity
// this controls the number of locks which can be active at any one time. | [
"NewSemaphore",
"is",
"used",
"to",
"create",
"a",
"new",
"semaphore",
"initalised",
"with",
"a",
"capacity",
"this",
"controls",
"the",
"number",
"of",
"locks",
"which",
"can",
"be",
"active",
"at",
"any",
"one",
"time",
"."
] | 2df9635f0ad020b2e82616b0fd87130aaa1ee12e | https://github.com/nicholasjackson/bench/blob/2df9635f0ad020b2e82616b0fd87130aaa1ee12e/semaphore/semaphore.go#L22-L40 | test |
nicholasjackson/bench | semaphore/semaphore.go | Release | func (t *Semaphore) Release() {
t.waitIfResizing()
// we need a read lock to ensure we do not resize whilst resizing
t.readMutex.RLock()
defer t.readMutex.RUnlock()
// make sure we have not called Release without Lock
if len(t.s) == 0 {
return
}
<-t.s
} | go | func (t *Semaphore) Release() {
t.waitIfResizing()
// we need a read lock to ensure we do not resize whilst resizing
t.readMutex.RLock()
defer t.readMutex.RUnlock()
// make sure we have not called Release without Lock
if len(t.s) == 0 {
return
}
<-t.s
} | [
"func",
"(",
"t",
"*",
"Semaphore",
")",
"Release",
"(",
")",
"{",
"t",
".",
"waitIfResizing",
"(",
")",
"\n",
"t",
".",
"readMutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"readMutex",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"len",
"(",
... | // Release unlocks the semaphore and allows new lock instances to be called without
// blocking if the number of locks currently equal the capacity.
// It is important to call Release at the end of any operation which aquires a lock. | [
"Release",
"unlocks",
"the",
"semaphore",
"and",
"allows",
"new",
"lock",
"instances",
"to",
"be",
"called",
"without",
"blocking",
"if",
"the",
"number",
"of",
"locks",
"currently",
"equal",
"the",
"capacity",
".",
"It",
"is",
"important",
"to",
"call",
"Re... | 2df9635f0ad020b2e82616b0fd87130aaa1ee12e | https://github.com/nicholasjackson/bench/blob/2df9635f0ad020b2e82616b0fd87130aaa1ee12e/semaphore/semaphore.go#L53-L65 | test |
nicholasjackson/bench | semaphore/semaphore.go | Resize | func (t *Semaphore) Resize(capacity int) {
// only allow one resize to be called from one thread
t.resizeMutex.Lock()
if capacity == cap(t.s) {
t.resizeMutex.Unlock()
return
}
// lock the locks
t.resizeLock()
t.readMutex.Lock()
defer t.resizeUnlock()
defer t.resizeMutex.Unlock()
defer t.readMutex.Unloc... | go | func (t *Semaphore) Resize(capacity int) {
// only allow one resize to be called from one thread
t.resizeMutex.Lock()
if capacity == cap(t.s) {
t.resizeMutex.Unlock()
return
}
// lock the locks
t.resizeLock()
t.readMutex.Lock()
defer t.resizeUnlock()
defer t.resizeMutex.Unlock()
defer t.readMutex.Unloc... | [
"func",
"(",
"t",
"*",
"Semaphore",
")",
"Resize",
"(",
"capacity",
"int",
")",
"{",
"t",
".",
"resizeMutex",
".",
"Lock",
"(",
")",
"\n",
"if",
"capacity",
"==",
"cap",
"(",
"t",
".",
"s",
")",
"{",
"t",
".",
"resizeMutex",
".",
"Unlock",
"(",
... | // Resize allows dynamic resizing of the semaphore, it can be used if it desired
// to increase the current number of allowable concurent processes. | [
"Resize",
"allows",
"dynamic",
"resizing",
"of",
"the",
"semaphore",
"it",
"can",
"be",
"used",
"if",
"it",
"desired",
"to",
"increase",
"the",
"current",
"number",
"of",
"allowable",
"concurent",
"processes",
"."
] | 2df9635f0ad020b2e82616b0fd87130aaa1ee12e | https://github.com/nicholasjackson/bench/blob/2df9635f0ad020b2e82616b0fd87130aaa1ee12e/semaphore/semaphore.go#L69-L94 | test |
nicholasjackson/bench | bench.go | AddOutput | func (b *Bench) AddOutput(interval time.Duration, writer io.Writer, output output.OutputFunc) {
o := outputContainer{
interval: interval,
writer: writer,
function: output,
}
b.outputs = append(b.outputs, o)
} | go | func (b *Bench) AddOutput(interval time.Duration, writer io.Writer, output output.OutputFunc) {
o := outputContainer{
interval: interval,
writer: writer,
function: output,
}
b.outputs = append(b.outputs, o)
} | [
"func",
"(",
"b",
"*",
"Bench",
")",
"AddOutput",
"(",
"interval",
"time",
".",
"Duration",
",",
"writer",
"io",
".",
"Writer",
",",
"output",
"output",
".",
"OutputFunc",
")",
"{",
"o",
":=",
"outputContainer",
"{",
"interval",
":",
"interval",
",",
"... | // AddOutput adds an output writer to Bench | [
"AddOutput",
"adds",
"an",
"output",
"writer",
"to",
"Bench"
] | 2df9635f0ad020b2e82616b0fd87130aaa1ee12e | https://github.com/nicholasjackson/bench/blob/2df9635f0ad020b2e82616b0fd87130aaa1ee12e/bench.go#L56-L65 | test |
nicholasjackson/bench | bench.go | RunBenchmarks | func (b *Bench) RunBenchmarks(r RequestFunc) {
b.request = r
results := b.internalRun(b.showProgress)
b.processResults(results)
} | go | func (b *Bench) RunBenchmarks(r RequestFunc) {
b.request = r
results := b.internalRun(b.showProgress)
b.processResults(results)
} | [
"func",
"(",
"b",
"*",
"Bench",
")",
"RunBenchmarks",
"(",
"r",
"RequestFunc",
")",
"{",
"b",
".",
"request",
"=",
"r",
"\n",
"results",
":=",
"b",
".",
"internalRun",
"(",
"b",
".",
"showProgress",
")",
"\n",
"b",
".",
"processResults",
"(",
"result... | // RunBenchmarks runs the benchmarking for the given function | [
"RunBenchmarks",
"runs",
"the",
"benchmarking",
"for",
"the",
"given",
"function"
] | 2df9635f0ad020b2e82616b0fd87130aaa1ee12e | https://github.com/nicholasjackson/bench/blob/2df9635f0ad020b2e82616b0fd87130aaa1ee12e/bench.go#L68-L73 | test |
geoffgarside/ber | ber.go | parseBool | func parseBool(bytes []byte) (ret bool, err error) {
if len(bytes) != 1 {
err = asn1.SyntaxError{Msg: "invalid boolean"}
return
}
// DER demands that "If the encoding represents the boolean value TRUE,
// its single contents octet shall have all eight bits set to one."
// Thus only 0 and 255 are valid encoded... | go | func parseBool(bytes []byte) (ret bool, err error) {
if len(bytes) != 1 {
err = asn1.SyntaxError{Msg: "invalid boolean"}
return
}
// DER demands that "If the encoding represents the boolean value TRUE,
// its single contents octet shall have all eight bits set to one."
// Thus only 0 and 255 are valid encoded... | [
"func",
"parseBool",
"(",
"bytes",
"[",
"]",
"byte",
")",
"(",
"ret",
"bool",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"bytes",
")",
"!=",
"1",
"{",
"err",
"=",
"asn1",
".",
"SyntaxError",
"{",
"Msg",
":",
"\"invalid boolean\"",
"}",
"\n",
... | // We start by dealing with each of the primitive types in turn.
// BOOLEAN | [
"We",
"start",
"by",
"dealing",
"with",
"each",
"of",
"the",
"primitive",
"types",
"in",
"turn",
".",
"BOOLEAN"
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L34-L53 | test |
geoffgarside/ber | ber.go | checkInteger | func checkInteger(bytes []byte) error {
if len(bytes) == 0 {
return asn1.StructuralError{Msg: "empty integer"}
}
if len(bytes) == 1 {
return nil
}
if (bytes[0] == 0 && bytes[1]&0x80 == 0) || (bytes[0] == 0xff && bytes[1]&0x80 == 0x80) {
return asn1.StructuralError{Msg: "integer not minimally-encoded"}
}
re... | go | func checkInteger(bytes []byte) error {
if len(bytes) == 0 {
return asn1.StructuralError{Msg: "empty integer"}
}
if len(bytes) == 1 {
return nil
}
if (bytes[0] == 0 && bytes[1]&0x80 == 0) || (bytes[0] == 0xff && bytes[1]&0x80 == 0x80) {
return asn1.StructuralError{Msg: "integer not minimally-encoded"}
}
re... | [
"func",
"checkInteger",
"(",
"bytes",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"bytes",
")",
"==",
"0",
"{",
"return",
"asn1",
".",
"StructuralError",
"{",
"Msg",
":",
"\"empty integer\"",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"bytes"... | // INTEGER
// checkInteger returns nil if the given bytes are a valid DER-encoded
// INTEGER and an error otherwise. | [
"INTEGER",
"checkInteger",
"returns",
"nil",
"if",
"the",
"given",
"bytes",
"are",
"a",
"valid",
"DER",
"-",
"encoded",
"INTEGER",
"and",
"an",
"error",
"otherwise",
"."
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L59-L70 | test |
geoffgarside/ber | ber.go | parseInt64 | func parseInt64(bytes []byte) (ret int64, err error) {
err = checkInteger(bytes)
if err != nil {
return
}
if len(bytes) > 8 {
// We'll overflow an int64 in this case.
err = asn1.StructuralError{Msg: "integer too large"}
return
}
for bytesRead := 0; bytesRead < len(bytes); bytesRead++ {
ret <<= 8
ret |... | go | func parseInt64(bytes []byte) (ret int64, err error) {
err = checkInteger(bytes)
if err != nil {
return
}
if len(bytes) > 8 {
// We'll overflow an int64 in this case.
err = asn1.StructuralError{Msg: "integer too large"}
return
}
for bytesRead := 0; bytesRead < len(bytes); bytesRead++ {
ret <<= 8
ret |... | [
"func",
"parseInt64",
"(",
"bytes",
"[",
"]",
"byte",
")",
"(",
"ret",
"int64",
",",
"err",
"error",
")",
"{",
"err",
"=",
"checkInteger",
"(",
"bytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"len",
"(",
"bytes... | // parseInt64 treats the given bytes as a big-endian, signed integer and
// returns the result. | [
"parseInt64",
"treats",
"the",
"given",
"bytes",
"as",
"a",
"big",
"-",
"endian",
"signed",
"integer",
"and",
"returns",
"the",
"result",
"."
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L74-L93 | test |
geoffgarside/ber | ber.go | parseInt32 | func parseInt32(bytes []byte) (int32, error) {
if err := checkInteger(bytes); err != nil {
return 0, err
}
ret64, err := parseInt64(bytes)
if err != nil {
return 0, err
}
if ret64 != int64(int32(ret64)) {
return 0, asn1.StructuralError{Msg: "integer too large"}
}
return int32(ret64), nil
} | go | func parseInt32(bytes []byte) (int32, error) {
if err := checkInteger(bytes); err != nil {
return 0, err
}
ret64, err := parseInt64(bytes)
if err != nil {
return 0, err
}
if ret64 != int64(int32(ret64)) {
return 0, asn1.StructuralError{Msg: "integer too large"}
}
return int32(ret64), nil
} | [
"func",
"parseInt32",
"(",
"bytes",
"[",
"]",
"byte",
")",
"(",
"int32",
",",
"error",
")",
"{",
"if",
"err",
":=",
"checkInteger",
"(",
"bytes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"ret64",
",",
"err",
... | // parseInt treats the given bytes as a big-endian, signed integer and returns
// the result. | [
"parseInt",
"treats",
"the",
"given",
"bytes",
"as",
"a",
"big",
"-",
"endian",
"signed",
"integer",
"and",
"returns",
"the",
"result",
"."
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L97-L109 | test |
geoffgarside/ber | ber.go | parseBigInt | func parseBigInt(bytes []byte) (*big.Int, error) {
if err := checkInteger(bytes); err != nil {
return nil, err
}
ret := new(big.Int)
if len(bytes) > 0 && bytes[0]&0x80 == 0x80 {
// This is a negative number.
notBytes := make([]byte, len(bytes))
for i := range notBytes {
notBytes[i] = ^bytes[i]
}
ret.... | go | func parseBigInt(bytes []byte) (*big.Int, error) {
if err := checkInteger(bytes); err != nil {
return nil, err
}
ret := new(big.Int)
if len(bytes) > 0 && bytes[0]&0x80 == 0x80 {
// This is a negative number.
notBytes := make([]byte, len(bytes))
for i := range notBytes {
notBytes[i] = ^bytes[i]
}
ret.... | [
"func",
"parseBigInt",
"(",
"bytes",
"[",
"]",
"byte",
")",
"(",
"*",
"big",
".",
"Int",
",",
"error",
")",
"{",
"if",
"err",
":=",
"checkInteger",
"(",
"bytes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"... | // parseBigInt treats the given bytes as a big-endian, signed integer and returns
// the result. | [
"parseBigInt",
"treats",
"the",
"given",
"bytes",
"as",
"a",
"big",
"-",
"endian",
"signed",
"integer",
"and",
"returns",
"the",
"result",
"."
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L115-L133 | test |
geoffgarside/ber | ber.go | parseBitString | func parseBitString(bytes []byte) (ret asn1.BitString, err error) {
if len(bytes) == 0 {
err = asn1.SyntaxError{Msg: "zero length BIT STRING"}
return
}
paddingBits := int(bytes[0])
if paddingBits > 7 ||
len(bytes) == 1 && paddingBits > 0 ||
bytes[len(bytes)-1]&((1<<bytes[0])-1) != 0 {
err = asn1.SyntaxErr... | go | func parseBitString(bytes []byte) (ret asn1.BitString, err error) {
if len(bytes) == 0 {
err = asn1.SyntaxError{Msg: "zero length BIT STRING"}
return
}
paddingBits := int(bytes[0])
if paddingBits > 7 ||
len(bytes) == 1 && paddingBits > 0 ||
bytes[len(bytes)-1]&((1<<bytes[0])-1) != 0 {
err = asn1.SyntaxErr... | [
"func",
"parseBitString",
"(",
"bytes",
"[",
"]",
"byte",
")",
"(",
"ret",
"asn1",
".",
"BitString",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"bytes",
")",
"==",
"0",
"{",
"err",
"=",
"asn1",
".",
"SyntaxError",
"{",
"Msg",
":",
"\"zero len... | // BIT STRING
// parseBitString parses an ASN.1 bit string from the given byte slice and returns it. | [
"BIT",
"STRING",
"parseBitString",
"parses",
"an",
"ASN",
".",
"1",
"bit",
"string",
"from",
"the",
"given",
"byte",
"slice",
"and",
"returns",
"it",
"."
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L138-L153 | test |
geoffgarside/ber | ber.go | parseObjectIdentifier | func parseObjectIdentifier(bytes []byte) (s []int, err error) {
if len(bytes) == 0 {
err = asn1.SyntaxError{Msg: "zero length OBJECT IDENTIFIER"}
return
}
// In the worst case, we get two elements from the first byte (which is
// encoded differently) and then every varint is a single byte long.
s = make([]int... | go | func parseObjectIdentifier(bytes []byte) (s []int, err error) {
if len(bytes) == 0 {
err = asn1.SyntaxError{Msg: "zero length OBJECT IDENTIFIER"}
return
}
// In the worst case, we get two elements from the first byte (which is
// encoded differently) and then every varint is a single byte long.
s = make([]int... | [
"func",
"parseObjectIdentifier",
"(",
"bytes",
"[",
"]",
"byte",
")",
"(",
"s",
"[",
"]",
"int",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"bytes",
")",
"==",
"0",
"{",
"err",
"=",
"asn1",
".",
"SyntaxError",
"{",
"Msg",
":",
"\"zero length ... | // OBJECT IDENTIFIER
// parseObjectIdentifier parses an OBJECT IDENTIFIER from the given bytes and
// returns it. An object identifier is a sequence of variable length integers
// that are assigned in a hierarchy. | [
"OBJECT",
"IDENTIFIER",
"parseObjectIdentifier",
"parses",
"an",
"OBJECT",
"IDENTIFIER",
"from",
"the",
"given",
"bytes",
"and",
"returns",
"it",
".",
"An",
"object",
"identifier",
"is",
"a",
"sequence",
"of",
"variable",
"length",
"integers",
"that",
"are",
"as... | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L160-L196 | test |
geoffgarside/ber | ber.go | parseBase128Int | func parseBase128Int(bytes []byte, initOffset int) (ret, offset int, err error) {
ret, offset, err = _parseBase128Int(bytes, initOffset)
if offset-initOffset >= 4 {
err = asn1.StructuralError{Msg: "base 128 integer too large"}
return
}
return
} | go | func parseBase128Int(bytes []byte, initOffset int) (ret, offset int, err error) {
ret, offset, err = _parseBase128Int(bytes, initOffset)
if offset-initOffset >= 4 {
err = asn1.StructuralError{Msg: "base 128 integer too large"}
return
}
return
} | [
"func",
"parseBase128Int",
"(",
"bytes",
"[",
"]",
"byte",
",",
"initOffset",
"int",
")",
"(",
"ret",
",",
"offset",
"int",
",",
"err",
"error",
")",
"{",
"ret",
",",
"offset",
",",
"err",
"=",
"_parseBase128Int",
"(",
"bytes",
",",
"initOffset",
")",
... | // parseBase128Int parses a base-128 encoded int from the given offset in the
// given byte slice. It returns the value and the new offset. | [
"parseBase128Int",
"parses",
"a",
"base",
"-",
"128",
"encoded",
"int",
"from",
"the",
"given",
"offset",
"in",
"the",
"given",
"byte",
"slice",
".",
"It",
"returns",
"the",
"value",
"and",
"the",
"new",
"offset",
"."
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L215-L224 | test |
geoffgarside/ber | ber.go | parseGeneralizedTime | func parseGeneralizedTime(bytes []byte) (ret time.Time, err error) {
const formatStr = "20060102150405Z0700"
s := string(bytes)
if ret, err = time.Parse(formatStr, s); err != nil {
return
}
if serialized := ret.Format(formatStr); serialized != s {
err = fmt.Errorf("asn1: time did not serialize back to the or... | go | func parseGeneralizedTime(bytes []byte) (ret time.Time, err error) {
const formatStr = "20060102150405Z0700"
s := string(bytes)
if ret, err = time.Parse(formatStr, s); err != nil {
return
}
if serialized := ret.Format(formatStr); serialized != s {
err = fmt.Errorf("asn1: time did not serialize back to the or... | [
"func",
"parseGeneralizedTime",
"(",
"bytes",
"[",
"]",
"byte",
")",
"(",
"ret",
"time",
".",
"Time",
",",
"err",
"error",
")",
"{",
"const",
"formatStr",
"=",
"\"20060102150405Z0700\"",
"\n",
"s",
":=",
"string",
"(",
"bytes",
")",
"\n",
"if",
"ret",
... | // parseGeneralizedTime parses the GeneralizedTime from the given byte slice
// and returns the resulting time. | [
"parseGeneralizedTime",
"parses",
"the",
"GeneralizedTime",
"from",
"the",
"given",
"byte",
"slice",
"and",
"returns",
"the",
"resulting",
"time",
"."
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L256-L269 | test |
geoffgarside/ber | ber.go | parsePrintableString | func parsePrintableString(bytes []byte) (ret string, err error) {
for _, b := range bytes {
if !isPrintable(b) {
err = asn1.SyntaxError{Msg: "PrintableString contains invalid character"}
return
}
}
ret = string(bytes)
return
} | go | func parsePrintableString(bytes []byte) (ret string, err error) {
for _, b := range bytes {
if !isPrintable(b) {
err = asn1.SyntaxError{Msg: "PrintableString contains invalid character"}
return
}
}
ret = string(bytes)
return
} | [
"func",
"parsePrintableString",
"(",
"bytes",
"[",
"]",
"byte",
")",
"(",
"ret",
"string",
",",
"err",
"error",
")",
"{",
"for",
"_",
",",
"b",
":=",
"range",
"bytes",
"{",
"if",
"!",
"isPrintable",
"(",
"b",
")",
"{",
"err",
"=",
"asn1",
".",
"S... | // PrintableString
// parsePrintableString parses a ASN.1 PrintableString from the given byte
// array and returns it. | [
"PrintableString",
"parsePrintableString",
"parses",
"a",
"ASN",
".",
"1",
"PrintableString",
"from",
"the",
"given",
"byte",
"array",
"and",
"returns",
"it",
"."
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L275-L284 | test |
geoffgarside/ber | ber.go | isPrintable | func isPrintable(b byte) bool {
return 'a' <= b && b <= 'z' ||
'A' <= b && b <= 'Z' ||
'0' <= b && b <= '9' ||
'\'' <= b && b <= ')' ||
'+' <= b && b <= '/' ||
b == ' ' ||
b == ':' ||
b == '=' ||
b == '?' ||
// This is technically not allowed in a PrintableString.
// However, x509 certificates with... | go | func isPrintable(b byte) bool {
return 'a' <= b && b <= 'z' ||
'A' <= b && b <= 'Z' ||
'0' <= b && b <= '9' ||
'\'' <= b && b <= ')' ||
'+' <= b && b <= '/' ||
b == ' ' ||
b == ':' ||
b == '=' ||
b == '?' ||
// This is technically not allowed in a PrintableString.
// However, x509 certificates with... | [
"func",
"isPrintable",
"(",
"b",
"byte",
")",
"bool",
"{",
"return",
"'a'",
"<=",
"b",
"&&",
"b",
"<=",
"'z'",
"||",
"'A'",
"<=",
"b",
"&&",
"b",
"<=",
"'Z'",
"||",
"'0'",
"<=",
"b",
"&&",
"b",
"<=",
"'9'",
"||",
"'\\''",
"<=",
"b",
"&&",
"b"... | // isPrintable reports whether the given b is in the ASN.1 PrintableString set. | [
"isPrintable",
"reports",
"whether",
"the",
"given",
"b",
"is",
"in",
"the",
"ASN",
".",
"1",
"PrintableString",
"set",
"."
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L287-L301 | test |
geoffgarside/ber | ber.go | parseSequenceOf | func parseSequenceOf(bytes []byte, sliceType reflect.Type, elemType reflect.Type) (ret reflect.Value, err error) {
expectedTag, compoundType, ok := getUniversalType(elemType)
if !ok {
err = asn1.StructuralError{Msg: "unknown Go type for slice"}
return
}
// First we iterate over the input and count the number o... | go | func parseSequenceOf(bytes []byte, sliceType reflect.Type, elemType reflect.Type) (ret reflect.Value, err error) {
expectedTag, compoundType, ok := getUniversalType(elemType)
if !ok {
err = asn1.StructuralError{Msg: "unknown Go type for slice"}
return
}
// First we iterate over the input and count the number o... | [
"func",
"parseSequenceOf",
"(",
"bytes",
"[",
"]",
"byte",
",",
"sliceType",
"reflect",
".",
"Type",
",",
"elemType",
"reflect",
".",
"Type",
")",
"(",
"ret",
"reflect",
".",
"Value",
",",
"err",
"error",
")",
"{",
"expectedTag",
",",
"compoundType",
","... | // parseSequenceOf is used for SEQUENCE OF and SET OF values. It tries to parse
// a number of ASN.1 values from the given byte slice and returns them as a
// slice of Go values of the given type. | [
"parseSequenceOf",
"is",
"used",
"for",
"SEQUENCE",
"OF",
"and",
"SET",
"OF",
"values",
".",
"It",
"tries",
"to",
"parse",
"a",
"number",
"of",
"ASN",
".",
"1",
"values",
"from",
"the",
"given",
"byte",
"slice",
"and",
"returns",
"them",
"as",
"a",
"sl... | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L413-L461 | test |
geoffgarside/ber | ber.go | invalidLength | func invalidLength(offset, length, sliceLength int) bool {
return offset+length < offset || offset+length > sliceLength
} | go | func invalidLength(offset, length, sliceLength int) bool {
return offset+length < offset || offset+length > sliceLength
} | [
"func",
"invalidLength",
"(",
"offset",
",",
"length",
",",
"sliceLength",
"int",
")",
"bool",
"{",
"return",
"offset",
"+",
"length",
"<",
"offset",
"||",
"offset",
"+",
"length",
">",
"sliceLength",
"\n",
"}"
] | // invalidLength returns true iff offset + length > sliceLength, or if the
// addition would overflow. | [
"invalidLength",
"returns",
"true",
"iff",
"offset",
"+",
"length",
">",
"sliceLength",
"or",
"if",
"the",
"addition",
"would",
"overflow",
"."
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L476-L478 | test |
geoffgarside/ber | ber.go | setDefaultValue | func setDefaultValue(v reflect.Value, params fieldParameters) (ok bool) {
if !params.optional {
return
}
ok = true
if params.defaultValue == nil {
return
}
if canHaveDefaultValue(v.Kind()) {
v.SetInt(*params.defaultValue)
}
return
} | go | func setDefaultValue(v reflect.Value, params fieldParameters) (ok bool) {
if !params.optional {
return
}
ok = true
if params.defaultValue == nil {
return
}
if canHaveDefaultValue(v.Kind()) {
v.SetInt(*params.defaultValue)
}
return
} | [
"func",
"setDefaultValue",
"(",
"v",
"reflect",
".",
"Value",
",",
"params",
"fieldParameters",
")",
"(",
"ok",
"bool",
")",
"{",
"if",
"!",
"params",
".",
"optional",
"{",
"return",
"\n",
"}",
"\n",
"ok",
"=",
"true",
"\n",
"if",
"params",
".",
"def... | // setDefaultValue is used to install a default value, from a tag string, into
// a Value. It is successful if the field was optional, even if a default value
// wasn't provided or it failed to install it into the Value. | [
"setDefaultValue",
"is",
"used",
"to",
"install",
"a",
"default",
"value",
"from",
"a",
"tag",
"string",
"into",
"a",
"Value",
".",
"It",
"is",
"successful",
"if",
"the",
"field",
"was",
"optional",
"even",
"if",
"a",
"default",
"value",
"wasn",
"t",
"pr... | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L820-L832 | test |
geoffgarside/ber | ber.go | UnmarshalWithParams | func UnmarshalWithParams(b []byte, val interface{}, params string) (rest []byte, err error) {
v := reflect.ValueOf(val).Elem()
offset, err := parseField(v, b, 0, parseFieldParameters(params))
if err != nil {
return nil, err
}
return b[offset:], nil
} | go | func UnmarshalWithParams(b []byte, val interface{}, params string) (rest []byte, err error) {
v := reflect.ValueOf(val).Elem()
offset, err := parseField(v, b, 0, parseFieldParameters(params))
if err != nil {
return nil, err
}
return b[offset:], nil
} | [
"func",
"UnmarshalWithParams",
"(",
"b",
"[",
"]",
"byte",
",",
"val",
"interface",
"{",
"}",
",",
"params",
"string",
")",
"(",
"rest",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"val",
")",
".",
... | // UnmarshalWithParams allows field parameters to be specified for the
// top-level element. The form of the params is the same as the field tags. | [
"UnmarshalWithParams",
"allows",
"field",
"parameters",
"to",
"be",
"specified",
"for",
"the",
"top",
"-",
"level",
"element",
".",
"The",
"form",
"of",
"the",
"params",
"is",
"the",
"same",
"as",
"the",
"field",
"tags",
"."
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/ber.go#L892-L899 | test |
geoffgarside/ber | common.go | parseFieldParameters | func parseFieldParameters(str string) (ret fieldParameters) {
for _, part := range strings.Split(str, ",") {
switch {
case part == "optional":
ret.optional = true
case part == "explicit":
ret.explicit = true
if ret.tag == nil {
ret.tag = new(int)
}
case part == "generalized":
ret.timeType = ... | go | func parseFieldParameters(str string) (ret fieldParameters) {
for _, part := range strings.Split(str, ",") {
switch {
case part == "optional":
ret.optional = true
case part == "explicit":
ret.explicit = true
if ret.tag == nil {
ret.tag = new(int)
}
case part == "generalized":
ret.timeType = ... | [
"func",
"parseFieldParameters",
"(",
"str",
"string",
")",
"(",
"ret",
"fieldParameters",
")",
"{",
"for",
"_",
",",
"part",
":=",
"range",
"strings",
".",
"Split",
"(",
"str",
",",
"\",\"",
")",
"{",
"switch",
"{",
"case",
"part",
"==",
"\"optional\"",
... | // Given a tag string with the format specified in the package comment,
// parseFieldParameters will parse it into a fieldParameters structure,
// ignoring unknown parts of the string. | [
"Given",
"a",
"tag",
"string",
"with",
"the",
"format",
"specified",
"in",
"the",
"package",
"comment",
"parseFieldParameters",
"will",
"parse",
"it",
"into",
"a",
"fieldParameters",
"structure",
"ignoring",
"unknown",
"parts",
"of",
"the",
"string",
"."
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/common.go#L61-L105 | test |
geoffgarside/ber | common.go | getUniversalType | func getUniversalType(t reflect.Type) (tagNumber int, isCompound, ok bool) {
switch t {
case objectIdentifierType:
return tagOID, false, true
case bitStringType:
return tagBitString, false, true
case timeType:
return tagUTCTime, false, true
case enumeratedType:
return tagEnum, false, true
case bigIntType:... | go | func getUniversalType(t reflect.Type) (tagNumber int, isCompound, ok bool) {
switch t {
case objectIdentifierType:
return tagOID, false, true
case bitStringType:
return tagBitString, false, true
case timeType:
return tagUTCTime, false, true
case enumeratedType:
return tagEnum, false, true
case bigIntType:... | [
"func",
"getUniversalType",
"(",
"t",
"reflect",
".",
"Type",
")",
"(",
"tagNumber",
"int",
",",
"isCompound",
",",
"ok",
"bool",
")",
"{",
"switch",
"t",
"{",
"case",
"objectIdentifierType",
":",
"return",
"tagOID",
",",
"false",
",",
"true",
"\n",
"cas... | // Given a reflected Go type, getUniversalType returns the default tag number
// and expected compound flag. | [
"Given",
"a",
"reflected",
"Go",
"type",
"getUniversalType",
"returns",
"the",
"default",
"tag",
"number",
"and",
"expected",
"compound",
"flag",
"."
] | 27a1aff36ce64dbe5d93c08cc5f161983134ddc5 | https://github.com/geoffgarside/ber/blob/27a1aff36ce64dbe5d93c08cc5f161983134ddc5/common.go#L109-L141 | test |
manifoldco/go-base32 | base32.go | DecodeString | func DecodeString(raw string) ([]byte, error) {
pad := 8 - (len(raw) % 8)
nb := []byte(raw)
if pad != 8 {
nb = make([]byte, len(raw)+pad)
copy(nb, raw)
for i := 0; i < pad; i++ {
nb[len(raw)+i] = '='
}
}
return lowerBase32.DecodeString(string(nb))
} | go | func DecodeString(raw string) ([]byte, error) {
pad := 8 - (len(raw) % 8)
nb := []byte(raw)
if pad != 8 {
nb = make([]byte, len(raw)+pad)
copy(nb, raw)
for i := 0; i < pad; i++ {
nb[len(raw)+i] = '='
}
}
return lowerBase32.DecodeString(string(nb))
} | [
"func",
"DecodeString",
"(",
"raw",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"pad",
":=",
"8",
"-",
"(",
"len",
"(",
"raw",
")",
"%",
"8",
")",
"\n",
"nb",
":=",
"[",
"]",
"byte",
"(",
"raw",
")",
"\n",
"if",
"pad",
"!=... | // DecodeString decodes the given base32 encodeed bytes | [
"DecodeString",
"decodes",
"the",
"given",
"base32",
"encodeed",
"bytes"
] | 47b2838451516c36d06986c7b85bf1355522ecbb | https://github.com/manifoldco/go-base32/blob/47b2838451516c36d06986c7b85bf1355522ecbb/base32.go#L20-L32 | test |
skyrings/skyring-common | dbprovider/mongodb/mailnotifier.go | MailNotifier | func (m MongoDb) MailNotifier(ctxt string) (models.MailNotifier, error) {
c := m.Connect(models.COLL_NAME_MAIL_NOTIFIER)
defer m.Close(c)
var notifier []models.MailNotifier
if err := c.Find(nil).All(¬ifier); err != nil || len(notifier) == 0 {
logger.Get().Error("%s-Unable to read MailNotifier from DB: %v", ctx... | go | func (m MongoDb) MailNotifier(ctxt string) (models.MailNotifier, error) {
c := m.Connect(models.COLL_NAME_MAIL_NOTIFIER)
defer m.Close(c)
var notifier []models.MailNotifier
if err := c.Find(nil).All(¬ifier); err != nil || len(notifier) == 0 {
logger.Get().Error("%s-Unable to read MailNotifier from DB: %v", ctx... | [
"func",
"(",
"m",
"MongoDb",
")",
"MailNotifier",
"(",
"ctxt",
"string",
")",
"(",
"models",
".",
"MailNotifier",
",",
"error",
")",
"{",
"c",
":=",
"m",
".",
"Connect",
"(",
"models",
".",
"COLL_NAME_MAIL_NOTIFIER",
")",
"\n",
"defer",
"m",
".",
"Clos... | // User returns the Mail notifier. | [
"User",
"returns",
"the",
"Mail",
"notifier",
"."
] | d1c0bb1cbd5ed8438be1385c85c4f494608cde1e | https://github.com/skyrings/skyring-common/blob/d1c0bb1cbd5ed8438be1385c85c4f494608cde1e/dbprovider/mongodb/mailnotifier.go#L28-L38 | test |
skyrings/skyring-common | dbprovider/mongodb/mailnotifier.go | SaveMailNotifier | func (m MongoDb) SaveMailNotifier(ctxt string, notifier models.MailNotifier) error {
c := m.Connect(models.COLL_NAME_MAIL_NOTIFIER)
defer m.Close(c)
_, err := c.Upsert(bson.M{}, bson.M{"$set": notifier})
if err != nil {
logger.Get().Error("%s-Error Updating the mail notifier info for: %s Error: %v", ctxt, notifie... | go | func (m MongoDb) SaveMailNotifier(ctxt string, notifier models.MailNotifier) error {
c := m.Connect(models.COLL_NAME_MAIL_NOTIFIER)
defer m.Close(c)
_, err := c.Upsert(bson.M{}, bson.M{"$set": notifier})
if err != nil {
logger.Get().Error("%s-Error Updating the mail notifier info for: %s Error: %v", ctxt, notifie... | [
"func",
"(",
"m",
"MongoDb",
")",
"SaveMailNotifier",
"(",
"ctxt",
"string",
",",
"notifier",
"models",
".",
"MailNotifier",
")",
"error",
"{",
"c",
":=",
"m",
".",
"Connect",
"(",
"models",
".",
"COLL_NAME_MAIL_NOTIFIER",
")",
"\n",
"defer",
"m",
".",
"... | // Save mail notifier adds a new mail notifier, it replaces the existing one if there
// is already a notifier available. | [
"Save",
"mail",
"notifier",
"adds",
"a",
"new",
"mail",
"notifier",
"it",
"replaces",
"the",
"existing",
"one",
"if",
"there",
"is",
"already",
"a",
"notifier",
"available",
"."
] | d1c0bb1cbd5ed8438be1385c85c4f494608cde1e | https://github.com/skyrings/skyring-common/blob/d1c0bb1cbd5ed8438be1385c85c4f494608cde1e/dbprovider/mongodb/mailnotifier.go#L42-L51 | test |
skyrings/skyring-common | provisioner/provision_provider.go | RegisterProvider | func RegisterProvider(name string, factory ProvidersFactory) {
providersMutex.Lock()
defer providersMutex.Unlock()
if _, found := providers[name]; found {
logger.Get().Critical("Auth provider %s was registered twice", name)
}
providers[name] = factory
} | go | func RegisterProvider(name string, factory ProvidersFactory) {
providersMutex.Lock()
defer providersMutex.Unlock()
if _, found := providers[name]; found {
logger.Get().Critical("Auth provider %s was registered twice", name)
}
providers[name] = factory
} | [
"func",
"RegisterProvider",
"(",
"name",
"string",
",",
"factory",
"ProvidersFactory",
")",
"{",
"providersMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"providersMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"_",
",",
"found",
":=",
"providers",
"[",
"name... | // RegisterPlugin registers a plugin by name. This
// is expected to happen during app startup. | [
"RegisterPlugin",
"registers",
"a",
"plugin",
"by",
"name",
".",
"This",
"is",
"expected",
"to",
"happen",
"during",
"app",
"startup",
"."
] | d1c0bb1cbd5ed8438be1385c85c4f494608cde1e | https://github.com/skyrings/skyring-common/blob/d1c0bb1cbd5ed8438be1385c85c4f494608cde1e/provisioner/provision_provider.go#L43-L50 | test |
skyrings/skyring-common | dbprovider/mongodb/monogodbprovider.go | InitDb | func (m MongoDb) InitDb() error {
if err := m.InitUser(); err != nil {
logger.Get().Error("Error Initilaizing User Table", err)
return err
}
return nil
} | go | func (m MongoDb) InitDb() error {
if err := m.InitUser(); err != nil {
logger.Get().Error("Error Initilaizing User Table", err)
return err
}
return nil
} | [
"func",
"(",
"m",
"MongoDb",
")",
"InitDb",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"m",
".",
"InitUser",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Get",
"(",
")",
".",
"Error",
"(",
"\"Error Initilaizing User Table\"",
",",
"err",
... | //Set up the indexes for the Db
//Can be called during the initialization | [
"Set",
"up",
"the",
"indexes",
"for",
"the",
"Db",
"Can",
"be",
"called",
"during",
"the",
"initialization"
] | d1c0bb1cbd5ed8438be1385c85c4f494608cde1e | https://github.com/skyrings/skyring-common/blob/d1c0bb1cbd5ed8438be1385c85c4f494608cde1e/dbprovider/mongodb/monogodbprovider.go#L76-L82 | test |
skyrings/skyring-common | utils/util.go | Until | func Until(f func(), period time.Duration, stopCh <-chan struct{}) {
for {
select {
case <-stopCh:
return
default:
}
func() {
defer HandleCrash()
f()
}()
time.Sleep(period)
}
} | go | func Until(f func(), period time.Duration, stopCh <-chan struct{}) {
for {
select {
case <-stopCh:
return
default:
}
func() {
defer HandleCrash()
f()
}()
time.Sleep(period)
}
} | [
"func",
"Until",
"(",
"f",
"func",
"(",
")",
",",
"period",
"time",
".",
"Duration",
",",
"stopCh",
"<-",
"chan",
"struct",
"{",
"}",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"stopCh",
":",
"return",
"\n",
"default",
":",
"}",
"\n",
"fu... | // Until loops until stop channel is closed, running f every period.
// Catches any panics, and keeps going. f may not be invoked if
// stop channel is already closed. | [
"Until",
"loops",
"until",
"stop",
"channel",
"is",
"closed",
"running",
"f",
"every",
"period",
".",
"Catches",
"any",
"panics",
"and",
"keeps",
"going",
".",
"f",
"may",
"not",
"be",
"invoked",
"if",
"stop",
"channel",
"is",
"already",
"closed",
"."
] | d1c0bb1cbd5ed8438be1385c85c4f494608cde1e | https://github.com/skyrings/skyring-common/blob/d1c0bb1cbd5ed8438be1385c85c4f494608cde1e/utils/util.go#L52-L65 | test |
skyrings/skyring-common | utils/util.go | logPanic | func logPanic(r interface{}) {
callers := ""
for i := 0; true; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
callers = callers + fmt.Sprintf("%v:%v\n", file, line)
}
logger.Get().Error("Recovered from panic: %#v (%v)\n%v", r, r, callers)
} | go | func logPanic(r interface{}) {
callers := ""
for i := 0; true; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
callers = callers + fmt.Sprintf("%v:%v\n", file, line)
}
logger.Get().Error("Recovered from panic: %#v (%v)\n%v", r, r, callers)
} | [
"func",
"logPanic",
"(",
"r",
"interface",
"{",
"}",
")",
"{",
"callers",
":=",
"\"\"",
"\n",
"for",
"i",
":=",
"0",
";",
"true",
";",
"i",
"++",
"{",
"_",
",",
"file",
",",
"line",
",",
"ok",
":=",
"runtime",
".",
"Caller",
"(",
"i",
")",
"\... | // logPanic logs the caller tree when a panic occurs. | [
"logPanic",
"logs",
"the",
"caller",
"tree",
"when",
"a",
"panic",
"occurs",
"."
] | d1c0bb1cbd5ed8438be1385c85c4f494608cde1e | https://github.com/skyrings/skyring-common/blob/d1c0bb1cbd5ed8438be1385c85c4f494608cde1e/utils/util.go#L68-L78 | test |
skyrings/skyring-common | dbprovider/mongodb/user.go | User | func (m MongoDb) User(username string) (user models.User, e error) {
c := m.Connect(models.COLL_NAME_USER)
defer m.Close(c)
err := c.Find(bson.M{"username": username}).One(&user)
if err != nil {
return user, ErrMissingUser
}
return user, nil
} | go | func (m MongoDb) User(username string) (user models.User, e error) {
c := m.Connect(models.COLL_NAME_USER)
defer m.Close(c)
err := c.Find(bson.M{"username": username}).One(&user)
if err != nil {
return user, ErrMissingUser
}
return user, nil
} | [
"func",
"(",
"m",
"MongoDb",
")",
"User",
"(",
"username",
"string",
")",
"(",
"user",
"models",
".",
"User",
",",
"e",
"error",
")",
"{",
"c",
":=",
"m",
".",
"Connect",
"(",
"models",
".",
"COLL_NAME_USER",
")",
"\n",
"defer",
"m",
".",
"Close",
... | // User returns the user with the given username. Error is set to
// ErrMissingUser if user is not found. | [
"User",
"returns",
"the",
"user",
"with",
"the",
"given",
"username",
".",
"Error",
"is",
"set",
"to",
"ErrMissingUser",
"if",
"user",
"is",
"not",
"found",
"."
] | d1c0bb1cbd5ed8438be1385c85c4f494608cde1e | https://github.com/skyrings/skyring-common/blob/d1c0bb1cbd5ed8438be1385c85c4f494608cde1e/dbprovider/mongodb/user.go#L28-L36 | test |
skyrings/skyring-common | dbprovider/mongodb/user.go | Users | func (m MongoDb) Users(filter interface{}) (us []models.User, e error) {
c := m.Connect(models.COLL_NAME_USER)
defer m.Close(c)
err := c.Find(filter).All(&us)
if err != nil {
logger.Get().Error("Error getting record from DB. error: %v", err)
return us, mkmgoerror(err.Error())
}
return us, nil
} | go | func (m MongoDb) Users(filter interface{}) (us []models.User, e error) {
c := m.Connect(models.COLL_NAME_USER)
defer m.Close(c)
err := c.Find(filter).All(&us)
if err != nil {
logger.Get().Error("Error getting record from DB. error: %v", err)
return us, mkmgoerror(err.Error())
}
return us, nil
} | [
"func",
"(",
"m",
"MongoDb",
")",
"Users",
"(",
"filter",
"interface",
"{",
"}",
")",
"(",
"us",
"[",
"]",
"models",
".",
"User",
",",
"e",
"error",
")",
"{",
"c",
":=",
"m",
".",
"Connect",
"(",
"models",
".",
"COLL_NAME_USER",
")",
"\n",
"defer... | // Users returns a slice of all users. | [
"Users",
"returns",
"a",
"slice",
"of",
"all",
"users",
"."
] | d1c0bb1cbd5ed8438be1385c85c4f494608cde1e | https://github.com/skyrings/skyring-common/blob/d1c0bb1cbd5ed8438be1385c85c4f494608cde1e/dbprovider/mongodb/user.go#L39-L49 | test |
skyrings/skyring-common | dbprovider/mongodb/user.go | SaveUser | func (m MongoDb) SaveUser(user models.User) error {
c := m.Connect(models.COLL_NAME_USER)
defer m.Close(c)
_, err := c.Upsert(bson.M{"username": user.Username}, bson.M{"$set": user})
if err != nil {
logger.Get().Error("Error deleting record from DB for user: %s. error: %v", user.Username, err)
return mkmgoerro... | go | func (m MongoDb) SaveUser(user models.User) error {
c := m.Connect(models.COLL_NAME_USER)
defer m.Close(c)
_, err := c.Upsert(bson.M{"username": user.Username}, bson.M{"$set": user})
if err != nil {
logger.Get().Error("Error deleting record from DB for user: %s. error: %v", user.Username, err)
return mkmgoerro... | [
"func",
"(",
"m",
"MongoDb",
")",
"SaveUser",
"(",
"user",
"models",
".",
"User",
")",
"error",
"{",
"c",
":=",
"m",
".",
"Connect",
"(",
"models",
".",
"COLL_NAME_USER",
")",
"\n",
"defer",
"m",
".",
"Close",
"(",
"c",
")",
"\n",
"_",
",",
"err"... | // SaveUser adds a new user, replacing if the same username is in use. | [
"SaveUser",
"adds",
"a",
"new",
"user",
"replacing",
"if",
"the",
"same",
"username",
"is",
"in",
"use",
"."
] | d1c0bb1cbd5ed8438be1385c85c4f494608cde1e | https://github.com/skyrings/skyring-common/blob/d1c0bb1cbd5ed8438be1385c85c4f494608cde1e/dbprovider/mongodb/user.go#L52-L62 | test |
skyrings/skyring-common | dbprovider/mongodb/user.go | DeleteUser | func (m MongoDb) DeleteUser(username string) error {
c := m.Connect(models.COLL_NAME_USER)
defer m.Close(c)
// raises error if "username" doesn't exist
err := c.Remove(bson.M{"username": username})
if err != nil {
logger.Get().Error("Error deleting record from DB for user: %s. error: %v", username, err)
retur... | go | func (m MongoDb) DeleteUser(username string) error {
c := m.Connect(models.COLL_NAME_USER)
defer m.Close(c)
// raises error if "username" doesn't exist
err := c.Remove(bson.M{"username": username})
if err != nil {
logger.Get().Error("Error deleting record from DB for user: %s. error: %v", username, err)
retur... | [
"func",
"(",
"m",
"MongoDb",
")",
"DeleteUser",
"(",
"username",
"string",
")",
"error",
"{",
"c",
":=",
"m",
".",
"Connect",
"(",
"models",
".",
"COLL_NAME_USER",
")",
"\n",
"defer",
"m",
".",
"Close",
"(",
"c",
")",
"\n",
"err",
":=",
"c",
".",
... | // DeleteUser removes a user. ErrNotFound is returned if the user isn't found. | [
"DeleteUser",
"removes",
"a",
"user",
".",
"ErrNotFound",
"is",
"returned",
"if",
"the",
"user",
"isn",
"t",
"found",
"."
] | d1c0bb1cbd5ed8438be1385c85c4f494608cde1e | https://github.com/skyrings/skyring-common/blob/d1c0bb1cbd5ed8438be1385c85c4f494608cde1e/dbprovider/mongodb/user.go#L65-L76 | test |
pantheon-systems/go-certauth | certutils/certutils_pre_go18.go | LoadCACertFile | func LoadCACertFile(cert string) (*x509.CertPool, error) {
// validate caCert, and setup certpool
ca, err := ioutil.ReadFile(cert)
if err != nil {
return nil, fmt.Errorf("could not load CA Certificate: %s ", err.Error())
}
certPool := x509.NewCertPool()
if err := certPool.AppendCertsFromPEM(ca); !err {
retur... | go | func LoadCACertFile(cert string) (*x509.CertPool, error) {
// validate caCert, and setup certpool
ca, err := ioutil.ReadFile(cert)
if err != nil {
return nil, fmt.Errorf("could not load CA Certificate: %s ", err.Error())
}
certPool := x509.NewCertPool()
if err := certPool.AppendCertsFromPEM(ca); !err {
retur... | [
"func",
"LoadCACertFile",
"(",
"cert",
"string",
")",
"(",
"*",
"x509",
".",
"CertPool",
",",
"error",
")",
"{",
"ca",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"cert",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
... | // LoadCACertFile reads in a CA cert file that may contain multiple certs
// and gives you back a proper x509.CertPool for your fun and proffit | [
"LoadCACertFile",
"reads",
"in",
"a",
"CA",
"cert",
"file",
"that",
"may",
"contain",
"multiple",
"certs",
"and",
"gives",
"you",
"back",
"a",
"proper",
"x509",
".",
"CertPool",
"for",
"your",
"fun",
"and",
"proffit"
] | 8764720d23a5034dd9fab090815b7859463c68f6 | https://github.com/pantheon-systems/go-certauth/blob/8764720d23a5034dd9fab090815b7859463c68f6/certutils/certutils_pre_go18.go#L104-L117 | test |
pantheon-systems/go-certauth | certauth.go | NewAuth | func NewAuth(opts ...Options) *Auth {
o := Options{}
if len(opts) != 0 {
o = opts[0]
}
h := defaultAuthErrorHandler
if o.AuthErrorHandler != nil {
h = o.AuthErrorHandler
}
return &Auth{
opt: o,
authErrHandler: http.HandlerFunc(h),
}
} | go | func NewAuth(opts ...Options) *Auth {
o := Options{}
if len(opts) != 0 {
o = opts[0]
}
h := defaultAuthErrorHandler
if o.AuthErrorHandler != nil {
h = o.AuthErrorHandler
}
return &Auth{
opt: o,
authErrHandler: http.HandlerFunc(h),
}
} | [
"func",
"NewAuth",
"(",
"opts",
"...",
"Options",
")",
"*",
"Auth",
"{",
"o",
":=",
"Options",
"{",
"}",
"\n",
"if",
"len",
"(",
"opts",
")",
"!=",
"0",
"{",
"o",
"=",
"opts",
"[",
"0",
"]",
"\n",
"}",
"\n",
"h",
":=",
"defaultAuthErrorHandler",
... | // NewAuth returns an auth | [
"NewAuth",
"returns",
"an",
"auth"
] | 8764720d23a5034dd9fab090815b7859463c68f6 | https://github.com/pantheon-systems/go-certauth/blob/8764720d23a5034dd9fab090815b7859463c68f6/certauth.go#L63-L78 | test |
pantheon-systems/go-certauth | certauth.go | ValidateRequest | func (a *Auth) ValidateRequest(r *http.Request) error {
// ensure we can process this request
if r.TLS == nil || r.TLS.VerifiedChains == nil {
return errors.New("no cert chain detected")
}
// TODO: Figure out if having multiple validated peer leaf certs is possible. For now, only validate
// one cert, and make ... | go | func (a *Auth) ValidateRequest(r *http.Request) error {
// ensure we can process this request
if r.TLS == nil || r.TLS.VerifiedChains == nil {
return errors.New("no cert chain detected")
}
// TODO: Figure out if having multiple validated peer leaf certs is possible. For now, only validate
// one cert, and make ... | [
"func",
"(",
"a",
"*",
"Auth",
")",
"ValidateRequest",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"if",
"r",
".",
"TLS",
"==",
"nil",
"||",
"r",
".",
"TLS",
".",
"VerifiedChains",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"... | // ValidateRequest perfomrs verification on the TLS certs and chain | [
"ValidateRequest",
"perfomrs",
"verification",
"on",
"the",
"TLS",
"certs",
"and",
"chain"
] | 8764720d23a5034dd9fab090815b7859463c68f6 | https://github.com/pantheon-systems/go-certauth/blob/8764720d23a5034dd9fab090815b7859463c68f6/certauth.go#L121-L136 | test |
pantheon-systems/go-certauth | certauth.go | Process | func (a *Auth) Process(w http.ResponseWriter, r *http.Request) error {
if err := a.ValidateRequest(r); err != nil {
return err
}
// Validate OU
if len(a.opt.AllowedOUs) > 0 {
err := a.ValidateOU(r.TLS.VerifiedChains[0][0])
if err != nil {
a.authErrHandler.ServeHTTP(w, r)
return err
}
}
// Validate... | go | func (a *Auth) Process(w http.ResponseWriter, r *http.Request) error {
if err := a.ValidateRequest(r); err != nil {
return err
}
// Validate OU
if len(a.opt.AllowedOUs) > 0 {
err := a.ValidateOU(r.TLS.VerifiedChains[0][0])
if err != nil {
a.authErrHandler.ServeHTTP(w, r)
return err
}
}
// Validate... | [
"func",
"(",
"a",
"*",
"Auth",
")",
"Process",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"if",
"err",
":=",
"a",
".",
"ValidateRequest",
"(",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"return... | // Process is the main Entrypoint | [
"Process",
"is",
"the",
"main",
"Entrypoint"
] | 8764720d23a5034dd9fab090815b7859463c68f6 | https://github.com/pantheon-systems/go-certauth/blob/8764720d23a5034dd9fab090815b7859463c68f6/certauth.go#L139-L162 | test |
pantheon-systems/go-certauth | certauth.go | ValidateCN | func (a *Auth) ValidateCN(verifiedCert *x509.Certificate) error {
var failed []string
for _, cn := range a.opt.AllowedCNs {
if cn == verifiedCert.Subject.CommonName {
return nil
}
failed = append(failed, verifiedCert.Subject.CommonName)
}
return fmt.Errorf("cert failed CN validation for %v, Allowed: %v", ... | go | func (a *Auth) ValidateCN(verifiedCert *x509.Certificate) error {
var failed []string
for _, cn := range a.opt.AllowedCNs {
if cn == verifiedCert.Subject.CommonName {
return nil
}
failed = append(failed, verifiedCert.Subject.CommonName)
}
return fmt.Errorf("cert failed CN validation for %v, Allowed: %v", ... | [
"func",
"(",
"a",
"*",
"Auth",
")",
"ValidateCN",
"(",
"verifiedCert",
"*",
"x509",
".",
"Certificate",
")",
"error",
"{",
"var",
"failed",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"cn",
":=",
"range",
"a",
".",
"opt",
".",
"AllowedCNs",
"{",
"if... | // ValidateCN checks the CN of a verified peer cert and raises a 403 if the CN doesn't match any CN in the AllowedCNs list. | [
"ValidateCN",
"checks",
"the",
"CN",
"of",
"a",
"verified",
"peer",
"cert",
"and",
"raises",
"a",
"403",
"if",
"the",
"CN",
"doesn",
"t",
"match",
"any",
"CN",
"in",
"the",
"AllowedCNs",
"list",
"."
] | 8764720d23a5034dd9fab090815b7859463c68f6 | https://github.com/pantheon-systems/go-certauth/blob/8764720d23a5034dd9fab090815b7859463c68f6/certauth.go#L165-L175 | test |
pantheon-systems/go-certauth | certauth.go | ValidateOU | func (a *Auth) ValidateOU(verifiedCert *x509.Certificate) error {
var failed []string
for _, ou := range a.opt.AllowedOUs {
for _, clientOU := range verifiedCert.Subject.OrganizationalUnit {
if ou == clientOU {
return nil
}
failed = append(failed, clientOU)
}
}
return fmt.Errorf("cert failed OU va... | go | func (a *Auth) ValidateOU(verifiedCert *x509.Certificate) error {
var failed []string
for _, ou := range a.opt.AllowedOUs {
for _, clientOU := range verifiedCert.Subject.OrganizationalUnit {
if ou == clientOU {
return nil
}
failed = append(failed, clientOU)
}
}
return fmt.Errorf("cert failed OU va... | [
"func",
"(",
"a",
"*",
"Auth",
")",
"ValidateOU",
"(",
"verifiedCert",
"*",
"x509",
".",
"Certificate",
")",
"error",
"{",
"var",
"failed",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"ou",
":=",
"range",
"a",
".",
"opt",
".",
"AllowedOUs",
"{",
"fo... | // ValidateOU checks the OU of a verified peer cert and raises 403 if the OU doesn't match any OU in the AllowedOUs list. | [
"ValidateOU",
"checks",
"the",
"OU",
"of",
"a",
"verified",
"peer",
"cert",
"and",
"raises",
"403",
"if",
"the",
"OU",
"doesn",
"t",
"match",
"any",
"OU",
"in",
"the",
"AllowedOUs",
"list",
"."
] | 8764720d23a5034dd9fab090815b7859463c68f6 | https://github.com/pantheon-systems/go-certauth/blob/8764720d23a5034dd9fab090815b7859463c68f6/certauth.go#L178-L190 | test |
jmank88/nuts | key.go | KeyLen | func KeyLen(x uint64) int {
n := 1
if x >= 1<<32 {
x >>= 32
n += 4
}
if x >= 1<<16 {
x >>= 16
n += 2
}
if x >= 1<<8 {
x >>= 8
n += 1
}
return n
} | go | func KeyLen(x uint64) int {
n := 1
if x >= 1<<32 {
x >>= 32
n += 4
}
if x >= 1<<16 {
x >>= 16
n += 2
}
if x >= 1<<8 {
x >>= 8
n += 1
}
return n
} | [
"func",
"KeyLen",
"(",
"x",
"uint64",
")",
"int",
"{",
"n",
":=",
"1",
"\n",
"if",
"x",
">=",
"1",
"<<",
"32",
"{",
"x",
">>=",
"32",
"\n",
"n",
"+=",
"4",
"\n",
"}",
"\n",
"if",
"x",
">=",
"1",
"<<",
"16",
"{",
"x",
">>=",
"16",
"\n",
... | // KeyLen returns the minimum number of bytes required to represent x; the result is 1 for x == 0.
// Returns 1-8. | [
"KeyLen",
"returns",
"the",
"minimum",
"number",
"of",
"bytes",
"required",
"to",
"represent",
"x",
";",
"the",
"result",
"is",
"1",
"for",
"x",
"==",
"0",
".",
"Returns",
"1",
"-",
"8",
"."
] | 8b28145dffc87104e66d074f62ea8080edfad7c8 | https://github.com/jmank88/nuts/blob/8b28145dffc87104e66d074f62ea8080edfad7c8/key.go#L5-L20 | test |
giantswarm/certctl | service/cert-signer/cert_signer.go | DefaultConfig | func DefaultConfig() Config {
newClientConfig := vaultclient.DefaultConfig()
newClientConfig.Address = "http://127.0.0.1:8200"
newVaultClient, err := vaultclient.NewClient(newClientConfig)
if err != nil {
panic(err)
}
newConfig := Config{
// Dependencies.
VaultClient: newVaultClient,
}
return newConfig
... | go | func DefaultConfig() Config {
newClientConfig := vaultclient.DefaultConfig()
newClientConfig.Address = "http://127.0.0.1:8200"
newVaultClient, err := vaultclient.NewClient(newClientConfig)
if err != nil {
panic(err)
}
newConfig := Config{
// Dependencies.
VaultClient: newVaultClient,
}
return newConfig
... | [
"func",
"DefaultConfig",
"(",
")",
"Config",
"{",
"newClientConfig",
":=",
"vaultclient",
".",
"DefaultConfig",
"(",
")",
"\n",
"newClientConfig",
".",
"Address",
"=",
"\"http://127.0.0.1:8200\"",
"\n",
"newVaultClient",
",",
"err",
":=",
"vaultclient",
".",
"NewC... | // DefaultConfig provides a default configuration to create a certificate
// signer. | [
"DefaultConfig",
"provides",
"a",
"default",
"configuration",
"to",
"create",
"a",
"certificate",
"signer",
"."
] | 2a6615f61499cd09a8d5ced9a5fade322d2de254 | https://github.com/giantswarm/certctl/blob/2a6615f61499cd09a8d5ced9a5fade322d2de254/service/cert-signer/cert_signer.go#L24-L38 | test |
giantswarm/certctl | service/cert-signer/cert_signer.go | New | func New(config Config) (spec.CertSigner, error) {
newCertSigner := &certSigner{
Config: config,
}
// Dependencies.
if newCertSigner.VaultClient == nil {
return nil, microerror.Maskf(invalidConfigError, "Vault client must not be empty")
}
return newCertSigner, nil
} | go | func New(config Config) (spec.CertSigner, error) {
newCertSigner := &certSigner{
Config: config,
}
// Dependencies.
if newCertSigner.VaultClient == nil {
return nil, microerror.Maskf(invalidConfigError, "Vault client must not be empty")
}
return newCertSigner, nil
} | [
"func",
"New",
"(",
"config",
"Config",
")",
"(",
"spec",
".",
"CertSigner",
",",
"error",
")",
"{",
"newCertSigner",
":=",
"&",
"certSigner",
"{",
"Config",
":",
"config",
",",
"}",
"\n",
"if",
"newCertSigner",
".",
"VaultClient",
"==",
"nil",
"{",
"r... | // New creates a new configured certificate signer. | [
"New",
"creates",
"a",
"new",
"configured",
"certificate",
"signer",
"."
] | 2a6615f61499cd09a8d5ced9a5fade322d2de254 | https://github.com/giantswarm/certctl/blob/2a6615f61499cd09a8d5ced9a5fade322d2de254/service/cert-signer/cert_signer.go#L41-L52 | test |
giantswarm/certctl | service/vault-factory/vault_factory.go | New | func New(config Config) (spec.VaultFactory, error) {
newVaultFactory := &vaultFactory{
Config: config,
}
// Dependencies.
if newVaultFactory.Address == "" {
return nil, microerror.Maskf(invalidConfigError, "Vault address must not be empty")
}
if newVaultFactory.AdminToken == "" {
return nil, microerror.Mas... | go | func New(config Config) (spec.VaultFactory, error) {
newVaultFactory := &vaultFactory{
Config: config,
}
// Dependencies.
if newVaultFactory.Address == "" {
return nil, microerror.Maskf(invalidConfigError, "Vault address must not be empty")
}
if newVaultFactory.AdminToken == "" {
return nil, microerror.Mas... | [
"func",
"New",
"(",
"config",
"Config",
")",
"(",
"spec",
".",
"VaultFactory",
",",
"error",
")",
"{",
"newVaultFactory",
":=",
"&",
"vaultFactory",
"{",
"Config",
":",
"config",
",",
"}",
"\n",
"if",
"newVaultFactory",
".",
"Address",
"==",
"\"\"",
"{",... | // New creates a new configured Vault factory. | [
"New",
"creates",
"a",
"new",
"configured",
"Vault",
"factory",
"."
] | 2a6615f61499cd09a8d5ced9a5fade322d2de254 | https://github.com/giantswarm/certctl/blob/2a6615f61499cd09a8d5ced9a5fade322d2de254/service/vault-factory/vault_factory.go#L30-L44 | test |
giantswarm/certctl | service/pki/service.go | DefaultServiceConfig | func DefaultServiceConfig() ServiceConfig {
newClientConfig := vaultclient.DefaultConfig()
newClientConfig.Address = "http://127.0.0.1:8200"
newVaultClient, err := vaultclient.NewClient(newClientConfig)
if err != nil {
panic(err)
}
newConfig := ServiceConfig{
// Dependencies.
VaultClient: newVaultClient,
... | go | func DefaultServiceConfig() ServiceConfig {
newClientConfig := vaultclient.DefaultConfig()
newClientConfig.Address = "http://127.0.0.1:8200"
newVaultClient, err := vaultclient.NewClient(newClientConfig)
if err != nil {
panic(err)
}
newConfig := ServiceConfig{
// Dependencies.
VaultClient: newVaultClient,
... | [
"func",
"DefaultServiceConfig",
"(",
")",
"ServiceConfig",
"{",
"newClientConfig",
":=",
"vaultclient",
".",
"DefaultConfig",
"(",
")",
"\n",
"newClientConfig",
".",
"Address",
"=",
"\"http://127.0.0.1:8200\"",
"\n",
"newVaultClient",
",",
"err",
":=",
"vaultclient",
... | // DefaultServiceConfig provides a default configuration to create a PKI controller. | [
"DefaultServiceConfig",
"provides",
"a",
"default",
"configuration",
"to",
"create",
"a",
"PKI",
"controller",
"."
] | 2a6615f61499cd09a8d5ced9a5fade322d2de254 | https://github.com/giantswarm/certctl/blob/2a6615f61499cd09a8d5ced9a5fade322d2de254/service/pki/service.go#L17-L31 | test |
giantswarm/certctl | service/pki/service.go | NewService | func NewService(config ServiceConfig) (Service, error) {
// Dependencies.
if config.VaultClient == nil {
return nil, microerror.Maskf(invalidConfigError, "Vault client must not be empty")
}
newService := &service{
ServiceConfig: config,
}
return newService, nil
} | go | func NewService(config ServiceConfig) (Service, error) {
// Dependencies.
if config.VaultClient == nil {
return nil, microerror.Maskf(invalidConfigError, "Vault client must not be empty")
}
newService := &service{
ServiceConfig: config,
}
return newService, nil
} | [
"func",
"NewService",
"(",
"config",
"ServiceConfig",
")",
"(",
"Service",
",",
"error",
")",
"{",
"if",
"config",
".",
"VaultClient",
"==",
"nil",
"{",
"return",
"nil",
",",
"microerror",
".",
"Maskf",
"(",
"invalidConfigError",
",",
"\"Vault client must not ... | // NewService creates a new configured PKI controller. | [
"NewService",
"creates",
"a",
"new",
"configured",
"PKI",
"controller",
"."
] | 2a6615f61499cd09a8d5ced9a5fade322d2de254 | https://github.com/giantswarm/certctl/blob/2a6615f61499cd09a8d5ced9a5fade322d2de254/service/pki/service.go#L34-L45 | test |
giantswarm/certctl | service/pki/service.go | Delete | func (s *service) Delete(clusterID string) error {
// Create a client for the system backend configured with the Vault token
// used for the current cluster's PKI backend.
sysBackend := s.VaultClient.Sys()
// Unmount the PKI backend, if it exists.
mounted, err := s.IsMounted(clusterID)
if err != nil {
return m... | go | func (s *service) Delete(clusterID string) error {
// Create a client for the system backend configured with the Vault token
// used for the current cluster's PKI backend.
sysBackend := s.VaultClient.Sys()
// Unmount the PKI backend, if it exists.
mounted, err := s.IsMounted(clusterID)
if err != nil {
return m... | [
"func",
"(",
"s",
"*",
"service",
")",
"Delete",
"(",
"clusterID",
"string",
")",
"error",
"{",
"sysBackend",
":=",
"s",
".",
"VaultClient",
".",
"Sys",
"(",
")",
"\n",
"mounted",
",",
"err",
":=",
"s",
".",
"IsMounted",
"(",
"clusterID",
")",
"\n",
... | // PKI management. | [
"PKI",
"management",
"."
] | 2a6615f61499cd09a8d5ced9a5fade322d2de254 | https://github.com/giantswarm/certctl/blob/2a6615f61499cd09a8d5ced9a5fade322d2de254/service/pki/service.go#L53-L71 | test |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.