option.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package unit
  15. import (
  16. "fmt"
  17. )
  18. type UnitOption struct {
  19. Section string
  20. Name string
  21. Value string
  22. }
  23. func NewUnitOption(section, name, value string) *UnitOption {
  24. return &UnitOption{Section: section, Name: name, Value: value}
  25. }
  26. func (uo *UnitOption) String() string {
  27. return fmt.Sprintf("{Section: %q, Name: %q, Value: %q}", uo.Section, uo.Name, uo.Value)
  28. }
  29. func (uo *UnitOption) Match(other *UnitOption) bool {
  30. return uo.Section == other.Section &&
  31. uo.Name == other.Name &&
  32. uo.Value == other.Value
  33. }
  34. func AllMatch(u1 []*UnitOption, u2 []*UnitOption) bool {
  35. length := len(u1)
  36. if length != len(u2) {
  37. return false
  38. }
  39. for i := 0; i < length; i++ {
  40. if !u1[i].Match(u2[i]) {
  41. return false
  42. }
  43. }
  44. return true
  45. }