函数重命名
This commit is contained in:
parent
341b7197b8
commit
ab56f45790
|
@ -96,7 +96,7 @@ func ToBool[T comparable](t T) bool {
|
|||
return vv != t
|
||||
}
|
||||
|
||||
func GetValFromContext[V, K any](ctx context.Context, k K, defaults V) V {
|
||||
func GetContextVal[V, K any](ctx context.Context, k K, defaults V) V {
|
||||
v := ctx.Value(k)
|
||||
if v == nil {
|
||||
return defaults
|
||||
|
|
|
@ -261,8 +261,8 @@ func TestGetValFromContext(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetValFromContext(tt.args.ctx, tt.args.k, tt.args.defaults); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("GetValFromContext() = %v, want %v", got, tt.want)
|
||||
if got := GetContextVal(tt.args.ctx, tt.args.k, tt.args.defaults); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("GetContextVal() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -36,10 +36,10 @@ func CategoriesAndTags(a ...any) (terms []models.TermsMy, err error) {
|
|||
w := model.SqlBuilder{
|
||||
{"tt.taxonomy", "in", ""},
|
||||
}
|
||||
if helper.GetValFromContext(ctx, "onlyTop", false) {
|
||||
if helper.GetContextVal(ctx, "onlyTop", false) {
|
||||
w = append(w, []string{"tt.parent", "=", "0", "int"})
|
||||
}
|
||||
if !helper.GetValFromContext(ctx, "showCountZero", false) {
|
||||
if !helper.GetContextVal(ctx, "showCountZero", false) {
|
||||
w = append(w, []string{"tt.count", ">", "0", "int"})
|
||||
}
|
||||
terms, err = model.Finds[models.TermsMy](ctx, model.Conditions(
|
||||
|
|
|
@ -65,7 +65,7 @@ func pagination[T Model](db dbQuery, ctx context.Context, q QueryCondition, page
|
|||
return
|
||||
}
|
||||
q.Offset = offset
|
||||
m := helper.GetValFromContext[*[]map[string]string](ctx, "handle=>toMap", nil)
|
||||
m := helper.GetContextVal[*[]map[string]string](ctx, "handle=>toMap", nil)
|
||||
if m == nil {
|
||||
r, err = finds[T](db, ctx, q)
|
||||
return
|
||||
|
|
|
@ -36,7 +36,7 @@ func SetGet(db *SqlxQuery, fn func(context.Context, any, string, ...any) error)
|
|||
}
|
||||
|
||||
func (r *SqlxQuery) Selects(ctx context.Context, dest any, sql string, params ...any) error {
|
||||
v := helper.GetValFromContext(ctx, "handle=>", "")
|
||||
v := helper.GetContextVal(ctx, "handle=>", "")
|
||||
if v != "" {
|
||||
switch v {
|
||||
case "string":
|
||||
|
@ -51,7 +51,7 @@ func (r *SqlxQuery) Selects(ctx context.Context, dest any, sql string, params ..
|
|||
}
|
||||
|
||||
func (r *SqlxQuery) Gets(ctx context.Context, dest any, sql string, params ...any) error {
|
||||
v := helper.GetValFromContext(ctx, "handle=>", "")
|
||||
v := helper.GetContextVal(ctx, "handle=>", "")
|
||||
if v != "" {
|
||||
switch v {
|
||||
case "string":
|
||||
|
|
Loading…
Reference in New Issue
Block a user