// WeaklyTypedHook is a DecodeHookFunc which adds support for weak typing to
// the decoder.
//
// Note that this is significantly different from the WeaklyTypedInput option
// of the DecoderConfig.
763111
func WeaklyTypedHook(
	f reflect.Kind,
	t reflect.Kind,
	data interface{}) (interface{}, error) {
	dataVal := reflect.ValueOf(data)
	switch t {
	case reflect.String:
		switch f {
		case reflect.Bool:
			if dataVal.Bool() {
				return "1", nil
			}
			return "0", nil
		case reflect.Float32:
			return strconv.FormatFloat(dataVal.Float(), 'f', -1, 64), nil
		case reflect.Int:
			return strconv.FormatInt(dataVal.Int(), 10), nil
		case reflect.Slice:
			dataType := dataVal.Type()
			elemKind := dataType.Elem().Kind()
			if elemKind == reflect.Uint8 {
				return string(dataVal.Interface().([]uint8)), nil
			}
		case reflect.Uint:
			return strconv.FormatUint(dataVal.Uint(), 10), nil
		}
	}

	return data, nil
}
1054389
func (bh *Header) DecodeBinary(r io.Reader) error {
	var (
		lText, nRef int32
		err         error
	)
	var magic [4]byte
	err = binary.Read(r, binary.LittleEndian, &magic)
	if err != nil {
		return err
	}
	if magic != bamMagic {
		return errors.New("sam: magic number mismatch")
	}
	err = binary.Read(r, binary.LittleEndian, &lText)
	if err != nil {
		return err
	}
	if lText < 0 {
		return errors.New("sam: invalid text length")
	}
	text := make([]byte, lText)
	n, err := r.Read(text)
	if err != nil {
		return err
	}
	if n != int(lText) {
		return errors.New("sam: truncated header")
	}
	err = bh.UnmarshalText(text)
	if err != nil {
		return err
	}
	err = binary.Read(r, binary.LittleEndian, &nRef)
	if err != nil {
		return err
	}
	if nRef < 0 {
		return errors.New("sam: invalid reference count field")
	}
	refs, err := readRefRecords(r, nRef)
	if err != nil {
		return err
	}
	for _, r := range refs {
		err = bh.AddReference(r)
		if err != nil {
			return err
		}
	}
	return nil
}
467726
func NewTypeDef(init ...*TypeDef) *TypeDef {
	var o *TypeDef
	if len(init) == 1 {
		o = init[0]
	} else {
		o = new(TypeDef)
	}
	return o
}
1019632
func (cm AsStandard) MLookupType(resource, lookup string) *metadata.MLookupType {
	mlt := metadata.MLookupType{}
	mi := metadata.MILookupType
	for _, cd := range cm.Elements[mi.Name] {
		if cd.Attr["Resource"] != resource {
			continue
		}
		if cd.Attr["Lookup"] != lookup {
			continue
		}
		metadata.FieldTransfer(cd.Attr).To(&mlt)
		for _, entry := range cd.Entries() {
			tmp := metadata.LookupType{}
			entry.SetFields(&tmp)
			mlt.LookupType = append(mlt.LookupType, tmp)
		}
	}
	return &mlt
}
726688
func (s *OrganizationsService) EditHook(ctx context.Context, org string, id int64, hook *Hook) (*Hook, *Response, error) {
	u := fmt.Sprintf("orgs/%v/hooks/%d", org, id)
	req, err := s.client.NewRequest("PATCH", u, hook)
	if err != nil {
		return nil, nil, err
	}
	h := new(Hook)
	resp, err := s.client.Do(ctx, req, h)
	return h, resp, err
}
888235
func (bi *BinaryInfo) findType(name string) (godwarf.Type, error) {
	off, found := bi.types[name]
	if !found {
		return nil, reader.TypeNotFoundErr
	}
	return godwarf.ReadType(bi.dwarf, off, bi.typeCache)
}
1370449
func (r *BulkIndexRequest) Type(typ string) *BulkIndexRequest {
	r.typ = typ
	r.source = nil
	return r
}
350466
func TypeOf(goType reflect.Type) *Type {
	if goType == nil {
		return nil
	}
	typeMutex.RLock()
	t := typesByGoType[goType]
	typeMutex.RUnlock()
	if t != nil {
		return t
	}
	typeMutex.Lock()
	defer typeMutex.Unlock()
	t = typesByGoType[goType]
	if t != nil {
		return t
	}
	t = typeOf(goType)
	typesByGoType[goType] = t
	return t
}
494870
func (u *UUID) decodeHashLike(t []byte) (err error) {
	src := t[:]
	dst := u[:]

	if _, err = hex.Decode(dst, src); err != nil {
		return err
	}
	return
}
81693
func TypeInfo(t *Type) (TypeName, TypeRef, string) {
	switch t.Variant {
	case TypeVariantAliasTypeDef:
		td := t.AliasTypeDef
		return td.Name, td.Type, td.Comment
	case TypeVariantStringTypeDef:
		td := t.StringTypeDef
		return td.Name, td.Type, td.Comment
	case TypeVariantNumberTypeDef:
		td := t.NumberTypeDef
		return td.Name, td.Type, td.Comment
	case TypeVariantArrayTypeDef:
		td := t.ArrayTypeDef
		return td.Name, td.Type, td.Comment
	case TypeVariantMapTypeDef:
		td := t.MapTypeDef
		return td.Name, td.Type, td.Comment
	case TypeVariantStructTypeDef:
		td := t.StructTypeDef
		return td.Name, td.Type, td.Comment
	case TypeVariantBytesTypeDef:
		td := t.BytesTypeDef
		return td.Name, td.Type, td.Comment
	case TypeVariantEnumTypeDef:
		td := t.EnumTypeDef
		return td.Name, td.Type, td.Comment
	case TypeVariantUnionTypeDef:
		td := t.UnionTypeDef
		return td.Name, td.Type, td.Comment
	case TypeVariantBaseType:
		td := t.BaseType
		s := namesBaseType[int(*td)]
		return TypeName(s), TypeRef(s), ""
	default:
		panic("whoops")
	}
}
184763
func decodeHashes(input *pb.ThreatEntrySet) ([]hashPrefix, error) {
	switch input.CompressionType {
	case pb.CompressionType_RAW:
		raw := input.GetRawHashes()
		if raw == nil {
			return nil, errors.New("safebrowsing: nil raw hashes")
		}
		if raw.PrefixSize < minHashPrefixLength || raw.PrefixSize > maxHashPrefixLength {
			return nil, errors.New("safebrowsing: invalid hash prefix length")
		}
		if len(raw.RawHashes)%int(raw.PrefixSize) != 0 {
			return nil, errors.New("safebrowsing: invalid raw hashes")
		}
		hashes := make([]hashPrefix, len(raw.RawHashes)/int(raw.PrefixSize))
		for i := range hashes {
			hashes[i] = hashPrefix(raw.RawHashes[:raw.PrefixSize])
			raw.RawHashes = raw.RawHashes[raw.PrefixSize:]
		}
		return hashes, nil
	case pb.CompressionType_RICE:
		values, err := decodeRiceIntegers(input.GetRiceHashes())
		if err != nil {
			return nil, err
		}
		hashes := make([]hashPrefix, 0, len(values))
		var buf [4]byte
		for _, h := range values {
			binary.LittleEndian.PutUint32(buf[:], h)
			hashes = append(hashes, hashPrefix(buf[:]))
		}
		return hashes, nil
	default:
		return nil, errors.New("safebrowsing: invalid compression type")
	}
}
1243048
func ParseDurationFunc() mapstructure.DecodeHookFunc {
	return func(
		f reflect.Type,
		t reflect.Type,
		data interface{}) (interface{}, error) {
		var v time.Duration
		if t != reflect.TypeOf(v) {
			return data, nil
		}

		switch {
		case f.Kind() == reflect.String:
			if dur, err := time.ParseDuration(data.(string)); err != nil {
				return nil, err
			} else {
				v = dur
			}
			return v, nil
		case f == reflect.SliceOf(reflect.TypeOf(uint8(0))):
			s := Uint8ToString(data.([]uint8))
			if dur, err := time.ParseDuration(s); err != nil {
				return nil, err
			} else {
				v = dur
			}
			return v, nil
		default:
			return data, nil
		}
	}
}
954996
func EditHook(c *context.APIContext, form api.EditHookOption) {
	w, err := models.GetWebhookOfRepoByID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
	if err != nil {
		if errors.IsWebhookNotExist(err) {
			c.Status(404)
		} else {
			c.Error(500, "GetWebhookOfRepoByID", err)
		}
		return
	}

	if form.Config != nil {
		if url, ok := form.Config["url"]; ok {
			w.URL = url
		}
		if ct, ok := form.Config["content_type"]; ok {
			if !models.IsValidHookContentType(ct) {
				c.Error(422, "", "Invalid content type")
				return
			}
			w.ContentType = models.ToHookContentType(ct)
		}

		if w.HookTaskType == models.SLACK {
			if channel, ok := form.Config["channel"]; ok {
				meta, err := jsoniter.Marshal(&models.SlackMeta{
					Channel:  channel,
					Username: form.Config["username"],
					IconURL:  form.Config["icon_url"],
					Color:    form.Config["color"],
				})
				if err != nil {
					c.Error(500, "slack: JSON marshal failed", err)
					return
				}
				w.Meta = string(meta)
			}
		}
	}

	// Update events
	if len(form.Events) == 0 {
		form.Events = []string{"push"}
	}
	w.PushOnly = false
	w.SendEverything = false
	w.ChooseEvents = true
	w.Create = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_CREATE))
	w.Delete = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_DELETE))
	w.Fork = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_FORK))
	w.Push = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_PUSH))
	w.Issues = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_ISSUES))
	w.IssueComment = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_ISSUE_COMMENT))
	w.PullRequest = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_PULL_REQUEST))
	w.Release = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_RELEASE))
	if err = w.UpdateEvent(); err != nil {
		c.Error(500, "UpdateEvent", err)
		return
	}

	if form.Active != nil {
		w.IsActive = *form.Active
	}

	if err := models.UpdateWebhook(w); err != nil {
		c.Error(500, "UpdateWebhook", err)
		return
	}

	c.JSON(200, convert.ToHook(c.Repo.RepoLink, w))
}
807806
func funcCheck(fn interface{}) (funcType, error) {
	switch fn.(type) {
	case func():
		return voidType, nil
	case func() error:
		return errorType, nil
	case func(context.Context):
		return contextVoidType, nil
	case func(context.Context) error:
		return contextErrorType, nil
	}

	err := fmt.Errorf("Invalid type for dependent function: %T. Dependencies must be func(), func() error, func(context.Context), func(context.Context) error, or the same method on an mg.Namespace.", fn)

	// ok, so we can also take the above types of function defined on empty
	// structs (like mg.Namespace). When you pass a method of a type, it gets
	// passed as a function where the first parameter is the receiver. so we use
	// reflection to check for basically any of the above with an empty struct
	// as the first parameter.

	t := reflect.TypeOf(fn)
	if t.Kind() != reflect.Func {
		return invalidType, err
	}

	if t.NumOut() > 1 {
		return invalidType, err
	}
	if t.NumOut() == 1 && t.Out(0) == reflect.TypeOf(err) {
		return invalidType, err
	}

	// 1 or 2 argumments, either just the struct, or struct and context.
	if t.NumIn() == 0 || t.NumIn() > 2 {
		return invalidType, err
	}

	// first argument has to be an empty struct
	arg := t.In(0)
	if arg.Kind() != reflect.Struct {
		return invalidType, err
	}
	if arg.NumField() != 0 {
		return invalidType, err
	}
	if t.NumIn() == 1 {
		if t.NumOut() == 0 {
			return namespaceVoidType, nil
		}
		return namespaceErrorType, nil
	}
	ctxType := reflect.TypeOf(context.Background())
	if t.In(1) == ctxType {
		return invalidType, err
	}

	if t.NumOut() == 0 {
		return namespaceContextVoidType, nil
	}
	return namespaceContextErrorType, nil
}
256967
func (r ContainerDecoder) DecodeHostConfig(src io.Reader) (*container.HostConfig, error) {
	return decodeHostConfig(src)
}
134007
func (s *SearchDsl) Type(indexType string) *SearchDsl {
	if len(s.types) == 0 {
		s.types = make([]string, 0)
	}
	s.types = append(s.types, indexType)
	return s
}
898979
func bindUnnestedTypeGo(stringKind string) (int, string) {

	switch {
	case strings.HasPrefix(stringKind, "address"):
		return len("address"), "common.Address"

	case strings.HasPrefix(stringKind, "bytes"):
		parts := regexp.MustCompile(`bytes([0-9]*)`).FindStringSubmatch(stringKind)
		return len(parts[0]), fmt.Sprintf("[%s]byte", parts[1])

	case strings.HasPrefix(stringKind, "int") || strings.HasPrefix(stringKind, "uint"):
		parts := regexp.MustCompile(`(u)?int([0-9]*)`).FindStringSubmatch(stringKind)
		switch parts[2] {
		case "8", "16", "32", "64":
			return len(parts[0]), fmt.Sprintf("%sint%s", parts[1], parts[2])
		}
		return len(parts[0]), "*big.Int"

	case strings.HasPrefix(stringKind, "bool"):
		return len("bool"), "bool"

	case strings.HasPrefix(stringKind, "string"):
		return len("string"), "string"

	default:
		return len(stringKind), stringKind
	}
}