Files
gitea/models/unittest/reflection.go
silverwind 82d40296b0 chore(deps): bump tool deps and pin, update golangci-lint (#37574)
1. Pin all makefile go deps to exact version, renovate will bump them in the future
2. Bump all deps and golangci-lint and fix all new issues, most are from modernize

Signed-off-by: silverwind <me@silverwind.io>
Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com>
2026-05-08 04:49:34 +00:00

41 lines
812 B
Go

// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package unittest
import (
"fmt"
"reflect"
)
func fieldByName(v reflect.Value, field string) reflect.Value {
if v.Kind() == reflect.Pointer {
v = v.Elem()
}
f := v.FieldByName(field)
if !f.IsValid() {
panic(fmt.Errorf("can not read %s for %v", field, v))
}
return f
}
type reflectionValue struct {
v reflect.Value
}
func reflectionWrap(v any) *reflectionValue {
return &reflectionValue{v: reflect.ValueOf(v)}
}
func (rv *reflectionValue) int(field string) int {
return int(fieldByName(rv.v, field).Int())
}
func (rv *reflectionValue) str(field string) string {
return fieldByName(rv.v, field).String()
}
func (rv *reflectionValue) bool(field string) bool {
return fieldByName(rv.v, field).Bool()
}