Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sergeymakinen/go-systemdconf
systemd configuration file parser/serializer
https://github.com/sergeymakinen/go-systemdconf
go golang marshal parser serializer systemd systemd-configuration systemd-networkd systemd-unit unit unmarshal
Last synced: 4 months ago
JSON representation
systemd configuration file parser/serializer
- Host: GitHub
- URL: https://github.com/sergeymakinen/go-systemdconf
- Owner: sergeymakinen
- License: bsd-3-clause
- Created: 2020-01-02T00:10:23.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-19T12:17:02.000Z (10 months ago)
- Last Synced: 2024-10-16T22:55:12.064Z (4 months ago)
- Topics: go, golang, marshal, parser, serializer, systemd, systemd-configuration, systemd-networkd, systemd-unit, unit, unmarshal
- Language: Go
- Homepage:
- Size: 286 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# systemdconf
[![tests](https://github.com/sergeymakinen/go-systemdconf/workflows/tests/badge.svg)](https://github.com/sergeymakinen/go-systemdconf/actions?query=workflow%3Atests)
[![Go Reference](https://pkg.go.dev/badge/github.com/sergeymakinen/go-systemdconf.svg)](https://pkg.go.dev/github.com/sergeymakinen/go-systemdconf/v2)
[![Go Report Card](https://goreportcard.com/badge/github.com/sergeymakinen/go-systemdconf)](https://goreportcard.com/report/github.com/sergeymakinen/go-systemdconf)
[![codecov](https://codecov.io/gh/sergeymakinen/go-systemdconf/branch/master/graph/badge.svg)](https://codecov.io/gh/sergeymakinen/go-systemdconf)Package systemdconf implements encoding and decoding of systemd configuration files
as defined by systemd.syntax (see https://www.freedesktop.org/software/systemd/man/systemd.syntax.html for details).The mapping between systemd and Go is described
in the documentation for the Marshal and Unmarshal functions## Installation
Use go get:
```bash
go get github.com/sergeymakinen/go-systemdconf/v2
```Then import the package into your own code:
```go
import "github.com/sergeymakinen/go-systemdconf/v2"
```## Example
### Marshal
```go
service := unit.ServiceFile{
Unit: unit.UnitSection{
Description: systemdconf.Value{"Simple firewall"},
},
Service: unit.ServiceSection{
Type: systemdconf.Value{"oneshot"},
RemainAfterExit: systemdconf.Value{"yes"},
ExecStart: systemdconf.Value{
"/usr/local/sbin/simple-firewall-start1",
"/usr/local/sbin/simple-firewall-start2",
},
ExecStop: systemdconf.Value{"/usr/local/sbin/simple-firewall-stop"},
},
Install: unit.InstallSection{
WantedBy: systemdconf.Value{"multi-user.target"},
},
}
b, _ := systemdconf.Marshal(service)fmt.Println(string(b))
// Output:
// [Unit]
// Description=Simple firewall
//
// [Service]
// Type=oneshot
// RemainAfterExit=yes
// ExecStart=/usr/local/sbin/simple-firewall-start1
// ExecStart=/usr/local/sbin/simple-firewall-start2
// ExecStop=/usr/local/sbin/simple-firewall-stop
//
// [Install]
// WantedBy=multi-user.target
```### Unmarshal
```go
file := `[Unit]
Description=Simple firewall[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/sbin/simple-firewall-start
ExecStop=/usr/local/sbin/simple-firewall-stop[Install]
WantedBy=multi-user.target`var service unit.ServiceFile
systemdconf.Unmarshal([]byte(file), &service)fmt.Println(service.Unit.Description)
b, _ := service.Service.RemainAfterExit.Bool()
fmt.Println(b)
// Output:
// Simple firewall
// true
```## License
BSD 3-Clause