Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passthrough additional data to the conversion methods #76

Closed
pavelpatrin opened this issue May 24, 2023 · 1 comment
Closed

Passthrough additional data to the conversion methods #76

pavelpatrin opened this issue May 24, 2023 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@pavelpatrin
Copy link
Contributor

I have a Job model, it has set of Task IDs stored in []int field.

I want to calculate some task statistics in converter extension function using preloaded set of Tasks, but I have access only ti Job instance. Can I somehow passthrough preloaded tasks to use them while converting the job?

E.g., we can get them from the context, or another passed object or map.

// goverter:extend JobTaskStatsToPb
type Converter interface {
    JobToPb(context.Context, models.Job) taskspb.Job
}

func JobTaskStatsToPb(ctx context.Context, value models.JobTaskStats) taskspb.JobTaskStats {
    jobTaskIDs := value.TaskIDs
    tasksData := ctx.Value("TasksStorageCtxKey").(map[int]models.Task)
    ... use tasks data from context to calculate job task stats ...
    return calculatedJobTaskStats
}
@jmattheis
Copy link
Owner

I'd say this is a duplicate of #68 and the solution described in here is a little less type safe because of the casting required when using context.Context.

@jmattheis jmattheis closed this as not planned Won't fix, can't repro, duplicate, stale May 24, 2023
@jmattheis jmattheis added the duplicate This issue or pull request already exists label May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants