option.go 606 B

123456789101112131415161718192021222324252627282930313233343536
  1. package unit
  2. import (
  3. "fmt"
  4. )
  5. type UnitOption struct {
  6. Section string
  7. Name string
  8. Value string
  9. }
  10. func (uo *UnitOption) String() string {
  11. return fmt.Sprintf("{Section: %q, Name: %q, Value: %q}", uo.Section, uo.Name, uo.Value)
  12. }
  13. func (uo *UnitOption) Match(other *UnitOption) bool {
  14. return uo.Section == other.Section &&
  15. uo.Name == other.Name &&
  16. uo.Value == other.Value
  17. }
  18. func AllMatch(u1 []*UnitOption, u2 []*UnitOption) bool {
  19. length := len(u1)
  20. if length != len(u2) {
  21. return false
  22. }
  23. for i := 0; i < length; i++ {
  24. if !u1[i].Match(u2[i]) {
  25. return false
  26. }
  27. }
  28. return true
  29. }