id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
21,100
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
21,101
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
21,102
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
21,103
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
21,104
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
21,105
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
21,106
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
21,107
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
21,108
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
21,109
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
21,110
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
21,111
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
21,112
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
21,113
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
21,114
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
21,115
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
21,116
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
21,117
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
21,118
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
21,119
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
21,120
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
21,121
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
21,122
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
21,123
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
21,124
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
21,125
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
21,126
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
21,127
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
21,128
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
21,129
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
21,130
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
21,131
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
21,132
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
21,133
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
21,134
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
21,135
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
21,136
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
21,137
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
21,138
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
21,139
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
21,140
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
21,141
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
21,142
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
21,143
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
21,144
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
21,145
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
21,146
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
21,147
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
21,148
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
21,149
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
21,150
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
21,151
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
21,152
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
21,153
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
21,154
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
21,155
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
21,156
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
21,157
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
21,158
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
21,159
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
21,160
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
21,161
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
21,162
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
21,163
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
21,164
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
21,165
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
21,166
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
21,167
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
21,168
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
21,169
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
21,170
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
21,171
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
21,172
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
21,173
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
21,174
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
21,175
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
21,176
muesli/beehive
bees/options.go
Bind
func (opts BeeOptions) Bind(name string, dst interface{}) error { v := opts.Value(name) if v == nil { return errors.New("Option with name " + name + " not found") } return ConvertValue(v, dst) }
go
func (opts BeeOptions) Bind(name string, dst interface{}) error { v := opts.Value(name) if v == nil { return errors.New("Option with name " + name + " not found") } return ConvertValue(v, dst) }
[ "func", "(", "opts", "BeeOptions", ")", "Bind", "(", "name", "string", ",", "dst", "interface", "{", "}", ")", "error", "{", "v", ":=", "opts", ".", "Value", "(", "name", ")", "\n", "if", "v", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", "+", "name", "+", "\"", "\"", ")", "\n", "}", "\n\n", "return", "ConvertValue", "(", "v", ",", "dst", ")", "\n", "}" ]
// Bind a value from a BeeOptions slice.
[ "Bind", "a", "value", "from", "a", "BeeOptions", "slice", "." ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/options.go#L57-L64
21,177
muesli/beehive
bees/telegrambee/telegrambee.go
getAPIKey
func getAPIKey(options *bees.BeeOptions) string { var apiKey string options.Bind("api_key", &apiKey) if strings.HasPrefix(apiKey, "file://") { buf, err := ioutil.ReadFile(strings.TrimPrefix(apiKey, "file://")) if err != nil { panic("Error reading API key file " + apiKey) } apiKey = string(buf) } if strings.HasPrefix(apiKey, "env://") { buf := strings.TrimPrefix(apiKey, "env://") apiKey = os.Getenv(string(buf)) } return strings.TrimSpace(apiKey) }
go
func getAPIKey(options *bees.BeeOptions) string { var apiKey string options.Bind("api_key", &apiKey) if strings.HasPrefix(apiKey, "file://") { buf, err := ioutil.ReadFile(strings.TrimPrefix(apiKey, "file://")) if err != nil { panic("Error reading API key file " + apiKey) } apiKey = string(buf) } if strings.HasPrefix(apiKey, "env://") { buf := strings.TrimPrefix(apiKey, "env://") apiKey = os.Getenv(string(buf)) } return strings.TrimSpace(apiKey) }
[ "func", "getAPIKey", "(", "options", "*", "bees", ".", "BeeOptions", ")", "string", "{", "var", "apiKey", "string", "\n", "options", ".", "Bind", "(", "\"", "\"", ",", "&", "apiKey", ")", "\n\n", "if", "strings", ".", "HasPrefix", "(", "apiKey", ",", "\"", "\"", ")", "{", "buf", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "strings", ".", "TrimPrefix", "(", "apiKey", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "\"", "\"", "+", "apiKey", ")", "\n", "}", "\n", "apiKey", "=", "string", "(", "buf", ")", "\n", "}", "\n\n", "if", "strings", ".", "HasPrefix", "(", "apiKey", ",", "\"", "\"", ")", "{", "buf", ":=", "strings", ".", "TrimPrefix", "(", "apiKey", ",", "\"", "\"", ")", "\n", "apiKey", "=", "os", ".", "Getenv", "(", "string", "(", "buf", ")", ")", "\n", "}", "\n\n", "return", "strings", ".", "TrimSpace", "(", "apiKey", ")", "\n", "}" ]
// Gets the Bot's API key from a file, the recipe config or the // TELEGRAM_API_KEY environment variable.
[ "Gets", "the", "Bot", "s", "API", "key", "from", "a", "file", "the", "recipe", "config", "or", "the", "TELEGRAM_API_KEY", "environment", "variable", "." ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/telegrambee/telegrambee.go#L136-L154
21,178
muesli/beehive
bees/config.go
NewBeeConfig
func NewBeeConfig(name, class, description string, options BeeOptions) (BeeConfig, error) { if len(name) == 0 { return BeeConfig{}, errors.New("A Bee's name can't be empty") } b := GetBee(name) if b != nil { return BeeConfig{}, errors.New("A Bee with that name already exists") } f := GetFactory(class) if f == nil { return BeeConfig{}, errors.New("Invalid class specified") } return BeeConfig{ Name: name, Class: class, Description: description, Options: options, }, nil }
go
func NewBeeConfig(name, class, description string, options BeeOptions) (BeeConfig, error) { if len(name) == 0 { return BeeConfig{}, errors.New("A Bee's name can't be empty") } b := GetBee(name) if b != nil { return BeeConfig{}, errors.New("A Bee with that name already exists") } f := GetFactory(class) if f == nil { return BeeConfig{}, errors.New("Invalid class specified") } return BeeConfig{ Name: name, Class: class, Description: description, Options: options, }, nil }
[ "func", "NewBeeConfig", "(", "name", ",", "class", ",", "description", "string", ",", "options", "BeeOptions", ")", "(", "BeeConfig", ",", "error", ")", "{", "if", "len", "(", "name", ")", "==", "0", "{", "return", "BeeConfig", "{", "}", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "b", ":=", "GetBee", "(", "name", ")", "\n", "if", "b", "!=", "nil", "{", "return", "BeeConfig", "{", "}", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "f", ":=", "GetFactory", "(", "class", ")", "\n", "if", "f", "==", "nil", "{", "return", "BeeConfig", "{", "}", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "BeeConfig", "{", "Name", ":", "name", ",", "Class", ":", "class", ",", "Description", ":", "description", ",", "Options", ":", "options", ",", "}", ",", "nil", "\n", "}" ]
// NewBeeConfig validates a configuration and sets up a new BeeConfig
[ "NewBeeConfig", "validates", "a", "configuration", "and", "sets", "up", "a", "new", "BeeConfig" ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/config.go#L35-L56
21,179
muesli/beehive
bees/config.go
BeeConfigs
func BeeConfigs() []BeeConfig { bs := []BeeConfig{} for _, b := range bees { bs = append(bs, (*b).Config()) } return bs }
go
func BeeConfigs() []BeeConfig { bs := []BeeConfig{} for _, b := range bees { bs = append(bs, (*b).Config()) } return bs }
[ "func", "BeeConfigs", "(", ")", "[", "]", "BeeConfig", "{", "bs", ":=", "[", "]", "BeeConfig", "{", "}", "\n", "for", "_", ",", "b", ":=", "range", "bees", "{", "bs", "=", "append", "(", "bs", ",", "(", "*", "b", ")", ".", "Config", "(", ")", ")", "\n", "}", "\n\n", "return", "bs", "\n", "}" ]
// BeeConfigs returns configs for all Bees.
[ "BeeConfigs", "returns", "configs", "for", "all", "Bees", "." ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/config.go#L59-L66
21,180
muesli/beehive
bees/filters.go
execFilter
func execFilter(filter string, opts map[string]interface{}) bool { f := *filters.GetFilter("template") log.Println("\tExecuting filter:", filter) defer func() { if e := recover(); e != nil { log.Println("Fatal filter event:", e) } }() return f.Passes(opts, filter) }
go
func execFilter(filter string, opts map[string]interface{}) bool { f := *filters.GetFilter("template") log.Println("\tExecuting filter:", filter) defer func() { if e := recover(); e != nil { log.Println("Fatal filter event:", e) } }() return f.Passes(opts, filter) }
[ "func", "execFilter", "(", "filter", "string", ",", "opts", "map", "[", "string", "]", "interface", "{", "}", ")", "bool", "{", "f", ":=", "*", "filters", ".", "GetFilter", "(", "\"", "\"", ")", "\n", "log", ".", "Println", "(", "\"", "\\t", "\"", ",", "filter", ")", "\n\n", "defer", "func", "(", ")", "{", "if", "e", ":=", "recover", "(", ")", ";", "e", "!=", "nil", "{", "log", ".", "Println", "(", "\"", "\"", ",", "e", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "return", "f", ".", "Passes", "(", "opts", ",", "filter", ")", "\n", "}" ]
// execFilter executes a filter. Returns whether the filter passed or not.
[ "execFilter", "executes", "a", "filter", ".", "Returns", "whether", "the", "filter", "passed", "or", "not", "." ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/filters.go#L38-L49
21,181
muesli/beehive
bees/openweathermapbee/event.go
TriggerWeatherInformationEvent
func (mod *OpenweathermapBee) TriggerWeatherInformationEvent(v *owm.Weather) { weather := bees.Event{ Bee: mod.Name(), Name: "main_weather", Options: []bees.Placeholder{ { Name: "id", Type: "int", Value: v.ID, }, { Name: "main", Type: "string", Value: v.Main, }, { Name: "description", Type: "string", Value: v.Description, }, { Name: "icon", Type: "string", Value: v.Icon, }, }, } mod.evchan <- weather }
go
func (mod *OpenweathermapBee) TriggerWeatherInformationEvent(v *owm.Weather) { weather := bees.Event{ Bee: mod.Name(), Name: "main_weather", Options: []bees.Placeholder{ { Name: "id", Type: "int", Value: v.ID, }, { Name: "main", Type: "string", Value: v.Main, }, { Name: "description", Type: "string", Value: v.Description, }, { Name: "icon", Type: "string", Value: v.Icon, }, }, } mod.evchan <- weather }
[ "func", "(", "mod", "*", "OpenweathermapBee", ")", "TriggerWeatherInformationEvent", "(", "v", "*", "owm", ".", "Weather", ")", "{", "weather", ":=", "bees", ".", "Event", "{", "Bee", ":", "mod", ".", "Name", "(", ")", ",", "Name", ":", "\"", "\"", ",", "Options", ":", "[", "]", "bees", ".", "Placeholder", "{", "{", "Name", ":", "\"", "\"", ",", "Type", ":", "\"", "\"", ",", "Value", ":", "v", ".", "ID", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Type", ":", "\"", "\"", ",", "Value", ":", "v", ".", "Main", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Type", ":", "\"", "\"", ",", "Value", ":", "v", ".", "Description", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Type", ":", "\"", "\"", ",", "Value", ":", "v", ".", "Icon", ",", "}", ",", "}", ",", "}", "\n", "mod", ".", "evchan", "<-", "weather", "\n", "}" ]
// WeatherInformationEvent triggers a weather event
[ "WeatherInformationEvent", "triggers", "a", "weather", "event" ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/openweathermapbee/event.go#L186-L214
21,182
muesli/beehive
filters/template/templatefilter.go
Passes
func (filter *TemplateFilter) Passes(data interface{}, value interface{}) bool { switch v := value.(type) { case string: var res bytes.Buffer if strings.Index(v, "{{test") >= 0 { v = strings.Replace(v, "{{test", "{{if", -1) v += "true{{end}}" } tmpl, err := template.New("_" + v).Funcs(templatehelper.FuncMap).Parse(v) if err == nil { err = tmpl.Execute(&res, data) } if err != nil { panic(err) } return strings.TrimSpace(res.String()) == "true" } return false }
go
func (filter *TemplateFilter) Passes(data interface{}, value interface{}) bool { switch v := value.(type) { case string: var res bytes.Buffer if strings.Index(v, "{{test") >= 0 { v = strings.Replace(v, "{{test", "{{if", -1) v += "true{{end}}" } tmpl, err := template.New("_" + v).Funcs(templatehelper.FuncMap).Parse(v) if err == nil { err = tmpl.Execute(&res, data) } if err != nil { panic(err) } return strings.TrimSpace(res.String()) == "true" } return false }
[ "func", "(", "filter", "*", "TemplateFilter", ")", "Passes", "(", "data", "interface", "{", "}", ",", "value", "interface", "{", "}", ")", "bool", "{", "switch", "v", ":=", "value", ".", "(", "type", ")", "{", "case", "string", ":", "var", "res", "bytes", ".", "Buffer", "\n\n", "if", "strings", ".", "Index", "(", "v", ",", "\"", "\"", ")", ">=", "0", "{", "v", "=", "strings", ".", "Replace", "(", "v", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "v", "+=", "\"", "\"", "\n", "}", "\n\n", "tmpl", ",", "err", ":=", "template", ".", "New", "(", "\"", "\"", "+", "v", ")", ".", "Funcs", "(", "templatehelper", ".", "FuncMap", ")", ".", "Parse", "(", "v", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "tmpl", ".", "Execute", "(", "&", "res", ",", "data", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n\n", "return", "strings", ".", "TrimSpace", "(", "res", ".", "String", "(", ")", ")", "==", "\"", "\"", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// Passes returns true when the Filter matched the data.
[ "Passes", "returns", "true", "when", "the", "Filter", "matched", "the", "data", "." ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/filters/template/templatefilter.go#L48-L70
21,183
muesli/beehive
api/resources/hives/hives_response.go
AddHive
func (r *HiveResponse) AddHive(hive *bees.BeeFactoryInterface) { r.hives[(*hive).Name()] = hive }
go
func (r *HiveResponse) AddHive(hive *bees.BeeFactoryInterface) { r.hives[(*hive).Name()] = hive }
[ "func", "(", "r", "*", "HiveResponse", ")", "AddHive", "(", "hive", "*", "bees", ".", "BeeFactoryInterface", ")", "{", "r", ".", "hives", "[", "(", "*", "hive", ")", ".", "Name", "(", ")", "]", "=", "hive", "\n", "}" ]
// AddHive adds a hive to the response
[ "AddHive", "adds", "a", "hive", "to", "the", "response" ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/hives/hives_response.go#L64-L66
21,184
muesli/beehive
api/resources/bees/bees_response.go
AddBee
func (r *BeeResponse) AddBee(bee *bees.BeeInterface) { r.bees[(*bee).Name()] = bee hive := bees.GetFactory((*bee).Namespace()) if hive == nil { panic("Hive for Bee not found") } r.hives[(*hive).Name()] = hive r.Hives = append(r.Hives, hives.PrepareHiveResponse(r.Context, hive)) }
go
func (r *BeeResponse) AddBee(bee *bees.BeeInterface) { r.bees[(*bee).Name()] = bee hive := bees.GetFactory((*bee).Namespace()) if hive == nil { panic("Hive for Bee not found") } r.hives[(*hive).Name()] = hive r.Hives = append(r.Hives, hives.PrepareHiveResponse(r.Context, hive)) }
[ "func", "(", "r", "*", "BeeResponse", ")", "AddBee", "(", "bee", "*", "bees", ".", "BeeInterface", ")", "{", "r", ".", "bees", "[", "(", "*", "bee", ")", ".", "Name", "(", ")", "]", "=", "bee", "\n\n", "hive", ":=", "bees", ".", "GetFactory", "(", "(", "*", "bee", ")", ".", "Namespace", "(", ")", ")", "\n", "if", "hive", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "r", ".", "hives", "[", "(", "*", "hive", ")", ".", "Name", "(", ")", "]", "=", "hive", "\n", "r", ".", "Hives", "=", "append", "(", "r", ".", "Hives", ",", "hives", ".", "PrepareHiveResponse", "(", "r", ".", "Context", ",", "hive", ")", ")", "\n", "}" ]
// AddBee adds a bee to the response
[ "AddBee", "adds", "a", "bee", "to", "the", "response" ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/bees/bees_response.go#L66-L76
21,185
muesli/beehive
api/api.go
Run
func Run() { // to see what happens in the package, uncomment the following //restful.TraceLogger(log.New(os.Stdout, "[restful] ", log.LstdFlags|log.Lshortfile)) // Setup web-service smolderConfig := smolder.APIConfig{ BaseURL: canonicalURL, PathPrefix: "v1/", } context := &context.APIContext{ Config: smolderConfig, } wsContainer := smolder.NewSmolderContainer(smolderConfig, nil, nil) wsContainer.Router(restful.CurlyRouter{}) ws := new(restful.WebService) ws.Route(ws.GET("/images/{subpath:*}").To(assetHandler)) ws.Route(ws.GET("/oauth2/{subpath:*}").To(oauth2Handler)) ws.Route(ws.GET("/{subpath:*}").To(assetHandler)) ws.Route(ws.GET("/").To(assetHandler)) wsContainer.Add(ws) func(resources ...smolder.APIResource) { for _, r := range resources { r.Register(wsContainer, smolderConfig, context) } }( &hives.HiveResource{}, &bees.BeeResource{}, &chains.ChainResource{}, &actions.ActionResource{}, &logs.LogResource{}, ) server := &http.Server{Addr: bind, Handler: wsContainer} go func() { log.Fatal(server.ListenAndServe()) }() }
go
func Run() { // to see what happens in the package, uncomment the following //restful.TraceLogger(log.New(os.Stdout, "[restful] ", log.LstdFlags|log.Lshortfile)) // Setup web-service smolderConfig := smolder.APIConfig{ BaseURL: canonicalURL, PathPrefix: "v1/", } context := &context.APIContext{ Config: smolderConfig, } wsContainer := smolder.NewSmolderContainer(smolderConfig, nil, nil) wsContainer.Router(restful.CurlyRouter{}) ws := new(restful.WebService) ws.Route(ws.GET("/images/{subpath:*}").To(assetHandler)) ws.Route(ws.GET("/oauth2/{subpath:*}").To(oauth2Handler)) ws.Route(ws.GET("/{subpath:*}").To(assetHandler)) ws.Route(ws.GET("/").To(assetHandler)) wsContainer.Add(ws) func(resources ...smolder.APIResource) { for _, r := range resources { r.Register(wsContainer, smolderConfig, context) } }( &hives.HiveResource{}, &bees.BeeResource{}, &chains.ChainResource{}, &actions.ActionResource{}, &logs.LogResource{}, ) server := &http.Server{Addr: bind, Handler: wsContainer} go func() { log.Fatal(server.ListenAndServe()) }() }
[ "func", "Run", "(", ")", "{", "// to see what happens in the package, uncomment the following", "//restful.TraceLogger(log.New(os.Stdout, \"[restful] \", log.LstdFlags|log.Lshortfile))", "// Setup web-service", "smolderConfig", ":=", "smolder", ".", "APIConfig", "{", "BaseURL", ":", "canonicalURL", ",", "PathPrefix", ":", "\"", "\"", ",", "}", "\n", "context", ":=", "&", "context", ".", "APIContext", "{", "Config", ":", "smolderConfig", ",", "}", "\n\n", "wsContainer", ":=", "smolder", ".", "NewSmolderContainer", "(", "smolderConfig", ",", "nil", ",", "nil", ")", "\n", "wsContainer", ".", "Router", "(", "restful", ".", "CurlyRouter", "{", "}", ")", "\n", "ws", ":=", "new", "(", "restful", ".", "WebService", ")", "\n", "ws", ".", "Route", "(", "ws", ".", "GET", "(", "\"", "\"", ")", ".", "To", "(", "assetHandler", ")", ")", "\n", "ws", ".", "Route", "(", "ws", ".", "GET", "(", "\"", "\"", ")", ".", "To", "(", "oauth2Handler", ")", ")", "\n", "ws", ".", "Route", "(", "ws", ".", "GET", "(", "\"", "\"", ")", ".", "To", "(", "assetHandler", ")", ")", "\n", "ws", ".", "Route", "(", "ws", ".", "GET", "(", "\"", "\"", ")", ".", "To", "(", "assetHandler", ")", ")", "\n", "wsContainer", ".", "Add", "(", "ws", ")", "\n\n", "func", "(", "resources", "...", "smolder", ".", "APIResource", ")", "{", "for", "_", ",", "r", ":=", "range", "resources", "{", "r", ".", "Register", "(", "wsContainer", ",", "smolderConfig", ",", "context", ")", "\n", "}", "\n", "}", "(", "&", "hives", ".", "HiveResource", "{", "}", ",", "&", "bees", ".", "BeeResource", "{", "}", ",", "&", "chains", ".", "ChainResource", "{", "}", ",", "&", "actions", ".", "ActionResource", "{", "}", ",", "&", "logs", ".", "LogResource", "{", "}", ",", ")", "\n\n", "server", ":=", "&", "http", ".", "Server", "{", "Addr", ":", "bind", ",", "Handler", ":", "wsContainer", "}", "\n", "go", "func", "(", ")", "{", "log", ".", "Fatal", "(", "server", ".", "ListenAndServe", "(", ")", ")", "\n", "}", "(", ")", "\n", "}" ]
// Run sets up the restful API container and an HTTP server go-routine
[ "Run", "sets", "up", "the", "restful", "API", "container", "and", "an", "HTTP", "server", "go", "-", "routine" ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/api.go#L164-L202
21,186
muesli/beehive
bees/cronbee/cron/crontime.go
DurationUntilNextEvent
func (c *crontime) DurationUntilNextEvent() time.Duration { return c.nextEvent().Sub(time.Now()) }
go
func (c *crontime) DurationUntilNextEvent() time.Duration { return c.nextEvent().Sub(time.Now()) }
[ "func", "(", "c", "*", "crontime", ")", "DurationUntilNextEvent", "(", ")", "time", ".", "Duration", "{", "return", "c", ".", "nextEvent", "(", ")", ".", "Sub", "(", "time", ".", "Now", "(", ")", ")", "\n", "}" ]
// Returns the time.Duration until the next event.
[ "Returns", "the", "time", ".", "Duration", "until", "the", "next", "event", "." ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L52-L54
21,187
muesli/beehive
bees/cronbee/cron/crontime.go
calculateEvent
func (c *crontime) calculateEvent(baseTime time.Time) time.Time { c.calculationInProgress = true defer c.setCalculationInProgress(false) baseTime = setNanoecond(baseTime, 10000) c.calculatedTime = baseTime // Ignore all Events in the Past & initial 'result' //c.calculatedTime = setNanoecond(c.calculatedTime, 10000) c.nextValidMonth(baseTime) c.nextValidDay(baseTime) c.nextValidHour(baseTime) c.nextValidMinute(baseTime) c.nextValidSecond(baseTime) log.Println("Cronbee has found a time stamp: ", c.calculatedTime) return c.calculatedTime }
go
func (c *crontime) calculateEvent(baseTime time.Time) time.Time { c.calculationInProgress = true defer c.setCalculationInProgress(false) baseTime = setNanoecond(baseTime, 10000) c.calculatedTime = baseTime // Ignore all Events in the Past & initial 'result' //c.calculatedTime = setNanoecond(c.calculatedTime, 10000) c.nextValidMonth(baseTime) c.nextValidDay(baseTime) c.nextValidHour(baseTime) c.nextValidMinute(baseTime) c.nextValidSecond(baseTime) log.Println("Cronbee has found a time stamp: ", c.calculatedTime) return c.calculatedTime }
[ "func", "(", "c", "*", "crontime", ")", "calculateEvent", "(", "baseTime", "time", ".", "Time", ")", "time", ".", "Time", "{", "c", ".", "calculationInProgress", "=", "true", "\n", "defer", "c", ".", "setCalculationInProgress", "(", "false", ")", "\n", "baseTime", "=", "setNanoecond", "(", "baseTime", ",", "10000", ")", "\n", "c", ".", "calculatedTime", "=", "baseTime", "// Ignore all Events in the Past & initial 'result'", "\n", "//c.calculatedTime = setNanoecond(c.calculatedTime, 10000)", "c", ".", "nextValidMonth", "(", "baseTime", ")", "\n", "c", ".", "nextValidDay", "(", "baseTime", ")", "\n", "c", ".", "nextValidHour", "(", "baseTime", ")", "\n", "c", ".", "nextValidMinute", "(", "baseTime", ")", "\n", "c", ".", "nextValidSecond", "(", "baseTime", ")", "\n", "log", ".", "Println", "(", "\"", "\"", ",", "c", ".", "calculatedTime", ")", "\n", "return", "c", ".", "calculatedTime", "\n", "}" ]
// This functions calculates the next event
[ "This", "functions", "calculates", "the", "next", "event" ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L93-L106
21,188
muesli/beehive
bees/cronbee/cron/crontime.go
nextValidMonth
func (c *crontime) nextValidMonth(baseTime time.Time) { for _, mon := range c.month { if mon >= int(c.calculatedTime.Month()) { //log.Print("Inside Month", mon, c.calculatedTime) c.calculatedTime = setMonth(c.calculatedTime, mon) //log.Println(" :: and out", c.calculatedTime) return } } // If no result was found try it again in the following year c.calculatedTime = c.calculatedTime.AddDate(1, 0, 0) c.calculatedTime = setMonth(c.calculatedTime, c.month[0]) //log.Println("Cronbee: Month", c.calculatedTime, baseTime, c.month) c.nextValidMonth(baseTime) }
go
func (c *crontime) nextValidMonth(baseTime time.Time) { for _, mon := range c.month { if mon >= int(c.calculatedTime.Month()) { //log.Print("Inside Month", mon, c.calculatedTime) c.calculatedTime = setMonth(c.calculatedTime, mon) //log.Println(" :: and out", c.calculatedTime) return } } // If no result was found try it again in the following year c.calculatedTime = c.calculatedTime.AddDate(1, 0, 0) c.calculatedTime = setMonth(c.calculatedTime, c.month[0]) //log.Println("Cronbee: Month", c.calculatedTime, baseTime, c.month) c.nextValidMonth(baseTime) }
[ "func", "(", "c", "*", "crontime", ")", "nextValidMonth", "(", "baseTime", "time", ".", "Time", ")", "{", "for", "_", ",", "mon", ":=", "range", "c", ".", "month", "{", "if", "mon", ">=", "int", "(", "c", ".", "calculatedTime", ".", "Month", "(", ")", ")", "{", "//log.Print(\"Inside Month\", mon, c.calculatedTime)", "c", ".", "calculatedTime", "=", "setMonth", "(", "c", ".", "calculatedTime", ",", "mon", ")", "\n", "//log.Println(\" :: and out\", c.calculatedTime)", "return", "\n", "}", "\n", "}", "\n", "// If no result was found try it again in the following year", "c", ".", "calculatedTime", "=", "c", ".", "calculatedTime", ".", "AddDate", "(", "1", ",", "0", ",", "0", ")", "\n", "c", ".", "calculatedTime", "=", "setMonth", "(", "c", ".", "calculatedTime", ",", "c", ".", "month", "[", "0", "]", ")", "\n", "//log.Println(\"Cronbee: Month\", c.calculatedTime, baseTime, c.month)", "c", ".", "nextValidMonth", "(", "baseTime", ")", "\n", "}" ]
// Calculates the next valid Month based upon the previous results.
[ "Calculates", "the", "next", "valid", "Month", "based", "upon", "the", "previous", "results", "." ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L109-L123
21,189
muesli/beehive
bees/cronbee/cron/crontime.go
nextValidDay
func (c *crontime) nextValidDay(baseTime time.Time) { for _, dom := range c.dom { if dom >= c.calculatedTime.Day() { for _, dow := range c.dow { if monthHasDow(dow, dom, int(c.calculatedTime.Month()), c.calculatedTime.Year()) { c.calculatedTime = setDay(c.calculatedTime, dom) //log.Println("Cronbee: Day-INS-1:", c.calculatedTime) return } } } } /* else { for _, dow := range c.dow { if monthHasDow(dow, dom, int(c.calculatedTime.Month()), c.calculatedTime.Year()){ c.calculatedTime = setDay(c.calculatedTime, dom) log.Println("Cronbee: Day-INS-2:", c.calculatedTime) return } } }*/ // If no result was found try it again in the following month. c.calculatedTime = c.calculatedTime.AddDate(0, 1, 0) c.calculatedTime = setDay(c.calculatedTime, c.dom[0]) //log.Println("Cronbee: Day", c.calculatedTime, baseTime) c.nextValidMonth(baseTime) c.nextValidDay(baseTime) }
go
func (c *crontime) nextValidDay(baseTime time.Time) { for _, dom := range c.dom { if dom >= c.calculatedTime.Day() { for _, dow := range c.dow { if monthHasDow(dow, dom, int(c.calculatedTime.Month()), c.calculatedTime.Year()) { c.calculatedTime = setDay(c.calculatedTime, dom) //log.Println("Cronbee: Day-INS-1:", c.calculatedTime) return } } } } /* else { for _, dow := range c.dow { if monthHasDow(dow, dom, int(c.calculatedTime.Month()), c.calculatedTime.Year()){ c.calculatedTime = setDay(c.calculatedTime, dom) log.Println("Cronbee: Day-INS-2:", c.calculatedTime) return } } }*/ // If no result was found try it again in the following month. c.calculatedTime = c.calculatedTime.AddDate(0, 1, 0) c.calculatedTime = setDay(c.calculatedTime, c.dom[0]) //log.Println("Cronbee: Day", c.calculatedTime, baseTime) c.nextValidMonth(baseTime) c.nextValidDay(baseTime) }
[ "func", "(", "c", "*", "crontime", ")", "nextValidDay", "(", "baseTime", "time", ".", "Time", ")", "{", "for", "_", ",", "dom", ":=", "range", "c", ".", "dom", "{", "if", "dom", ">=", "c", ".", "calculatedTime", ".", "Day", "(", ")", "{", "for", "_", ",", "dow", ":=", "range", "c", ".", "dow", "{", "if", "monthHasDow", "(", "dow", ",", "dom", ",", "int", "(", "c", ".", "calculatedTime", ".", "Month", "(", ")", ")", ",", "c", ".", "calculatedTime", ".", "Year", "(", ")", ")", "{", "c", ".", "calculatedTime", "=", "setDay", "(", "c", ".", "calculatedTime", ",", "dom", ")", "\n", "//log.Println(\"Cronbee: Day-INS-1:\", c.calculatedTime)", "return", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "/* else {\n\t\tfor _, dow := range c.dow {\n\t\t\tif monthHasDow(dow, dom, int(c.calculatedTime.Month()), c.calculatedTime.Year()){\n\t\t\t\tc.calculatedTime = setDay(c.calculatedTime, dom)\n\t\t\t\tlog.Println(\"Cronbee: Day-INS-2:\", c.calculatedTime)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}*/", "\n", "// If no result was found try it again in the following month.", "c", ".", "calculatedTime", "=", "c", ".", "calculatedTime", ".", "AddDate", "(", "0", ",", "1", ",", "0", ")", "\n", "c", ".", "calculatedTime", "=", "setDay", "(", "c", ".", "calculatedTime", ",", "c", ".", "dom", "[", "0", "]", ")", "\n", "//log.Println(\"Cronbee: Day\", c.calculatedTime, baseTime)", "c", ".", "nextValidMonth", "(", "baseTime", ")", "\n", "c", ".", "nextValidDay", "(", "baseTime", ")", "\n", "}" ]
// Calculates the next valid Day based upon the previous results.
[ "Calculates", "the", "next", "valid", "Day", "based", "upon", "the", "previous", "results", "." ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L126-L152
21,190
muesli/beehive
bees/cronbee/cron/crontime.go
nextValidHour
func (c *crontime) nextValidHour(baseTime time.Time) { for _, hour := range c.hour { if c.calculatedTime.Day() == baseTime.Day() { if !hasPassed(hour, c.calculatedTime.Hour()) { c.calculatedTime = setHour(c.calculatedTime, hour) return } } else { c.calculatedTime = setHour(c.calculatedTime, hour) return } } // If no result was found try it again in the following day. c.calculatedTime = c.calculatedTime.AddDate(0, 0, 1) // <-| c.calculatedTime = setHour(c.calculatedTime, c.hour[0]) // | //log.Println("Cronbee: Hour", c.calculatedTime, baseTime) // | c.nextValidMonth(baseTime) // May trigger a new month --------| c.nextValidDay(baseTime) c.nextValidHour(baseTime) }
go
func (c *crontime) nextValidHour(baseTime time.Time) { for _, hour := range c.hour { if c.calculatedTime.Day() == baseTime.Day() { if !hasPassed(hour, c.calculatedTime.Hour()) { c.calculatedTime = setHour(c.calculatedTime, hour) return } } else { c.calculatedTime = setHour(c.calculatedTime, hour) return } } // If no result was found try it again in the following day. c.calculatedTime = c.calculatedTime.AddDate(0, 0, 1) // <-| c.calculatedTime = setHour(c.calculatedTime, c.hour[0]) // | //log.Println("Cronbee: Hour", c.calculatedTime, baseTime) // | c.nextValidMonth(baseTime) // May trigger a new month --------| c.nextValidDay(baseTime) c.nextValidHour(baseTime) }
[ "func", "(", "c", "*", "crontime", ")", "nextValidHour", "(", "baseTime", "time", ".", "Time", ")", "{", "for", "_", ",", "hour", ":=", "range", "c", ".", "hour", "{", "if", "c", ".", "calculatedTime", ".", "Day", "(", ")", "==", "baseTime", ".", "Day", "(", ")", "{", "if", "!", "hasPassed", "(", "hour", ",", "c", ".", "calculatedTime", ".", "Hour", "(", ")", ")", "{", "c", ".", "calculatedTime", "=", "setHour", "(", "c", ".", "calculatedTime", ",", "hour", ")", "\n", "return", "\n", "}", "\n", "}", "else", "{", "c", ".", "calculatedTime", "=", "setHour", "(", "c", ".", "calculatedTime", ",", "hour", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "// If no result was found try it again in the following day.", "c", ".", "calculatedTime", "=", "c", ".", "calculatedTime", ".", "AddDate", "(", "0", ",", "0", ",", "1", ")", "// <-|", "\n", "c", ".", "calculatedTime", "=", "setHour", "(", "c", ".", "calculatedTime", ",", "c", ".", "hour", "[", "0", "]", ")", "// |", "\n", "//log.Println(\"Cronbee: Hour\", c.calculatedTime, baseTime) // |", "c", ".", "nextValidMonth", "(", "baseTime", ")", "// May trigger a new month --------|", "\n", "c", ".", "nextValidDay", "(", "baseTime", ")", "\n", "c", ".", "nextValidHour", "(", "baseTime", ")", "\n", "}" ]
// Calculates the next valid Hour based upon the previous results.
[ "Calculates", "the", "next", "valid", "Hour", "based", "upon", "the", "previous", "results", "." ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L155-L174
21,191
muesli/beehive
bees/cronbee/cron/crontime.go
nextValidMinute
func (c *crontime) nextValidMinute(baseTime time.Time) { for _, min := range c.minute { if c.calculatedTime.Hour() == baseTime.Hour() { if !hasPassed(min, c.calculatedTime.Minute()) { c.calculatedTime = setMinute(c.calculatedTime, min) return } } else { c.calculatedTime = setMinute(c.calculatedTime, min) return } } c.calculatedTime = c.calculatedTime.Add(1 * time.Hour) c.calculatedTime = setMinute(c.calculatedTime, c.minute[0]) //log.Println("Cronbee: Minute", c.calculatedTime, baseTime) c.nextValidHour(baseTime) c.nextValidMinute(baseTime) }
go
func (c *crontime) nextValidMinute(baseTime time.Time) { for _, min := range c.minute { if c.calculatedTime.Hour() == baseTime.Hour() { if !hasPassed(min, c.calculatedTime.Minute()) { c.calculatedTime = setMinute(c.calculatedTime, min) return } } else { c.calculatedTime = setMinute(c.calculatedTime, min) return } } c.calculatedTime = c.calculatedTime.Add(1 * time.Hour) c.calculatedTime = setMinute(c.calculatedTime, c.minute[0]) //log.Println("Cronbee: Minute", c.calculatedTime, baseTime) c.nextValidHour(baseTime) c.nextValidMinute(baseTime) }
[ "func", "(", "c", "*", "crontime", ")", "nextValidMinute", "(", "baseTime", "time", ".", "Time", ")", "{", "for", "_", ",", "min", ":=", "range", "c", ".", "minute", "{", "if", "c", ".", "calculatedTime", ".", "Hour", "(", ")", "==", "baseTime", ".", "Hour", "(", ")", "{", "if", "!", "hasPassed", "(", "min", ",", "c", ".", "calculatedTime", ".", "Minute", "(", ")", ")", "{", "c", ".", "calculatedTime", "=", "setMinute", "(", "c", ".", "calculatedTime", ",", "min", ")", "\n", "return", "\n", "}", "\n", "}", "else", "{", "c", ".", "calculatedTime", "=", "setMinute", "(", "c", ".", "calculatedTime", ",", "min", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "c", ".", "calculatedTime", "=", "c", ".", "calculatedTime", ".", "Add", "(", "1", "*", "time", ".", "Hour", ")", "\n", "c", ".", "calculatedTime", "=", "setMinute", "(", "c", ".", "calculatedTime", ",", "c", ".", "minute", "[", "0", "]", ")", "\n", "//log.Println(\"Cronbee: Minute\", c.calculatedTime, baseTime)", "c", ".", "nextValidHour", "(", "baseTime", ")", "\n", "c", ".", "nextValidMinute", "(", "baseTime", ")", "\n", "}" ]
// Calculates the next valid Minute based upon the previous results.
[ "Calculates", "the", "next", "valid", "Minute", "based", "upon", "the", "previous", "results", "." ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L177-L194
21,192
muesli/beehive
bees/cronbee/cron/crontime.go
nextValidSecond
func (c *crontime) nextValidSecond(baseTime time.Time) { for _, sec := range c.second { if !c.minuteHasPassed(baseTime) { // check if sec is in the past. <= prevents triggering the same event twice if sec > c.calculatedTime.Second() { c.calculatedTime = setSecond(c.calculatedTime, sec) return } } else { c.calculatedTime = setSecond(c.calculatedTime, sec) return } } c.calculatedTime = c.calculatedTime.Add(1 * time.Minute) c.calculatedTime = setSecond(c.calculatedTime, 0) //log.Println("Cronbee: Second", c.calculatedTime, baseTime) c.nextValidMinute(baseTime) c.nextValidSecond(baseTime) }
go
func (c *crontime) nextValidSecond(baseTime time.Time) { for _, sec := range c.second { if !c.minuteHasPassed(baseTime) { // check if sec is in the past. <= prevents triggering the same event twice if sec > c.calculatedTime.Second() { c.calculatedTime = setSecond(c.calculatedTime, sec) return } } else { c.calculatedTime = setSecond(c.calculatedTime, sec) return } } c.calculatedTime = c.calculatedTime.Add(1 * time.Minute) c.calculatedTime = setSecond(c.calculatedTime, 0) //log.Println("Cronbee: Second", c.calculatedTime, baseTime) c.nextValidMinute(baseTime) c.nextValidSecond(baseTime) }
[ "func", "(", "c", "*", "crontime", ")", "nextValidSecond", "(", "baseTime", "time", ".", "Time", ")", "{", "for", "_", ",", "sec", ":=", "range", "c", ".", "second", "{", "if", "!", "c", ".", "minuteHasPassed", "(", "baseTime", ")", "{", "// check if sec is in the past. <= prevents triggering the same event twice", "if", "sec", ">", "c", ".", "calculatedTime", ".", "Second", "(", ")", "{", "c", ".", "calculatedTime", "=", "setSecond", "(", "c", ".", "calculatedTime", ",", "sec", ")", "\n", "return", "\n", "}", "\n", "}", "else", "{", "c", ".", "calculatedTime", "=", "setSecond", "(", "c", ".", "calculatedTime", ",", "sec", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "c", ".", "calculatedTime", "=", "c", ".", "calculatedTime", ".", "Add", "(", "1", "*", "time", ".", "Minute", ")", "\n", "c", ".", "calculatedTime", "=", "setSecond", "(", "c", ".", "calculatedTime", ",", "0", ")", "\n", "//log.Println(\"Cronbee: Second\", c.calculatedTime, baseTime)", "c", ".", "nextValidMinute", "(", "baseTime", ")", "\n", "c", ".", "nextValidSecond", "(", "baseTime", ")", "\n", "}" ]
// Calculates the next valid Second based upon the previous results.
[ "Calculates", "the", "next", "valid", "Second", "based", "upon", "the", "previous", "results", "." ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L197-L215
21,193
muesli/beehive
bees/factories.go
GetFactory
func GetFactory(identifier string) *BeeFactoryInterface { factory, ok := factories[identifier] if ok { return factory } return nil }
go
func GetFactory(identifier string) *BeeFactoryInterface { factory, ok := factories[identifier] if ok { return factory } return nil }
[ "func", "GetFactory", "(", "identifier", "string", ")", "*", "BeeFactoryInterface", "{", "factory", ",", "ok", ":=", "factories", "[", "identifier", "]", "\n", "if", "ok", "{", "return", "factory", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// GetFactory returns the factory with a specific name.
[ "GetFactory", "returns", "the", "factory", "with", "a", "specific", "name", "." ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/factories.go#L118-L125
21,194
muesli/beehive
bees/factories.go
GetFactories
func GetFactories() []*BeeFactoryInterface { r := []*BeeFactoryInterface{} for _, factory := range factories { r = append(r, factory) } return r }
go
func GetFactories() []*BeeFactoryInterface { r := []*BeeFactoryInterface{} for _, factory := range factories { r = append(r, factory) } return r }
[ "func", "GetFactories", "(", ")", "[", "]", "*", "BeeFactoryInterface", "{", "r", ":=", "[", "]", "*", "BeeFactoryInterface", "{", "}", "\n", "for", "_", ",", "factory", ":=", "range", "factories", "{", "r", "=", "append", "(", "r", ",", "factory", ")", "\n", "}", "\n\n", "return", "r", "\n", "}" ]
// GetFactories returns all known bee factories.
[ "GetFactories", "returns", "all", "known", "bee", "factories", "." ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/factories.go#L128-L135
21,195
muesli/beehive
bees/chains.go
GetChain
func GetChain(id string) *Chain { for _, c := range chains { if c.Name == id { return &c } } return nil }
go
func GetChain(id string) *Chain { for _, c := range chains { if c.Name == id { return &c } } return nil }
[ "func", "GetChain", "(", "id", "string", ")", "*", "Chain", "{", "for", "_", ",", "c", ":=", "range", "chains", "{", "if", "c", ".", "Name", "==", "id", "{", "return", "&", "c", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// GetChain returns a chain with a specific id
[ "GetChain", "returns", "a", "chain", "with", "a", "specific", "id" ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/chains.go#L52-L60
21,196
muesli/beehive
bees/chains.go
SetChains
func SetChains(cs []Chain) { newcs := []Chain{} // migrate old chain style for _, c := range cs { for _, el := range c.Elements { if el.Action.Name != "" { el.Action.ID = UUID() c.Actions = append(c.Actions, el.Action.ID) actions = append(actions, el.Action) } if el.Filter.Name != "" { //FIXME: migrate old style filters c.Filters = append(c.Filters, el.Filter.Options.Value.(string)) } } c.Elements = []ChainElement{} newcs = append(newcs, c) } chains = newcs }
go
func SetChains(cs []Chain) { newcs := []Chain{} // migrate old chain style for _, c := range cs { for _, el := range c.Elements { if el.Action.Name != "" { el.Action.ID = UUID() c.Actions = append(c.Actions, el.Action.ID) actions = append(actions, el.Action) } if el.Filter.Name != "" { //FIXME: migrate old style filters c.Filters = append(c.Filters, el.Filter.Options.Value.(string)) } } c.Elements = []ChainElement{} newcs = append(newcs, c) } chains = newcs }
[ "func", "SetChains", "(", "cs", "[", "]", "Chain", ")", "{", "newcs", ":=", "[", "]", "Chain", "{", "}", "\n", "// migrate old chain style", "for", "_", ",", "c", ":=", "range", "cs", "{", "for", "_", ",", "el", ":=", "range", "c", ".", "Elements", "{", "if", "el", ".", "Action", ".", "Name", "!=", "\"", "\"", "{", "el", ".", "Action", ".", "ID", "=", "UUID", "(", ")", "\n", "c", ".", "Actions", "=", "append", "(", "c", ".", "Actions", ",", "el", ".", "Action", ".", "ID", ")", "\n", "actions", "=", "append", "(", "actions", ",", "el", ".", "Action", ")", "\n", "}", "\n", "if", "el", ".", "Filter", ".", "Name", "!=", "\"", "\"", "{", "//FIXME: migrate old style filters", "c", ".", "Filters", "=", "append", "(", "c", ".", "Filters", ",", "el", ".", "Filter", ".", "Options", ".", "Value", ".", "(", "string", ")", ")", "\n", "}", "\n", "}", "\n", "c", ".", "Elements", "=", "[", "]", "ChainElement", "{", "}", "\n\n", "newcs", "=", "append", "(", "newcs", ",", "c", ")", "\n", "}", "\n\n", "chains", "=", "newcs", "\n", "}" ]
// SetChains sets the currently configured chains
[ "SetChains", "sets", "the", "currently", "configured", "chains" ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/chains.go#L63-L84
21,197
muesli/beehive
bees/chains.go
execChains
func execChains(event *Event) { for _, c := range chains { if c.Event.Name != event.Name || c.Event.Bee != event.Bee { continue } m := make(map[string]interface{}) for _, opt := range event.Options { m[opt.Name] = opt.Value } ctx.FillMap(m) failed := false log.Println("Executing chain:", c.Name, "-", c.Description) for _, el := range c.Filters { if execFilter(el, m) { log.Println("\t\tPassed filter!") } else { log.Println("\t\tDid not pass filter!") failed = true break } } if failed { continue } for _, el := range c.Actions { action := GetAction(el) if action == nil { log.Println("\t\tERROR: Unknown action referenced!") continue } execAction(*action, m) } } }
go
func execChains(event *Event) { for _, c := range chains { if c.Event.Name != event.Name || c.Event.Bee != event.Bee { continue } m := make(map[string]interface{}) for _, opt := range event.Options { m[opt.Name] = opt.Value } ctx.FillMap(m) failed := false log.Println("Executing chain:", c.Name, "-", c.Description) for _, el := range c.Filters { if execFilter(el, m) { log.Println("\t\tPassed filter!") } else { log.Println("\t\tDid not pass filter!") failed = true break } } if failed { continue } for _, el := range c.Actions { action := GetAction(el) if action == nil { log.Println("\t\tERROR: Unknown action referenced!") continue } execAction(*action, m) } } }
[ "func", "execChains", "(", "event", "*", "Event", ")", "{", "for", "_", ",", "c", ":=", "range", "chains", "{", "if", "c", ".", "Event", ".", "Name", "!=", "event", ".", "Name", "||", "c", ".", "Event", ".", "Bee", "!=", "event", ".", "Bee", "{", "continue", "\n", "}", "\n\n", "m", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "for", "_", ",", "opt", ":=", "range", "event", ".", "Options", "{", "m", "[", "opt", ".", "Name", "]", "=", "opt", ".", "Value", "\n", "}", "\n", "ctx", ".", "FillMap", "(", "m", ")", "\n\n", "failed", ":=", "false", "\n", "log", ".", "Println", "(", "\"", "\"", ",", "c", ".", "Name", ",", "\"", "\"", ",", "c", ".", "Description", ")", "\n", "for", "_", ",", "el", ":=", "range", "c", ".", "Filters", "{", "if", "execFilter", "(", "el", ",", "m", ")", "{", "log", ".", "Println", "(", "\"", "\\t", "\\t", "\"", ")", "\n", "}", "else", "{", "log", ".", "Println", "(", "\"", "\\t", "\\t", "\"", ")", "\n", "failed", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "failed", "{", "continue", "\n", "}", "\n\n", "for", "_", ",", "el", ":=", "range", "c", ".", "Actions", "{", "action", ":=", "GetAction", "(", "el", ")", "\n", "if", "action", "==", "nil", "{", "log", ".", "Println", "(", "\"", "\\t", "\\t", "\"", ")", "\n", "continue", "\n", "}", "\n", "execAction", "(", "*", "action", ",", "m", ")", "\n", "}", "\n", "}", "\n", "}" ]
// execChains executes chains for an event we received
[ "execChains", "executes", "chains", "for", "an", "event", "we", "received" ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/chains.go#L87-L123
21,198
muesli/beehive
app/app.go
AddFlags
func AddFlags(flags []CliFlag) { for _, flag := range flags { appflags = append(appflags, flag) } }
go
func AddFlags(flags []CliFlag) { for _, flag := range flags { appflags = append(appflags, flag) } }
[ "func", "AddFlags", "(", "flags", "[", "]", "CliFlag", ")", "{", "for", "_", ",", "flag", ":=", "range", "flags", "{", "appflags", "=", "append", "(", "appflags", ",", "flag", ")", "\n", "}", "\n", "}" ]
// AddFlags adds CliFlags to appflags
[ "AddFlags", "adds", "CliFlags", "to", "appflags" ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/app/app.go#L42-L46
21,199
muesli/beehive
app/app.go
Run
func Run() { for _, f := range appflags { switch f.Value.(type) { case string: flag.StringVar((f.V).(*string), f.Name, f.Value.(string), f.Desc) case bool: flag.BoolVar((f.V).(*bool), f.Name, f.Value.(bool), f.Desc) } } flag.Parse() }
go
func Run() { for _, f := range appflags { switch f.Value.(type) { case string: flag.StringVar((f.V).(*string), f.Name, f.Value.(string), f.Desc) case bool: flag.BoolVar((f.V).(*bool), f.Name, f.Value.(bool), f.Desc) } } flag.Parse() }
[ "func", "Run", "(", ")", "{", "for", "_", ",", "f", ":=", "range", "appflags", "{", "switch", "f", ".", "Value", ".", "(", "type", ")", "{", "case", "string", ":", "flag", ".", "StringVar", "(", "(", "f", ".", "V", ")", ".", "(", "*", "string", ")", ",", "f", ".", "Name", ",", "f", ".", "Value", ".", "(", "string", ")", ",", "f", ".", "Desc", ")", "\n", "case", "bool", ":", "flag", ".", "BoolVar", "(", "(", "f", ".", "V", ")", ".", "(", "*", "bool", ")", ",", "f", ".", "Name", ",", "f", ".", "Value", ".", "(", "bool", ")", ",", "f", ".", "Desc", ")", "\n", "}", "\n", "}", "\n\n", "flag", ".", "Parse", "(", ")", "\n", "}" ]
// Run sets up all the cli-param mappings
[ "Run", "sets", "up", "all", "the", "cli", "-", "param", "mappings" ]
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/app/app.go#L49-L60