gitea源码

event.go 657B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2025 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package gtprof
  4. type EventConfig struct {
  5. attributes []*TraceAttribute
  6. }
  7. type EventOption interface {
  8. applyEvent(*EventConfig)
  9. }
  10. type applyEventFunc func(*EventConfig)
  11. func (f applyEventFunc) applyEvent(cfg *EventConfig) {
  12. f(cfg)
  13. }
  14. func WithAttributes(attrs ...*TraceAttribute) EventOption {
  15. return applyEventFunc(func(cfg *EventConfig) {
  16. cfg.attributes = append(cfg.attributes, attrs...)
  17. })
  18. }
  19. func eventConfigFromOptions(options ...EventOption) *EventConfig {
  20. cfg := &EventConfig{}
  21. for _, opt := range options {
  22. opt.applyEvent(cfg)
  23. }
  24. return cfg
  25. }