idx
int64 0
167k
| question
stringlengths 60
3.56k
| target
stringlengths 5
1.43k
| len_question
int64 21
889
| len_target
int64 3
529
|
---|---|---|---|---|
200 | func ( ts * Store ) Size ( id string ) ( int64 , error ) { sz , err := fileutil . DirSize ( ts . GetPath ( id ) ) if err != nil { return - 1 , errwrap . Wrap ( errors . New ( " " ) , err ) } return sz , nil } | Size returns the size of the rootfs for the provided id . It is a relatively expensive operation it goes through all the files and adds up their size . | 68 | 31 |
201 | func ( ts * Store ) GetImageHash ( id string ) ( string , error ) { treepath := ts . GetPath ( id ) imgHash , err := ioutil . ReadFile ( filepath . Join ( treepath , imagefilename ) ) if err != nil { return " " , errwrap . Wrap ( errors . New ( " " ) , err ) } return string ( imgHash ) , nil } | GetImageHash returns the hash of the image that uses the tree store identified by id . | 89 | 18 |
202 | func HasPrefix ( p string ) FilterFunc { return FilterFunc ( func ( m * Mount ) bool { return strings . HasPrefix ( m . MountPoint , p ) } ) } | HasPrefix returns a FilterFunc which returns true if the mountpoint of a given mount has prefix p else false . | 42 | 25 |
203 | func ParseMounts ( pid uint ) ( Mounts , error ) { var procPath string if pid == 0 { procPath = " " } else { procPath = fmt . Sprintf ( " " , pid ) } mi , err := os . Open ( procPath ) if err != nil { return nil , err } defer mi . Close ( ) return parseMountinfo ( mi ) } | ParseMounts returns all mountpoints associated with a process mount namespace . The special value 0 as pid argument is used to specify the current process . | 82 | 30 |
204 | func findResources ( isolators types . Isolators ) ( mem , cpus int64 ) { for _ , i := range isolators { switch v := i . Value ( ) . ( type ) { case * types . ResourceMemory : mem = v . Limit ( ) . Value ( ) // Convert bytes into megabytes mem /= 1024 * 1024 case * types . ResourceCPU : cpus = v . Limit ( ) . Value ( ) } } return mem , cpus } | findResources finds value of last isolator for particular type . | 100 | 12 |
205 | func wrapStructLevelFunc ( fn StructLevelFunc ) StructLevelFuncCtx { return func ( ctx context . Context , sl StructLevel ) { fn ( sl ) } } | wrapStructLevelFunc wraps normal StructLevelFunc makes it compatible with StructLevelFuncCtx | 40 | 21 |
206 | func ( v * validate ) ExtractType ( field reflect . Value ) ( reflect . Value , reflect . Kind , bool ) { return v . extractTypeInternal ( field , false ) } | ExtractType gets the actual underlying type of field value . | 38 | 12 |
207 | func ( v * validate ) ReportError ( field interface { } , fieldName , structFieldName , tag , param string ) { fv , kind , _ := v . extractTypeInternal ( reflect . ValueOf ( field ) , false ) if len ( structFieldName ) == 0 { structFieldName = fieldName } v . str1 = string ( append ( v . ns , fieldName ... ) ) if v . v . hasTagNameFunc || fieldName != structFieldName { v . str2 = string ( append ( v . actualNs , structFieldName ... ) ) } else { v . str2 = v . str1 } if kind == reflect . Invalid { v . errs = append ( v . errs , & fieldError { v : v . v , tag : tag , actualTag : tag , ns : v . str1 , structNs : v . str2 , fieldLen : uint8 ( len ( fieldName ) ) , structfieldLen : uint8 ( len ( structFieldName ) ) , param : param , kind : kind , } , ) return } v . errs = append ( v . errs , & fieldError { v : v . v , tag : tag , actualTag : tag , ns : v . str1 , structNs : v . str2 , fieldLen : uint8 ( len ( fieldName ) ) , structfieldLen : uint8 ( len ( structFieldName ) ) , value : fv . Interface ( ) , param : param , kind : kind , typ : fv . Type ( ) , } , ) } | ReportError reports an error just by passing the field and tag information | 334 | 13 |
208 | func ValidateValuer ( field reflect . Value ) interface { } { if valuer , ok := field . Interface ( ) . ( driver . Valuer ) ; ok { val , err := valuer . Value ( ) if err == nil { return val } // handle the error how you want } return nil } | ValidateValuer implements validator . CustomTypeFunc | 65 | 12 |
209 | func ( e * InvalidValidationError ) Error ( ) string { if e . Type == nil { return " " } return " " + e . Type . String ( ) + " " } | Error returns InvalidValidationError message | 40 | 7 |
210 | func ( ve ValidationErrors ) Error ( ) string { buff := bytes . NewBufferString ( " " ) var fe * fieldError for i := 0 ; i < len ( ve ) ; i ++ { fe = ve [ i ] . ( * fieldError ) buff . WriteString ( fe . Error ( ) ) buff . WriteString ( " \n " ) } return strings . TrimSpace ( buff . String ( ) ) } | Error is intended for use in development + debugging and not intended to be a production error message . It allows ValidationErrors to subscribe to the Error interface . All information to create an error message specific to your application is contained within the FieldError found within the ValidationErrors array | 92 | 57 |
211 | func ( ve ValidationErrors ) Translate ( ut ut . Translator ) ValidationErrorsTranslations { trans := make ( ValidationErrorsTranslations ) var fe * fieldError for i := 0 ; i < len ( ve ) ; i ++ { fe = ve [ i ] . ( * fieldError ) // // in case an Anonymous struct was used, ensure that the key // // would be 'Username' instead of ".Username" // if len(fe.ns) > 0 && fe.ns[:1] == "." { // trans[fe.ns[1:]] = fe.Translate(ut) // continue // } trans [ fe . ns ] = fe . Translate ( ut ) } return trans } | Translate translates all of the ValidationErrors | 157 | 10 |
212 | func ( fe * fieldError ) Field ( ) string { return fe . ns [ len ( fe . ns ) - int ( fe . fieldLen ) : ] // // return fe.field // fld := fe.ns[len(fe.ns)-int(fe.fieldLen):] // log.Println("FLD:", fld) // if len(fld) > 0 && fld[:1] == "." { // return fld[1:] // } // return fld } | Field returns the fields name with the tag name taking precedence over the fields actual name . | 108 | 17 |
213 | func ( fe * fieldError ) StructField ( ) string { // return fe.structField return fe . structNs [ len ( fe . structNs ) - int ( fe . structfieldLen ) : ] } | returns the fields actual name from the struct when able to determine . | 44 | 14 |
214 | func ( fe * fieldError ) Error ( ) string { return fmt . Sprintf ( fieldErrMsg , fe . ns , fe . Field ( ) , fe . tag ) } | Error returns the fieldError s error message | 38 | 8 |
215 | func NotBlank ( fl validator . FieldLevel ) bool { field := fl . Field ( ) switch field . Kind ( ) { case reflect . String : return len ( strings . TrimSpace ( field . String ( ) ) ) > 0 case reflect . Chan , reflect . Map , reflect . Slice , reflect . Array : return field . Len ( ) > 0 case reflect . Ptr , reflect . Interface , reflect . Func : return ! field . IsNil ( ) default : return field . IsValid ( ) && field . Interface ( ) != reflect . Zero ( field . Type ( ) ) . Interface ( ) } } | NotBlank is the validation function for validating if the current field has a value or length greater than zero or is not a space only string . | 133 | 30 |
216 | func wrapFunc ( fn Func ) FuncCtx { if fn == nil { return nil // be sure not to wrap a bad function. } return func ( ctx context . Context , fl FieldLevel ) bool { return fn ( fl ) } } | wrapFunc wraps noramal Func makes it compatible with FuncCtx | 54 | 17 |
217 | func isUnique ( fl FieldLevel ) bool { field := fl . Field ( ) v := reflect . ValueOf ( struct { } { } ) switch field . Kind ( ) { case reflect . Slice , reflect . Array : m := reflect . MakeMap ( reflect . MapOf ( field . Type ( ) . Elem ( ) , v . Type ( ) ) ) for i := 0 ; i < field . Len ( ) ; i ++ { m . SetMapIndex ( field . Index ( i ) , v ) } return field . Len ( ) == m . Len ( ) case reflect . Map : m := reflect . MakeMap ( reflect . MapOf ( field . Type ( ) . Elem ( ) , v . Type ( ) ) ) for _ , k := range field . MapKeys ( ) { m . SetMapIndex ( field . MapIndex ( k ) , v ) } return field . Len ( ) == m . Len ( ) default : panic ( fmt . Sprintf ( " " , field . Interface ( ) ) ) } } | isUnique is the validation function for validating if each array|slice|map value is unique | 219 | 19 |
218 | func isMAC ( fl FieldLevel ) bool { _ , err := net . ParseMAC ( fl . Field ( ) . String ( ) ) return err == nil } | IsMAC is the validation function for validating if the field s value is a valid MAC address . | 35 | 20 |
219 | func isCIDRv4 ( fl FieldLevel ) bool { ip , _ , err := net . ParseCIDR ( fl . Field ( ) . String ( ) ) return err == nil && ip . To4 ( ) != nil } | IsCIDRv4 is the validation function for validating if the field s value is a valid v4 CIDR address . | 52 | 28 |
220 | func isCIDR ( fl FieldLevel ) bool { _ , _ , err := net . ParseCIDR ( fl . Field ( ) . String ( ) ) return err == nil } | IsCIDR is the validation function for validating if the field s value is a valid v4 or v6 CIDR address . | 41 | 29 |
221 | func isIPv6 ( fl FieldLevel ) bool { ip := net . ParseIP ( fl . Field ( ) . String ( ) ) return ip != nil && ip . To4 ( ) == nil } | IsIPv6 is the validation function for validating if the field s value is a valid v6 IP address . | 44 | 24 |
222 | func isIP ( fl FieldLevel ) bool { ip := net . ParseIP ( fl . Field ( ) . String ( ) ) return ip != nil } | IsIP is the validation function for validating if the field s value is a valid v4 or v6 IP address . | 33 | 25 |
223 | func isSSN ( fl FieldLevel ) bool { field := fl . Field ( ) if field . Len ( ) != 11 { return false } return sSNRegex . MatchString ( field . String ( ) ) } | IsSSN is the validation function for validating if the field s value is a valid SSN . | 46 | 21 |
224 | 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 ( " " , field . Interface ( ) ) ) } return longitudeRegex . MatchString ( v ) } | IsLongitude is the validation function for validating if the field s value is a valid longitude coordinate . | 219 | 22 |
225 | 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 ] ) } | IsDataURI is the validation function for validating if the field s value is a valid data URI . | 82 | 21 |
226 | func hasMultiByteCharacter ( fl FieldLevel ) bool { field := fl . Field ( ) if field . Len ( ) == 0 { return true } return multibyteRegex . MatchString ( field . String ( ) ) } | HasMultiByteCharacter is the validation function for validating if the field s value has a multi byte character . | 49 | 22 |
227 | 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 } | IsISBN13 is the validation function for validating if the field s value is a valid v13 ISBN . | 155 | 23 |
228 | 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 } | IsISBN10 is the validation function for validating if the field s value is a valid v10 ISBN . | 155 | 23 |
229 | 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 } | IsEthereumAddress is the validation function for validating if the field s value is a valid ethereum address based currently only on the format | 94 | 28 |
230 | func isBitcoinAddress ( fl FieldLevel ) bool { address := fl . Field ( ) . String ( ) if ! btcAddressRegex . MatchString ( address ) { return false } alphabet := [ ] byte ( " " ) 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 } | IsBitcoinAddress is the validation function for validating if the field s value is a valid btc address | 238 | 21 |
231 | 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 := " " 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 } | IsBitcoinBech32Address is the validation function for validating if the field s value is a valid bech32 btc address | 455 | 27 |
232 | func containsRune ( fl FieldLevel ) bool { r , _ := utf8 . DecodeRuneInString ( fl . Param ( ) ) return strings . ContainsRune ( fl . Field ( ) . String ( ) , r ) } | ContainsRune is the validation function for validating that the field s value contains the rune specified within the param . | 52 | 24 |
233 | func containsAny ( fl FieldLevel ) bool { return strings . ContainsAny ( fl . Field ( ) . String ( ) , fl . Param ( ) ) } | ContainsAny is the validation function for validating that the field s value contains any of the characters specified within the param . | 33 | 25 |
234 | func contains ( fl FieldLevel ) bool { return strings . Contains ( fl . Field ( ) . String ( ) , fl . Param ( ) ) } | Contains is the validation function for validating that the field s value contains the text specified within the param . | 31 | 22 |
235 | func startsWith ( fl FieldLevel ) bool { return strings . HasPrefix ( fl . Field ( ) . String ( ) , fl . Param ( ) ) } | StartsWith is the validation function for validating that the field s value starts with the text specified within the param . | 34 | 24 |
236 | func endsWith ( fl FieldLevel ) bool { return strings . HasSuffix ( fl . Field ( ) . String ( ) , fl . Param ( ) ) } | EndsWith is the validation function for validating that the field s value ends with the text specified within the param . | 35 | 24 |
237 | func fieldContains ( fl FieldLevel ) bool { field := fl . Field ( ) currentField , _ , ok := fl . GetStructFieldOK ( ) if ! ok { return false } return strings . Contains ( field . String ( ) , currentField . String ( ) ) } | FieldContains is the validation function for validating if the current field s value contains the field specified by the param s value . | 59 | 26 |
238 | func fieldExcludes ( fl FieldLevel ) bool { field := fl . Field ( ) currentField , _ , ok := fl . GetStructFieldOK ( ) if ! ok { return true } return ! strings . Contains ( field . String ( ) , currentField . String ( ) ) } | FieldExcludes is the validation function for validating if the current field s value excludes the field specified by the param s value . | 60 | 26 |
239 | 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 ( ) } | 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 . | 311 | 35 |
240 | 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 ( " " , field . Interface ( ) ) ) } | IsEq is the validation function for validating if the current field s value is equal to the param s value . | 216 | 24 |
241 | 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 ( " " , field . Interface ( ) ) ) } | IsURI is the validation function for validating if the current field s value is a valid URI . | 201 | 20 |
242 | 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 ( " " , field . Interface ( ) ) ) } | isUrnRFC2141 is the validation function for validating if the current field s value is a valid URN as per RFC 2141 . | 78 | 30 |
243 | 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 ( " " , field . Interface ( ) ) ) } | IsFile is the validation function for validating if the current field s value is a valid file path . | 80 | 21 |
244 | 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 ( ) ) } } | IsNumber is the validation function for validating if the current field s value is a valid number . | 115 | 20 |
245 | 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 ( ) } } | HasValue is the validation function for validating if the current field s value is not the default static value . | 118 | 22 |
246 | 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 ( " " , field . Interface ( ) ) ) } | IsLte is the validation function for validating if the current field s value is less than or equal to the param s value . | 291 | 27 |
247 | func isTCP4AddrResolvable ( fl FieldLevel ) bool { if ! isIP4Addr ( fl ) { return false } _ , err := net . ResolveTCPAddr ( " " , fl . Field ( ) . String ( ) ) return err == nil } | IsTCP4AddrResolvable is the validation function for validating if the field s value is a resolvable tcp4 address . | 62 | 30 |
248 | func isUDPAddrResolvable ( fl FieldLevel ) bool { if ! isIP4Addr ( fl ) && ! isIP6Addr ( fl ) { return false } _ , err := net . ResolveUDPAddr ( " " , fl . Field ( ) . String ( ) ) return err == nil } | IsUDPAddrResolvable is the validation function for validating if the field s value is a resolvable udp address . | 71 | 29 |
249 | func isIP4AddrResolvable ( fl FieldLevel ) bool { if ! isIPv4 ( fl ) { return false } _ , err := net . ResolveIPAddr ( " " , fl . Field ( ) . String ( ) ) return err == nil } | IsIP4AddrResolvable is the validation function for validating if the field s value is a resolvable ip4 address . | 59 | 29 |
250 | func isIP6AddrResolvable ( fl FieldLevel ) bool { if ! isIPv6 ( fl ) { return false } _ , err := net . ResolveIPAddr ( " " , fl . Field ( ) . String ( ) ) return err == nil } | IsIP6AddrResolvable is the validation function for validating if the field s value is a resolvable ip6 address . | 59 | 29 |
251 | func isIPAddrResolvable ( fl FieldLevel ) bool { if ! isIP ( fl ) { return false } _ , err := net . ResolveIPAddr ( " " , fl . Field ( ) . String ( ) ) return err == nil } | IsIPAddrResolvable is the validation function for validating if the field s value is a resolvable ip address . | 56 | 27 |
252 | func isUnixAddrResolvable ( fl FieldLevel ) bool { _ , err := net . ResolveUnixAddr ( " " , fl . Field ( ) . String ( ) ) return err == nil } | IsUnixAddrResolvable is the validation function for validating if the field s value is a resolvable unix address . | 45 | 28 |
253 | 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 } } | 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 . | 199 | 31 |
254 | func asInt ( param string ) int64 { i , err := strconv . ParseInt ( param , 0 , 64 ) panicIf ( err ) return i } | asInt returns the parameter as a int64 or panics if it can t convert | 35 | 17 |
255 | func asUint ( param string ) uint64 { i , err := strconv . ParseUint ( param , 0 , 64 ) panicIf ( err ) return i } | asUint returns the parameter as a uint64 or panics if it can t convert | 37 | 18 |
256 | func asFloat ( param string ) float64 { i , err := strconv . ParseFloat ( param , 64 ) panicIf ( err ) return i } | asFloat returns the parameter as a float64 or panics if it can t convert | 33 | 17 |
257 | 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 } | New returns a new instance of validate with sane defaults . | 294 | 11 |
258 | func ( v * Validate ) RegisterValidationCtx ( tag string , fn FuncCtx ) error { return v . registerValidation ( tag , fn , false ) } | RegisterValidationCtx does the same as RegisterValidation on accepts a FuncCtx validation allowing context . Context validation support . | 38 | 27 |
259 | 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 } | RegisterTranslation registers translations against the provided tag . | 142 | 9 |
260 | 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 ) } } | parent and current will be the same the first run of validateStruct | 459 | 13 |
261 | func ( v * validate ) GetStructFieldOK ( ) ( reflect . Value , reflect . Kind , bool ) { return v . getStructFieldOKInternal ( v . slflParent , v . ct . param ) } | GetStructFieldOK returns Param returns param for validation against current field | 47 | 13 |
262 | func ( r * ActionResource ) Register ( container * restful . Container , config smolder . APIConfig , context smolder . APIContextFactory ) { r . Name = " " r . TypeName = " " r . Endpoint = " " r . Doc = " " r . Config = config r . Context = context r . Init ( container , r ) } | Register this resource with the container to setup all the routes | 81 | 11 |
263 | func ( r * BeeResource ) Validate ( context smolder . APIContext , data interface { } , request * restful . Request ) error { // ps := data.(*BeePostStruct) // FIXME return nil } | Validate checks an incoming request for data errors | 49 | 9 |
264 | func RegisterBee ( bee BeeInterface ) { log . Println ( " " , bee . Name ( ) , " " , bee . Description ( ) ) bees [ bee . Name ( ) ] = & bee } | RegisterBee gets called by Bees to register themselves . | 44 | 10 |
265 | func GetBee ( identifier string ) * BeeInterface { bee , ok := bees [ identifier ] if ok { return bee } return nil } | GetBee returns a bee with a specific name . | 28 | 10 |
266 | func GetBees ( ) [ ] * BeeInterface { r := [ ] * BeeInterface { } for _ , bee := range bees { r = append ( r , bee ) } return r } | GetBees returns all known bees . | 41 | 8 |
267 | func startBee ( bee * BeeInterface , fatals int ) { if fatals >= 3 { log . Println ( " " , ( * bee ) . Name ( ) , " " , fatals , " " ) ( * bee ) . Stop ( ) return } ( * bee ) . WaitGroup ( ) . Add ( 1 ) defer ( * bee ) . WaitGroup ( ) . Done ( ) defer func ( bee * BeeInterface ) { if e := recover ( ) ; e != nil { log . Println ( " " , e , fatals ) go startBee ( bee , fatals + 1 ) } } ( bee ) ( * bee ) . Run ( eventsIn ) } | startBee starts a bee and recovers from panics . | 144 | 11 |
268 | func NewBeeInstance ( bee BeeConfig ) * BeeInterface { factory := GetFactory ( bee . Class ) if factory == nil { panic ( " " + bee . Class ) } mod := ( * factory ) . New ( bee . Name , bee . Description , bee . Options ) RegisterBee ( mod ) return & mod } | NewBeeInstance sets up a new Bee with supplied config . | 67 | 12 |
269 | func StartBee ( bee BeeConfig ) * BeeInterface { b := NewBeeInstance ( bee ) ( * b ) . Start ( ) go func ( mod * BeeInterface ) { startBee ( mod , 0 ) } ( b ) return b } | StartBee starts a bee . | 51 | 6 |
270 | func StartBees ( beeList [ ] BeeConfig ) { eventsIn = make ( chan Event ) go handleEvents ( ) for _ , bee := range beeList { StartBee ( bee ) } } | StartBees starts all registered bees . | 43 | 8 |
271 | func StopBees ( ) { for _ , bee := range bees { log . Println ( " " , ( * bee ) . Name ( ) ) ( * bee ) . Stop ( ) } close ( eventsIn ) bees = make ( map [ string ] * BeeInterface ) } | StopBees stops all bees gracefully . | 59 | 9 |
272 | func RestartBee ( bee * BeeInterface ) { ( * bee ) . Stop ( ) ( * bee ) . SetSigChan ( make ( chan bool ) ) ( * bee ) . Start ( ) go func ( mod * BeeInterface ) { startBee ( mod , 0 ) } ( bee ) } | RestartBee restarts a Bee . | 65 | 8 |
273 | 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 } | NewBee returns a new bee and sets up sig - channel & waitGroup . | 76 | 16 |
274 | func ( bee * Bee ) Stop ( ) { if ! bee . IsRunning ( ) { return } log . Println ( bee . Name ( ) , " " ) close ( bee . SigChan ) bee . waitGroup . Wait ( ) bee . Running = false log . Println ( bee . Name ( ) , " " ) } | Stop gracefully stops a Bee . | 70 | 7 |
275 | 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 ) } | Logln logs args | 81 | 4 |
276 | func ( bee * Bee ) Logf ( format string , args ... interface { } ) { s := fmt . Sprintf ( format , args ... ) log . Printf ( " " , bee . Name ( ) , s ) Log ( bee . Name ( ) , s , 0 ) } | Logf logs a formatted string | 60 | 6 |
277 | func ( bee * Bee ) LogErrorf ( format string , args ... interface { } ) { s := fmt . Sprintf ( format , args ... ) log . Errorf ( " " , bee . Name ( ) , s ) Log ( bee . Name ( ) , s , 1 ) } | LogErrorf logs a formatted error string | 61 | 8 |
278 | 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 ) } | LogFatal logs a fatal error | 82 | 7 |
279 | func handleEvents ( ) { for { event , ok := <- eventsIn if ! ok { log . Println ( ) log . Println ( " " ) break } bee := GetBee ( event . Bee ) ( * bee ) . LogEvent ( ) log . Println ( ) log . Println ( " " , event . Bee , " " , event . Name , " " , GetEventDescriptor ( & event ) . Description ) for _ , v := range event . Options { log . Println ( " \t " , v ) } go func ( ) { defer func ( ) { if e := recover ( ) ; e != nil { log . Printf ( " " , e , debug . Stack ( ) ) } } ( ) execChains ( & event ) } ( ) } } | handleEvents handles incoming events and executes matching Chains . | 169 | 10 |
280 | func GetFilter ( identifier string ) * FilterInterface { filter , ok := filters [ identifier ] if ok { return filter } return nil } | GetFilter returns a filter with a specific name | 28 | 9 |
281 | func ( r * ActionResponse ) AddAction ( action * bees . Action ) { r . actions = append ( r . actions , action ) r . Actions = append ( r . Actions , prepareActionResponse ( r . Context , action ) ) } | AddAction adds a action to the response | 51 | 8 |
282 | func ( r * LogResponse ) AddLog ( log * bees . LogMessage ) { r . logs = append ( r . logs , log ) r . Logs = append ( r . Logs , prepareLogResponse ( r . Context , log ) ) } | AddLog adds a log to the response | 54 | 8 |
283 | func GetAction ( id string ) * Action { for _ , a := range actions { if a . ID == id { return & a } } return nil } | GetAction returns one action with a specific ID . | 33 | 10 |
284 | 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 = " " 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 ( " \t " , a . Bee , " " , a . Name , " " , GetActionDescriptor ( & a ) . Description ) for _ , v := range a . Options { log . Println ( " \t \t " , v ) } ( * bee ) . Action ( a ) } else { log . Println ( " \t " , a . Bee , " " , a . Name , " " , GetActionDescriptor ( & a ) . Description ) for _ , v := range a . Options { log . Println ( " \t \t " , v ) } } return true } | execAction executes an action and map its ins & outs . | 370 | 12 |
285 | func ( context * APIContext ) NewAPIContext ( ) smolder . APIContext { ctx := & APIContext { Config : context . Config , } return ctx } | NewAPIContext returns a new polly context | 44 | 11 |
286 | 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 } } } } | SetValue sets a value in the Placeholder slice . | 121 | 11 |
287 | func ( ph Placeholders ) Value ( name string ) interface { } { for _ , p := range ph { if p . Name == name { return p . Value } } return nil } | Value retrieves a value from a Placeholder slice . | 39 | 11 |
288 | func ( ph Placeholders ) Bind ( name string , dst interface { } ) error { v := ph . Value ( name ) if v == nil { return errors . New ( " " + name + " " ) } return ConvertValue ( v , dst ) } | Bind a value from a Placeholder slice . | 54 | 9 |
289 | func GetActionDescriptor ( action * Action ) ActionDescriptor { bee := GetBee ( action . Bee ) if bee == nil { panic ( " " + action . Bee + " " ) } factory := ( * GetFactory ( ( * bee ) . Namespace ( ) ) ) for _ , ac := range factory . Actions ( ) { if ac . Name == action . Name { return ac } } return ActionDescriptor { } } | GetActionDescriptor returns the ActionDescriptor matching an action . | 94 | 15 |
290 | func GetEventDescriptor ( event * Event ) EventDescriptor { bee := GetBee ( event . Bee ) if bee == nil { panic ( " " + event . Bee + " " ) } factory := ( * GetFactory ( ( * bee ) . Namespace ( ) ) ) for _ , ev := range factory . Events ( ) { if ev . Name == event . Name { return ev } } return EventDescriptor { } } | GetEventDescriptor returns the EventDescriptor matching an event . | 94 | 15 |
291 | func ( factory * IrcBeeFactory ) States ( ) [ ] bees . StateDescriptor { opts := [ ] bees . StateDescriptor { { Name : " " , Description : " " , Type : " " , } , { Name : " " , Description : " " , Type : " " , } , } return opts } | States returns the state values provided by this Bee . | 74 | 10 |
292 | func ( r * ChainResponse ) AddChain ( chain bees . Chain ) { r . chains [ chain . Name ] = & chain } | AddChain adds a chain to the response | 28 | 8 |
293 | func ( c * crontime ) checkValues ( ) { for _ , sec := range c . second { if sec >= 60 || sec < 0 { log . Panicln ( " \" \" " ) } } for _ , min := range c . second { if min >= 60 || min < 0 { log . Panicln ( " \" \" " ) } } for _ , hour := range c . hour { if hour >= 24 || hour < 0 { log . Panicln ( " \" \" " ) } } for _ , dow := range c . dow { if dow >= 7 || dow < 0 { log . Panicln ( " \" \" " ) } } for _ , dom := range c . dom { if dom >= 32 || dom < 1 { log . Panicln ( " \" \" " ) } } for _ , month := range c . month { if month >= 13 || month < 1 { log . Panicln ( " \" \" " ) } } } | Look for obvious nonsense in the config . | 200 | 8 |
294 | 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 } | Returns an array filled with all values between a and b considering the base . | 76 | 15 |
295 | func NewLogMessage ( bee string , message string , messageType uint ) LogMessage { return LogMessage { ID : UUID ( ) , Bee : bee , Message : message , MessageType : messageType , Timestamp : time . Now ( ) , } } | NewLogMessage returns a newly composed LogMessage | 54 | 9 |
296 | func Log ( bee string , message string , messageType uint ) { logMutex . Lock ( ) defer logMutex . Unlock ( ) logs [ bee ] = append ( logs [ bee ] , NewLogMessage ( bee , message , messageType ) ) } | Log adds a new LogMessage to the log | 54 | 9 |
297 | 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 } | GetLogs returns all logs for a Bee . | 91 | 10 |
298 | 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 := " " switch color { case " " : c = " " case " " : c = " " case " " : c = " " case " " : c = " " case " " : c = " " case " " : c = " " case " " : c = " " case " " : c = " " case " " : c = " " case " " : c = " " case " " : c = " " case " " : c = " " case " " : c = " " case " " : c = " " case " " : c = " " case " " : c = " " } return " \x03 " + c + val + " \x03 " } | Colored wraps val in color styling tags . | 252 | 9 |
299 | func ( opts BeeOptions ) Value ( name string ) interface { } { for _ , opt := range opts { if opt . Name == name { return opt . Value } } return nil } | Value retrieves a value from a BeeOptions slice . | 41 | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.