Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Oct 30, 2018
1 parent ececa23 commit b5305d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
34 changes: 13 additions & 21 deletions gqlopencensus/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,46 @@ type config struct {
}

// Option is anything that can configure Tracer.
type Option interface {
apply(cfg *config)
}

type optionFunc func(cfg *config)

func (opt optionFunc) apply(cfg *config) {
opt(cfg)
}
type Option func(cfg *config)

// WithStartOperationExecution returns option that execute some process on StartOperationExecution step.
func WithStartOperationExecution(f func(ctx context.Context) context.Context) Option {
return optionFunc(func(cfg *config) {
return func(cfg *config) {
cfg.tracer.startOperationExecutions = append(cfg.tracer.startOperationExecutions, f)
})
}
}

// WithStartFieldExecution returns option that execute some process on StartFieldExecution step.
func WithStartFieldExecution(f func(ctx context.Context, field graphql.CollectedField) context.Context) Option {
return optionFunc(func(cfg *config) {
return func(cfg *config) {
cfg.tracer.startFieldExecutions = append(cfg.tracer.startFieldExecutions, f)
})
}
}

// WithStartFieldResolverExecution returns option that execute some process on StartFieldResolverExecution step.
func WithStartFieldResolverExecution(f func(ctx context.Context, rc *graphql.ResolverContext) context.Context) Option {
return optionFunc(func(cfg *config) {
return func(cfg *config) {
cfg.tracer.startFieldResolverExecutions = append(cfg.tracer.startFieldResolverExecutions, f)
})
}
}

// WithStartFieldChildExecution returns option that execute some process on StartFieldChildExecution step.
func WithStartFieldChildExecution(f func(ctx context.Context) context.Context) Option {
return optionFunc(func(cfg *config) {
return func(cfg *config) {
cfg.tracer.startFieldChildExecutions = append(cfg.tracer.startFieldChildExecutions, f)
})
}
}

// WithEndFieldExecution returns option that execute some process on EndFieldExecution step.
func WithEndFieldExecution(f func(ctx context.Context)) Option {
return optionFunc(func(cfg *config) {
return func(cfg *config) {
cfg.tracer.endFieldExecutions = append(cfg.tracer.endFieldExecutions, f)
})
}
}

// WithEndOperationExecutions returns option that execute some process on EndOperationExecutions step.
func WithEndOperationExecutions(f func(ctx context.Context)) Option {
return optionFunc(func(cfg *config) {
return func(cfg *config) {
cfg.tracer.endOperationExecutions = append(cfg.tracer.endOperationExecutions, f)
})
}
}
2 changes: 1 addition & 1 deletion gqlopencensus/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func New(opts ...Option) graphql.Tracer {
cfg := &config{tracer}

for _, opt := range opts {
opt.apply(cfg)
opt(cfg)
}

return tracer
Expand Down

0 comments on commit b5305d7

Please sign in to comment.