Skip to content

v3 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2025
Merged

v3 #6

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
open-pull-requests-limit: 0
- package-ecosystem: gomod
directory: /
schedule:
interval: monthly
open-pull-requests-limit: 0
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
push:
tags:
- '*'
name: Release
jobs:
goreleaser:
name: GoReleaser
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on:
push:
pull_request:
name: Test
jobs:
test:
name: Test
strategy:
fail-fast: false
matrix:
go-version:
- 1.23.x
- 1.24.x
- 1.x
os:
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Test
run: go test -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
40 changes: 0 additions & 40 deletions .github/workflows/tests.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
builds:
- skip: true

release:
prerelease: auto
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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)
[![Test](https://github.com/sergeymakinen/go-systemdconf/actions/workflows/test.yml/badge.svg)](https://github.com/sergeymakinen/go-systemdconf/actions/workflows/test.yml)
[![Go Reference](https://pkg.go.dev/badge/github.com/sergeymakinen/go-systemdconf.svg)](https://pkg.go.dev/github.com/sergeymakinen/go-systemdconf/v3)
[![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)

Expand All @@ -16,13 +16,13 @@ in the documentation for the Marshal and Unmarshal functions
Use go get:

```bash
go get github.com/sergeymakinen/go-systemdconf/v2
go get github.com/sergeymakinen/go-systemdconf/v3
```

Then import the package into your own code:

```go
import "github.com/sergeymakinen/go-systemdconf/v2"
import "github.com/sergeymakinen/go-systemdconf/v3"
```


Expand Down
97 changes: 97 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Package ast contains a parser and a printer for systemd configuration files through AST trees.
package ast

import "fmt"

// Position describes an arbitrary source position
// including line and column location.
type Position struct {
Offset int // byte offset, starting at 0
Line int // line number, starting at 1
Column int // column number, starting at 1 (character count per line)
}

func (p Position) String() string {
s := "-"
if p.Line != 0 {
s = fmt.Sprintf("%d", p.Line)
if p.Column != 0 {
s += fmt.Sprintf(":%d", p.Column)
}
}
return s
}

// Node describes a basic node.
type Node interface {
Pos() Position // position of first character belonging to the node
End() Position // position of last character belonging to the node
}

// Children is a collection of child nodes.
type Children []Node

func (c Children) Pos() Position { return c[0].Pos() }
func (c Children) End() Position { return c[len(c)-1].End() }

// File represents a systemd configuration file.
type File struct {
Children Children // Comment, Include, and Section nodes

pos, end Position
}

func (f *File) Pos() Position { return f.pos }
func (f *File) End() Position { return f.end }

// Comment represents a single comment.
type Comment struct {
Text string // comment text starting with # or ;

pos, end Position
}

func (c *Comment) Pos() Position { return c.pos }
func (c *Comment) End() Position { return c.end }

// Include represents a .include directive (obsolete).
type Include struct {
Path string // include path as specified in the directive

pos, end Position
}

func (i *Include) Pos() Position { return i.pos }
func (i *Include) End() Position { return i.end }

// Section represents a configuration section.
type Section struct {
Name string // section name
Children Children // Comment, Include, and Entry nodes

pos, end Position
}

func (s *Section) Pos() Position { return s.pos }
func (s *Section) End() Position { return s.end }

// Entry represents a single key-value configuration entry.
type Entry struct {
Key string // key name
Value string // entry value

pos, end Position
}

func (e *Entry) Pos() Position { return e.pos }
func (e *Entry) End() Position { return e.end }

// ParseError is returned for parsing errors.
type ParseError struct {
Err error // the actual error
Pos Position // position where the error occurred
}

func (p *ParseError) Error() string {
return fmt.Sprintf("%v at %s", p.Err, p.Pos)
}
Loading
Loading