// creates new enum field
// f : enum's member
// e : the enum representation
496219
func newEnumField(f interface{}, e enum) enumField {
	var val string

	// field name = enum name + field name
	name := fmt.Sprintf("%v%v", e.Name, f)

	// first, any characters that don't match any valid variable character are replaced with '_'
	alwaysInvalid := regexp.MustCompile("[^a-zA-Z0-9_]")
	validName := alwaysInvalid.ReplaceAllLiteralString(name, "_")

	switch v := f.(type) {
	case string:
		val = fmt.Sprintf(`"%v"`, v)
	case int:
		val = fmt.Sprintf("%v", v)
	}
	return enumField{
		Name:  validName,
		Value: val,
		Type:  e.Name,
	}
}
886215
func Newf(format string, a ...interface{}) Goof {
	return WithError(fmt.Sprintf(format, a), nil)
}
552550
func NewEnumFlag(defaultValue string, vs []string) *EnumFlag {
	f := &EnumFlag{
		i:            -1,
		vs:           vs,
		defaultValue: defaultValue,
	}
	return f
}
273566
func (self *EnumTypeDef) Init() *EnumTypeDef {
	if self.Elements == nil {
		self.Elements = make([]*EnumElementDef, 0)
	}
	return self
}
414051
func (p *parserMixin) Enums(options ...string) (target *[]string) {
	target = new([]string)
	p.EnumsVar(target, options...)
	return
}
594478
func (self *EnumTypeDef) UnmarshalJSON(b []byte) error {
	var m rawEnumTypeDef
	err := json.Unmarshal(b, &m)
	if err == nil {
		o := EnumTypeDef(m)
		*self = *((&o).Init())
		err = self.Validate()
	}
	return err
}
1356376
func (api *API) CreateField(ctx context.Context, indexName string, fieldName string, opts ...FieldOption) (*Field, error) {
	span, _ := tracing.StartSpanFromContext(ctx, "API.CreateField")
	defer span.Finish()

	if err := api.validate(apiCreateField); err != nil {
		return nil, errors.Wrap(err, "validating api method")
	}

	// Apply functional options.
	fo := FieldOptions{}
	for _, opt := range opts {
		err := opt(&fo)
		if err != nil {
			return nil, errors.Wrap(err, "applying option")
		}
	}

	// Find index.
	index := api.holder.Index(indexName)
	if index == nil {
		return nil, newNotFoundError(ErrIndexNotFound)
	}

	// Create field.
	field, err := index.CreateField(fieldName, opts...)
	if err != nil {
		return nil, errors.Wrap(err, "creating field")
	}

	// Send the create field message to all nodes.
	err = api.server.SendSync(
		&CreateFieldMessage{
			Index: indexName,
			Field: fieldName,
			Meta:  &fo,
		})
	if err != nil {
		api.server.logger.Printf("problem sending CreateField message: %s", err)
		return nil, errors.Wrap(err, "sending CreateField message")
	}
	api.holder.Stats.CountWithCustomTags("createField", 1, 1.0, []string{fmt.Sprintf("index:%s", indexName)})
	return field, nil
}
540682
func (b binding) LookupEnum(p descriptor.Parameter) *descriptor.Enum {
	e, err := b.Registry.LookupEnum("", p.Target.GetTypeName())
	if err != nil {
		return nil
	}
	return e
}
239356
func (p *printer) Enum(enum *descriptor.EnumDescriptorProto) {
	p.MaybeLeadingComments(enum)
	defer p.open("enum %s", enum.GetName())()

	for _, v := range enum.Value {
		p.EnumValue(v)
	}
}
1011194
func (fs *FSObjects) createFsJSON(object, fsMetaPath string) error {
	fsMeta := newFSMetaV1()
	fsMeta.Meta = make(map[string]string)
	fsMeta.Meta["etag"] = GenETag()
	contentType := mimedb.TypeByExtension(path.Ext(object))
	fsMeta.Meta["content-type"] = contentType
	wlk, werr := fs.rwPool.Create(fsMetaPath)
	if werr == nil {
		_, err := fsMeta.WriteTo(wlk)
		wlk.Close()
		return err
	}
	return werr
}
1124032
func NewBaseType(init ...interface{}) BaseType {
	if len(init) == 1 {
		switch v := init[0].(type) {
		case BaseType:
			return v
		case int:
			return BaseType(v)
		case int32:
			return BaseType(v)
		case string:
			for i, s := range namesBaseType {
				if s == v {
					return BaseType(i)
				}
			}
		default:
			panic("Bad init value for BaseType enum")
		}
	}
	return BaseType(0) //default to the first enum value
}
223751
func HiddenFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string) *Field {
	ret := HiddenField(name)
	ret.SetValue(fmt.Sprintf("%v", val.Field(fieldNo).Interface()))
	return ret
}
66914
func Enum(path, in string, data interface{}, enum interface{}) *errors.Validation {
	val := reflect.ValueOf(enum)
	if val.Kind() != reflect.Slice {
		return nil
	}

	var values []interface{}
	for i := 0; i < val.Len(); i++ {
		ele := val.Index(i)
		enumValue := ele.Interface()
		if data != nil {
			if reflect.DeepEqual(data, enumValue) {
				return nil
			}
			actualType := reflect.TypeOf(enumValue)
			if actualType == nil { // Safeguard. Frankly, I don't know how we may get a nil
				continue
			}
			expectedValue := reflect.ValueOf(data)
			if expectedValue.IsValid() && expectedValue.Type().ConvertibleTo(actualType) {
				// Attempt comparison after type conversion
				if reflect.DeepEqual(expectedValue.Convert(actualType).Interface(), enumValue) {
					return nil
				}
			}
		}
		values = append(values, enumValue)
	}
	return errors.EnumFail(path, in, data, values)
}
137411
func NewMfType(s string) (mfType, error) {
	var e mfType
	err := e.FromString(s)
	if err != nil {
		return 0, err
	}
	return e, nil
}
907
func (fn *RandomFunction) Field(field string) *RandomFunction {
	fn.field = field
	return fn
}
464507
func MakeField(name string, value interface{}, ftype FieldType) Field {
	f := Field{Name: name, Value: ValueOf(value)}
	f.setType(ftype)
	return f
}
1264607
func initOptionMeta(fn optionFunc, field string, init_value interface{}) optionFunc {
	return func(f *Flag, option, value string) error {
		if _, ok := f.optionMeta[field]; !ok {
			f.optionMeta[field] = init_value
		}
		return fn(f, option, value)
	}
}