...

Source file src/github.com/coreos/go-systemd/v22/unit/option.go

Documentation: github.com/coreos/go-systemd/v22/unit

     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  
    15  package unit
    16  
    17  import (
    18  	"fmt"
    19  )
    20  
    21  // UnitOption represents an option in a systemd unit file.
    22  type UnitOption struct {
    23  	Section string
    24  	Name    string
    25  	Value   string
    26  }
    27  
    28  // NewUnitOption returns a new UnitOption instance with pre-set values.
    29  func NewUnitOption(section, name, value string) *UnitOption {
    30  	return &UnitOption{Section: section, Name: name, Value: value}
    31  }
    32  
    33  func (uo *UnitOption) String() string {
    34  	return fmt.Sprintf("{Section: %q, Name: %q, Value: %q}", uo.Section, uo.Name, uo.Value)
    35  }
    36  
    37  // Match compares two UnitOptions and returns true if they are identical.
    38  func (uo *UnitOption) Match(other *UnitOption) bool {
    39  	return uo.Section == other.Section &&
    40  		uo.Name == other.Name &&
    41  		uo.Value == other.Value
    42  }
    43  
    44  // AllMatch compares two slices of UnitOptions and returns true if they are
    45  // identical.
    46  func AllMatch(u1 []*UnitOption, u2 []*UnitOption) bool {
    47  	length := len(u1)
    48  	if length != len(u2) {
    49  		return false
    50  	}
    51  
    52  	for i := 0; i < length; i++ {
    53  		if !u1[i].Match(u2[i]) {
    54  			return false
    55  		}
    56  	}
    57  
    58  	return true
    59  }
    60  

View as plain text