repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
rkt/rkt | store/treestore/tree.go | Size | func (ts *Store) Size(id string) (int64, error) {
sz, err := fileutil.DirSize(ts.GetPath(id))
if err != nil {
return -1, errwrap.Wrap(errors.New("error calculating size"), err)
}
return sz, nil
} | go | func (ts *Store) Size(id string) (int64, error) {
sz, err := fileutil.DirSize(ts.GetPath(id))
if err != nil {
return -1, errwrap.Wrap(errors.New("error calculating size"), err)
}
return sz, nil
} | [
"func",
"(",
"ts",
"*",
"Store",
")",
"Size",
"(",
"id",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"sz",
",",
"err",
":=",
"fileutil",
".",
"DirSize",
"(",
"ts",
".",
"GetPath",
"(",
"id",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"sz",
",",
"nil",
"\n",
"}"
] | // Size returns the size of the rootfs for the provided id. It is a relatively
// expensive operation, it goes through all the files and adds up their size. | [
"Size",
"returns",
"the",
"size",
"of",
"the",
"rootfs",
"for",
"the",
"provided",
"id",
".",
"It",
"is",
"a",
"relatively",
"expensive",
"operation",
"it",
"goes",
"through",
"all",
"the",
"files",
"and",
"adds",
"up",
"their",
"size",
"."
] | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/treestore/tree.go#L385-L391 | train |
rkt/rkt | store/treestore/tree.go | GetImageHash | func (ts *Store) GetImageHash(id string) (string, error) {
treepath := ts.GetPath(id)
imgHash, err := ioutil.ReadFile(filepath.Join(treepath, imagefilename))
if err != nil {
return "", errwrap.Wrap(errors.New("cannot read image file"), err)
}
return string(imgHash), nil
} | go | func (ts *Store) GetImageHash(id string) (string, error) {
treepath := ts.GetPath(id)
imgHash, err := ioutil.ReadFile(filepath.Join(treepath, imagefilename))
if err != nil {
return "", errwrap.Wrap(errors.New("cannot read image file"), err)
}
return string(imgHash), nil
} | [
"func",
"(",
"ts",
"*",
"Store",
")",
"GetImageHash",
"(",
"id",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"treepath",
":=",
"ts",
".",
"GetPath",
"(",
"id",
")",
"\n\n",
"imgHash",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filepath",
".",
"Join",
"(",
"treepath",
",",
"imagefilename",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"string",
"(",
"imgHash",
")",
",",
"nil",
"\n",
"}"
] | // GetImageHash returns the hash of the image that uses the tree store
// identified by id. | [
"GetImageHash",
"returns",
"the",
"hash",
"of",
"the",
"image",
"that",
"uses",
"the",
"tree",
"store",
"identified",
"by",
"id",
"."
] | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/treestore/tree.go#L395-L404 | train |
rkt/rkt | pkg/mountinfo/mountinfo.go | HasPrefix | func HasPrefix(p string) FilterFunc {
return FilterFunc(func(m *Mount) bool {
return strings.HasPrefix(m.MountPoint, p)
})
} | go | func HasPrefix(p string) FilterFunc {
return FilterFunc(func(m *Mount) bool {
return strings.HasPrefix(m.MountPoint, p)
})
} | [
"func",
"HasPrefix",
"(",
"p",
"string",
")",
"FilterFunc",
"{",
"return",
"FilterFunc",
"(",
"func",
"(",
"m",
"*",
"Mount",
")",
"bool",
"{",
"return",
"strings",
".",
"HasPrefix",
"(",
"m",
".",
"MountPoint",
",",
"p",
")",
"\n",
"}",
")",
"\n",
"}"
] | // HasPrefix returns a FilterFunc which returns true if
// the mountpoint of a given mount has prefix p, else false. | [
"HasPrefix",
"returns",
"a",
"FilterFunc",
"which",
"returns",
"true",
"if",
"the",
"mountpoint",
"of",
"a",
"given",
"mount",
"has",
"prefix",
"p",
"else",
"false",
"."
] | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/mountinfo/mountinfo.go#L32-L36 | train |
rkt/rkt | pkg/mountinfo/mountinfo.go | ParseMounts | func ParseMounts(pid uint) (Mounts, error) {
var procPath string
if pid == 0 {
procPath = "/proc/self/mountinfo"
} else {
procPath = fmt.Sprintf("/proc/%d/mountinfo", pid)
}
mi, err := os.Open(procPath)
if err != nil {
return nil, err
}
defer mi.Close()
return parseMountinfo(mi)
} | go | func ParseMounts(pid uint) (Mounts, error) {
var procPath string
if pid == 0 {
procPath = "/proc/self/mountinfo"
} else {
procPath = fmt.Sprintf("/proc/%d/mountinfo", pid)
}
mi, err := os.Open(procPath)
if err != nil {
return nil, err
}
defer mi.Close()
return parseMountinfo(mi)
} | [
"func",
"ParseMounts",
"(",
"pid",
"uint",
")",
"(",
"Mounts",
",",
"error",
")",
"{",
"var",
"procPath",
"string",
"\n",
"if",
"pid",
"==",
"0",
"{",
"procPath",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"procPath",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pid",
")",
"\n",
"}",
"\n\n",
"mi",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"procPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"mi",
".",
"Close",
"(",
")",
"\n\n",
"return",
"parseMountinfo",
"(",
"mi",
")",
"\n",
"}"
] | // ParseMounts returns all mountpoints associated with a process mount namespace.
// The special value 0 as pid argument is used to specify the current process. | [
"ParseMounts",
"returns",
"all",
"mountpoints",
"associated",
"with",
"a",
"process",
"mount",
"namespace",
".",
"The",
"special",
"value",
"0",
"as",
"pid",
"argument",
"is",
"used",
"to",
"specify",
"the",
"current",
"process",
"."
] | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/mountinfo/mountinfo.go#L40-L55 | train |
rkt/rkt | stage1/init/kvm/resources.go | findResources | func findResources(isolators types.Isolators) (mem, cpus int64) {
for _, i := range isolators {
switch v := i.Value().(type) {
case *types.ResourceMemory:
mem = v.Limit().Value()
// Convert bytes into megabytes
mem /= 1024 * 1024
case *types.ResourceCPU:
cpus = v.Limit().Value()
}
}
return mem, cpus
} | go | func findResources(isolators types.Isolators) (mem, cpus int64) {
for _, i := range isolators {
switch v := i.Value().(type) {
case *types.ResourceMemory:
mem = v.Limit().Value()
// Convert bytes into megabytes
mem /= 1024 * 1024
case *types.ResourceCPU:
cpus = v.Limit().Value()
}
}
return mem, cpus
} | [
"func",
"findResources",
"(",
"isolators",
"types",
".",
"Isolators",
")",
"(",
"mem",
",",
"cpus",
"int64",
")",
"{",
"for",
"_",
",",
"i",
":=",
"range",
"isolators",
"{",
"switch",
"v",
":=",
"i",
".",
"Value",
"(",
")",
".",
"(",
"type",
")",
"{",
"case",
"*",
"types",
".",
"ResourceMemory",
":",
"mem",
"=",
"v",
".",
"Limit",
"(",
")",
".",
"Value",
"(",
")",
"\n",
"// Convert bytes into megabytes",
"mem",
"/=",
"1024",
"*",
"1024",
"\n",
"case",
"*",
"types",
".",
"ResourceCPU",
":",
"cpus",
"=",
"v",
".",
"Limit",
"(",
")",
".",
"Value",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"mem",
",",
"cpus",
"\n",
"}"
] | // findResources finds value of last isolator for particular type. | [
"findResources",
"finds",
"value",
"of",
"last",
"isolator",
"for",
"particular",
"type",
"."
] | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/kvm/resources.go#L42-L54 | train |
go-playground/validator | struct_level.go | wrapStructLevelFunc | func wrapStructLevelFunc(fn StructLevelFunc) StructLevelFuncCtx {
return func(ctx context.Context, sl StructLevel) {
fn(sl)
}
} | go | func wrapStructLevelFunc(fn StructLevelFunc) StructLevelFuncCtx {
return func(ctx context.Context, sl StructLevel) {
fn(sl)
}
} | [
"func",
"wrapStructLevelFunc",
"(",
"fn",
"StructLevelFunc",
")",
"StructLevelFuncCtx",
"{",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"sl",
"StructLevel",
")",
"{",
"fn",
"(",
"sl",
")",
"\n",
"}",
"\n",
"}"
] | // wrapStructLevelFunc wraps normal StructLevelFunc makes it compatible with StructLevelFuncCtx | [
"wrapStructLevelFunc",
"wraps",
"normal",
"StructLevelFunc",
"makes",
"it",
"compatible",
"with",
"StructLevelFuncCtx"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/struct_level.go#L16-L20 | train |
go-playground/validator | struct_level.go | ExtractType | func (v *validate) ExtractType(field reflect.Value) (reflect.Value, reflect.Kind, bool) {
return v.extractTypeInternal(field, false)
} | go | func (v *validate) ExtractType(field reflect.Value) (reflect.Value, reflect.Kind, bool) {
return v.extractTypeInternal(field, false)
} | [
"func",
"(",
"v",
"*",
"validate",
")",
"ExtractType",
"(",
"field",
"reflect",
".",
"Value",
")",
"(",
"reflect",
".",
"Value",
",",
"reflect",
".",
"Kind",
",",
"bool",
")",
"{",
"return",
"v",
".",
"extractTypeInternal",
"(",
"field",
",",
"false",
")",
"\n",
"}"
] | // ExtractType gets the actual underlying type of field value. | [
"ExtractType",
"gets",
"the",
"actual",
"underlying",
"type",
"of",
"field",
"value",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/struct_level.go#L104-L106 | train |
go-playground/validator | struct_level.go | ReportError | func (v *validate) ReportError(field interface{}, fieldName, structFieldName, tag, param string) {
fv, kind, _ := v.extractTypeInternal(reflect.ValueOf(field), false)
if len(structFieldName) == 0 {
structFieldName = fieldName
}
v.str1 = string(append(v.ns, fieldName...))
if v.v.hasTagNameFunc || fieldName != structFieldName {
v.str2 = string(append(v.actualNs, structFieldName...))
} else {
v.str2 = v.str1
}
if kind == reflect.Invalid {
v.errs = append(v.errs,
&fieldError{
v: v.v,
tag: tag,
actualTag: tag,
ns: v.str1,
structNs: v.str2,
fieldLen: uint8(len(fieldName)),
structfieldLen: uint8(len(structFieldName)),
param: param,
kind: kind,
},
)
return
}
v.errs = append(v.errs,
&fieldError{
v: v.v,
tag: tag,
actualTag: tag,
ns: v.str1,
structNs: v.str2,
fieldLen: uint8(len(fieldName)),
structfieldLen: uint8(len(structFieldName)),
value: fv.Interface(),
param: param,
kind: kind,
typ: fv.Type(),
},
)
} | go | func (v *validate) ReportError(field interface{}, fieldName, structFieldName, tag, param string) {
fv, kind, _ := v.extractTypeInternal(reflect.ValueOf(field), false)
if len(structFieldName) == 0 {
structFieldName = fieldName
}
v.str1 = string(append(v.ns, fieldName...))
if v.v.hasTagNameFunc || fieldName != structFieldName {
v.str2 = string(append(v.actualNs, structFieldName...))
} else {
v.str2 = v.str1
}
if kind == reflect.Invalid {
v.errs = append(v.errs,
&fieldError{
v: v.v,
tag: tag,
actualTag: tag,
ns: v.str1,
structNs: v.str2,
fieldLen: uint8(len(fieldName)),
structfieldLen: uint8(len(structFieldName)),
param: param,
kind: kind,
},
)
return
}
v.errs = append(v.errs,
&fieldError{
v: v.v,
tag: tag,
actualTag: tag,
ns: v.str1,
structNs: v.str2,
fieldLen: uint8(len(fieldName)),
structfieldLen: uint8(len(structFieldName)),
value: fv.Interface(),
param: param,
kind: kind,
typ: fv.Type(),
},
)
} | [
"func",
"(",
"v",
"*",
"validate",
")",
"ReportError",
"(",
"field",
"interface",
"{",
"}",
",",
"fieldName",
",",
"structFieldName",
",",
"tag",
",",
"param",
"string",
")",
"{",
"fv",
",",
"kind",
",",
"_",
":=",
"v",
".",
"extractTypeInternal",
"(",
"reflect",
".",
"ValueOf",
"(",
"field",
")",
",",
"false",
")",
"\n\n",
"if",
"len",
"(",
"structFieldName",
")",
"==",
"0",
"{",
"structFieldName",
"=",
"fieldName",
"\n",
"}",
"\n\n",
"v",
".",
"str1",
"=",
"string",
"(",
"append",
"(",
"v",
".",
"ns",
",",
"fieldName",
"...",
")",
")",
"\n\n",
"if",
"v",
".",
"v",
".",
"hasTagNameFunc",
"||",
"fieldName",
"!=",
"structFieldName",
"{",
"v",
".",
"str2",
"=",
"string",
"(",
"append",
"(",
"v",
".",
"actualNs",
",",
"structFieldName",
"...",
")",
")",
"\n",
"}",
"else",
"{",
"v",
".",
"str2",
"=",
"v",
".",
"str1",
"\n",
"}",
"\n\n",
"if",
"kind",
"==",
"reflect",
".",
"Invalid",
"{",
"v",
".",
"errs",
"=",
"append",
"(",
"v",
".",
"errs",
",",
"&",
"fieldError",
"{",
"v",
":",
"v",
".",
"v",
",",
"tag",
":",
"tag",
",",
"actualTag",
":",
"tag",
",",
"ns",
":",
"v",
".",
"str1",
",",
"structNs",
":",
"v",
".",
"str2",
",",
"fieldLen",
":",
"uint8",
"(",
"len",
"(",
"fieldName",
")",
")",
",",
"structfieldLen",
":",
"uint8",
"(",
"len",
"(",
"structFieldName",
")",
")",
",",
"param",
":",
"param",
",",
"kind",
":",
"kind",
",",
"}",
",",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"v",
".",
"errs",
"=",
"append",
"(",
"v",
".",
"errs",
",",
"&",
"fieldError",
"{",
"v",
":",
"v",
".",
"v",
",",
"tag",
":",
"tag",
",",
"actualTag",
":",
"tag",
",",
"ns",
":",
"v",
".",
"str1",
",",
"structNs",
":",
"v",
".",
"str2",
",",
"fieldLen",
":",
"uint8",
"(",
"len",
"(",
"fieldName",
")",
")",
",",
"structfieldLen",
":",
"uint8",
"(",
"len",
"(",
"structFieldName",
")",
")",
",",
"value",
":",
"fv",
".",
"Interface",
"(",
")",
",",
"param",
":",
"param",
",",
"kind",
":",
"kind",
",",
"typ",
":",
"fv",
".",
"Type",
"(",
")",
",",
"}",
",",
")",
"\n",
"}"
] | // ReportError reports an error just by passing the field and tag information | [
"ReportError",
"reports",
"an",
"error",
"just",
"by",
"passing",
"the",
"field",
"and",
"tag",
"information"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/struct_level.go#L109-L158 | train |
go-playground/validator | _examples/custom/main.go | ValidateValuer | func ValidateValuer(field reflect.Value) interface{} {
if valuer, ok := field.Interface().(driver.Valuer); ok {
val, err := valuer.Value()
if err == nil {
return val
}
// handle the error how you want
}
return nil
} | go | func ValidateValuer(field reflect.Value) interface{} {
if valuer, ok := field.Interface().(driver.Valuer); ok {
val, err := valuer.Value()
if err == nil {
return val
}
// handle the error how you want
}
return nil
} | [
"func",
"ValidateValuer",
"(",
"field",
"reflect",
".",
"Value",
")",
"interface",
"{",
"}",
"{",
"if",
"valuer",
",",
"ok",
":=",
"field",
".",
"Interface",
"(",
")",
".",
"(",
"driver",
".",
"Valuer",
")",
";",
"ok",
"{",
"val",
",",
"err",
":=",
"valuer",
".",
"Value",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"val",
"\n",
"}",
"\n",
"// handle the error how you want",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // ValidateValuer implements validator.CustomTypeFunc | [
"ValidateValuer",
"implements",
"validator",
".",
"CustomTypeFunc"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/_examples/custom/main.go#L39-L51 | train |
go-playground/validator | errors.go | Error | func (e *InvalidValidationError) Error() string {
if e.Type == nil {
return "validator: (nil)"
}
return "validator: (nil " + e.Type.String() + ")"
} | go | func (e *InvalidValidationError) Error() string {
if e.Type == nil {
return "validator: (nil)"
}
return "validator: (nil " + e.Type.String() + ")"
} | [
"func",
"(",
"e",
"*",
"InvalidValidationError",
")",
"Error",
"(",
")",
"string",
"{",
"if",
"e",
".",
"Type",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
"+",
"e",
".",
"Type",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"}"
] | // Error returns InvalidValidationError message | [
"Error",
"returns",
"InvalidValidationError",
"message"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/errors.go#L26-L33 | train |
go-playground/validator | errors.go | Error | func (ve ValidationErrors) Error() string {
buff := bytes.NewBufferString("")
var fe *fieldError
for i := 0; i < len(ve); i++ {
fe = ve[i].(*fieldError)
buff.WriteString(fe.Error())
buff.WriteString("\n")
}
return strings.TrimSpace(buff.String())
} | go | func (ve ValidationErrors) Error() string {
buff := bytes.NewBufferString("")
var fe *fieldError
for i := 0; i < len(ve); i++ {
fe = ve[i].(*fieldError)
buff.WriteString(fe.Error())
buff.WriteString("\n")
}
return strings.TrimSpace(buff.String())
} | [
"func",
"(",
"ve",
"ValidationErrors",
")",
"Error",
"(",
")",
"string",
"{",
"buff",
":=",
"bytes",
".",
"NewBufferString",
"(",
"\"",
"\"",
")",
"\n\n",
"var",
"fe",
"*",
"fieldError",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"ve",
")",
";",
"i",
"++",
"{",
"fe",
"=",
"ve",
"[",
"i",
"]",
".",
"(",
"*",
"fieldError",
")",
"\n",
"buff",
".",
"WriteString",
"(",
"fe",
".",
"Error",
"(",
")",
")",
"\n",
"buff",
".",
"WriteString",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"TrimSpace",
"(",
"buff",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // Error is intended for use in development + debugging and not intended to be a production error message.
// It allows ValidationErrors to subscribe to the Error interface.
// All information to create an error message specific to your application is contained within
// the FieldError found within the ValidationErrors array | [
"Error",
"is",
"intended",
"for",
"use",
"in",
"development",
"+",
"debugging",
"and",
"not",
"intended",
"to",
"be",
"a",
"production",
"error",
"message",
".",
"It",
"allows",
"ValidationErrors",
"to",
"subscribe",
"to",
"the",
"Error",
"interface",
".",
"All",
"information",
"to",
"create",
"an",
"error",
"message",
"specific",
"to",
"your",
"application",
"is",
"contained",
"within",
"the",
"FieldError",
"found",
"within",
"the",
"ValidationErrors",
"array"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/errors.go#L43-L57 | train |
go-playground/validator | errors.go | Translate | func (ve ValidationErrors) Translate(ut ut.Translator) ValidationErrorsTranslations {
trans := make(ValidationErrorsTranslations)
var fe *fieldError
for i := 0; i < len(ve); i++ {
fe = ve[i].(*fieldError)
// // in case an Anonymous struct was used, ensure that the key
// // would be 'Username' instead of ".Username"
// if len(fe.ns) > 0 && fe.ns[:1] == "." {
// trans[fe.ns[1:]] = fe.Translate(ut)
// continue
// }
trans[fe.ns] = fe.Translate(ut)
}
return trans
} | go | func (ve ValidationErrors) Translate(ut ut.Translator) ValidationErrorsTranslations {
trans := make(ValidationErrorsTranslations)
var fe *fieldError
for i := 0; i < len(ve); i++ {
fe = ve[i].(*fieldError)
// // in case an Anonymous struct was used, ensure that the key
// // would be 'Username' instead of ".Username"
// if len(fe.ns) > 0 && fe.ns[:1] == "." {
// trans[fe.ns[1:]] = fe.Translate(ut)
// continue
// }
trans[fe.ns] = fe.Translate(ut)
}
return trans
} | [
"func",
"(",
"ve",
"ValidationErrors",
")",
"Translate",
"(",
"ut",
"ut",
".",
"Translator",
")",
"ValidationErrorsTranslations",
"{",
"trans",
":=",
"make",
"(",
"ValidationErrorsTranslations",
")",
"\n\n",
"var",
"fe",
"*",
"fieldError",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"ve",
")",
";",
"i",
"++",
"{",
"fe",
"=",
"ve",
"[",
"i",
"]",
".",
"(",
"*",
"fieldError",
")",
"\n\n",
"// // in case an Anonymous struct was used, ensure that the key",
"// // would be 'Username' instead of \".Username\"",
"// if len(fe.ns) > 0 && fe.ns[:1] == \".\" {",
"// \ttrans[fe.ns[1:]] = fe.Translate(ut)",
"// \tcontinue",
"// }",
"trans",
"[",
"fe",
".",
"ns",
"]",
"=",
"fe",
".",
"Translate",
"(",
"ut",
")",
"\n",
"}",
"\n\n",
"return",
"trans",
"\n",
"}"
] | // Translate translates all of the ValidationErrors | [
"Translate",
"translates",
"all",
"of",
"the",
"ValidationErrors"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/errors.go#L60-L80 | train |
go-playground/validator | errors.go | Field | func (fe *fieldError) Field() string {
return fe.ns[len(fe.ns)-int(fe.fieldLen):]
// // return fe.field
// fld := fe.ns[len(fe.ns)-int(fe.fieldLen):]
// log.Println("FLD:", fld)
// if len(fld) > 0 && fld[:1] == "." {
// return fld[1:]
// }
// return fld
} | go | func (fe *fieldError) Field() string {
return fe.ns[len(fe.ns)-int(fe.fieldLen):]
// // return fe.field
// fld := fe.ns[len(fe.ns)-int(fe.fieldLen):]
// log.Println("FLD:", fld)
// if len(fld) > 0 && fld[:1] == "." {
// return fld[1:]
// }
// return fld
} | [
"func",
"(",
"fe",
"*",
"fieldError",
")",
"Field",
"(",
")",
"string",
"{",
"return",
"fe",
".",
"ns",
"[",
"len",
"(",
"fe",
".",
"ns",
")",
"-",
"int",
"(",
"fe",
".",
"fieldLen",
")",
":",
"]",
"\n",
"// // return fe.field",
"// fld := fe.ns[len(fe.ns)-int(fe.fieldLen):]",
"// log.Println(\"FLD:\", fld)",
"// if len(fld) > 0 && fld[:1] == \".\" {",
"// \treturn fld[1:]",
"// }",
"// return fld",
"}"
] | // Field returns the fields name with the tag name taking precedence over the
// fields actual name. | [
"Field",
"returns",
"the",
"fields",
"name",
"with",
"the",
"tag",
"name",
"taking",
"precedence",
"over",
"the",
"fields",
"actual",
"name",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/errors.go#L206-L219 | train |
go-playground/validator | errors.go | StructField | func (fe *fieldError) StructField() string {
// return fe.structField
return fe.structNs[len(fe.structNs)-int(fe.structfieldLen):]
} | go | func (fe *fieldError) StructField() string {
// return fe.structField
return fe.structNs[len(fe.structNs)-int(fe.structfieldLen):]
} | [
"func",
"(",
"fe",
"*",
"fieldError",
")",
"StructField",
"(",
")",
"string",
"{",
"// return fe.structField",
"return",
"fe",
".",
"structNs",
"[",
"len",
"(",
"fe",
".",
"structNs",
")",
"-",
"int",
"(",
"fe",
".",
"structfieldLen",
")",
":",
"]",
"\n",
"}"
] | // returns the fields actual name from the struct, when able to determine. | [
"returns",
"the",
"fields",
"actual",
"name",
"from",
"the",
"struct",
"when",
"able",
"to",
"determine",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/errors.go#L222-L225 | train |
go-playground/validator | errors.go | Error | func (fe *fieldError) Error() string {
return fmt.Sprintf(fieldErrMsg, fe.ns, fe.Field(), fe.tag)
} | go | func (fe *fieldError) Error() string {
return fmt.Sprintf(fieldErrMsg, fe.ns, fe.Field(), fe.tag)
} | [
"func",
"(",
"fe",
"*",
"fieldError",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"fieldErrMsg",
",",
"fe",
".",
"ns",
",",
"fe",
".",
"Field",
"(",
")",
",",
"fe",
".",
"tag",
")",
"\n",
"}"
] | // Error returns the fieldError's error message | [
"Error",
"returns",
"the",
"fieldError",
"s",
"error",
"message"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/errors.go#L250-L252 | train |
go-playground/validator | non-standard/validators/notblank.go | NotBlank | func NotBlank(fl validator.FieldLevel) bool {
field := fl.Field()
switch field.Kind() {
case reflect.String:
return len(strings.TrimSpace(field.String())) > 0
case reflect.Chan, reflect.Map, reflect.Slice, reflect.Array:
return field.Len() > 0
case reflect.Ptr, reflect.Interface, reflect.Func:
return !field.IsNil()
default:
return field.IsValid() && field.Interface() != reflect.Zero(field.Type()).Interface()
}
} | go | func NotBlank(fl validator.FieldLevel) bool {
field := fl.Field()
switch field.Kind() {
case reflect.String:
return len(strings.TrimSpace(field.String())) > 0
case reflect.Chan, reflect.Map, reflect.Slice, reflect.Array:
return field.Len() > 0
case reflect.Ptr, reflect.Interface, reflect.Func:
return !field.IsNil()
default:
return field.IsValid() && field.Interface() != reflect.Zero(field.Type()).Interface()
}
} | [
"func",
"NotBlank",
"(",
"fl",
"validator",
".",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n\n",
"switch",
"field",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"String",
":",
"return",
"len",
"(",
"strings",
".",
"TrimSpace",
"(",
"field",
".",
"String",
"(",
")",
")",
")",
">",
"0",
"\n",
"case",
"reflect",
".",
"Chan",
",",
"reflect",
".",
"Map",
",",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Array",
":",
"return",
"field",
".",
"Len",
"(",
")",
">",
"0",
"\n",
"case",
"reflect",
".",
"Ptr",
",",
"reflect",
".",
"Interface",
",",
"reflect",
".",
"Func",
":",
"return",
"!",
"field",
".",
"IsNil",
"(",
")",
"\n",
"default",
":",
"return",
"field",
".",
"IsValid",
"(",
")",
"&&",
"field",
".",
"Interface",
"(",
")",
"!=",
"reflect",
".",
"Zero",
"(",
"field",
".",
"Type",
"(",
")",
")",
".",
"Interface",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // NotBlank is the validation function for validating if the current field
// has a value or length greater than zero, or is not a space only string. | [
"NotBlank",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"current",
"field",
"has",
"a",
"value",
"or",
"length",
"greater",
"than",
"zero",
"or",
"is",
"not",
"a",
"space",
"only",
"string",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/non-standard/validators/notblank.go#L12-L25 | train |
go-playground/validator | baked_in.go | wrapFunc | func wrapFunc(fn Func) FuncCtx {
if fn == nil {
return nil // be sure not to wrap a bad function.
}
return func(ctx context.Context, fl FieldLevel) bool {
return fn(fl)
}
} | go | func wrapFunc(fn Func) FuncCtx {
if fn == nil {
return nil // be sure not to wrap a bad function.
}
return func(ctx context.Context, fl FieldLevel) bool {
return fn(fl)
}
} | [
"func",
"wrapFunc",
"(",
"fn",
"Func",
")",
"FuncCtx",
"{",
"if",
"fn",
"==",
"nil",
"{",
"return",
"nil",
"// be sure not to wrap a bad function.",
"\n",
"}",
"\n",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"fl",
"FieldLevel",
")",
"bool",
"{",
"return",
"fn",
"(",
"fl",
")",
"\n",
"}",
"\n",
"}"
] | // wrapFunc wraps noramal Func makes it compatible with FuncCtx | [
"wrapFunc",
"wraps",
"noramal",
"Func",
"makes",
"it",
"compatible",
"with",
"FuncCtx"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L30-L37 | train |
go-playground/validator | baked_in.go | isUnique | func isUnique(fl FieldLevel) bool {
field := fl.Field()
v := reflect.ValueOf(struct{}{})
switch field.Kind() {
case reflect.Slice, reflect.Array:
m := reflect.MakeMap(reflect.MapOf(field.Type().Elem(), v.Type()))
for i := 0; i < field.Len(); i++ {
m.SetMapIndex(field.Index(i), v)
}
return field.Len() == m.Len()
case reflect.Map:
m := reflect.MakeMap(reflect.MapOf(field.Type().Elem(), v.Type()))
for _, k := range field.MapKeys() {
m.SetMapIndex(field.MapIndex(k), v)
}
return field.Len() == m.Len()
default:
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
}
} | go | func isUnique(fl FieldLevel) bool {
field := fl.Field()
v := reflect.ValueOf(struct{}{})
switch field.Kind() {
case reflect.Slice, reflect.Array:
m := reflect.MakeMap(reflect.MapOf(field.Type().Elem(), v.Type()))
for i := 0; i < field.Len(); i++ {
m.SetMapIndex(field.Index(i), v)
}
return field.Len() == m.Len()
case reflect.Map:
m := reflect.MakeMap(reflect.MapOf(field.Type().Elem(), v.Type()))
for _, k := range field.MapKeys() {
m.SetMapIndex(field.MapIndex(k), v)
}
return field.Len() == m.Len()
default:
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
}
} | [
"func",
"isUnique",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"struct",
"{",
"}",
"{",
"}",
")",
"\n\n",
"switch",
"field",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Array",
":",
"m",
":=",
"reflect",
".",
"MakeMap",
"(",
"reflect",
".",
"MapOf",
"(",
"field",
".",
"Type",
"(",
")",
".",
"Elem",
"(",
")",
",",
"v",
".",
"Type",
"(",
")",
")",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"field",
".",
"Len",
"(",
")",
";",
"i",
"++",
"{",
"m",
".",
"SetMapIndex",
"(",
"field",
".",
"Index",
"(",
"i",
")",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"field",
".",
"Len",
"(",
")",
"==",
"m",
".",
"Len",
"(",
")",
"\n",
"case",
"reflect",
".",
"Map",
":",
"m",
":=",
"reflect",
".",
"MakeMap",
"(",
"reflect",
".",
"MapOf",
"(",
"field",
".",
"Type",
"(",
")",
".",
"Elem",
"(",
")",
",",
"v",
".",
"Type",
"(",
")",
")",
")",
"\n\n",
"for",
"_",
",",
"k",
":=",
"range",
"field",
".",
"MapKeys",
"(",
")",
"{",
"m",
".",
"SetMapIndex",
"(",
"field",
".",
"MapIndex",
"(",
"k",
")",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"field",
".",
"Len",
"(",
")",
"==",
"m",
".",
"Len",
"(",
")",
"\n",
"default",
":",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"field",
".",
"Interface",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"}"
] | // isUnique is the validation function for validating if each array|slice|map value is unique | [
"isUnique",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"each",
"array|slice|map",
"value",
"is",
"unique"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L220-L243 | train |
go-playground/validator | baked_in.go | isMAC | func isMAC(fl FieldLevel) bool {
_, err := net.ParseMAC(fl.Field().String())
return err == nil
} | go | func isMAC(fl FieldLevel) bool {
_, err := net.ParseMAC(fl.Field().String())
return err == nil
} | [
"func",
"isMAC",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"_",
",",
"err",
":=",
"net",
".",
"ParseMAC",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // IsMAC is the validation function for validating if the field's value is a valid MAC address. | [
"IsMAC",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"valid",
"MAC",
"address",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L246-L251 | train |
go-playground/validator | baked_in.go | isCIDRv4 | func isCIDRv4(fl FieldLevel) bool {
ip, _, err := net.ParseCIDR(fl.Field().String())
return err == nil && ip.To4() != nil
} | go | func isCIDRv4(fl FieldLevel) bool {
ip, _, err := net.ParseCIDR(fl.Field().String())
return err == nil && ip.To4() != nil
} | [
"func",
"isCIDRv4",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"ip",
",",
"_",
",",
"err",
":=",
"net",
".",
"ParseCIDR",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"err",
"==",
"nil",
"&&",
"ip",
".",
"To4",
"(",
")",
"!=",
"nil",
"\n",
"}"
] | // IsCIDRv4 is the validation function for validating if the field's value is a valid v4 CIDR address. | [
"IsCIDRv4",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"valid",
"v4",
"CIDR",
"address",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L254-L259 | train |
go-playground/validator | baked_in.go | isCIDR | func isCIDR(fl FieldLevel) bool {
_, _, err := net.ParseCIDR(fl.Field().String())
return err == nil
} | go | func isCIDR(fl FieldLevel) bool {
_, _, err := net.ParseCIDR(fl.Field().String())
return err == nil
} | [
"func",
"isCIDR",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"_",
",",
"_",
",",
"err",
":=",
"net",
".",
"ParseCIDR",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // IsCIDR is the validation function for validating if the field's value is a valid v4 or v6 CIDR address. | [
"IsCIDR",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"valid",
"v4",
"or",
"v6",
"CIDR",
"address",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L270-L275 | train |
go-playground/validator | baked_in.go | isIPv6 | func isIPv6(fl FieldLevel) bool {
ip := net.ParseIP(fl.Field().String())
return ip != nil && ip.To4() == nil
} | go | func isIPv6(fl FieldLevel) bool {
ip := net.ParseIP(fl.Field().String())
return ip != nil && ip.To4() == nil
} | [
"func",
"isIPv6",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"ip",
":=",
"net",
".",
"ParseIP",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"ip",
"!=",
"nil",
"&&",
"ip",
".",
"To4",
"(",
")",
"==",
"nil",
"\n",
"}"
] | // IsIPv6 is the validation function for validating if the field's value is a valid v6 IP address. | [
"IsIPv6",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"valid",
"v6",
"IP",
"address",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L286-L291 | train |
go-playground/validator | baked_in.go | isIP | func isIP(fl FieldLevel) bool {
ip := net.ParseIP(fl.Field().String())
return ip != nil
} | go | func isIP(fl FieldLevel) bool {
ip := net.ParseIP(fl.Field().String())
return ip != nil
} | [
"func",
"isIP",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"ip",
":=",
"net",
".",
"ParseIP",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"ip",
"!=",
"nil",
"\n",
"}"
] | // IsIP is the validation function for validating if the field's value is a valid v4 or v6 IP address. | [
"IsIP",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"valid",
"v4",
"or",
"v6",
"IP",
"address",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L294-L299 | train |
go-playground/validator | baked_in.go | isSSN | func isSSN(fl FieldLevel) bool {
field := fl.Field()
if field.Len() != 11 {
return false
}
return sSNRegex.MatchString(field.String())
} | go | func isSSN(fl FieldLevel) bool {
field := fl.Field()
if field.Len() != 11 {
return false
}
return sSNRegex.MatchString(field.String())
} | [
"func",
"isSSN",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n\n",
"if",
"field",
".",
"Len",
"(",
")",
"!=",
"11",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"sSNRegex",
".",
"MatchString",
"(",
"field",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // IsSSN is the validation function for validating if the field's value is a valid SSN. | [
"IsSSN",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"valid",
"SSN",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L302-L311 | train |
go-playground/validator | baked_in.go | isLongitude | func isLongitude(fl FieldLevel) bool {
field := fl.Field()
var v string
switch field.Kind() {
case reflect.String:
v = field.String()
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
v = strconv.FormatInt(field.Int(), 10)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
v = strconv.FormatUint(field.Uint(), 10)
case reflect.Float32:
v = strconv.FormatFloat(field.Float(), 'f', -1, 32)
case reflect.Float64:
v = strconv.FormatFloat(field.Float(), 'f', -1, 64)
default:
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
}
return longitudeRegex.MatchString(v)
} | go | func isLongitude(fl FieldLevel) bool {
field := fl.Field()
var v string
switch field.Kind() {
case reflect.String:
v = field.String()
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
v = strconv.FormatInt(field.Int(), 10)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
v = strconv.FormatUint(field.Uint(), 10)
case reflect.Float32:
v = strconv.FormatFloat(field.Float(), 'f', -1, 32)
case reflect.Float64:
v = strconv.FormatFloat(field.Float(), 'f', -1, 64)
default:
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
}
return longitudeRegex.MatchString(v)
} | [
"func",
"isLongitude",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n\n",
"var",
"v",
"string",
"\n",
"switch",
"field",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"String",
":",
"v",
"=",
"field",
".",
"String",
"(",
")",
"\n",
"case",
"reflect",
".",
"Int",
",",
"reflect",
".",
"Int8",
",",
"reflect",
".",
"Int16",
",",
"reflect",
".",
"Int32",
",",
"reflect",
".",
"Int64",
":",
"v",
"=",
"strconv",
".",
"FormatInt",
"(",
"field",
".",
"Int",
"(",
")",
",",
"10",
")",
"\n",
"case",
"reflect",
".",
"Uint",
",",
"reflect",
".",
"Uint8",
",",
"reflect",
".",
"Uint16",
",",
"reflect",
".",
"Uint32",
",",
"reflect",
".",
"Uint64",
":",
"v",
"=",
"strconv",
".",
"FormatUint",
"(",
"field",
".",
"Uint",
"(",
")",
",",
"10",
")",
"\n",
"case",
"reflect",
".",
"Float32",
":",
"v",
"=",
"strconv",
".",
"FormatFloat",
"(",
"field",
".",
"Float",
"(",
")",
",",
"'f'",
",",
"-",
"1",
",",
"32",
")",
"\n",
"case",
"reflect",
".",
"Float64",
":",
"v",
"=",
"strconv",
".",
"FormatFloat",
"(",
"field",
".",
"Float",
"(",
")",
",",
"'f'",
",",
"-",
"1",
",",
"64",
")",
"\n",
"default",
":",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"field",
".",
"Interface",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"return",
"longitudeRegex",
".",
"MatchString",
"(",
"v",
")",
"\n",
"}"
] | // IsLongitude is the validation function for validating if the field's value is a valid longitude coordinate. | [
"IsLongitude",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"valid",
"longitude",
"coordinate",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L314-L334 | train |
go-playground/validator | baked_in.go | isDataURI | func isDataURI(fl FieldLevel) bool {
uri := strings.SplitN(fl.Field().String(), ",", 2)
if len(uri) != 2 {
return false
}
if !dataURIRegex.MatchString(uri[0]) {
return false
}
return base64Regex.MatchString(uri[1])
} | go | func isDataURI(fl FieldLevel) bool {
uri := strings.SplitN(fl.Field().String(), ",", 2)
if len(uri) != 2 {
return false
}
if !dataURIRegex.MatchString(uri[0]) {
return false
}
return base64Regex.MatchString(uri[1])
} | [
"func",
"isDataURI",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"uri",
":=",
"strings",
".",
"SplitN",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
",",
"\"",
"\"",
",",
"2",
")",
"\n\n",
"if",
"len",
"(",
"uri",
")",
"!=",
"2",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"!",
"dataURIRegex",
".",
"MatchString",
"(",
"uri",
"[",
"0",
"]",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"base64Regex",
".",
"MatchString",
"(",
"uri",
"[",
"1",
"]",
")",
"\n",
"}"
] | // IsDataURI is the validation function for validating if the field's value is a valid data URI. | [
"IsDataURI",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"valid",
"data",
"URI",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L360-L373 | train |
go-playground/validator | baked_in.go | hasMultiByteCharacter | func hasMultiByteCharacter(fl FieldLevel) bool {
field := fl.Field()
if field.Len() == 0 {
return true
}
return multibyteRegex.MatchString(field.String())
} | go | func hasMultiByteCharacter(fl FieldLevel) bool {
field := fl.Field()
if field.Len() == 0 {
return true
}
return multibyteRegex.MatchString(field.String())
} | [
"func",
"hasMultiByteCharacter",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n\n",
"if",
"field",
".",
"Len",
"(",
")",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"multibyteRegex",
".",
"MatchString",
"(",
"field",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // HasMultiByteCharacter is the validation function for validating if the field's value has a multi byte character. | [
"HasMultiByteCharacter",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"has",
"a",
"multi",
"byte",
"character",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L376-L385 | train |
go-playground/validator | baked_in.go | isISBN13 | func isISBN13(fl FieldLevel) bool {
s := strings.Replace(strings.Replace(fl.Field().String(), "-", "", 4), " ", "", 4)
if !iSBN13Regex.MatchString(s) {
return false
}
var checksum int32
var i int32
factor := []int32{1, 3}
for i = 0; i < 12; i++ {
checksum += factor[i%2] * int32(s[i]-'0')
}
return (int32(s[12]-'0'))-((10-(checksum%10))%10) == 0
} | go | func isISBN13(fl FieldLevel) bool {
s := strings.Replace(strings.Replace(fl.Field().String(), "-", "", 4), " ", "", 4)
if !iSBN13Regex.MatchString(s) {
return false
}
var checksum int32
var i int32
factor := []int32{1, 3}
for i = 0; i < 12; i++ {
checksum += factor[i%2] * int32(s[i]-'0')
}
return (int32(s[12]-'0'))-((10-(checksum%10))%10) == 0
} | [
"func",
"isISBN13",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"s",
":=",
"strings",
".",
"Replace",
"(",
"strings",
".",
"Replace",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"4",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"4",
")",
"\n\n",
"if",
"!",
"iSBN13Regex",
".",
"MatchString",
"(",
"s",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"var",
"checksum",
"int32",
"\n",
"var",
"i",
"int32",
"\n\n",
"factor",
":=",
"[",
"]",
"int32",
"{",
"1",
",",
"3",
"}",
"\n\n",
"for",
"i",
"=",
"0",
";",
"i",
"<",
"12",
";",
"i",
"++",
"{",
"checksum",
"+=",
"factor",
"[",
"i",
"%",
"2",
"]",
"*",
"int32",
"(",
"s",
"[",
"i",
"]",
"-",
"'0'",
")",
"\n",
"}",
"\n\n",
"return",
"(",
"int32",
"(",
"s",
"[",
"12",
"]",
"-",
"'0'",
")",
")",
"-",
"(",
"(",
"10",
"-",
"(",
"checksum",
"%",
"10",
")",
")",
"%",
"10",
")",
"==",
"0",
"\n",
"}"
] | // IsISBN13 is the validation function for validating if the field's value is a valid v13 ISBN. | [
"IsISBN13",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"valid",
"v13",
"ISBN",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L443-L461 | train |
go-playground/validator | baked_in.go | isISBN10 | func isISBN10(fl FieldLevel) bool {
s := strings.Replace(strings.Replace(fl.Field().String(), "-", "", 3), " ", "", 3)
if !iSBN10Regex.MatchString(s) {
return false
}
var checksum int32
var i int32
for i = 0; i < 9; i++ {
checksum += (i + 1) * int32(s[i]-'0')
}
if s[9] == 'X' {
checksum += 10 * 10
} else {
checksum += 10 * int32(s[9]-'0')
}
return checksum%11 == 0
} | go | func isISBN10(fl FieldLevel) bool {
s := strings.Replace(strings.Replace(fl.Field().String(), "-", "", 3), " ", "", 3)
if !iSBN10Regex.MatchString(s) {
return false
}
var checksum int32
var i int32
for i = 0; i < 9; i++ {
checksum += (i + 1) * int32(s[i]-'0')
}
if s[9] == 'X' {
checksum += 10 * 10
} else {
checksum += 10 * int32(s[9]-'0')
}
return checksum%11 == 0
} | [
"func",
"isISBN10",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"s",
":=",
"strings",
".",
"Replace",
"(",
"strings",
".",
"Replace",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"3",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"3",
")",
"\n\n",
"if",
"!",
"iSBN10Regex",
".",
"MatchString",
"(",
"s",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"var",
"checksum",
"int32",
"\n",
"var",
"i",
"int32",
"\n\n",
"for",
"i",
"=",
"0",
";",
"i",
"<",
"9",
";",
"i",
"++",
"{",
"checksum",
"+=",
"(",
"i",
"+",
"1",
")",
"*",
"int32",
"(",
"s",
"[",
"i",
"]",
"-",
"'0'",
")",
"\n",
"}",
"\n\n",
"if",
"s",
"[",
"9",
"]",
"==",
"'X'",
"{",
"checksum",
"+=",
"10",
"*",
"10",
"\n",
"}",
"else",
"{",
"checksum",
"+=",
"10",
"*",
"int32",
"(",
"s",
"[",
"9",
"]",
"-",
"'0'",
")",
"\n",
"}",
"\n\n",
"return",
"checksum",
"%",
"11",
"==",
"0",
"\n",
"}"
] | // IsISBN10 is the validation function for validating if the field's value is a valid v10 ISBN. | [
"IsISBN10",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"valid",
"v10",
"ISBN",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L464-L486 | train |
go-playground/validator | baked_in.go | isEthereumAddress | func isEthereumAddress(fl FieldLevel) bool {
address := fl.Field().String()
if !ethAddressRegex.MatchString(address) {
return false
}
if ethaddressRegexUpper.MatchString(address) || ethAddressRegexLower.MatchString(address) {
return true
}
// checksum validation is blocked by https://github.com/golang/crypto/pull/28
return true
} | go | func isEthereumAddress(fl FieldLevel) bool {
address := fl.Field().String()
if !ethAddressRegex.MatchString(address) {
return false
}
if ethaddressRegexUpper.MatchString(address) || ethAddressRegexLower.MatchString(address) {
return true
}
// checksum validation is blocked by https://github.com/golang/crypto/pull/28
return true
} | [
"func",
"isEthereumAddress",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"address",
":=",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
"\n\n",
"if",
"!",
"ethAddressRegex",
".",
"MatchString",
"(",
"address",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"ethaddressRegexUpper",
".",
"MatchString",
"(",
"address",
")",
"||",
"ethAddressRegexLower",
".",
"MatchString",
"(",
"address",
")",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"// checksum validation is blocked by https://github.com/golang/crypto/pull/28",
"return",
"true",
"\n",
"}"
] | // IsEthereumAddress is the validation function for validating if the field's value is a valid ethereum address based currently only on the format | [
"IsEthereumAddress",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"valid",
"ethereum",
"address",
"based",
"currently",
"only",
"on",
"the",
"format"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L489-L503 | train |
go-playground/validator | baked_in.go | isBitcoinAddress | func isBitcoinAddress(fl FieldLevel) bool {
address := fl.Field().String()
if !btcAddressRegex.MatchString(address) {
return false
}
alphabet := []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
decode := [25]byte{}
for _, n := range []byte(address) {
d := bytes.IndexByte(alphabet, n)
for i := 24; i >= 0; i-- {
d += 58 * int(decode[i])
decode[i] = byte(d % 256)
d /= 256
}
}
h := sha256.New()
_, _ = h.Write(decode[:21])
d := h.Sum([]byte{})
h = sha256.New()
_, _ = h.Write(d)
validchecksum := [4]byte{}
computedchecksum := [4]byte{}
copy(computedchecksum[:], h.Sum(d[:0]))
copy(validchecksum[:], decode[21:])
return validchecksum == computedchecksum
} | go | func isBitcoinAddress(fl FieldLevel) bool {
address := fl.Field().String()
if !btcAddressRegex.MatchString(address) {
return false
}
alphabet := []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
decode := [25]byte{}
for _, n := range []byte(address) {
d := bytes.IndexByte(alphabet, n)
for i := 24; i >= 0; i-- {
d += 58 * int(decode[i])
decode[i] = byte(d % 256)
d /= 256
}
}
h := sha256.New()
_, _ = h.Write(decode[:21])
d := h.Sum([]byte{})
h = sha256.New()
_, _ = h.Write(d)
validchecksum := [4]byte{}
computedchecksum := [4]byte{}
copy(computedchecksum[:], h.Sum(d[:0]))
copy(validchecksum[:], decode[21:])
return validchecksum == computedchecksum
} | [
"func",
"isBitcoinAddress",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"address",
":=",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
"\n\n",
"if",
"!",
"btcAddressRegex",
".",
"MatchString",
"(",
"address",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"alphabet",
":=",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
"\n\n",
"decode",
":=",
"[",
"25",
"]",
"byte",
"{",
"}",
"\n\n",
"for",
"_",
",",
"n",
":=",
"range",
"[",
"]",
"byte",
"(",
"address",
")",
"{",
"d",
":=",
"bytes",
".",
"IndexByte",
"(",
"alphabet",
",",
"n",
")",
"\n\n",
"for",
"i",
":=",
"24",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"d",
"+=",
"58",
"*",
"int",
"(",
"decode",
"[",
"i",
"]",
")",
"\n",
"decode",
"[",
"i",
"]",
"=",
"byte",
"(",
"d",
"%",
"256",
")",
"\n",
"d",
"/=",
"256",
"\n",
"}",
"\n",
"}",
"\n\n",
"h",
":=",
"sha256",
".",
"New",
"(",
")",
"\n",
"_",
",",
"_",
"=",
"h",
".",
"Write",
"(",
"decode",
"[",
":",
"21",
"]",
")",
"\n",
"d",
":=",
"h",
".",
"Sum",
"(",
"[",
"]",
"byte",
"{",
"}",
")",
"\n",
"h",
"=",
"sha256",
".",
"New",
"(",
")",
"\n",
"_",
",",
"_",
"=",
"h",
".",
"Write",
"(",
"d",
")",
"\n\n",
"validchecksum",
":=",
"[",
"4",
"]",
"byte",
"{",
"}",
"\n",
"computedchecksum",
":=",
"[",
"4",
"]",
"byte",
"{",
"}",
"\n\n",
"copy",
"(",
"computedchecksum",
"[",
":",
"]",
",",
"h",
".",
"Sum",
"(",
"d",
"[",
":",
"0",
"]",
")",
")",
"\n",
"copy",
"(",
"validchecksum",
"[",
":",
"]",
",",
"decode",
"[",
"21",
":",
"]",
")",
"\n\n",
"return",
"validchecksum",
"==",
"computedchecksum",
"\n",
"}"
] | // IsBitcoinAddress is the validation function for validating if the field's value is a valid btc address | [
"IsBitcoinAddress",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"valid",
"btc",
"address"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L506-L540 | train |
go-playground/validator | baked_in.go | isBitcoinBech32Address | func isBitcoinBech32Address(fl FieldLevel) bool {
address := fl.Field().String()
if !btcLowerAddressRegexBech32.MatchString(address) && !btcUpperAddressRegexBech32.MatchString(address) {
return false
}
am := len(address) % 8
if am == 0 || am == 3 || am == 5 {
return false
}
address = strings.ToLower(address)
alphabet := "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
hr := []int{3, 3, 0, 2, 3} // the human readable part will always be bc
addr := address[3:]
dp := make([]int, 0, len(addr))
for _, c := range addr {
dp = append(dp, strings.IndexRune(alphabet, c))
}
ver := dp[0]
if ver < 0 || ver > 16 {
return false
}
if ver == 0 {
if len(address) != 42 && len(address) != 62 {
return false
}
}
values := append(hr, dp...)
GEN := []int{0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3}
p := 1
for _, v := range values {
b := p >> 25
p = (p&0x1ffffff)<<5 ^ v
for i := 0; i < 5; i++ {
if (b>>uint(i))&1 == 1 {
p ^= GEN[i]
}
}
}
if p != 1 {
return false
}
b := uint(0)
acc := 0
mv := (1 << 5) - 1
var sw []int
for _, v := range dp[1 : len(dp)-6] {
acc = (acc << 5) | v
b += 5
for b >= 8 {
b -= 8
sw = append(sw, (acc>>b)&mv)
}
}
if len(sw) < 2 || len(sw) > 40 {
return false
}
return true
} | go | func isBitcoinBech32Address(fl FieldLevel) bool {
address := fl.Field().String()
if !btcLowerAddressRegexBech32.MatchString(address) && !btcUpperAddressRegexBech32.MatchString(address) {
return false
}
am := len(address) % 8
if am == 0 || am == 3 || am == 5 {
return false
}
address = strings.ToLower(address)
alphabet := "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
hr := []int{3, 3, 0, 2, 3} // the human readable part will always be bc
addr := address[3:]
dp := make([]int, 0, len(addr))
for _, c := range addr {
dp = append(dp, strings.IndexRune(alphabet, c))
}
ver := dp[0]
if ver < 0 || ver > 16 {
return false
}
if ver == 0 {
if len(address) != 42 && len(address) != 62 {
return false
}
}
values := append(hr, dp...)
GEN := []int{0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3}
p := 1
for _, v := range values {
b := p >> 25
p = (p&0x1ffffff)<<5 ^ v
for i := 0; i < 5; i++ {
if (b>>uint(i))&1 == 1 {
p ^= GEN[i]
}
}
}
if p != 1 {
return false
}
b := uint(0)
acc := 0
mv := (1 << 5) - 1
var sw []int
for _, v := range dp[1 : len(dp)-6] {
acc = (acc << 5) | v
b += 5
for b >= 8 {
b -= 8
sw = append(sw, (acc>>b)&mv)
}
}
if len(sw) < 2 || len(sw) > 40 {
return false
}
return true
} | [
"func",
"isBitcoinBech32Address",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"address",
":=",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
"\n\n",
"if",
"!",
"btcLowerAddressRegexBech32",
".",
"MatchString",
"(",
"address",
")",
"&&",
"!",
"btcUpperAddressRegexBech32",
".",
"MatchString",
"(",
"address",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"am",
":=",
"len",
"(",
"address",
")",
"%",
"8",
"\n\n",
"if",
"am",
"==",
"0",
"||",
"am",
"==",
"3",
"||",
"am",
"==",
"5",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"address",
"=",
"strings",
".",
"ToLower",
"(",
"address",
")",
"\n\n",
"alphabet",
":=",
"\"",
"\"",
"\n\n",
"hr",
":=",
"[",
"]",
"int",
"{",
"3",
",",
"3",
",",
"0",
",",
"2",
",",
"3",
"}",
"// the human readable part will always be bc",
"\n",
"addr",
":=",
"address",
"[",
"3",
":",
"]",
"\n",
"dp",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"0",
",",
"len",
"(",
"addr",
")",
")",
"\n\n",
"for",
"_",
",",
"c",
":=",
"range",
"addr",
"{",
"dp",
"=",
"append",
"(",
"dp",
",",
"strings",
".",
"IndexRune",
"(",
"alphabet",
",",
"c",
")",
")",
"\n",
"}",
"\n\n",
"ver",
":=",
"dp",
"[",
"0",
"]",
"\n\n",
"if",
"ver",
"<",
"0",
"||",
"ver",
">",
"16",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"ver",
"==",
"0",
"{",
"if",
"len",
"(",
"address",
")",
"!=",
"42",
"&&",
"len",
"(",
"address",
")",
"!=",
"62",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"values",
":=",
"append",
"(",
"hr",
",",
"dp",
"...",
")",
"\n\n",
"GEN",
":=",
"[",
"]",
"int",
"{",
"0x3b6a57b2",
",",
"0x26508e6d",
",",
"0x1ea119fa",
",",
"0x3d4233dd",
",",
"0x2a1462b3",
"}",
"\n\n",
"p",
":=",
"1",
"\n\n",
"for",
"_",
",",
"v",
":=",
"range",
"values",
"{",
"b",
":=",
"p",
">>",
"25",
"\n",
"p",
"=",
"(",
"p",
"&",
"0x1ffffff",
")",
"<<",
"5",
"^",
"v",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"5",
";",
"i",
"++",
"{",
"if",
"(",
"b",
">>",
"uint",
"(",
"i",
")",
")",
"&",
"1",
"==",
"1",
"{",
"p",
"^=",
"GEN",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"p",
"!=",
"1",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"b",
":=",
"uint",
"(",
"0",
")",
"\n",
"acc",
":=",
"0",
"\n",
"mv",
":=",
"(",
"1",
"<<",
"5",
")",
"-",
"1",
"\n",
"var",
"sw",
"[",
"]",
"int",
"\n\n",
"for",
"_",
",",
"v",
":=",
"range",
"dp",
"[",
"1",
":",
"len",
"(",
"dp",
")",
"-",
"6",
"]",
"{",
"acc",
"=",
"(",
"acc",
"<<",
"5",
")",
"|",
"v",
"\n",
"b",
"+=",
"5",
"\n",
"for",
"b",
">=",
"8",
"{",
"b",
"-=",
"8",
"\n",
"sw",
"=",
"append",
"(",
"sw",
",",
"(",
"acc",
">>",
"b",
")",
"&",
"mv",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"sw",
")",
"<",
"2",
"||",
"len",
"(",
"sw",
")",
">",
"40",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // IsBitcoinBech32Address is the validation function for validating if the field's value is a valid bech32 btc address | [
"IsBitcoinBech32Address",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"valid",
"bech32",
"btc",
"address"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L543-L620 | train |
go-playground/validator | baked_in.go | containsRune | func containsRune(fl FieldLevel) bool {
r, _ := utf8.DecodeRuneInString(fl.Param())
return strings.ContainsRune(fl.Field().String(), r)
} | go | func containsRune(fl FieldLevel) bool {
r, _ := utf8.DecodeRuneInString(fl.Param())
return strings.ContainsRune(fl.Field().String(), r)
} | [
"func",
"containsRune",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"r",
",",
"_",
":=",
"utf8",
".",
"DecodeRuneInString",
"(",
"fl",
".",
"Param",
"(",
")",
")",
"\n\n",
"return",
"strings",
".",
"ContainsRune",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
",",
"r",
")",
"\n",
"}"
] | // ContainsRune is the validation function for validating that the field's value contains the rune specified within the param. | [
"ContainsRune",
"is",
"the",
"validation",
"function",
"for",
"validating",
"that",
"the",
"field",
"s",
"value",
"contains",
"the",
"rune",
"specified",
"within",
"the",
"param",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L638-L643 | train |
go-playground/validator | baked_in.go | containsAny | func containsAny(fl FieldLevel) bool {
return strings.ContainsAny(fl.Field().String(), fl.Param())
} | go | func containsAny(fl FieldLevel) bool {
return strings.ContainsAny(fl.Field().String(), fl.Param())
} | [
"func",
"containsAny",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"return",
"strings",
".",
"ContainsAny",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
",",
"fl",
".",
"Param",
"(",
")",
")",
"\n",
"}"
] | // ContainsAny is the validation function for validating that the field's value contains any of the characters specified within the param. | [
"ContainsAny",
"is",
"the",
"validation",
"function",
"for",
"validating",
"that",
"the",
"field",
"s",
"value",
"contains",
"any",
"of",
"the",
"characters",
"specified",
"within",
"the",
"param",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L646-L648 | train |
go-playground/validator | baked_in.go | contains | func contains(fl FieldLevel) bool {
return strings.Contains(fl.Field().String(), fl.Param())
} | go | func contains(fl FieldLevel) bool {
return strings.Contains(fl.Field().String(), fl.Param())
} | [
"func",
"contains",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"return",
"strings",
".",
"Contains",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
",",
"fl",
".",
"Param",
"(",
")",
")",
"\n",
"}"
] | // Contains is the validation function for validating that the field's value contains the text specified within the param. | [
"Contains",
"is",
"the",
"validation",
"function",
"for",
"validating",
"that",
"the",
"field",
"s",
"value",
"contains",
"the",
"text",
"specified",
"within",
"the",
"param",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L651-L653 | train |
go-playground/validator | baked_in.go | startsWith | func startsWith(fl FieldLevel) bool {
return strings.HasPrefix(fl.Field().String(), fl.Param())
} | go | func startsWith(fl FieldLevel) bool {
return strings.HasPrefix(fl.Field().String(), fl.Param())
} | [
"func",
"startsWith",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"return",
"strings",
".",
"HasPrefix",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
",",
"fl",
".",
"Param",
"(",
")",
")",
"\n",
"}"
] | // StartsWith is the validation function for validating that the field's value starts with the text specified within the param. | [
"StartsWith",
"is",
"the",
"validation",
"function",
"for",
"validating",
"that",
"the",
"field",
"s",
"value",
"starts",
"with",
"the",
"text",
"specified",
"within",
"the",
"param",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L656-L658 | train |
go-playground/validator | baked_in.go | endsWith | func endsWith(fl FieldLevel) bool {
return strings.HasSuffix(fl.Field().String(), fl.Param())
} | go | func endsWith(fl FieldLevel) bool {
return strings.HasSuffix(fl.Field().String(), fl.Param())
} | [
"func",
"endsWith",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"return",
"strings",
".",
"HasSuffix",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
",",
"fl",
".",
"Param",
"(",
")",
")",
"\n",
"}"
] | // EndsWith is the validation function for validating that the field's value ends with the text specified within the param. | [
"EndsWith",
"is",
"the",
"validation",
"function",
"for",
"validating",
"that",
"the",
"field",
"s",
"value",
"ends",
"with",
"the",
"text",
"specified",
"within",
"the",
"param",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L661-L663 | train |
go-playground/validator | baked_in.go | fieldContains | func fieldContains(fl FieldLevel) bool {
field := fl.Field()
currentField, _, ok := fl.GetStructFieldOK()
if !ok {
return false
}
return strings.Contains(field.String(), currentField.String())
} | go | func fieldContains(fl FieldLevel) bool {
field := fl.Field()
currentField, _, ok := fl.GetStructFieldOK()
if !ok {
return false
}
return strings.Contains(field.String(), currentField.String())
} | [
"func",
"fieldContains",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n\n",
"currentField",
",",
"_",
",",
"ok",
":=",
"fl",
".",
"GetStructFieldOK",
"(",
")",
"\n\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"Contains",
"(",
"field",
".",
"String",
"(",
")",
",",
"currentField",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // FieldContains is the validation function for validating if the current field's value contains the field specified by the param's value. | [
"FieldContains",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"current",
"field",
"s",
"value",
"contains",
"the",
"field",
"specified",
"by",
"the",
"param",
"s",
"value",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L666-L676 | train |
go-playground/validator | baked_in.go | fieldExcludes | func fieldExcludes(fl FieldLevel) bool {
field := fl.Field()
currentField, _, ok := fl.GetStructFieldOK()
if !ok {
return true
}
return !strings.Contains(field.String(), currentField.String())
} | go | func fieldExcludes(fl FieldLevel) bool {
field := fl.Field()
currentField, _, ok := fl.GetStructFieldOK()
if !ok {
return true
}
return !strings.Contains(field.String(), currentField.String())
} | [
"func",
"fieldExcludes",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n\n",
"currentField",
",",
"_",
",",
"ok",
":=",
"fl",
".",
"GetStructFieldOK",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"!",
"strings",
".",
"Contains",
"(",
"field",
".",
"String",
"(",
")",
",",
"currentField",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // FieldExcludes is the validation function for validating if the current field's value excludes the field specified by the param's value. | [
"FieldExcludes",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"current",
"field",
"s",
"value",
"excludes",
"the",
"field",
"specified",
"by",
"the",
"param",
"s",
"value",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L679-L688 | train |
go-playground/validator | baked_in.go | isEqCrossStructField | func isEqCrossStructField(fl FieldLevel) bool {
field := fl.Field()
kind := field.Kind()
topField, topKind, ok := fl.GetStructFieldOK()
if !ok || topKind != kind {
return false
}
switch kind {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return topField.Int() == field.Int()
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return topField.Uint() == field.Uint()
case reflect.Float32, reflect.Float64:
return topField.Float() == field.Float()
case reflect.Slice, reflect.Map, reflect.Array:
return int64(topField.Len()) == int64(field.Len())
case reflect.Struct:
fieldType := field.Type()
// Not Same underlying type i.e. struct and time
if fieldType != topField.Type() {
return false
}
if fieldType == timeType {
t := field.Interface().(time.Time)
fieldTime := topField.Interface().(time.Time)
return fieldTime.Equal(t)
}
}
// default reflect.String:
return topField.String() == field.String()
} | go | func isEqCrossStructField(fl FieldLevel) bool {
field := fl.Field()
kind := field.Kind()
topField, topKind, ok := fl.GetStructFieldOK()
if !ok || topKind != kind {
return false
}
switch kind {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return topField.Int() == field.Int()
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return topField.Uint() == field.Uint()
case reflect.Float32, reflect.Float64:
return topField.Float() == field.Float()
case reflect.Slice, reflect.Map, reflect.Array:
return int64(topField.Len()) == int64(field.Len())
case reflect.Struct:
fieldType := field.Type()
// Not Same underlying type i.e. struct and time
if fieldType != topField.Type() {
return false
}
if fieldType == timeType {
t := field.Interface().(time.Time)
fieldTime := topField.Interface().(time.Time)
return fieldTime.Equal(t)
}
}
// default reflect.String:
return topField.String() == field.String()
} | [
"func",
"isEqCrossStructField",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n",
"kind",
":=",
"field",
".",
"Kind",
"(",
")",
"\n\n",
"topField",
",",
"topKind",
",",
"ok",
":=",
"fl",
".",
"GetStructFieldOK",
"(",
")",
"\n",
"if",
"!",
"ok",
"||",
"topKind",
"!=",
"kind",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"switch",
"kind",
"{",
"case",
"reflect",
".",
"Int",
",",
"reflect",
".",
"Int8",
",",
"reflect",
".",
"Int16",
",",
"reflect",
".",
"Int32",
",",
"reflect",
".",
"Int64",
":",
"return",
"topField",
".",
"Int",
"(",
")",
"==",
"field",
".",
"Int",
"(",
")",
"\n\n",
"case",
"reflect",
".",
"Uint",
",",
"reflect",
".",
"Uint8",
",",
"reflect",
".",
"Uint16",
",",
"reflect",
".",
"Uint32",
",",
"reflect",
".",
"Uint64",
",",
"reflect",
".",
"Uintptr",
":",
"return",
"topField",
".",
"Uint",
"(",
")",
"==",
"field",
".",
"Uint",
"(",
")",
"\n\n",
"case",
"reflect",
".",
"Float32",
",",
"reflect",
".",
"Float64",
":",
"return",
"topField",
".",
"Float",
"(",
")",
"==",
"field",
".",
"Float",
"(",
")",
"\n\n",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Map",
",",
"reflect",
".",
"Array",
":",
"return",
"int64",
"(",
"topField",
".",
"Len",
"(",
")",
")",
"==",
"int64",
"(",
"field",
".",
"Len",
"(",
")",
")",
"\n\n",
"case",
"reflect",
".",
"Struct",
":",
"fieldType",
":=",
"field",
".",
"Type",
"(",
")",
"\n\n",
"// Not Same underlying type i.e. struct and time",
"if",
"fieldType",
"!=",
"topField",
".",
"Type",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"fieldType",
"==",
"timeType",
"{",
"t",
":=",
"field",
".",
"Interface",
"(",
")",
".",
"(",
"time",
".",
"Time",
")",
"\n",
"fieldTime",
":=",
"topField",
".",
"Interface",
"(",
")",
".",
"(",
"time",
".",
"Time",
")",
"\n\n",
"return",
"fieldTime",
".",
"Equal",
"(",
"t",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// default reflect.String:",
"return",
"topField",
".",
"String",
"(",
")",
"==",
"field",
".",
"String",
"(",
")",
"\n",
"}"
] | // IsEqCrossStructField is the validation function for validating that the current field's value is equal to the field, within a separate struct, specified by the param's value. | [
"IsEqCrossStructField",
"is",
"the",
"validation",
"function",
"for",
"validating",
"that",
"the",
"current",
"field",
"s",
"value",
"is",
"equal",
"to",
"the",
"field",
"within",
"a",
"separate",
"struct",
"specified",
"by",
"the",
"param",
"s",
"value",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L981-L1025 | train |
go-playground/validator | baked_in.go | isEq | func isEq(fl FieldLevel) bool {
field := fl.Field()
param := fl.Param()
switch field.Kind() {
case reflect.String:
return field.String() == param
case reflect.Slice, reflect.Map, reflect.Array:
p := asInt(param)
return int64(field.Len()) == p
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
p := asInt(param)
return field.Int() == p
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
p := asUint(param)
return field.Uint() == p
case reflect.Float32, reflect.Float64:
p := asFloat(param)
return field.Float() == p
}
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} | go | func isEq(fl FieldLevel) bool {
field := fl.Field()
param := fl.Param()
switch field.Kind() {
case reflect.String:
return field.String() == param
case reflect.Slice, reflect.Map, reflect.Array:
p := asInt(param)
return int64(field.Len()) == p
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
p := asInt(param)
return field.Int() == p
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
p := asUint(param)
return field.Uint() == p
case reflect.Float32, reflect.Float64:
p := asFloat(param)
return field.Float() == p
}
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} | [
"func",
"isEq",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n",
"param",
":=",
"fl",
".",
"Param",
"(",
")",
"\n\n",
"switch",
"field",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"String",
":",
"return",
"field",
".",
"String",
"(",
")",
"==",
"param",
"\n\n",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Map",
",",
"reflect",
".",
"Array",
":",
"p",
":=",
"asInt",
"(",
"param",
")",
"\n\n",
"return",
"int64",
"(",
"field",
".",
"Len",
"(",
")",
")",
"==",
"p",
"\n\n",
"case",
"reflect",
".",
"Int",
",",
"reflect",
".",
"Int8",
",",
"reflect",
".",
"Int16",
",",
"reflect",
".",
"Int32",
",",
"reflect",
".",
"Int64",
":",
"p",
":=",
"asInt",
"(",
"param",
")",
"\n\n",
"return",
"field",
".",
"Int",
"(",
")",
"==",
"p",
"\n\n",
"case",
"reflect",
".",
"Uint",
",",
"reflect",
".",
"Uint8",
",",
"reflect",
".",
"Uint16",
",",
"reflect",
".",
"Uint32",
",",
"reflect",
".",
"Uint64",
",",
"reflect",
".",
"Uintptr",
":",
"p",
":=",
"asUint",
"(",
"param",
")",
"\n\n",
"return",
"field",
".",
"Uint",
"(",
")",
"==",
"p",
"\n\n",
"case",
"reflect",
".",
"Float32",
",",
"reflect",
".",
"Float64",
":",
"p",
":=",
"asFloat",
"(",
"param",
")",
"\n\n",
"return",
"field",
".",
"Float",
"(",
")",
"==",
"p",
"\n",
"}",
"\n\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"field",
".",
"Interface",
"(",
")",
")",
")",
"\n",
"}"
] | // IsEq is the validation function for validating if the current field's value is equal to the param's value. | [
"IsEq",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"current",
"field",
"s",
"value",
"is",
"equal",
"to",
"the",
"param",
"s",
"value",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L1076-L1108 | train |
go-playground/validator | baked_in.go | isURI | func isURI(fl FieldLevel) bool {
field := fl.Field()
switch field.Kind() {
case reflect.String:
s := field.String()
// checks needed as of Go 1.6 because of change https://github.com/golang/go/commit/617c93ce740c3c3cc28cdd1a0d712be183d0b328#diff-6c2d018290e298803c0c9419d8739885L195
// emulate browser and strip the '#' suffix prior to validation. see issue-#237
if i := strings.Index(s, "#"); i > -1 {
s = s[:i]
}
if len(s) == 0 {
return false
}
_, err := url.ParseRequestURI(s)
return err == nil
}
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} | go | func isURI(fl FieldLevel) bool {
field := fl.Field()
switch field.Kind() {
case reflect.String:
s := field.String()
// checks needed as of Go 1.6 because of change https://github.com/golang/go/commit/617c93ce740c3c3cc28cdd1a0d712be183d0b328#diff-6c2d018290e298803c0c9419d8739885L195
// emulate browser and strip the '#' suffix prior to validation. see issue-#237
if i := strings.Index(s, "#"); i > -1 {
s = s[:i]
}
if len(s) == 0 {
return false
}
_, err := url.ParseRequestURI(s)
return err == nil
}
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} | [
"func",
"isURI",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n\n",
"switch",
"field",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"String",
":",
"s",
":=",
"field",
".",
"String",
"(",
")",
"\n\n",
"// checks needed as of Go 1.6 because of change https://github.com/golang/go/commit/617c93ce740c3c3cc28cdd1a0d712be183d0b328#diff-6c2d018290e298803c0c9419d8739885L195",
"// emulate browser and strip the '#' suffix prior to validation. see issue-#237",
"if",
"i",
":=",
"strings",
".",
"Index",
"(",
"s",
",",
"\"",
"\"",
")",
";",
"i",
">",
"-",
"1",
"{",
"s",
"=",
"s",
"[",
":",
"i",
"]",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"err",
":=",
"url",
".",
"ParseRequestURI",
"(",
"s",
")",
"\n\n",
"return",
"err",
"==",
"nil",
"\n",
"}",
"\n\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"field",
".",
"Interface",
"(",
")",
")",
")",
"\n",
"}"
] | // IsURI is the validation function for validating if the current field's value is a valid URI. | [
"IsURI",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"current",
"field",
"s",
"value",
"is",
"a",
"valid",
"URI",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L1121-L1147 | train |
go-playground/validator | baked_in.go | isUrnRFC2141 | func isUrnRFC2141(fl FieldLevel) bool {
field := fl.Field()
switch field.Kind() {
case reflect.String:
str := field.String()
_, match := urn.Parse([]byte(str))
return match
}
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} | go | func isUrnRFC2141(fl FieldLevel) bool {
field := fl.Field()
switch field.Kind() {
case reflect.String:
str := field.String()
_, match := urn.Parse([]byte(str))
return match
}
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} | [
"func",
"isUrnRFC2141",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n\n",
"switch",
"field",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"String",
":",
"str",
":=",
"field",
".",
"String",
"(",
")",
"\n\n",
"_",
",",
"match",
":=",
"urn",
".",
"Parse",
"(",
"[",
"]",
"byte",
"(",
"str",
")",
")",
"\n\n",
"return",
"match",
"\n",
"}",
"\n\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"field",
".",
"Interface",
"(",
")",
")",
")",
"\n",
"}"
] | // isUrnRFC2141 is the validation function for validating if the current field's value is a valid URN as per RFC 2141. | [
"isUrnRFC2141",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"current",
"field",
"s",
"value",
"is",
"a",
"valid",
"URN",
"as",
"per",
"RFC",
"2141",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L1184-L1199 | train |
go-playground/validator | baked_in.go | isFile | func isFile(fl FieldLevel) bool {
field := fl.Field()
switch field.Kind() {
case reflect.String:
fileInfo, err := os.Stat(field.String())
if err != nil {
return false
}
return !fileInfo.IsDir()
}
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} | go | func isFile(fl FieldLevel) bool {
field := fl.Field()
switch field.Kind() {
case reflect.String:
fileInfo, err := os.Stat(field.String())
if err != nil {
return false
}
return !fileInfo.IsDir()
}
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} | [
"func",
"isFile",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n\n",
"switch",
"field",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"String",
":",
"fileInfo",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"field",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"!",
"fileInfo",
".",
"IsDir",
"(",
")",
"\n",
"}",
"\n\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"field",
".",
"Interface",
"(",
")",
")",
")",
"\n",
"}"
] | // IsFile is the validation function for validating if the current field's value is a valid file path. | [
"IsFile",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"current",
"field",
"s",
"value",
"is",
"a",
"valid",
"file",
"path",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L1202-L1216 | train |
go-playground/validator | baked_in.go | isNumber | func isNumber(fl FieldLevel) bool {
switch fl.Field().Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64:
return true
default:
return numberRegex.MatchString(fl.Field().String())
}
} | go | func isNumber(fl FieldLevel) bool {
switch fl.Field().Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64:
return true
default:
return numberRegex.MatchString(fl.Field().String())
}
} | [
"func",
"isNumber",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"switch",
"fl",
".",
"Field",
"(",
")",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Int",
",",
"reflect",
".",
"Int8",
",",
"reflect",
".",
"Int16",
",",
"reflect",
".",
"Int32",
",",
"reflect",
".",
"Int64",
",",
"reflect",
".",
"Uint",
",",
"reflect",
".",
"Uint8",
",",
"reflect",
".",
"Uint16",
",",
"reflect",
".",
"Uint32",
",",
"reflect",
".",
"Uint64",
",",
"reflect",
".",
"Uintptr",
",",
"reflect",
".",
"Float32",
",",
"reflect",
".",
"Float64",
":",
"return",
"true",
"\n",
"default",
":",
"return",
"numberRegex",
".",
"MatchString",
"(",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}"
] | // IsNumber is the validation function for validating if the current field's value is a valid number. | [
"IsNumber",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"current",
"field",
"s",
"value",
"is",
"a",
"valid",
"number",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L1254-L1261 | train |
go-playground/validator | baked_in.go | hasValue | func hasValue(fl FieldLevel) bool {
field := fl.Field()
switch field.Kind() {
case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func:
return !field.IsNil()
default:
if fl.(*validate).fldIsPointer && field.Interface() != nil {
return true
}
return field.IsValid() && field.Interface() != reflect.Zero(field.Type()).Interface()
}
} | go | func hasValue(fl FieldLevel) bool {
field := fl.Field()
switch field.Kind() {
case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func:
return !field.IsNil()
default:
if fl.(*validate).fldIsPointer && field.Interface() != nil {
return true
}
return field.IsValid() && field.Interface() != reflect.Zero(field.Type()).Interface()
}
} | [
"func",
"hasValue",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n\n",
"switch",
"field",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Map",
",",
"reflect",
".",
"Ptr",
",",
"reflect",
".",
"Interface",
",",
"reflect",
".",
"Chan",
",",
"reflect",
".",
"Func",
":",
"return",
"!",
"field",
".",
"IsNil",
"(",
")",
"\n",
"default",
":",
"if",
"fl",
".",
"(",
"*",
"validate",
")",
".",
"fldIsPointer",
"&&",
"field",
".",
"Interface",
"(",
")",
"!=",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"field",
".",
"IsValid",
"(",
")",
"&&",
"field",
".",
"Interface",
"(",
")",
"!=",
"reflect",
".",
"Zero",
"(",
"field",
".",
"Type",
"(",
")",
")",
".",
"Interface",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // HasValue is the validation function for validating if the current field's value is not the default static value. | [
"HasValue",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"current",
"field",
"s",
"value",
"is",
"not",
"the",
"default",
"static",
"value",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L1299-L1314 | train |
go-playground/validator | baked_in.go | isLte | func isLte(fl FieldLevel) bool {
field := fl.Field()
param := fl.Param()
switch field.Kind() {
case reflect.String:
p := asInt(param)
return int64(utf8.RuneCountInString(field.String())) <= p
case reflect.Slice, reflect.Map, reflect.Array:
p := asInt(param)
return int64(field.Len()) <= p
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
p := asInt(param)
return field.Int() <= p
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
p := asUint(param)
return field.Uint() <= p
case reflect.Float32, reflect.Float64:
p := asFloat(param)
return field.Float() <= p
case reflect.Struct:
if field.Type() == timeType {
now := time.Now().UTC()
t := field.Interface().(time.Time)
return t.Before(now) || t.Equal(now)
}
}
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} | go | func isLte(fl FieldLevel) bool {
field := fl.Field()
param := fl.Param()
switch field.Kind() {
case reflect.String:
p := asInt(param)
return int64(utf8.RuneCountInString(field.String())) <= p
case reflect.Slice, reflect.Map, reflect.Array:
p := asInt(param)
return int64(field.Len()) <= p
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
p := asInt(param)
return field.Int() <= p
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
p := asUint(param)
return field.Uint() <= p
case reflect.Float32, reflect.Float64:
p := asFloat(param)
return field.Float() <= p
case reflect.Struct:
if field.Type() == timeType {
now := time.Now().UTC()
t := field.Interface().(time.Time)
return t.Before(now) || t.Equal(now)
}
}
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
} | [
"func",
"isLte",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"field",
":=",
"fl",
".",
"Field",
"(",
")",
"\n",
"param",
":=",
"fl",
".",
"Param",
"(",
")",
"\n\n",
"switch",
"field",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"String",
":",
"p",
":=",
"asInt",
"(",
"param",
")",
"\n\n",
"return",
"int64",
"(",
"utf8",
".",
"RuneCountInString",
"(",
"field",
".",
"String",
"(",
")",
")",
")",
"<=",
"p",
"\n\n",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Map",
",",
"reflect",
".",
"Array",
":",
"p",
":=",
"asInt",
"(",
"param",
")",
"\n\n",
"return",
"int64",
"(",
"field",
".",
"Len",
"(",
")",
")",
"<=",
"p",
"\n\n",
"case",
"reflect",
".",
"Int",
",",
"reflect",
".",
"Int8",
",",
"reflect",
".",
"Int16",
",",
"reflect",
".",
"Int32",
",",
"reflect",
".",
"Int64",
":",
"p",
":=",
"asInt",
"(",
"param",
")",
"\n\n",
"return",
"field",
".",
"Int",
"(",
")",
"<=",
"p",
"\n\n",
"case",
"reflect",
".",
"Uint",
",",
"reflect",
".",
"Uint8",
",",
"reflect",
".",
"Uint16",
",",
"reflect",
".",
"Uint32",
",",
"reflect",
".",
"Uint64",
",",
"reflect",
".",
"Uintptr",
":",
"p",
":=",
"asUint",
"(",
"param",
")",
"\n\n",
"return",
"field",
".",
"Uint",
"(",
")",
"<=",
"p",
"\n\n",
"case",
"reflect",
".",
"Float32",
",",
"reflect",
".",
"Float64",
":",
"p",
":=",
"asFloat",
"(",
"param",
")",
"\n\n",
"return",
"field",
".",
"Float",
"(",
")",
"<=",
"p",
"\n\n",
"case",
"reflect",
".",
"Struct",
":",
"if",
"field",
".",
"Type",
"(",
")",
"==",
"timeType",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
"\n",
"t",
":=",
"field",
".",
"Interface",
"(",
")",
".",
"(",
"time",
".",
"Time",
")",
"\n\n",
"return",
"t",
".",
"Before",
"(",
"now",
")",
"||",
"t",
".",
"Equal",
"(",
"now",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"field",
".",
"Interface",
"(",
")",
")",
")",
"\n",
"}"
] | // IsLte is the validation function for validating if the current field's value is less than or equal to the param's value. | [
"IsLte",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"current",
"field",
"s",
"value",
"is",
"less",
"than",
"or",
"equal",
"to",
"the",
"param",
"s",
"value",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L1637-L1681 | train |
go-playground/validator | baked_in.go | isTCP4AddrResolvable | func isTCP4AddrResolvable(fl FieldLevel) bool {
if !isIP4Addr(fl) {
return false
}
_, err := net.ResolveTCPAddr("tcp4", fl.Field().String())
return err == nil
} | go | func isTCP4AddrResolvable(fl FieldLevel) bool {
if !isIP4Addr(fl) {
return false
}
_, err := net.ResolveTCPAddr("tcp4", fl.Field().String())
return err == nil
} | [
"func",
"isTCP4AddrResolvable",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"if",
"!",
"isIP4Addr",
"(",
"fl",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"err",
":=",
"net",
".",
"ResolveTCPAddr",
"(",
"\"",
"\"",
",",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // IsTCP4AddrResolvable is the validation function for validating if the field's value is a resolvable tcp4 address. | [
"IsTCP4AddrResolvable",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"resolvable",
"tcp4",
"address",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L1733-L1741 | train |
go-playground/validator | baked_in.go | isUDPAddrResolvable | func isUDPAddrResolvable(fl FieldLevel) bool {
if !isIP4Addr(fl) && !isIP6Addr(fl) {
return false
}
_, err := net.ResolveUDPAddr("udp", fl.Field().String())
return err == nil
} | go | func isUDPAddrResolvable(fl FieldLevel) bool {
if !isIP4Addr(fl) && !isIP6Addr(fl) {
return false
}
_, err := net.ResolveUDPAddr("udp", fl.Field().String())
return err == nil
} | [
"func",
"isUDPAddrResolvable",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"if",
"!",
"isIP4Addr",
"(",
"fl",
")",
"&&",
"!",
"isIP6Addr",
"(",
"fl",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"err",
":=",
"net",
".",
"ResolveUDPAddr",
"(",
"\"",
"\"",
",",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // IsUDPAddrResolvable is the validation function for validating if the field's value is a resolvable udp address. | [
"IsUDPAddrResolvable",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"resolvable",
"udp",
"address",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L1792-L1801 | train |
go-playground/validator | baked_in.go | isIP4AddrResolvable | func isIP4AddrResolvable(fl FieldLevel) bool {
if !isIPv4(fl) {
return false
}
_, err := net.ResolveIPAddr("ip4", fl.Field().String())
return err == nil
} | go | func isIP4AddrResolvable(fl FieldLevel) bool {
if !isIPv4(fl) {
return false
}
_, err := net.ResolveIPAddr("ip4", fl.Field().String())
return err == nil
} | [
"func",
"isIP4AddrResolvable",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"if",
"!",
"isIPv4",
"(",
"fl",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"err",
":=",
"net",
".",
"ResolveIPAddr",
"(",
"\"",
"\"",
",",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // IsIP4AddrResolvable is the validation function for validating if the field's value is a resolvable ip4 address. | [
"IsIP4AddrResolvable",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"resolvable",
"ip4",
"address",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L1804-L1813 | train |
go-playground/validator | baked_in.go | isIP6AddrResolvable | func isIP6AddrResolvable(fl FieldLevel) bool {
if !isIPv6(fl) {
return false
}
_, err := net.ResolveIPAddr("ip6", fl.Field().String())
return err == nil
} | go | func isIP6AddrResolvable(fl FieldLevel) bool {
if !isIPv6(fl) {
return false
}
_, err := net.ResolveIPAddr("ip6", fl.Field().String())
return err == nil
} | [
"func",
"isIP6AddrResolvable",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"if",
"!",
"isIPv6",
"(",
"fl",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"err",
":=",
"net",
".",
"ResolveIPAddr",
"(",
"\"",
"\"",
",",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // IsIP6AddrResolvable is the validation function for validating if the field's value is a resolvable ip6 address. | [
"IsIP6AddrResolvable",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"resolvable",
"ip6",
"address",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L1816-L1825 | train |
go-playground/validator | baked_in.go | isIPAddrResolvable | func isIPAddrResolvable(fl FieldLevel) bool {
if !isIP(fl) {
return false
}
_, err := net.ResolveIPAddr("ip", fl.Field().String())
return err == nil
} | go | func isIPAddrResolvable(fl FieldLevel) bool {
if !isIP(fl) {
return false
}
_, err := net.ResolveIPAddr("ip", fl.Field().String())
return err == nil
} | [
"func",
"isIPAddrResolvable",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"if",
"!",
"isIP",
"(",
"fl",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"err",
":=",
"net",
".",
"ResolveIPAddr",
"(",
"\"",
"\"",
",",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // IsIPAddrResolvable is the validation function for validating if the field's value is a resolvable ip address. | [
"IsIPAddrResolvable",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"resolvable",
"ip",
"address",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L1828-L1837 | train |
go-playground/validator | baked_in.go | isUnixAddrResolvable | func isUnixAddrResolvable(fl FieldLevel) bool {
_, err := net.ResolveUnixAddr("unix", fl.Field().String())
return err == nil
} | go | func isUnixAddrResolvable(fl FieldLevel) bool {
_, err := net.ResolveUnixAddr("unix", fl.Field().String())
return err == nil
} | [
"func",
"isUnixAddrResolvable",
"(",
"fl",
"FieldLevel",
")",
"bool",
"{",
"_",
",",
"err",
":=",
"net",
".",
"ResolveUnixAddr",
"(",
"\"",
"\"",
",",
"fl",
".",
"Field",
"(",
")",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // IsUnixAddrResolvable is the validation function for validating if the field's value is a resolvable unix address. | [
"IsUnixAddrResolvable",
"is",
"the",
"validation",
"function",
"for",
"validating",
"if",
"the",
"field",
"s",
"value",
"is",
"a",
"resolvable",
"unix",
"address",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/baked_in.go#L1840-L1845 | train |
go-playground/validator | util.go | extractTypeInternal | func (v *validate) extractTypeInternal(current reflect.Value, nullable bool) (reflect.Value, reflect.Kind, bool) {
BEGIN:
switch current.Kind() {
case reflect.Ptr:
nullable = true
if current.IsNil() {
return current, reflect.Ptr, nullable
}
current = current.Elem()
goto BEGIN
case reflect.Interface:
nullable = true
if current.IsNil() {
return current, reflect.Interface, nullable
}
current = current.Elem()
goto BEGIN
case reflect.Invalid:
return current, reflect.Invalid, nullable
default:
if v.v.hasCustomFuncs {
if fn, ok := v.v.customFuncs[current.Type()]; ok {
current = reflect.ValueOf(fn(current))
goto BEGIN
}
}
return current, current.Kind(), nullable
}
} | go | func (v *validate) extractTypeInternal(current reflect.Value, nullable bool) (reflect.Value, reflect.Kind, bool) {
BEGIN:
switch current.Kind() {
case reflect.Ptr:
nullable = true
if current.IsNil() {
return current, reflect.Ptr, nullable
}
current = current.Elem()
goto BEGIN
case reflect.Interface:
nullable = true
if current.IsNil() {
return current, reflect.Interface, nullable
}
current = current.Elem()
goto BEGIN
case reflect.Invalid:
return current, reflect.Invalid, nullable
default:
if v.v.hasCustomFuncs {
if fn, ok := v.v.customFuncs[current.Type()]; ok {
current = reflect.ValueOf(fn(current))
goto BEGIN
}
}
return current, current.Kind(), nullable
}
} | [
"func",
"(",
"v",
"*",
"validate",
")",
"extractTypeInternal",
"(",
"current",
"reflect",
".",
"Value",
",",
"nullable",
"bool",
")",
"(",
"reflect",
".",
"Value",
",",
"reflect",
".",
"Kind",
",",
"bool",
")",
"{",
"BEGIN",
":",
"switch",
"current",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Ptr",
":",
"nullable",
"=",
"true",
"\n\n",
"if",
"current",
".",
"IsNil",
"(",
")",
"{",
"return",
"current",
",",
"reflect",
".",
"Ptr",
",",
"nullable",
"\n",
"}",
"\n\n",
"current",
"=",
"current",
".",
"Elem",
"(",
")",
"\n",
"goto",
"BEGIN",
"\n\n",
"case",
"reflect",
".",
"Interface",
":",
"nullable",
"=",
"true",
"\n\n",
"if",
"current",
".",
"IsNil",
"(",
")",
"{",
"return",
"current",
",",
"reflect",
".",
"Interface",
",",
"nullable",
"\n",
"}",
"\n\n",
"current",
"=",
"current",
".",
"Elem",
"(",
")",
"\n",
"goto",
"BEGIN",
"\n\n",
"case",
"reflect",
".",
"Invalid",
":",
"return",
"current",
",",
"reflect",
".",
"Invalid",
",",
"nullable",
"\n\n",
"default",
":",
"if",
"v",
".",
"v",
".",
"hasCustomFuncs",
"{",
"if",
"fn",
",",
"ok",
":=",
"v",
".",
"v",
".",
"customFuncs",
"[",
"current",
".",
"Type",
"(",
")",
"]",
";",
"ok",
"{",
"current",
"=",
"reflect",
".",
"ValueOf",
"(",
"fn",
"(",
"current",
")",
")",
"\n",
"goto",
"BEGIN",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"current",
",",
"current",
".",
"Kind",
"(",
")",
",",
"nullable",
"\n",
"}",
"\n",
"}"
] | // extractTypeInternal gets the actual underlying type of field value.
// It will dive into pointers, customTypes and return you the
// underlying value and it's kind. | [
"extractTypeInternal",
"gets",
"the",
"actual",
"underlying",
"type",
"of",
"field",
"value",
".",
"It",
"will",
"dive",
"into",
"pointers",
"customTypes",
"and",
"return",
"you",
"the",
"underlying",
"value",
"and",
"it",
"s",
"kind",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/util.go#L12-L53 | train |
go-playground/validator | util.go | asInt | func asInt(param string) int64 {
i, err := strconv.ParseInt(param, 0, 64)
panicIf(err)
return i
} | go | func asInt(param string) int64 {
i, err := strconv.ParseInt(param, 0, 64)
panicIf(err)
return i
} | [
"func",
"asInt",
"(",
"param",
"string",
")",
"int64",
"{",
"i",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"param",
",",
"0",
",",
"64",
")",
"\n",
"panicIf",
"(",
"err",
")",
"\n\n",
"return",
"i",
"\n",
"}"
] | // asInt returns the parameter as a int64
// or panics if it can't convert | [
"asInt",
"returns",
"the",
"parameter",
"as",
"a",
"int64",
"or",
"panics",
"if",
"it",
"can",
"t",
"convert"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/util.go#L225-L231 | train |
go-playground/validator | util.go | asUint | func asUint(param string) uint64 {
i, err := strconv.ParseUint(param, 0, 64)
panicIf(err)
return i
} | go | func asUint(param string) uint64 {
i, err := strconv.ParseUint(param, 0, 64)
panicIf(err)
return i
} | [
"func",
"asUint",
"(",
"param",
"string",
")",
"uint64",
"{",
"i",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"param",
",",
"0",
",",
"64",
")",
"\n",
"panicIf",
"(",
"err",
")",
"\n\n",
"return",
"i",
"\n",
"}"
] | // asUint returns the parameter as a uint64
// or panics if it can't convert | [
"asUint",
"returns",
"the",
"parameter",
"as",
"a",
"uint64",
"or",
"panics",
"if",
"it",
"can",
"t",
"convert"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/util.go#L235-L241 | train |
go-playground/validator | util.go | asFloat | func asFloat(param string) float64 {
i, err := strconv.ParseFloat(param, 64)
panicIf(err)
return i
} | go | func asFloat(param string) float64 {
i, err := strconv.ParseFloat(param, 64)
panicIf(err)
return i
} | [
"func",
"asFloat",
"(",
"param",
"string",
")",
"float64",
"{",
"i",
",",
"err",
":=",
"strconv",
".",
"ParseFloat",
"(",
"param",
",",
"64",
")",
"\n",
"panicIf",
"(",
"err",
")",
"\n\n",
"return",
"i",
"\n",
"}"
] | // asFloat returns the parameter as a float64
// or panics if it can't convert | [
"asFloat",
"returns",
"the",
"parameter",
"as",
"a",
"float64",
"or",
"panics",
"if",
"it",
"can",
"t",
"convert"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/util.go#L245-L251 | train |
go-playground/validator | validator_instance.go | New | func New() *Validate {
tc := new(tagCache)
tc.m.Store(make(map[string]*cTag))
sc := new(structCache)
sc.m.Store(make(map[reflect.Type]*cStruct))
v := &Validate{
tagName: defaultTagName,
aliases: make(map[string]string, len(bakedInAliases)),
validations: make(map[string]FuncCtx, len(bakedInValidators)),
tagCache: tc,
structCache: sc,
}
// must copy alias validators for separate validations to be used in each validator instance
for k, val := range bakedInAliases {
v.RegisterAlias(k, val)
}
// must copy validators for separate validations to be used in each instance
for k, val := range bakedInValidators {
// no need to error check here, baked in will always be valid
_ = v.registerValidation(k, wrapFunc(val), true)
}
v.pool = &sync.Pool{
New: func() interface{} {
return &validate{
v: v,
ns: make([]byte, 0, 64),
actualNs: make([]byte, 0, 64),
misc: make([]byte, 32),
}
},
}
return v
} | go | func New() *Validate {
tc := new(tagCache)
tc.m.Store(make(map[string]*cTag))
sc := new(structCache)
sc.m.Store(make(map[reflect.Type]*cStruct))
v := &Validate{
tagName: defaultTagName,
aliases: make(map[string]string, len(bakedInAliases)),
validations: make(map[string]FuncCtx, len(bakedInValidators)),
tagCache: tc,
structCache: sc,
}
// must copy alias validators for separate validations to be used in each validator instance
for k, val := range bakedInAliases {
v.RegisterAlias(k, val)
}
// must copy validators for separate validations to be used in each instance
for k, val := range bakedInValidators {
// no need to error check here, baked in will always be valid
_ = v.registerValidation(k, wrapFunc(val), true)
}
v.pool = &sync.Pool{
New: func() interface{} {
return &validate{
v: v,
ns: make([]byte, 0, 64),
actualNs: make([]byte, 0, 64),
misc: make([]byte, 32),
}
},
}
return v
} | [
"func",
"New",
"(",
")",
"*",
"Validate",
"{",
"tc",
":=",
"new",
"(",
"tagCache",
")",
"\n",
"tc",
".",
"m",
".",
"Store",
"(",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"cTag",
")",
")",
"\n\n",
"sc",
":=",
"new",
"(",
"structCache",
")",
"\n",
"sc",
".",
"m",
".",
"Store",
"(",
"make",
"(",
"map",
"[",
"reflect",
".",
"Type",
"]",
"*",
"cStruct",
")",
")",
"\n\n",
"v",
":=",
"&",
"Validate",
"{",
"tagName",
":",
"defaultTagName",
",",
"aliases",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"len",
"(",
"bakedInAliases",
")",
")",
",",
"validations",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"FuncCtx",
",",
"len",
"(",
"bakedInValidators",
")",
")",
",",
"tagCache",
":",
"tc",
",",
"structCache",
":",
"sc",
",",
"}",
"\n\n",
"// must copy alias validators for separate validations to be used in each validator instance",
"for",
"k",
",",
"val",
":=",
"range",
"bakedInAliases",
"{",
"v",
".",
"RegisterAlias",
"(",
"k",
",",
"val",
")",
"\n",
"}",
"\n\n",
"// must copy validators for separate validations to be used in each instance",
"for",
"k",
",",
"val",
":=",
"range",
"bakedInValidators",
"{",
"// no need to error check here, baked in will always be valid",
"_",
"=",
"v",
".",
"registerValidation",
"(",
"k",
",",
"wrapFunc",
"(",
"val",
")",
",",
"true",
")",
"\n",
"}",
"\n\n",
"v",
".",
"pool",
"=",
"&",
"sync",
".",
"Pool",
"{",
"New",
":",
"func",
"(",
")",
"interface",
"{",
"}",
"{",
"return",
"&",
"validate",
"{",
"v",
":",
"v",
",",
"ns",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"64",
")",
",",
"actualNs",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"64",
")",
",",
"misc",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"32",
")",
",",
"}",
"\n",
"}",
",",
"}",
"\n\n",
"return",
"v",
"\n",
"}"
] | // New returns a new instance of 'validate' with sane defaults. | [
"New",
"returns",
"a",
"new",
"instance",
"of",
"validate",
"with",
"sane",
"defaults",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/validator_instance.go#L75-L115 | train |
go-playground/validator | validator_instance.go | RegisterValidationCtx | func (v *Validate) RegisterValidationCtx(tag string, fn FuncCtx) error {
return v.registerValidation(tag, fn, false)
} | go | func (v *Validate) RegisterValidationCtx(tag string, fn FuncCtx) error {
return v.registerValidation(tag, fn, false)
} | [
"func",
"(",
"v",
"*",
"Validate",
")",
"RegisterValidationCtx",
"(",
"tag",
"string",
",",
"fn",
"FuncCtx",
")",
"error",
"{",
"return",
"v",
".",
"registerValidation",
"(",
"tag",
",",
"fn",
",",
"false",
")",
"\n",
"}"
] | // RegisterValidationCtx does the same as RegisterValidation on accepts a FuncCtx validation
// allowing context.Context validation support. | [
"RegisterValidationCtx",
"does",
"the",
"same",
"as",
"RegisterValidation",
"on",
"accepts",
"a",
"FuncCtx",
"validation",
"allowing",
"context",
".",
"Context",
"validation",
"support",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/validator_instance.go#L149-L151 | train |
go-playground/validator | validator_instance.go | RegisterTranslation | func (v *Validate) RegisterTranslation(tag string, trans ut.Translator, registerFn RegisterTranslationsFunc, translationFn TranslationFunc) (err error) {
if v.transTagFunc == nil {
v.transTagFunc = make(map[ut.Translator]map[string]TranslationFunc)
}
if err = registerFn(trans); err != nil {
return
}
m, ok := v.transTagFunc[trans]
if !ok {
m = make(map[string]TranslationFunc)
v.transTagFunc[trans] = m
}
m[tag] = translationFn
return
} | go | func (v *Validate) RegisterTranslation(tag string, trans ut.Translator, registerFn RegisterTranslationsFunc, translationFn TranslationFunc) (err error) {
if v.transTagFunc == nil {
v.transTagFunc = make(map[ut.Translator]map[string]TranslationFunc)
}
if err = registerFn(trans); err != nil {
return
}
m, ok := v.transTagFunc[trans]
if !ok {
m = make(map[string]TranslationFunc)
v.transTagFunc[trans] = m
}
m[tag] = translationFn
return
} | [
"func",
"(",
"v",
"*",
"Validate",
")",
"RegisterTranslation",
"(",
"tag",
"string",
",",
"trans",
"ut",
".",
"Translator",
",",
"registerFn",
"RegisterTranslationsFunc",
",",
"translationFn",
"TranslationFunc",
")",
"(",
"err",
"error",
")",
"{",
"if",
"v",
".",
"transTagFunc",
"==",
"nil",
"{",
"v",
".",
"transTagFunc",
"=",
"make",
"(",
"map",
"[",
"ut",
".",
"Translator",
"]",
"map",
"[",
"string",
"]",
"TranslationFunc",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"registerFn",
"(",
"trans",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"m",
",",
"ok",
":=",
"v",
".",
"transTagFunc",
"[",
"trans",
"]",
"\n",
"if",
"!",
"ok",
"{",
"m",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"TranslationFunc",
")",
"\n",
"v",
".",
"transTagFunc",
"[",
"trans",
"]",
"=",
"m",
"\n",
"}",
"\n\n",
"m",
"[",
"tag",
"]",
"=",
"translationFn",
"\n\n",
"return",
"\n",
"}"
] | // RegisterTranslation registers translations against the provided tag. | [
"RegisterTranslation",
"registers",
"translations",
"against",
"the",
"provided",
"tag",
"."
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/validator_instance.go#L236-L255 | train |
go-playground/validator | validator.go | validateStruct | func (v *validate) validateStruct(ctx context.Context, parent reflect.Value, current reflect.Value, typ reflect.Type, ns []byte, structNs []byte, ct *cTag) {
cs, ok := v.v.structCache.Get(typ)
if !ok {
cs = v.v.extractStructCache(current, typ.Name())
}
if len(ns) == 0 && len(cs.name) != 0 {
ns = append(ns, cs.name...)
ns = append(ns, '.')
structNs = append(structNs, cs.name...)
structNs = append(structNs, '.')
}
// ct is nil on top level struct, and structs as fields that have no tag info
// so if nil or if not nil and the structonly tag isn't present
if ct == nil || ct.typeof != typeStructOnly {
var f *cField
for i := 0; i < len(cs.fields); i++ {
f = cs.fields[i]
if v.isPartial {
if v.ffn != nil {
// used with StructFiltered
if v.ffn(append(structNs, f.name...)) {
continue
}
} else {
// used with StructPartial & StructExcept
_, ok = v.includeExclude[string(append(structNs, f.name...))]
if (ok && v.hasExcludes) || (!ok && !v.hasExcludes) {
continue
}
}
}
v.traverseField(ctx, parent, current.Field(f.idx), ns, structNs, f, f.cTags)
}
}
// check if any struct level validations, after all field validations already checked.
// first iteration will have no info about nostructlevel tag, and is checked prior to
// calling the next iteration of validateStruct called from traverseField.
if cs.fn != nil {
v.slflParent = parent
v.slCurrent = current
v.ns = ns
v.actualNs = structNs
cs.fn(ctx, v)
}
} | go | func (v *validate) validateStruct(ctx context.Context, parent reflect.Value, current reflect.Value, typ reflect.Type, ns []byte, structNs []byte, ct *cTag) {
cs, ok := v.v.structCache.Get(typ)
if !ok {
cs = v.v.extractStructCache(current, typ.Name())
}
if len(ns) == 0 && len(cs.name) != 0 {
ns = append(ns, cs.name...)
ns = append(ns, '.')
structNs = append(structNs, cs.name...)
structNs = append(structNs, '.')
}
// ct is nil on top level struct, and structs as fields that have no tag info
// so if nil or if not nil and the structonly tag isn't present
if ct == nil || ct.typeof != typeStructOnly {
var f *cField
for i := 0; i < len(cs.fields); i++ {
f = cs.fields[i]
if v.isPartial {
if v.ffn != nil {
// used with StructFiltered
if v.ffn(append(structNs, f.name...)) {
continue
}
} else {
// used with StructPartial & StructExcept
_, ok = v.includeExclude[string(append(structNs, f.name...))]
if (ok && v.hasExcludes) || (!ok && !v.hasExcludes) {
continue
}
}
}
v.traverseField(ctx, parent, current.Field(f.idx), ns, structNs, f, f.cTags)
}
}
// check if any struct level validations, after all field validations already checked.
// first iteration will have no info about nostructlevel tag, and is checked prior to
// calling the next iteration of validateStruct called from traverseField.
if cs.fn != nil {
v.slflParent = parent
v.slCurrent = current
v.ns = ns
v.actualNs = structNs
cs.fn(ctx, v)
}
} | [
"func",
"(",
"v",
"*",
"validate",
")",
"validateStruct",
"(",
"ctx",
"context",
".",
"Context",
",",
"parent",
"reflect",
".",
"Value",
",",
"current",
"reflect",
".",
"Value",
",",
"typ",
"reflect",
".",
"Type",
",",
"ns",
"[",
"]",
"byte",
",",
"structNs",
"[",
"]",
"byte",
",",
"ct",
"*",
"cTag",
")",
"{",
"cs",
",",
"ok",
":=",
"v",
".",
"v",
".",
"structCache",
".",
"Get",
"(",
"typ",
")",
"\n",
"if",
"!",
"ok",
"{",
"cs",
"=",
"v",
".",
"v",
".",
"extractStructCache",
"(",
"current",
",",
"typ",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"ns",
")",
"==",
"0",
"&&",
"len",
"(",
"cs",
".",
"name",
")",
"!=",
"0",
"{",
"ns",
"=",
"append",
"(",
"ns",
",",
"cs",
".",
"name",
"...",
")",
"\n",
"ns",
"=",
"append",
"(",
"ns",
",",
"'.'",
")",
"\n\n",
"structNs",
"=",
"append",
"(",
"structNs",
",",
"cs",
".",
"name",
"...",
")",
"\n",
"structNs",
"=",
"append",
"(",
"structNs",
",",
"'.'",
")",
"\n",
"}",
"\n\n",
"// ct is nil on top level struct, and structs as fields that have no tag info",
"// so if nil or if not nil and the structonly tag isn't present",
"if",
"ct",
"==",
"nil",
"||",
"ct",
".",
"typeof",
"!=",
"typeStructOnly",
"{",
"var",
"f",
"*",
"cField",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"cs",
".",
"fields",
")",
";",
"i",
"++",
"{",
"f",
"=",
"cs",
".",
"fields",
"[",
"i",
"]",
"\n\n",
"if",
"v",
".",
"isPartial",
"{",
"if",
"v",
".",
"ffn",
"!=",
"nil",
"{",
"// used with StructFiltered",
"if",
"v",
".",
"ffn",
"(",
"append",
"(",
"structNs",
",",
"f",
".",
"name",
"...",
")",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"}",
"else",
"{",
"// used with StructPartial & StructExcept",
"_",
",",
"ok",
"=",
"v",
".",
"includeExclude",
"[",
"string",
"(",
"append",
"(",
"structNs",
",",
"f",
".",
"name",
"...",
")",
")",
"]",
"\n\n",
"if",
"(",
"ok",
"&&",
"v",
".",
"hasExcludes",
")",
"||",
"(",
"!",
"ok",
"&&",
"!",
"v",
".",
"hasExcludes",
")",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"v",
".",
"traverseField",
"(",
"ctx",
",",
"parent",
",",
"current",
".",
"Field",
"(",
"f",
".",
"idx",
")",
",",
"ns",
",",
"structNs",
",",
"f",
",",
"f",
".",
"cTags",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// check if any struct level validations, after all field validations already checked.",
"// first iteration will have no info about nostructlevel tag, and is checked prior to",
"// calling the next iteration of validateStruct called from traverseField.",
"if",
"cs",
".",
"fn",
"!=",
"nil",
"{",
"v",
".",
"slflParent",
"=",
"parent",
"\n",
"v",
".",
"slCurrent",
"=",
"current",
"\n",
"v",
".",
"ns",
"=",
"ns",
"\n",
"v",
".",
"actualNs",
"=",
"structNs",
"\n\n",
"cs",
".",
"fn",
"(",
"ctx",
",",
"v",
")",
"\n",
"}",
"\n",
"}"
] | // parent and current will be the same the first run of validateStruct | [
"parent",
"and",
"current",
"will",
"be",
"the",
"same",
"the",
"first",
"run",
"of",
"validateStruct"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/validator.go#L33-L93 | train |
go-playground/validator | field_level.go | GetStructFieldOK | func (v *validate) GetStructFieldOK() (reflect.Value, reflect.Kind, bool) {
return v.getStructFieldOKInternal(v.slflParent, v.ct.param)
} | go | func (v *validate) GetStructFieldOK() (reflect.Value, reflect.Kind, bool) {
return v.getStructFieldOKInternal(v.slflParent, v.ct.param)
} | [
"func",
"(",
"v",
"*",
"validate",
")",
"GetStructFieldOK",
"(",
")",
"(",
"reflect",
".",
"Value",
",",
"reflect",
".",
"Kind",
",",
"bool",
")",
"{",
"return",
"v",
".",
"getStructFieldOKInternal",
"(",
"v",
".",
"slflParent",
",",
"v",
".",
"ct",
".",
"param",
")",
"\n",
"}"
] | // GetStructFieldOK returns Param returns param for validation against current field | [
"GetStructFieldOK",
"returns",
"Param",
"returns",
"param",
"for",
"validation",
"against",
"current",
"field"
] | e25e66164b537d7b3161dfede38466880534e783 | https://github.com/go-playground/validator/blob/e25e66164b537d7b3161dfede38466880534e783/field_level.go#L67-L69 | train |
muesli/beehive | api/resources/actions/actions.go | Register | func (r *ActionResource) Register(container *restful.Container, config smolder.APIConfig, context smolder.APIContextFactory) {
r.Name = "ActionResource"
r.TypeName = "action"
r.Endpoint = "actions"
r.Doc = "Manage actions"
r.Config = config
r.Context = context
r.Init(container, r)
} | go | func (r *ActionResource) Register(container *restful.Container, config smolder.APIConfig, context smolder.APIContextFactory) {
r.Name = "ActionResource"
r.TypeName = "action"
r.Endpoint = "actions"
r.Doc = "Manage actions"
r.Config = config
r.Context = context
r.Init(container, r)
} | [
"func",
"(",
"r",
"*",
"ActionResource",
")",
"Register",
"(",
"container",
"*",
"restful",
".",
"Container",
",",
"config",
"smolder",
".",
"APIConfig",
",",
"context",
"smolder",
".",
"APIContextFactory",
")",
"{",
"r",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"r",
".",
"TypeName",
"=",
"\"",
"\"",
"\n",
"r",
".",
"Endpoint",
"=",
"\"",
"\"",
"\n",
"r",
".",
"Doc",
"=",
"\"",
"\"",
"\n\n",
"r",
".",
"Config",
"=",
"config",
"\n",
"r",
".",
"Context",
"=",
"context",
"\n\n",
"r",
".",
"Init",
"(",
"container",
",",
"r",
")",
"\n",
"}"
] | // Register this resource with the container to setup all the routes | [
"Register",
"this",
"resource",
"with",
"the",
"container",
"to",
"setup",
"all",
"the",
"routes"
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/actions/actions.go#L40-L50 | train |
muesli/beehive | api/resources/bees/bees.go | Validate | func (r *BeeResource) Validate(context smolder.APIContext, data interface{}, request *restful.Request) error {
// ps := data.(*BeePostStruct)
// FIXME
return nil
} | go | func (r *BeeResource) Validate(context smolder.APIContext, data interface{}, request *restful.Request) error {
// ps := data.(*BeePostStruct)
// FIXME
return nil
} | [
"func",
"(",
"r",
"*",
"BeeResource",
")",
"Validate",
"(",
"context",
"smolder",
".",
"APIContext",
",",
"data",
"interface",
"{",
"}",
",",
"request",
"*",
"restful",
".",
"Request",
")",
"error",
"{",
"//\tps := data.(*BeePostStruct)",
"// FIXME",
"return",
"nil",
"\n",
"}"
] | // Validate checks an incoming request for data errors | [
"Validate",
"checks",
"an",
"incoming",
"request",
"for",
"data",
"errors"
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/bees/bees.go#L65-L69 | train |
muesli/beehive | bees/bees.go | RegisterBee | func RegisterBee(bee BeeInterface) {
log.Println("Worker bee ready:", bee.Name(), "-", bee.Description())
bees[bee.Name()] = &bee
} | go | func RegisterBee(bee BeeInterface) {
log.Println("Worker bee ready:", bee.Name(), "-", bee.Description())
bees[bee.Name()] = &bee
} | [
"func",
"RegisterBee",
"(",
"bee",
"BeeInterface",
")",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"bee",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
",",
"bee",
".",
"Description",
"(",
")",
")",
"\n\n",
"bees",
"[",
"bee",
".",
"Name",
"(",
")",
"]",
"=",
"&",
"bee",
"\n",
"}"
] | // RegisterBee gets called by Bees to register themselves. | [
"RegisterBee",
"gets",
"called",
"by",
"Bees",
"to",
"register",
"themselves",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L99-L103 | train |
muesli/beehive | bees/bees.go | GetBee | func GetBee(identifier string) *BeeInterface {
bee, ok := bees[identifier]
if ok {
return bee
}
return nil
} | go | func GetBee(identifier string) *BeeInterface {
bee, ok := bees[identifier]
if ok {
return bee
}
return nil
} | [
"func",
"GetBee",
"(",
"identifier",
"string",
")",
"*",
"BeeInterface",
"{",
"bee",
",",
"ok",
":=",
"bees",
"[",
"identifier",
"]",
"\n",
"if",
"ok",
"{",
"return",
"bee",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // GetBee returns a bee with a specific name. | [
"GetBee",
"returns",
"a",
"bee",
"with",
"a",
"specific",
"name",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L106-L113 | train |
muesli/beehive | bees/bees.go | GetBees | func GetBees() []*BeeInterface {
r := []*BeeInterface{}
for _, bee := range bees {
r = append(r, bee)
}
return r
} | go | func GetBees() []*BeeInterface {
r := []*BeeInterface{}
for _, bee := range bees {
r = append(r, bee)
}
return r
} | [
"func",
"GetBees",
"(",
")",
"[",
"]",
"*",
"BeeInterface",
"{",
"r",
":=",
"[",
"]",
"*",
"BeeInterface",
"{",
"}",
"\n",
"for",
"_",
",",
"bee",
":=",
"range",
"bees",
"{",
"r",
"=",
"append",
"(",
"r",
",",
"bee",
")",
"\n",
"}",
"\n\n",
"return",
"r",
"\n",
"}"
] | // GetBees returns all known bees. | [
"GetBees",
"returns",
"all",
"known",
"bees",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L116-L123 | train |
muesli/beehive | bees/bees.go | startBee | func startBee(bee *BeeInterface, fatals int) {
if fatals >= 3 {
log.Println("Terminating evil bee", (*bee).Name(), "after", fatals, "failed tries!")
(*bee).Stop()
return
}
(*bee).WaitGroup().Add(1)
defer (*bee).WaitGroup().Done()
defer func(bee *BeeInterface) {
if e := recover(); e != nil {
log.Println("Fatal bee event:", e, fatals)
go startBee(bee, fatals+1)
}
}(bee)
(*bee).Run(eventsIn)
} | go | func startBee(bee *BeeInterface, fatals int) {
if fatals >= 3 {
log.Println("Terminating evil bee", (*bee).Name(), "after", fatals, "failed tries!")
(*bee).Stop()
return
}
(*bee).WaitGroup().Add(1)
defer (*bee).WaitGroup().Done()
defer func(bee *BeeInterface) {
if e := recover(); e != nil {
log.Println("Fatal bee event:", e, fatals)
go startBee(bee, fatals+1)
}
}(bee)
(*bee).Run(eventsIn)
} | [
"func",
"startBee",
"(",
"bee",
"*",
"BeeInterface",
",",
"fatals",
"int",
")",
"{",
"if",
"fatals",
">=",
"3",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"(",
"*",
"bee",
")",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
",",
"fatals",
",",
"\"",
"\"",
")",
"\n",
"(",
"*",
"bee",
")",
".",
"Stop",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"(",
"*",
"bee",
")",
".",
"WaitGroup",
"(",
")",
".",
"Add",
"(",
"1",
")",
"\n",
"defer",
"(",
"*",
"bee",
")",
".",
"WaitGroup",
"(",
")",
".",
"Done",
"(",
")",
"\n\n",
"defer",
"func",
"(",
"bee",
"*",
"BeeInterface",
")",
"{",
"if",
"e",
":=",
"recover",
"(",
")",
";",
"e",
"!=",
"nil",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"e",
",",
"fatals",
")",
"\n",
"go",
"startBee",
"(",
"bee",
",",
"fatals",
"+",
"1",
")",
"\n",
"}",
"\n",
"}",
"(",
"bee",
")",
"\n\n",
"(",
"*",
"bee",
")",
".",
"Run",
"(",
"eventsIn",
")",
"\n",
"}"
] | // startBee starts a bee and recovers from panics. | [
"startBee",
"starts",
"a",
"bee",
"and",
"recovers",
"from",
"panics",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L126-L144 | train |
muesli/beehive | bees/bees.go | NewBeeInstance | func NewBeeInstance(bee BeeConfig) *BeeInterface {
factory := GetFactory(bee.Class)
if factory == nil {
panic("Unknown bee-class in config file: " + bee.Class)
}
mod := (*factory).New(bee.Name, bee.Description, bee.Options)
RegisterBee(mod)
return &mod
} | go | func NewBeeInstance(bee BeeConfig) *BeeInterface {
factory := GetFactory(bee.Class)
if factory == nil {
panic("Unknown bee-class in config file: " + bee.Class)
}
mod := (*factory).New(bee.Name, bee.Description, bee.Options)
RegisterBee(mod)
return &mod
} | [
"func",
"NewBeeInstance",
"(",
"bee",
"BeeConfig",
")",
"*",
"BeeInterface",
"{",
"factory",
":=",
"GetFactory",
"(",
"bee",
".",
"Class",
")",
"\n",
"if",
"factory",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"bee",
".",
"Class",
")",
"\n",
"}",
"\n",
"mod",
":=",
"(",
"*",
"factory",
")",
".",
"New",
"(",
"bee",
".",
"Name",
",",
"bee",
".",
"Description",
",",
"bee",
".",
"Options",
")",
"\n",
"RegisterBee",
"(",
"mod",
")",
"\n\n",
"return",
"&",
"mod",
"\n",
"}"
] | // NewBeeInstance sets up a new Bee with supplied config. | [
"NewBeeInstance",
"sets",
"up",
"a",
"new",
"Bee",
"with",
"supplied",
"config",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L147-L156 | train |
muesli/beehive | bees/bees.go | StartBee | func StartBee(bee BeeConfig) *BeeInterface {
b := NewBeeInstance(bee)
(*b).Start()
go func(mod *BeeInterface) {
startBee(mod, 0)
}(b)
return b
} | go | func StartBee(bee BeeConfig) *BeeInterface {
b := NewBeeInstance(bee)
(*b).Start()
go func(mod *BeeInterface) {
startBee(mod, 0)
}(b)
return b
} | [
"func",
"StartBee",
"(",
"bee",
"BeeConfig",
")",
"*",
"BeeInterface",
"{",
"b",
":=",
"NewBeeInstance",
"(",
"bee",
")",
"\n\n",
"(",
"*",
"b",
")",
".",
"Start",
"(",
")",
"\n",
"go",
"func",
"(",
"mod",
"*",
"BeeInterface",
")",
"{",
"startBee",
"(",
"mod",
",",
"0",
")",
"\n",
"}",
"(",
"b",
")",
"\n\n",
"return",
"b",
"\n",
"}"
] | // StartBee starts a bee. | [
"StartBee",
"starts",
"a",
"bee",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L166-L175 | train |
muesli/beehive | bees/bees.go | StartBees | func StartBees(beeList []BeeConfig) {
eventsIn = make(chan Event)
go handleEvents()
for _, bee := range beeList {
StartBee(bee)
}
} | go | func StartBees(beeList []BeeConfig) {
eventsIn = make(chan Event)
go handleEvents()
for _, bee := range beeList {
StartBee(bee)
}
} | [
"func",
"StartBees",
"(",
"beeList",
"[",
"]",
"BeeConfig",
")",
"{",
"eventsIn",
"=",
"make",
"(",
"chan",
"Event",
")",
"\n",
"go",
"handleEvents",
"(",
")",
"\n\n",
"for",
"_",
",",
"bee",
":=",
"range",
"beeList",
"{",
"StartBee",
"(",
"bee",
")",
"\n",
"}",
"\n",
"}"
] | // StartBees starts all registered bees. | [
"StartBees",
"starts",
"all",
"registered",
"bees",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L178-L185 | train |
muesli/beehive | bees/bees.go | StopBees | func StopBees() {
for _, bee := range bees {
log.Println("Stopping bee:", (*bee).Name())
(*bee).Stop()
}
close(eventsIn)
bees = make(map[string]*BeeInterface)
} | go | func StopBees() {
for _, bee := range bees {
log.Println("Stopping bee:", (*bee).Name())
(*bee).Stop()
}
close(eventsIn)
bees = make(map[string]*BeeInterface)
} | [
"func",
"StopBees",
"(",
")",
"{",
"for",
"_",
",",
"bee",
":=",
"range",
"bees",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"(",
"*",
"bee",
")",
".",
"Name",
"(",
")",
")",
"\n",
"(",
"*",
"bee",
")",
".",
"Stop",
"(",
")",
"\n",
"}",
"\n\n",
"close",
"(",
"eventsIn",
")",
"\n",
"bees",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"BeeInterface",
")",
"\n",
"}"
] | // StopBees stops all bees gracefully. | [
"StopBees",
"stops",
"all",
"bees",
"gracefully",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L188-L196 | train |
muesli/beehive | bees/bees.go | RestartBee | func RestartBee(bee *BeeInterface) {
(*bee).Stop()
(*bee).SetSigChan(make(chan bool))
(*bee).Start()
go func(mod *BeeInterface) {
startBee(mod, 0)
}(bee)
} | go | func RestartBee(bee *BeeInterface) {
(*bee).Stop()
(*bee).SetSigChan(make(chan bool))
(*bee).Start()
go func(mod *BeeInterface) {
startBee(mod, 0)
}(bee)
} | [
"func",
"RestartBee",
"(",
"bee",
"*",
"BeeInterface",
")",
"{",
"(",
"*",
"bee",
")",
".",
"Stop",
"(",
")",
"\n\n",
"(",
"*",
"bee",
")",
".",
"SetSigChan",
"(",
"make",
"(",
"chan",
"bool",
")",
")",
"\n",
"(",
"*",
"bee",
")",
".",
"Start",
"(",
")",
"\n",
"go",
"func",
"(",
"mod",
"*",
"BeeInterface",
")",
"{",
"startBee",
"(",
"mod",
",",
"0",
")",
"\n",
"}",
"(",
"bee",
")",
"\n",
"}"
] | // RestartBee restarts a Bee. | [
"RestartBee",
"restarts",
"a",
"Bee",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L199-L207 | train |
muesli/beehive | bees/bees.go | NewBee | func NewBee(name, factoryName, description string, options []BeeOption) Bee {
c := BeeConfig{
Name: name,
Class: factoryName,
Description: description,
Options: options,
}
b := Bee{
config: c,
SigChan: make(chan bool),
waitGroup: &sync.WaitGroup{},
}
return b
} | go | func NewBee(name, factoryName, description string, options []BeeOption) Bee {
c := BeeConfig{
Name: name,
Class: factoryName,
Description: description,
Options: options,
}
b := Bee{
config: c,
SigChan: make(chan bool),
waitGroup: &sync.WaitGroup{},
}
return b
} | [
"func",
"NewBee",
"(",
"name",
",",
"factoryName",
",",
"description",
"string",
",",
"options",
"[",
"]",
"BeeOption",
")",
"Bee",
"{",
"c",
":=",
"BeeConfig",
"{",
"Name",
":",
"name",
",",
"Class",
":",
"factoryName",
",",
"Description",
":",
"description",
",",
"Options",
":",
"options",
",",
"}",
"\n",
"b",
":=",
"Bee",
"{",
"config",
":",
"c",
",",
"SigChan",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"waitGroup",
":",
"&",
"sync",
".",
"WaitGroup",
"{",
"}",
",",
"}",
"\n\n",
"return",
"b",
"\n",
"}"
] | // NewBee returns a new bee and sets up sig-channel & waitGroup. | [
"NewBee",
"returns",
"a",
"new",
"bee",
"and",
"sets",
"up",
"sig",
"-",
"channel",
"&",
"waitGroup",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L216-L230 | train |
muesli/beehive | bees/bees.go | Stop | func (bee *Bee) Stop() {
if !bee.IsRunning() {
return
}
log.Println(bee.Name(), "stopping gracefully!")
close(bee.SigChan)
bee.waitGroup.Wait()
bee.Running = false
log.Println(bee.Name(), "stopped gracefully!")
} | go | func (bee *Bee) Stop() {
if !bee.IsRunning() {
return
}
log.Println(bee.Name(), "stopping gracefully!")
close(bee.SigChan)
bee.waitGroup.Wait()
bee.Running = false
log.Println(bee.Name(), "stopped gracefully!")
} | [
"func",
"(",
"bee",
"*",
"Bee",
")",
"Stop",
"(",
")",
"{",
"if",
"!",
"bee",
".",
"IsRunning",
"(",
")",
"{",
"return",
"\n",
"}",
"\n",
"log",
".",
"Println",
"(",
"bee",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
")",
"\n\n",
"close",
"(",
"bee",
".",
"SigChan",
")",
"\n",
"bee",
".",
"waitGroup",
".",
"Wait",
"(",
")",
"\n",
"bee",
".",
"Running",
"=",
"false",
"\n",
"log",
".",
"Println",
"(",
"bee",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Stop gracefully stops a Bee. | [
"Stop",
"gracefully",
"stops",
"a",
"Bee",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L301-L311 | train |
muesli/beehive | bees/bees.go | Logln | func (bee *Bee) Logln(args ...interface{}) {
a := []interface{}{"[" + bee.Name() + "]:"}
for _, v := range args {
a = append(a, v)
}
log.Println(a...)
Log(bee.Name(), fmt.Sprintln(args...), 0)
} | go | func (bee *Bee) Logln(args ...interface{}) {
a := []interface{}{"[" + bee.Name() + "]:"}
for _, v := range args {
a = append(a, v)
}
log.Println(a...)
Log(bee.Name(), fmt.Sprintln(args...), 0)
} | [
"func",
"(",
"bee",
"*",
"Bee",
")",
"Logln",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"a",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
"+",
"bee",
".",
"Name",
"(",
")",
"+",
"\"",
"\"",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"args",
"{",
"a",
"=",
"append",
"(",
"a",
",",
"v",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Println",
"(",
"a",
"...",
")",
"\n",
"Log",
"(",
"bee",
".",
"Name",
"(",
")",
",",
"fmt",
".",
"Sprintln",
"(",
"args",
"...",
")",
",",
"0",
")",
"\n",
"}"
] | // Logln logs args | [
"Logln",
"logs",
"args"
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L334-L342 | train |
muesli/beehive | bees/bees.go | Logf | func (bee *Bee) Logf(format string, args ...interface{}) {
s := fmt.Sprintf(format, args...)
log.Printf("[%s]: %s", bee.Name(), s)
Log(bee.Name(), s, 0)
} | go | func (bee *Bee) Logf(format string, args ...interface{}) {
s := fmt.Sprintf(format, args...)
log.Printf("[%s]: %s", bee.Name(), s)
Log(bee.Name(), s, 0)
} | [
"func",
"(",
"bee",
"*",
"Bee",
")",
"Logf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"s",
":=",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"args",
"...",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"bee",
".",
"Name",
"(",
")",
",",
"s",
")",
"\n",
"Log",
"(",
"bee",
".",
"Name",
"(",
")",
",",
"s",
",",
"0",
")",
"\n",
"}"
] | // Logf logs a formatted string | [
"Logf",
"logs",
"a",
"formatted",
"string"
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L345-L349 | train |
muesli/beehive | bees/bees.go | LogErrorf | func (bee *Bee) LogErrorf(format string, args ...interface{}) {
s := fmt.Sprintf(format, args...)
log.Errorf("[%s]: %s", bee.Name(), s)
Log(bee.Name(), s, 1)
} | go | func (bee *Bee) LogErrorf(format string, args ...interface{}) {
s := fmt.Sprintf(format, args...)
log.Errorf("[%s]: %s", bee.Name(), s)
Log(bee.Name(), s, 1)
} | [
"func",
"(",
"bee",
"*",
"Bee",
")",
"LogErrorf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"s",
":=",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"args",
"...",
")",
"\n",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"bee",
".",
"Name",
"(",
")",
",",
"s",
")",
"\n",
"Log",
"(",
"bee",
".",
"Name",
"(",
")",
",",
"s",
",",
"1",
")",
"\n",
"}"
] | // LogErrorf logs a formatted error string | [
"LogErrorf",
"logs",
"a",
"formatted",
"error",
"string"
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L352-L356 | train |
muesli/beehive | bees/bees.go | LogFatal | func (bee *Bee) LogFatal(args ...interface{}) {
a := []interface{}{"[" + bee.Name() + "]:"}
for _, v := range args {
a = append(a, v)
}
log.Panicln(a...)
Log(bee.Name(), fmt.Sprintln(args...), 2)
} | go | func (bee *Bee) LogFatal(args ...interface{}) {
a := []interface{}{"[" + bee.Name() + "]:"}
for _, v := range args {
a = append(a, v)
}
log.Panicln(a...)
Log(bee.Name(), fmt.Sprintln(args...), 2)
} | [
"func",
"(",
"bee",
"*",
"Bee",
")",
"LogFatal",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"a",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
"+",
"bee",
".",
"Name",
"(",
")",
"+",
"\"",
"\"",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"args",
"{",
"a",
"=",
"append",
"(",
"a",
",",
"v",
")",
"\n",
"}",
"\n",
"log",
".",
"Panicln",
"(",
"a",
"...",
")",
"\n",
"Log",
"(",
"bee",
".",
"Name",
"(",
")",
",",
"fmt",
".",
"Sprintln",
"(",
"args",
"...",
")",
",",
"2",
")",
"\n",
"}"
] | // LogFatal logs a fatal error | [
"LogFatal",
"logs",
"a",
"fatal",
"error"
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/bees.go#L359-L366 | train |
muesli/beehive | bees/events.go | handleEvents | func handleEvents() {
for {
event, ok := <-eventsIn
if !ok {
log.Println()
log.Println("Stopped event handler!")
break
}
bee := GetBee(event.Bee)
(*bee).LogEvent()
log.Println()
log.Println("Event received:", event.Bee, "/", event.Name, "-", GetEventDescriptor(&event).Description)
for _, v := range event.Options {
log.Println("\tOptions:", v)
}
go func() {
defer func() {
if e := recover(); e != nil {
log.Printf("Fatal chain event: %s %s", e, debug.Stack())
}
}()
execChains(&event)
}()
}
} | go | func handleEvents() {
for {
event, ok := <-eventsIn
if !ok {
log.Println()
log.Println("Stopped event handler!")
break
}
bee := GetBee(event.Bee)
(*bee).LogEvent()
log.Println()
log.Println("Event received:", event.Bee, "/", event.Name, "-", GetEventDescriptor(&event).Description)
for _, v := range event.Options {
log.Println("\tOptions:", v)
}
go func() {
defer func() {
if e := recover(); e != nil {
log.Printf("Fatal chain event: %s %s", e, debug.Stack())
}
}()
execChains(&event)
}()
}
} | [
"func",
"handleEvents",
"(",
")",
"{",
"for",
"{",
"event",
",",
"ok",
":=",
"<-",
"eventsIn",
"\n",
"if",
"!",
"ok",
"{",
"log",
".",
"Println",
"(",
")",
"\n",
"log",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"break",
"\n",
"}",
"\n\n",
"bee",
":=",
"GetBee",
"(",
"event",
".",
"Bee",
")",
"\n",
"(",
"*",
"bee",
")",
".",
"LogEvent",
"(",
")",
"\n\n",
"log",
".",
"Println",
"(",
")",
"\n",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"event",
".",
"Bee",
",",
"\"",
"\"",
",",
"event",
".",
"Name",
",",
"\"",
"\"",
",",
"GetEventDescriptor",
"(",
"&",
"event",
")",
".",
"Description",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"event",
".",
"Options",
"{",
"log",
".",
"Println",
"(",
"\"",
"\\t",
"\"",
",",
"v",
")",
"\n",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"e",
":=",
"recover",
"(",
")",
";",
"e",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"e",
",",
"debug",
".",
"Stack",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"execChains",
"(",
"&",
"event",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // handleEvents handles incoming events and executes matching Chains. | [
"handleEvents",
"handles",
"incoming",
"events",
"and",
"executes",
"matching",
"Chains",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/events.go#L39-L67 | train |
muesli/beehive | filters/filters.go | GetFilter | func GetFilter(identifier string) *FilterInterface {
filter, ok := filters[identifier]
if ok {
return filter
}
return nil
} | go | func GetFilter(identifier string) *FilterInterface {
filter, ok := filters[identifier]
if ok {
return filter
}
return nil
} | [
"func",
"GetFilter",
"(",
"identifier",
"string",
")",
"*",
"FilterInterface",
"{",
"filter",
",",
"ok",
":=",
"filters",
"[",
"identifier",
"]",
"\n",
"if",
"ok",
"{",
"return",
"filter",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // GetFilter returns a filter with a specific name | [
"GetFilter",
"returns",
"a",
"filter",
"with",
"a",
"specific",
"name"
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/filters/filters.go#L46-L53 | train |
muesli/beehive | api/resources/actions/actions_response.go | AddAction | func (r *ActionResponse) AddAction(action *bees.Action) {
r.actions = append(r.actions, action)
r.Actions = append(r.Actions, prepareActionResponse(r.Context, action))
} | go | func (r *ActionResponse) AddAction(action *bees.Action) {
r.actions = append(r.actions, action)
r.Actions = append(r.Actions, prepareActionResponse(r.Context, action))
} | [
"func",
"(",
"r",
"*",
"ActionResponse",
")",
"AddAction",
"(",
"action",
"*",
"bees",
".",
"Action",
")",
"{",
"r",
".",
"actions",
"=",
"append",
"(",
"r",
".",
"actions",
",",
"action",
")",
"\n",
"r",
".",
"Actions",
"=",
"append",
"(",
"r",
".",
"Actions",
",",
"prepareActionResponse",
"(",
"r",
".",
"Context",
",",
"action",
")",
")",
"\n",
"}"
] | // AddAction adds a action to the response | [
"AddAction",
"adds",
"a",
"action",
"to",
"the",
"response"
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/actions/actions_response.go#L53-L56 | train |
muesli/beehive | api/resources/logs/logs_response.go | AddLog | func (r *LogResponse) AddLog(log *bees.LogMessage) {
r.logs = append(r.logs, log)
r.Logs = append(r.Logs, prepareLogResponse(r.Context, log))
} | go | func (r *LogResponse) AddLog(log *bees.LogMessage) {
r.logs = append(r.logs, log)
r.Logs = append(r.Logs, prepareLogResponse(r.Context, log))
} | [
"func",
"(",
"r",
"*",
"LogResponse",
")",
"AddLog",
"(",
"log",
"*",
"bees",
".",
"LogMessage",
")",
"{",
"r",
".",
"logs",
"=",
"append",
"(",
"r",
".",
"logs",
",",
"log",
")",
"\n",
"r",
".",
"Logs",
"=",
"append",
"(",
"r",
".",
"Logs",
",",
"prepareLogResponse",
"(",
"r",
".",
"Context",
",",
"log",
")",
")",
"\n",
"}"
] | // AddLog adds a log to the response | [
"AddLog",
"adds",
"a",
"log",
"to",
"the",
"response"
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/logs/logs_response.go#L56-L59 | train |
muesli/beehive | bees/actions.go | GetAction | func GetAction(id string) *Action {
for _, a := range actions {
if a.ID == id {
return &a
}
}
return nil
} | go | func GetAction(id string) *Action {
for _, a := range actions {
if a.ID == id {
return &a
}
}
return nil
} | [
"func",
"GetAction",
"(",
"id",
"string",
")",
"*",
"Action",
"{",
"for",
"_",
",",
"a",
":=",
"range",
"actions",
"{",
"if",
"a",
".",
"ID",
"==",
"id",
"{",
"return",
"&",
"a",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // GetAction returns one action with a specific ID. | [
"GetAction",
"returns",
"one",
"action",
"with",
"a",
"specific",
"ID",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/actions.go#L51-L59 | train |
muesli/beehive | bees/actions.go | execAction | func execAction(action Action, opts map[string]interface{}) bool {
a := Action{
Bee: action.Bee,
Name: action.Name,
}
for _, opt := range action.Options {
ph := Placeholder{
Name: opt.Name,
}
switch opt.Value.(type) {
case string:
var value bytes.Buffer
tmpl, err := template.New(action.Bee + "_" + action.Name + "_" + opt.Name).Funcs(templatehelper.FuncMap).Parse(opt.Value.(string))
if err == nil {
err = tmpl.Execute(&value, opts)
}
if err != nil {
panic(err)
}
ph.Type = "string"
ph.Value = value.String()
default:
ph.Type = opt.Type
ph.Value = opt.Value
}
a.Options = append(a.Options, ph)
}
bee := GetBee(a.Bee)
if (*bee).IsRunning() {
(*bee).LogAction()
log.Println("\tExecuting action:", a.Bee, "/", a.Name, "-", GetActionDescriptor(&a).Description)
for _, v := range a.Options {
log.Println("\t\tOptions:", v)
}
(*bee).Action(a)
} else {
log.Println("\tNot executing action on stopped bee:", a.Bee, "/", a.Name, "-", GetActionDescriptor(&a).Description)
for _, v := range a.Options {
log.Println("\t\tOptions:", v)
}
}
return true
} | go | func execAction(action Action, opts map[string]interface{}) bool {
a := Action{
Bee: action.Bee,
Name: action.Name,
}
for _, opt := range action.Options {
ph := Placeholder{
Name: opt.Name,
}
switch opt.Value.(type) {
case string:
var value bytes.Buffer
tmpl, err := template.New(action.Bee + "_" + action.Name + "_" + opt.Name).Funcs(templatehelper.FuncMap).Parse(opt.Value.(string))
if err == nil {
err = tmpl.Execute(&value, opts)
}
if err != nil {
panic(err)
}
ph.Type = "string"
ph.Value = value.String()
default:
ph.Type = opt.Type
ph.Value = opt.Value
}
a.Options = append(a.Options, ph)
}
bee := GetBee(a.Bee)
if (*bee).IsRunning() {
(*bee).LogAction()
log.Println("\tExecuting action:", a.Bee, "/", a.Name, "-", GetActionDescriptor(&a).Description)
for _, v := range a.Options {
log.Println("\t\tOptions:", v)
}
(*bee).Action(a)
} else {
log.Println("\tNot executing action on stopped bee:", a.Bee, "/", a.Name, "-", GetActionDescriptor(&a).Description)
for _, v := range a.Options {
log.Println("\t\tOptions:", v)
}
}
return true
} | [
"func",
"execAction",
"(",
"action",
"Action",
",",
"opts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"bool",
"{",
"a",
":=",
"Action",
"{",
"Bee",
":",
"action",
".",
"Bee",
",",
"Name",
":",
"action",
".",
"Name",
",",
"}",
"\n\n",
"for",
"_",
",",
"opt",
":=",
"range",
"action",
".",
"Options",
"{",
"ph",
":=",
"Placeholder",
"{",
"Name",
":",
"opt",
".",
"Name",
",",
"}",
"\n\n",
"switch",
"opt",
".",
"Value",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"var",
"value",
"bytes",
".",
"Buffer",
"\n\n",
"tmpl",
",",
"err",
":=",
"template",
".",
"New",
"(",
"action",
".",
"Bee",
"+",
"\"",
"\"",
"+",
"action",
".",
"Name",
"+",
"\"",
"\"",
"+",
"opt",
".",
"Name",
")",
".",
"Funcs",
"(",
"templatehelper",
".",
"FuncMap",
")",
".",
"Parse",
"(",
"opt",
".",
"Value",
".",
"(",
"string",
")",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"tmpl",
".",
"Execute",
"(",
"&",
"value",
",",
"opts",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"ph",
".",
"Type",
"=",
"\"",
"\"",
"\n",
"ph",
".",
"Value",
"=",
"value",
".",
"String",
"(",
")",
"\n\n",
"default",
":",
"ph",
".",
"Type",
"=",
"opt",
".",
"Type",
"\n",
"ph",
".",
"Value",
"=",
"opt",
".",
"Value",
"\n",
"}",
"\n",
"a",
".",
"Options",
"=",
"append",
"(",
"a",
".",
"Options",
",",
"ph",
")",
"\n",
"}",
"\n\n",
"bee",
":=",
"GetBee",
"(",
"a",
".",
"Bee",
")",
"\n",
"if",
"(",
"*",
"bee",
")",
".",
"IsRunning",
"(",
")",
"{",
"(",
"*",
"bee",
")",
".",
"LogAction",
"(",
")",
"\n\n",
"log",
".",
"Println",
"(",
"\"",
"\\t",
"\"",
",",
"a",
".",
"Bee",
",",
"\"",
"\"",
",",
"a",
".",
"Name",
",",
"\"",
"\"",
",",
"GetActionDescriptor",
"(",
"&",
"a",
")",
".",
"Description",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"a",
".",
"Options",
"{",
"log",
".",
"Println",
"(",
"\"",
"\\t",
"\\t",
"\"",
",",
"v",
")",
"\n",
"}",
"\n\n",
"(",
"*",
"bee",
")",
".",
"Action",
"(",
"a",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Println",
"(",
"\"",
"\\t",
"\"",
",",
"a",
".",
"Bee",
",",
"\"",
"\"",
",",
"a",
".",
"Name",
",",
"\"",
"\"",
",",
"GetActionDescriptor",
"(",
"&",
"a",
")",
".",
"Description",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"a",
".",
"Options",
"{",
"log",
".",
"Println",
"(",
"\"",
"\\t",
"\\t",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // execAction executes an action and map its ins & outs. | [
"execAction",
"executes",
"an",
"action",
"and",
"map",
"its",
"ins",
"&",
"outs",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/actions.go#L67-L118 | train |
muesli/beehive | api/context/context.go | NewAPIContext | func (context *APIContext) NewAPIContext() smolder.APIContext {
ctx := &APIContext{
Config: context.Config,
}
return ctx
} | go | func (context *APIContext) NewAPIContext() smolder.APIContext {
ctx := &APIContext{
Config: context.Config,
}
return ctx
} | [
"func",
"(",
"context",
"*",
"APIContext",
")",
"NewAPIContext",
"(",
")",
"smolder",
".",
"APIContext",
"{",
"ctx",
":=",
"&",
"APIContext",
"{",
"Config",
":",
"context",
".",
"Config",
",",
"}",
"\n",
"return",
"ctx",
"\n",
"}"
] | // NewAPIContext returns a new polly context | [
"NewAPIContext",
"returns",
"a",
"new",
"polly",
"context"
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/context/context.go#L36-L41 | train |
muesli/beehive | bees/placeholders.go | SetValue | func (ph *Placeholders) SetValue(name string, _type string, value interface{}) {
if ph.Value(name) == nil {
p := Placeholder{
Name: name,
Type: _type,
Value: value,
}
*ph = append(*ph, p)
} else {
for i := 0; i < len(*ph); i++ {
if (*ph)[i].Name == name {
(*ph)[i].Type = _type
(*ph)[i].Value = value
}
}
}
} | go | func (ph *Placeholders) SetValue(name string, _type string, value interface{}) {
if ph.Value(name) == nil {
p := Placeholder{
Name: name,
Type: _type,
Value: value,
}
*ph = append(*ph, p)
} else {
for i := 0; i < len(*ph); i++ {
if (*ph)[i].Name == name {
(*ph)[i].Type = _type
(*ph)[i].Value = value
}
}
}
} | [
"func",
"(",
"ph",
"*",
"Placeholders",
")",
"SetValue",
"(",
"name",
"string",
",",
"_type",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"if",
"ph",
".",
"Value",
"(",
"name",
")",
"==",
"nil",
"{",
"p",
":=",
"Placeholder",
"{",
"Name",
":",
"name",
",",
"Type",
":",
"_type",
",",
"Value",
":",
"value",
",",
"}",
"\n",
"*",
"ph",
"=",
"append",
"(",
"*",
"ph",
",",
"p",
")",
"\n",
"}",
"else",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"*",
"ph",
")",
";",
"i",
"++",
"{",
"if",
"(",
"*",
"ph",
")",
"[",
"i",
"]",
".",
"Name",
"==",
"name",
"{",
"(",
"*",
"ph",
")",
"[",
"i",
"]",
".",
"Type",
"=",
"_type",
"\n",
"(",
"*",
"ph",
")",
"[",
"i",
"]",
".",
"Value",
"=",
"value",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // SetValue sets a value in the Placeholder slice. | [
"SetValue",
"sets",
"a",
"value",
"in",
"the",
"Placeholder",
"slice",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/placeholders.go#L45-L61 | train |
muesli/beehive | bees/placeholders.go | Value | func (ph Placeholders) Value(name string) interface{} {
for _, p := range ph {
if p.Name == name {
return p.Value
}
}
return nil
} | go | func (ph Placeholders) Value(name string) interface{} {
for _, p := range ph {
if p.Name == name {
return p.Value
}
}
return nil
} | [
"func",
"(",
"ph",
"Placeholders",
")",
"Value",
"(",
"name",
"string",
")",
"interface",
"{",
"}",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"ph",
"{",
"if",
"p",
".",
"Name",
"==",
"name",
"{",
"return",
"p",
".",
"Value",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Value retrieves a value from a Placeholder slice. | [
"Value",
"retrieves",
"a",
"value",
"from",
"a",
"Placeholder",
"slice",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/placeholders.go#L64-L72 | train |
muesli/beehive | bees/placeholders.go | Bind | func (ph Placeholders) Bind(name string, dst interface{}) error {
v := ph.Value(name)
if v == nil {
return errors.New("Placeholder with name " + name + " not found")
}
return ConvertValue(v, dst)
} | go | func (ph Placeholders) Bind(name string, dst interface{}) error {
v := ph.Value(name)
if v == nil {
return errors.New("Placeholder with name " + name + " not found")
}
return ConvertValue(v, dst)
} | [
"func",
"(",
"ph",
"Placeholders",
")",
"Bind",
"(",
"name",
"string",
",",
"dst",
"interface",
"{",
"}",
")",
"error",
"{",
"v",
":=",
"ph",
".",
"Value",
"(",
"name",
")",
"\n",
"if",
"v",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"name",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"ConvertValue",
"(",
"v",
",",
"dst",
")",
"\n",
"}"
] | // Bind a value from a Placeholder slice. | [
"Bind",
"a",
"value",
"from",
"a",
"Placeholder",
"slice",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/placeholders.go#L75-L82 | train |
muesli/beehive | bees/descriptors.go | GetActionDescriptor | func GetActionDescriptor(action *Action) ActionDescriptor {
bee := GetBee(action.Bee)
if bee == nil {
panic("Bee " + action.Bee + " not registered")
}
factory := (*GetFactory((*bee).Namespace()))
for _, ac := range factory.Actions() {
if ac.Name == action.Name {
return ac
}
}
return ActionDescriptor{}
} | go | func GetActionDescriptor(action *Action) ActionDescriptor {
bee := GetBee(action.Bee)
if bee == nil {
panic("Bee " + action.Bee + " not registered")
}
factory := (*GetFactory((*bee).Namespace()))
for _, ac := range factory.Actions() {
if ac.Name == action.Name {
return ac
}
}
return ActionDescriptor{}
} | [
"func",
"GetActionDescriptor",
"(",
"action",
"*",
"Action",
")",
"ActionDescriptor",
"{",
"bee",
":=",
"GetBee",
"(",
"action",
".",
"Bee",
")",
"\n",
"if",
"bee",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"action",
".",
"Bee",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"factory",
":=",
"(",
"*",
"GetFactory",
"(",
"(",
"*",
"bee",
")",
".",
"Namespace",
"(",
")",
")",
")",
"\n",
"for",
"_",
",",
"ac",
":=",
"range",
"factory",
".",
"Actions",
"(",
")",
"{",
"if",
"ac",
".",
"Name",
"==",
"action",
".",
"Name",
"{",
"return",
"ac",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"ActionDescriptor",
"{",
"}",
"\n",
"}"
] | // GetActionDescriptor returns the ActionDescriptor matching an action. | [
"GetActionDescriptor",
"returns",
"the",
"ActionDescriptor",
"matching",
"an",
"action",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/descriptors.go#L65-L78 | train |
muesli/beehive | bees/descriptors.go | GetEventDescriptor | func GetEventDescriptor(event *Event) EventDescriptor {
bee := GetBee(event.Bee)
if bee == nil {
panic("Bee " + event.Bee + " not registered")
}
factory := (*GetFactory((*bee).Namespace()))
for _, ev := range factory.Events() {
if ev.Name == event.Name {
return ev
}
}
return EventDescriptor{}
} | go | func GetEventDescriptor(event *Event) EventDescriptor {
bee := GetBee(event.Bee)
if bee == nil {
panic("Bee " + event.Bee + " not registered")
}
factory := (*GetFactory((*bee).Namespace()))
for _, ev := range factory.Events() {
if ev.Name == event.Name {
return ev
}
}
return EventDescriptor{}
} | [
"func",
"GetEventDescriptor",
"(",
"event",
"*",
"Event",
")",
"EventDescriptor",
"{",
"bee",
":=",
"GetBee",
"(",
"event",
".",
"Bee",
")",
"\n",
"if",
"bee",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"event",
".",
"Bee",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"factory",
":=",
"(",
"*",
"GetFactory",
"(",
"(",
"*",
"bee",
")",
".",
"Namespace",
"(",
")",
")",
")",
"\n",
"for",
"_",
",",
"ev",
":=",
"range",
"factory",
".",
"Events",
"(",
")",
"{",
"if",
"ev",
".",
"Name",
"==",
"event",
".",
"Name",
"{",
"return",
"ev",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"EventDescriptor",
"{",
"}",
"\n",
"}"
] | // GetEventDescriptor returns the EventDescriptor matching an event. | [
"GetEventDescriptor",
"returns",
"the",
"EventDescriptor",
"matching",
"an",
"event",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/descriptors.go#L81-L94 | train |
muesli/beehive | bees/ircbee/ircbeefactory.go | States | func (factory *IrcBeeFactory) States() []bees.StateDescriptor {
opts := []bees.StateDescriptor{
{
Name: "connected",
Description: "Whether this bee is currently connected to IRC",
Type: "bool",
},
{
Name: "channels",
Description: "Which channels this bee is currently connected to",
Type: "[]string",
},
}
return opts
} | go | func (factory *IrcBeeFactory) States() []bees.StateDescriptor {
opts := []bees.StateDescriptor{
{
Name: "connected",
Description: "Whether this bee is currently connected to IRC",
Type: "bool",
},
{
Name: "channels",
Description: "Which channels this bee is currently connected to",
Type: "[]string",
},
}
return opts
} | [
"func",
"(",
"factory",
"*",
"IrcBeeFactory",
")",
"States",
"(",
")",
"[",
"]",
"bees",
".",
"StateDescriptor",
"{",
"opts",
":=",
"[",
"]",
"bees",
".",
"StateDescriptor",
"{",
"{",
"Name",
":",
"\"",
"\"",
",",
"Description",
":",
"\"",
"\"",
",",
"Type",
":",
"\"",
"\"",
",",
"}",
",",
"{",
"Name",
":",
"\"",
"\"",
",",
"Description",
":",
"\"",
"\"",
",",
"Type",
":",
"\"",
"\"",
",",
"}",
",",
"}",
"\n",
"return",
"opts",
"\n",
"}"
] | // States returns the state values provided by this Bee. | [
"States",
"returns",
"the",
"state",
"values",
"provided",
"by",
"this",
"Bee",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/ircbee/ircbeefactory.go#L105-L119 | train |
muesli/beehive | api/resources/chains/chains_response.go | AddChain | func (r *ChainResponse) AddChain(chain bees.Chain) {
r.chains[chain.Name] = &chain
} | go | func (r *ChainResponse) AddChain(chain bees.Chain) {
r.chains[chain.Name] = &chain
} | [
"func",
"(",
"r",
"*",
"ChainResponse",
")",
"AddChain",
"(",
"chain",
"bees",
".",
"Chain",
")",
"{",
"r",
".",
"chains",
"[",
"chain",
".",
"Name",
"]",
"=",
"&",
"chain",
"\n",
"}"
] | // AddChain adds a chain to the response | [
"AddChain",
"adds",
"a",
"chain",
"to",
"the",
"response"
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/chains/chains_response.go#L58-L60 | train |
muesli/beehive | bees/cronbee/cron/cronparser.go | checkValues | func (c *crontime) checkValues() {
for _, sec := range c.second {
if sec >= 60 || sec < 0 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"Second\".")
}
}
for _, min := range c.second {
if min >= 60 || min < 0 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"Minute\".")
}
}
for _, hour := range c.hour {
if hour >= 24 || hour < 0 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"Hour\".")
}
}
for _, dow := range c.dow {
if dow >= 7 || dow < 0 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"DayOfWeek\".")
}
}
for _, dom := range c.dom {
if dom >= 32 || dom < 1 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"DayOfMonth\".")
}
}
for _, month := range c.month {
if month >= 13 || month < 1 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"Month\".")
}
}
} | go | func (c *crontime) checkValues() {
for _, sec := range c.second {
if sec >= 60 || sec < 0 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"Second\".")
}
}
for _, min := range c.second {
if min >= 60 || min < 0 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"Minute\".")
}
}
for _, hour := range c.hour {
if hour >= 24 || hour < 0 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"Hour\".")
}
}
for _, dow := range c.dow {
if dow >= 7 || dow < 0 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"DayOfWeek\".")
}
}
for _, dom := range c.dom {
if dom >= 32 || dom < 1 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"DayOfMonth\".")
}
}
for _, month := range c.month {
if month >= 13 || month < 1 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"Month\".")
}
}
} | [
"func",
"(",
"c",
"*",
"crontime",
")",
"checkValues",
"(",
")",
"{",
"for",
"_",
",",
"sec",
":=",
"range",
"c",
".",
"second",
"{",
"if",
"sec",
">=",
"60",
"||",
"sec",
"<",
"0",
"{",
"log",
".",
"Panicln",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"min",
":=",
"range",
"c",
".",
"second",
"{",
"if",
"min",
">=",
"60",
"||",
"min",
"<",
"0",
"{",
"log",
".",
"Panicln",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"hour",
":=",
"range",
"c",
".",
"hour",
"{",
"if",
"hour",
">=",
"24",
"||",
"hour",
"<",
"0",
"{",
"log",
".",
"Panicln",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"dow",
":=",
"range",
"c",
".",
"dow",
"{",
"if",
"dow",
">=",
"7",
"||",
"dow",
"<",
"0",
"{",
"log",
".",
"Panicln",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"dom",
":=",
"range",
"c",
".",
"dom",
"{",
"if",
"dom",
">=",
"32",
"||",
"dom",
"<",
"1",
"{",
"log",
".",
"Panicln",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"month",
":=",
"range",
"c",
".",
"month",
"{",
"if",
"month",
">=",
"13",
"||",
"month",
"<",
"1",
"{",
"log",
".",
"Panicln",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Look for obvious nonsense in the config. | [
"Look",
"for",
"obvious",
"nonsense",
"in",
"the",
"config",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/cronparser.go#L285-L321 | train |
muesli/beehive | bees/cronbee/cron/cronparser.go | valueRange | func valueRange(a, b, base int) []int {
value := make([]int, absoluteOverBreakpoint(a, b, base)+1)
i := 0
for ; a != b; a++ {
if a == base {
a = 0
}
value[i] = a
i++
}
value[i] = a
return value
} | go | func valueRange(a, b, base int) []int {
value := make([]int, absoluteOverBreakpoint(a, b, base)+1)
i := 0
for ; a != b; a++ {
if a == base {
a = 0
}
value[i] = a
i++
}
value[i] = a
return value
} | [
"func",
"valueRange",
"(",
"a",
",",
"b",
",",
"base",
"int",
")",
"[",
"]",
"int",
"{",
"value",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"absoluteOverBreakpoint",
"(",
"a",
",",
"b",
",",
"base",
")",
"+",
"1",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
";",
"a",
"!=",
"b",
";",
"a",
"++",
"{",
"if",
"a",
"==",
"base",
"{",
"a",
"=",
"0",
"\n",
"}",
"\n",
"value",
"[",
"i",
"]",
"=",
"a",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"value",
"[",
"i",
"]",
"=",
"a",
"\n",
"return",
"value",
"\n",
"}"
] | // Returns an array filled with all values between a and b considering
// the base. | [
"Returns",
"an",
"array",
"filled",
"with",
"all",
"values",
"between",
"a",
"and",
"b",
"considering",
"the",
"base",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/cronparser.go#L346-L358 | train |
muesli/beehive | bees/logs.go | NewLogMessage | func NewLogMessage(bee string, message string, messageType uint) LogMessage {
return LogMessage{
ID: UUID(),
Bee: bee,
Message: message,
MessageType: messageType,
Timestamp: time.Now(),
}
} | go | func NewLogMessage(bee string, message string, messageType uint) LogMessage {
return LogMessage{
ID: UUID(),
Bee: bee,
Message: message,
MessageType: messageType,
Timestamp: time.Now(),
}
} | [
"func",
"NewLogMessage",
"(",
"bee",
"string",
",",
"message",
"string",
",",
"messageType",
"uint",
")",
"LogMessage",
"{",
"return",
"LogMessage",
"{",
"ID",
":",
"UUID",
"(",
")",
",",
"Bee",
":",
"bee",
",",
"Message",
":",
"message",
",",
"MessageType",
":",
"messageType",
",",
"Timestamp",
":",
"time",
".",
"Now",
"(",
")",
",",
"}",
"\n",
"}"
] | // NewLogMessage returns a newly composed LogMessage | [
"NewLogMessage",
"returns",
"a",
"newly",
"composed",
"LogMessage"
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/logs.go#L52-L60 | train |
muesli/beehive | bees/logs.go | Log | func Log(bee string, message string, messageType uint) {
logMutex.Lock()
defer logMutex.Unlock()
logs[bee] = append(logs[bee], NewLogMessage(bee, message, messageType))
} | go | func Log(bee string, message string, messageType uint) {
logMutex.Lock()
defer logMutex.Unlock()
logs[bee] = append(logs[bee], NewLogMessage(bee, message, messageType))
} | [
"func",
"Log",
"(",
"bee",
"string",
",",
"message",
"string",
",",
"messageType",
"uint",
")",
"{",
"logMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"logMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"logs",
"[",
"bee",
"]",
"=",
"append",
"(",
"logs",
"[",
"bee",
"]",
",",
"NewLogMessage",
"(",
"bee",
",",
"message",
",",
"messageType",
")",
")",
"\n",
"}"
] | // Log adds a new LogMessage to the log | [
"Log",
"adds",
"a",
"new",
"LogMessage",
"to",
"the",
"log"
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/logs.go#L63-L68 | train |
muesli/beehive | bees/logs.go | GetLogs | func GetLogs(bee string) []LogMessage {
r := []LogMessage{}
logMutex.RLock()
for b, ls := range logs {
if len(bee) == 0 || bee == b {
for _, l := range ls {
r = append(r, l)
}
}
}
logMutex.RUnlock()
sort.Sort(LogSorter(r))
return r
} | go | func GetLogs(bee string) []LogMessage {
r := []LogMessage{}
logMutex.RLock()
for b, ls := range logs {
if len(bee) == 0 || bee == b {
for _, l := range ls {
r = append(r, l)
}
}
}
logMutex.RUnlock()
sort.Sort(LogSorter(r))
return r
} | [
"func",
"GetLogs",
"(",
"bee",
"string",
")",
"[",
"]",
"LogMessage",
"{",
"r",
":=",
"[",
"]",
"LogMessage",
"{",
"}",
"\n\n",
"logMutex",
".",
"RLock",
"(",
")",
"\n",
"for",
"b",
",",
"ls",
":=",
"range",
"logs",
"{",
"if",
"len",
"(",
"bee",
")",
"==",
"0",
"||",
"bee",
"==",
"b",
"{",
"for",
"_",
",",
"l",
":=",
"range",
"ls",
"{",
"r",
"=",
"append",
"(",
"r",
",",
"l",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"logMutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"sort",
".",
"Sort",
"(",
"LogSorter",
"(",
"r",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // GetLogs returns all logs for a Bee. | [
"GetLogs",
"returns",
"all",
"logs",
"for",
"a",
"Bee",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/logs.go#L71-L86 | train |
muesli/beehive | bees/ircbee/irctools/irctools.go | Colored | func Colored(val string, color string) string {
// 00 white 01 black 02 blue (navy) 03 green 04 red 05 brown (maroon)
// 06 purple 07 orange (olive) 08 yellow 09 light green (lime)
// 10 teal (a green/blue cyan) 11 light cyan (cyan) (aqua) 12 light blue (royal)
// 13 pink (light purple) (fuchsia) 14 grey 15 light grey (silver)
c := "01"
switch color {
case "white":
c = "00"
case "black":
c = "01"
case "blue":
c = "02"
case "green":
c = "03"
case "red":
c = "04"
case "brown":
c = "05"
case "purple":
c = "06"
case "orange":
c = "07"
case "yellow":
c = "08"
case "lime":
c = "09"
case "teal":
c = "10"
case "cyan":
c = "11"
case "lightblue":
c = "12"
case "pink":
c = "13"
case "grey":
c = "14"
case "silver":
c = "15"
}
return "\x03" + c + val + "\x03"
} | go | func Colored(val string, color string) string {
// 00 white 01 black 02 blue (navy) 03 green 04 red 05 brown (maroon)
// 06 purple 07 orange (olive) 08 yellow 09 light green (lime)
// 10 teal (a green/blue cyan) 11 light cyan (cyan) (aqua) 12 light blue (royal)
// 13 pink (light purple) (fuchsia) 14 grey 15 light grey (silver)
c := "01"
switch color {
case "white":
c = "00"
case "black":
c = "01"
case "blue":
c = "02"
case "green":
c = "03"
case "red":
c = "04"
case "brown":
c = "05"
case "purple":
c = "06"
case "orange":
c = "07"
case "yellow":
c = "08"
case "lime":
c = "09"
case "teal":
c = "10"
case "cyan":
c = "11"
case "lightblue":
c = "12"
case "pink":
c = "13"
case "grey":
c = "14"
case "silver":
c = "15"
}
return "\x03" + c + val + "\x03"
} | [
"func",
"Colored",
"(",
"val",
"string",
",",
"color",
"string",
")",
"string",
"{",
"// 00 white 01 black 02 blue (navy) 03 green 04 red 05 brown (maroon)",
"// 06 purple 07 orange (olive) 08 yellow 09 light green (lime)",
"// 10 teal (a green/blue cyan) 11 light cyan (cyan) (aqua) 12 light blue (royal)",
"// 13 pink (light purple) (fuchsia) 14 grey 15 light grey (silver)",
"c",
":=",
"\"",
"\"",
"\n",
"switch",
"color",
"{",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"c",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"\"",
"\\x03",
"\"",
"+",
"c",
"+",
"val",
"+",
"\"",
"\\x03",
"\"",
"\n",
"}"
] | // Colored wraps val in color styling tags. | [
"Colored",
"wraps",
"val",
"in",
"color",
"styling",
"tags",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/ircbee/irctools/irctools.go#L38-L80 | train |
muesli/beehive | bees/options.go | Value | func (opts BeeOptions) Value(name string) interface{} {
for _, opt := range opts {
if opt.Name == name {
return opt.Value
}
}
return nil
} | go | func (opts BeeOptions) Value(name string) interface{} {
for _, opt := range opts {
if opt.Name == name {
return opt.Value
}
}
return nil
} | [
"func",
"(",
"opts",
"BeeOptions",
")",
"Value",
"(",
"name",
"string",
")",
"interface",
"{",
"}",
"{",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"if",
"opt",
".",
"Name",
"==",
"name",
"{",
"return",
"opt",
".",
"Value",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Value retrieves a value from a BeeOptions slice. | [
"Value",
"retrieves",
"a",
"value",
"from",
"a",
"BeeOptions",
"slice",
"."
] | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/options.go#L46-L54 | train |