http urls monitor.

flags.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package viper
  2. import "github.com/spf13/pflag"
  3. // FlagValueSet is an interface that users can implement
  4. // to bind a set of flags to viper.
  5. type FlagValueSet interface {
  6. VisitAll(fn func(FlagValue))
  7. }
  8. // FlagValue is an interface that users can implement
  9. // to bind different flags to viper.
  10. type FlagValue interface {
  11. HasChanged() bool
  12. Name() string
  13. ValueString() string
  14. ValueType() string
  15. }
  16. // pflagValueSet is a wrapper around *pflag.ValueSet
  17. // that implements FlagValueSet.
  18. type pflagValueSet struct {
  19. flags *pflag.FlagSet
  20. }
  21. // VisitAll iterates over all *pflag.Flag inside the *pflag.FlagSet.
  22. func (p pflagValueSet) VisitAll(fn func(flag FlagValue)) {
  23. p.flags.VisitAll(func(flag *pflag.Flag) {
  24. fn(pflagValue{flag})
  25. })
  26. }
  27. // pflagValue is a wrapper aroung *pflag.flag
  28. // that implements FlagValue
  29. type pflagValue struct {
  30. flag *pflag.Flag
  31. }
  32. // HasChanges returns whether the flag has changes or not.
  33. func (p pflagValue) HasChanged() bool {
  34. return p.flag.Changed
  35. }
  36. // Name returns the name of the flag.
  37. func (p pflagValue) Name() string {
  38. return p.flag.Name
  39. }
  40. // ValueString returns the value of the flag as a string.
  41. func (p pflagValue) ValueString() string {
  42. return p.flag.Value.String()
  43. }
  44. // ValueType returns the type of the flag as a string.
  45. func (p pflagValue) ValueType() string {
  46. return p.flag.Value.Type()
  47. }