// Code produces Go code that runs the validation checks recursively over the given attribute.
199351
func (v *Validator) Code(att *design.AttributeDefinition, nonzero, required, hasDefault bool, target, context string, depth int, private bool) string {
	if _, ok := att.Metadata["struct:field:type"]; ok {
		// Skip validation generation for attributes with custom types
		return ""
	}
	buf := v.recurse(att, nonzero, required, hasDefault, target, context, depth, private)
	return buf.String()
}
392725
func Code(err error) codes.Code {
	if code, ok := Tag.In(err); ok {
		return code
	}
	// TODO(nodir): use status.FromError
	return grpc.Code(errors.Unwrap(err))
}
1111145
func (v *Validator) Validate(x interface{}) error {
	jsv, err := v.validator()
	if err != nil {
		return err
	}
	return jsv.Validate(x)
}
458973
func (r *CodeRequest) Validate(db ethdb.Database, msg *Msg) error {
	log.Debug("Validating code data", "hash", r.Hash)

	// Ensure we have a correct message with a single code element
	if msg.MsgType != MsgCode {
		return errInvalidMessageType
	}
	reply := msg.Obj.([][]byte)
	if len(reply) != 1 {
		return errInvalidEntryCount
	}
	data := reply[0]

	// Verify the data and store if checks out
	if hash := crypto.Keccak256Hash(data); r.Hash != hash {
		return errDataHashMismatch
	}
	r.Data = data
	return nil
}
536530
func (process *process) ExitCode() (int, error) {
	code, err := process.p.ExitCode()
	if err != nil {
		err = convertProcessError(err, process)
	}
	return code, err
}
692833
func (f Function) ExecCode() (string, error) {
	name := f.Name
	if f.Receiver != "" {
		name = f.Receiver + "{}." + name
	}
	if f.Package != "" {
		name = f.Package + "." + name
	}

	if f.IsContext && f.IsError {
		out := `
			wrapFn := func(ctx context.Context) error {
				return %s(ctx)
			}
			err := runTarget(wrapFn)`[1:]
		return fmt.Sprintf(out, name), nil
	}
	if f.IsContext && !f.IsError {
		out := `
			wrapFn := func(ctx context.Context) error {
				%s(ctx)
				return nil
			}
			err := runTarget(wrapFn)`[1:]
		return fmt.Sprintf(out, name), nil
	}
	if !f.IsContext && f.IsError {
		out := `
			wrapFn := func(ctx context.Context) error {
				return %s()
			}
			err := runTarget(wrapFn)`[1:]
		return fmt.Sprintf(out, name), nil
	}
	if !f.IsContext && !f.IsError {
		out := `
			wrapFn := func(ctx context.Context) error {
				%s()
				return nil
			}
			err := runTarget(wrapFn)`[1:]
		return fmt.Sprintf(out, name), nil
	}
	return "", fmt.Errorf("Error formatting ExecCode code for %#v", f)
}
949249
func (ex Example) GoCode() string {
	var buf bytes.Buffer
	m := exampleFuncMap
	if fMap, ok := exampleCustomizations[ex.API.PackageName()]; ok {
		m = fMap
	}
	tmpl := exampleTmpls.Funcs(m)
	if err := tmpl.ExecuteTemplate(&buf, "example", &ex); err != nil {
		panic(err)
	}

	return strings.TrimSpace(buf.String())
}
1251216
func (g *SearchService) Code(uri *Hyperlink, uriParams M) (codeSearchResults *CodeSearchResults, result *Result) {
	url, err := ExpandWithDefault(uri, &CodeSearchURL, uriParams)
	if err != nil {
		return nil, &Result{Err: err}
	}

	result = g.client.get(url, &codeSearchResults)
	return
}
238691
func (w *Waiter) GoCode() string {
	var buf bytes.Buffer
	if err := waiterTmpls.ExecuteTemplate(&buf, "waiter", w); err != nil {
		panic(err)
	}

	return buf.String()
}
828887
func WithCode(code int, format string, a ...interface{}) {
	// use Warning because Error will display a duplicate message to stderr
	glog.Warningf(format, a...)
	console.Fatal(format, a...)
	os.Exit(code)
}
149806
func (sv ShapeValidation) GoCode() string {
	var err error

	w := &bytes.Buffer{}
	switch sv.Type {
	case ShapeValidationRequired:
		err = validationGoCodeTmpls.ExecuteTemplate(w, "requiredValue", sv)
	case ShapeValidationMinVal:
		switch sv.Ref.Shape.Type {
		case "list", "map", "blob":
			err = validationGoCodeTmpls.ExecuteTemplate(w, "minLen", sv)
		case "string":
			err = validationGoCodeTmpls.ExecuteTemplate(w, "minLenString", sv)
		case "integer", "long", "float", "double":
			err = validationGoCodeTmpls.ExecuteTemplate(w, "minVal", sv)
		default:
			panic(fmt.Sprintf("ShapeValidation.GoCode, %s's type %s, no min value handling",
				sv.Name, sv.Ref.Shape.Type))
		}
	case ShapeValidationNested:
		switch sv.Ref.Shape.Type {
		case "map", "list":
			err = validationGoCodeTmpls.ExecuteTemplate(w, "nestedMapList", sv)
		default:
			err = validationGoCodeTmpls.ExecuteTemplate(w, "nestedStruct", sv)
		}
	default:
		panic(fmt.Sprintf("ShapeValidation.GoCode, %s's type %d, unknown validation type",
			sv.Name, sv.Type))
	}

	if err != nil {
		panic(fmt.Sprintf("ShapeValidation.GoCode failed, err: %v", err))
	}

	return w.String()
}
586545
func GenerateCode(secret string, t time.Time) (string, error) {
	return GenerateCodeCustom(secret, t, ValidateOpts{
		Period:    30,
		Skew:      1,
		Digits:    otp.DigitsSix,
		Algorithm: otp.AlgorithmSHA1,
	})
}
970472
func (a *Application) Validate(validator ApplicationValidator) *Application {
	a.validator = validator
	return a
}
327475
func (e *RequiredValidator) Validate(s interface{}) error {
	if e.TagName == "" {
		e.TagName = "required"
	}

	if e.TagValue == "" {
		e.TagValue = "true"
	}

	for _, field := range structs.Fields(s) {
		if err := e.processField("", field); err != nil {
			return err
		}
	}

	return nil
}
1079759
func (s *Spec) GetCode(msg interface{}) (uint64, bool) {
	s.init()
	typ := reflect.TypeOf(msg)
	if typ.Kind() == reflect.Ptr {
		typ = typ.Elem()
	}
	code, ok := s.codes[typ]
	return code, ok
}
394912
func TypeCode(g Generator, spec compile.TypeSpec) string {
	wire := g.Import("go.uber.org/thriftrw/wire")
	spec = compile.RootTypeSpec(spec)

	switch spec.(type) {
	case *compile.BoolSpec:
		return fmt.Sprintf("%s.TBool", wire)
	case *compile.I8Spec:
		return fmt.Sprintf("%s.TI8", wire)
	case *compile.I16Spec:
		return fmt.Sprintf("%s.TI16", wire)
	case *compile.I32Spec:
		return fmt.Sprintf("%s.TI32", wire)
	case *compile.I64Spec:
		return fmt.Sprintf("%s.TI64", wire)
	case *compile.DoubleSpec:
		return fmt.Sprintf("%s.TDouble", wire)
	case *compile.StringSpec, *compile.BinarySpec:
		return fmt.Sprintf("%s.TBinary", wire)
	case *compile.MapSpec:
		return fmt.Sprintf("%s.TMap", wire)
	case *compile.ListSpec:
		return fmt.Sprintf("%s.TList", wire)
	case *compile.SetSpec:
		return fmt.Sprintf("%s.TSet", wire)
	case *compile.EnumSpec:
		return fmt.Sprintf("%s.TI32", wire)
	case *compile.StructSpec:
		return fmt.Sprintf("%s.TStruct", wire)
	default:
		panic(fmt.Sprintf("unknown type spec %v (type %T)", spec, spec))
	}
}
207994
func (e *Encoder) Encode(in interface{}) (*dynamodb.AttributeValue, error) {
	av := &dynamodb.AttributeValue{}
	if err := e.encode(av, reflect.ValueOf(in), tag{}); err != nil {
		return nil, err
	}

	return av, nil
}