函数重命名
This commit is contained in:
parent
341b7197b8
commit
ab56f45790
|
@ -96,7 +96,7 @@ func ToBool[T comparable](t T) bool {
|
||||||
return vv != t
|
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)
|
v := ctx.Value(k)
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return defaults
|
return defaults
|
||||||
|
|
|
@ -261,8 +261,8 @@ func TestGetValFromContext(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
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) {
|
if got := GetContextVal(tt.args.ctx, tt.args.k, tt.args.defaults); !reflect.DeepEqual(got, tt.want) {
|
||||||
t.Errorf("GetValFromContext() = %v, want %v", 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{
|
w := model.SqlBuilder{
|
||||||
{"tt.taxonomy", "in", ""},
|
{"tt.taxonomy", "in", ""},
|
||||||
}
|
}
|
||||||
if helper.GetValFromContext(ctx, "onlyTop", false) {
|
if helper.GetContextVal(ctx, "onlyTop", false) {
|
||||||
w = append(w, []string{"tt.parent", "=", "0", "int"})
|
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"})
|
w = append(w, []string{"tt.count", ">", "0", "int"})
|
||||||
}
|
}
|
||||||
terms, err = model.Finds[models.TermsMy](ctx, model.Conditions(
|
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
|
return
|
||||||
}
|
}
|
||||||
q.Offset = offset
|
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 {
|
if m == nil {
|
||||||
r, err = finds[T](db, ctx, q)
|
r, err = finds[T](db, ctx, q)
|
||||||
return
|
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 {
|
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 != "" {
|
if v != "" {
|
||||||
switch v {
|
switch v {
|
||||||
case "string":
|
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 {
|
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 != "" {
|
if v != "" {
|
||||||
switch v {
|
switch v {
|
||||||
case "string":
|
case "string":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user