write the value to the full, absolute path, of a unified hierarchy
(path string, perm os.FileMode)
| 153 | |
| 154 | // write the value to the full, absolute path, of a unified hierarchy |
| 155 | func (c *Value) write(path string, perm os.FileMode) error { |
| 156 | var data []byte |
| 157 | switch t := c.value.(type) { |
| 158 | case uint64: |
| 159 | data = []byte(strconv.FormatUint(t, 10)) |
| 160 | case uint16: |
| 161 | data = []byte(strconv.FormatUint(uint64(t), 10)) |
| 162 | case int64: |
| 163 | data = []byte(strconv.FormatInt(t, 10)) |
| 164 | case []byte: |
| 165 | data = t |
| 166 | case string: |
| 167 | data = []byte(t) |
| 168 | case CPUMax: |
| 169 | data = []byte(t) |
| 170 | default: |
| 171 | return ErrInvalidFormat |
| 172 | } |
| 173 | |
| 174 | return os.WriteFile( |
| 175 | filepath.Join(path, c.filename), |
| 176 | data, |
| 177 | perm, |
| 178 | ) |
| 179 | } |
| 180 | |
| 181 | func writeValues(path string, values []Value) error { |
| 182 | for _, o := range values { |