go-systemd icon indicating copy to clipboard operation
go-systemd copied to clipboard

Feature request: Implement concrete types for systemd config files

Open Richterrettich opened this issue 7 years ago • 1 comments

The current unit package provides basic config file parsing with key value pairs as a results. It would be nice to have a typesafe api for systemd config files like service files or even a resolved.conf file. Something like this:

type ServiceConfig []*UnitOption

func (*s ServiceConfig) ExecStart() string {
//...
}

Maybe an API like the json package:

decoder := NewDecoder(reader)
var service ServiceConfig
err := decoder.Decode(&service)

An error could be returned if the unit contains invalid keys for that type.

I would volunteer to implement this if you are okay with this feature

Richterrettich avatar May 09 '18 15:05 Richterrettich

I'm not super-thrilled about it, but at the same time I would be interested in seeing this explored in a dedicated repository. In particular, I'd be interested in the maintainability and ergonomics of it.

A couple of cons that come to my mind on this:

  • field names and format varies across systemd release. This means that we are coupling this library API to specific systemd releases, and adding a maintenance burden on top
  • I fear that Go generics lack expressiveness to properly represent systemd options. It will likely end up with strings everywhere (like the status quo) or lot of interface{} and typecasting

lucab avatar May 25 '18 13:05 lucab