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

Add hook mechanism for result #149

Open
wenerme opened this issue Jan 3, 2018 · 0 comments
Open

Add hook mechanism for result #149

wenerme opened this issue Jan 3, 2018 · 0 comments

Comments

@wenerme
Copy link

wenerme commented Jan 3, 2018

For every result I want to execute a postconstruct method

func PostConstruct(v interface{}, ctx context.Context) error {
	c, ok := v.(interface {
		PostConstruct(ctx context.Context) error
	})
	if ok {
		return c.PostConstruct(ctx)
	}
	return nil
}

Because I construct resolver simply by &myResolver{value:v}, but when I want to use exists resolver

type myResolver struct{
    v MyValue
    *CommonResolver
}

I need to init the *CommonResolver after this resolver has created. So, I need a hook to postconstruct after every field has resolved.

One of my init look like this

func (self *myResolver) PostConstruct(ctx context.Context)(err error) {
	if self.ctx == nil {
		self.ctx,err = MustMyContextFrom(ctx)
	}
	if self.CommonResolver == nil {
		self.CommonResolver = &CommonResolver{Value: self.item}
	}
	return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant