-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
I have been hitting a wall with either the preprocess schema internals or how go manages types.
type IPFSPinFilter struct {
CIDs []string `query:"cid"`
Name string `query:"name"`
Match TextMatchingStrategy `query:"match"`
Status []db.PinningStatus `query:"status"`
Before *time.Time `query:"before"`
After *time.Time `query:"after"`
Meta map[string]string `query:"meta"`
Limit int `query:"limit"`
}
"Status": zog.Preprocess[[]db.PinningStatus, []db.PinningStatus](func(data []db.PinningStatus, ctx zog.Ctx) (out []db.PinningStatus, err error) {
if len(data) == 0 {
return nil, nil
}
firstEl := string(data[0])
parts := strings.Split(firstEl, ",")
trimmedParts := lo.FilterMap(parts, func(part string, _ int) (db.PinningStatus, bool) {
trimmed := strings.TrimSpace(part)
if trimmed != "" {
return db.PinningStatus(trimmed), true
}
return "", false
})
return (trimmedParts, nil
}, zog.Slice(zog.ZogStringLike[db.PinningStatus]().OneOf([]db.PinningStatus{
db.PinningStatusQueued,
db.PinningStatusPinning,
db.PinningStatusPinned,
db.PinningStatusFailed,
})).Optional()),
No matter what I do,
func (s *PreprocessSchema[F, T]) process(ctx *p.SchemaCtx) {
v, ok := ctx.Data.(F)
if !ok {
ctx.AddIssue(ctx.IssueFromCoerce(fmt.Errorf("preprocess expected %T but got %T", v, ctx.Data)))
return
}
this typecase seems to fail even when sprintf %T show they are the same type.
My more specific goal is the input is a csv value item, and i have to preprocess it.
type PinningStatus string
Im not sure if there is a go quirk to deal with, or if the internals are making assumptions since it seems the reflection creating .Interfaces() turns a [] into a *[] and a *[] into a **[].
Zog Panic: Type Cast Error
Current context: z.Ctx{Data: [failed,pinned,pinning,queued], ValPtr: [failed,pinned,pinning,queued], Path: Status, DType: slice, CanCatch: false, Exit: false, HasCaught: false }
Expected valPtr type to correspond with type defined in schema. But it does not. Expected type: **[]db.PinningStatus, got: *[]db.PinningStatus
Please advise. For now im likely going to have to create a custom type to deal with this input.
Metadata
Metadata
Assignees
Labels
No labels