Skip to content
Snippets Groups Projects
Verified Commit 474b968c authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: new postprocessing #2

parent 43baeb5a
No related branches found
No related tags found
No related merge requests found
...@@ -152,3 +152,4 @@ devenv.local.nix ...@@ -152,3 +152,4 @@ devenv.local.nix
# pre-commit # pre-commit
.pre-commit-config.yaml .pre-commit-config.yaml
/Session.vim
image: docker-registry.schukai.com:443/nixos-ci-devenv:latest
services:
- docker:dind
variables:
# The repo name as used in
# https://github.com/nix-community/NUR/blob/master/repos.json
NIXOS_VERSION: "23.05"
NIXPKGS_ALLOW_UNFREE: "1"
NIXPKGS_ALLOW_INSECURE: "1"
DOCKER_DRIVER: overlay2
GIT_DEPTH: 10
stages:
- build
- deploy
before_script:
- nix shell nixpkgs#coreutils-full -c mkdir -p /certs/client/
- nix shell nixpkgs#coreutils-full -c ln -fs /etc/ssl/certs/ca-bundle.crt /certs/client/ca.pem
- echo > .env-gitlab-ci
- variables=("HOME=$HOME" "CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME" "CI_REPOSITORY_URL=$CI_REPOSITORY_URL" "GITLAB_TOKEN=$GITLAB_TOKEN" "CI_JOB_TOKEN=$CI_JOB_TOKEN" "GITLAB_USER_EMAIL=$GITLAB_USER_EMAIL" "GITLAB_USER_NAME=\"$GITLAB_USER_NAME\"" "CI_REGISTRY_USER=$CI_REGISTRY_USER" "CI_PROJECT_ID=$CI_PROJECT_ID" "CI_PROJECT_DIR=$CI_PROJECT_DIR" "CI_API_V4_URL=$CI_API_V4_URL" "CI_PROJECT_NAME=$CI_PROJECT_NAME" "CI_COMMIT_SHORT_SHA=$CI_COMMIT_SHORT_SHA"); for var in "${variables[@]}"; do echo "$var" >> .env-gitlab-ci; done
- cat .env-gitlab-ci
after_script:
- if [ -f .env-gitlab-ci ]; then rm .env-gitlab-ci; fi
build:
stage: build
tags:
- nixos
script:
- devenv shell build-app
cache:
- key: nixos
paths:
- /nix/store
artifacts:
paths:
- dist
deploy:
stage: deploy
tags:
- nixos
script:
- devenv shell -c deploy-app
when: on_success
cache:
- key: nixos
paths:
- /nix/store
artifacts:
paths:
- dist
...@@ -11,3 +11,4 @@ GNU Affero General Public License for more details. ...@@ -11,3 +11,4 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
...@@ -325,7 +325,7 @@ func main() { ...@@ -325,7 +325,7 @@ func main() {
var h configuration.EventHook var h configuration.EventHook
h = &ChangeEventHandler{ h = &ChangeEventHandler{
callback: func(event configuration.ChangeEvent) { callback: func(event configuration.ChangeEvent) {
log := event.Changlog log := event.Changelog
msg = fmt.Sprintf("Change from %s to %s", log[0].From, log[0].To) msg = fmt.Sprintf("Change from %s to %s", log[0].From, log[0].To)
fmt.Println(msg) fmt.Println(msg)
closeChan <- true closeChan <- true
...@@ -349,6 +349,33 @@ func main() { ...@@ -349,6 +349,33 @@ func main() {
``` ```
### Environment variables
The configuration can also be loaded from environment variables. This is useful if you want to
define the configuration via environment variables. For example, if you want to use Docker.
With the `InitFromEnv(prefix)` function, you can set the configuration from environment variables.
You must call this function manually. The definition of the environment variables must be
done in the following format:
```go
config := struct {
Host string `env:"HOST"`
}{
Host: "localhost",
}
s := configuration.New(config)
s.InitFromEnv("APP")
```
In this example, the environment variable `APP_HOST` is used. The prefix is used to
to avoid collisions with other environment variables. You can also use an empty string
as a prefix. Then the environment variables are used directly.
### Error handling ### Error handling
If an error occurs, it is returned by the function `Errors()`. The errors can be handled as usual. If an error occurs, it is returned by the function `Errors()`. The errors can be handled as usual.
......
# https://taskfile.dev
version: '3'
tasks:
default:
cmds:
- task --list-all
silent: true
test:
desc: Execute unit tests in Go.
cmds:
- echo "Execute unit tests in Go."
- go test -cover -v ./...
test-fuzz:
desc: Conduct fuzzing tests.#
cmds:
- echo "Conduct fuzzing tests."
- go test -v -fuzztime=30s -fuzz=Fuzz ./...
add-licenses:
desc: Attach license headers to Go files.
cmds:
- echo "Attach license headers to Go files."
- addlicense -c "schukai GmbH" -s -l "AGPL-3.0" ./*.go
silent: true
check:
desc: Confirm repository status.
cmds:
- git diff-index --quiet HEAD || (echo "There are uncommitted changes after running make. Please commit or stash them before running make."; exit 1)
silent: true
build:
desc: Compile the application,
aliases:
- b
vars:
DEVENV_ROOT:
sh: echo "$DEVENV_ROOT"
cmds:
- devenv shell build-app
sources:
- source/**/*.go
- source/**/*.mod
- dist/**
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"github.com/imdario/mergo" "github.com/imdario/mergo"
) )
// NewSetting creates a new configuration setting // New NewSetting creates a new configuration setting
// with the given defaults. // with the given defaults.
func New[C any](defaults C) *Settings[C] { func New[C any](defaults C) *Settings[C] {
...@@ -39,7 +39,7 @@ func New[C any](defaults C) *Settings[C] { ...@@ -39,7 +39,7 @@ func New[C any](defaults C) *Settings[C] {
return s return s
} }
// Set the mnemonic // SetMnemonic Set the mnemonic
// The mnemonic is used to identify the configuration in the configuration file // The mnemonic is used to identify the configuration in the configuration file
func (s *Settings[C]) SetMnemonic(mnemonic string) *Settings[C] { func (s *Settings[C]) SetMnemonic(mnemonic string) *Settings[C] {
...@@ -58,7 +58,7 @@ func (s *Settings[C]) SetMnemonic(mnemonic string) *Settings[C] { ...@@ -58,7 +58,7 @@ func (s *Settings[C]) SetMnemonic(mnemonic string) *Settings[C] {
return s return s
} }
// Config() returns the configuration // Config returns the configuration
// Remember that the configuration is a copy of the original configuration. // Remember that the configuration is a copy of the original configuration.
// Changes to the configuration will not be reflected in the original configuration. // Changes to the configuration will not be reflected in the original configuration.
func (s *Settings[C]) Config() C { func (s *Settings[C]) Config() C {
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
) )
type ChangeEvent struct { type ChangeEvent struct {
Changlog diff.Changelog Changelog diff.Changelog
} }
type ChangeHook interface { type ChangeHook interface {
...@@ -44,7 +44,7 @@ func (s *Settings[C]) RemoveOnChangeHook(hook ChangeHook) *Settings[C] { ...@@ -44,7 +44,7 @@ func (s *Settings[C]) RemoveOnChangeHook(hook ChangeHook) *Settings[C] {
func (s *Settings[C]) notifyChangeHooks(changelog diff.Changelog) *Settings[C] { func (s *Settings[C]) notifyChangeHooks(changelog diff.Changelog) *Settings[C] {
for _, h := range s.hooks.change { for _, h := range s.hooks.change {
go h.Handle(ChangeEvent{Changlog: changelog}) go h.Handle(ChangeEvent{Changelog: changelog})
} }
return s return s
} }
...@@ -27,6 +27,7 @@ func (s *Settings[C]) setConfigInternal(config C, lock bool) *Settings[C] { ...@@ -27,6 +27,7 @@ func (s *Settings[C]) setConfigInternal(config C, lock bool) *Settings[C] {
defer func() { defer func() {
if len(changelog) > 0 { if len(changelog) > 0 {
s.notifyPostprocessingHooks(changelog)
s.notifyChangeHooks(changelog) s.notifyChangeHooks(changelog)
} }
......
...@@ -63,7 +63,7 @@ func TestReadmeExample(t *testing.T) { ...@@ -63,7 +63,7 @@ func TestReadmeExample(t *testing.T) {
var h ChangeHook var h ChangeHook
h = &ChangeEventHandler{ h = &ChangeEventHandler{
Callback: func(event ChangeEvent) { Callback: func(event ChangeEvent) {
log := event.Changlog log := event.Changelog
msg = fmt.Sprintf("Change from %s to %s", log[0].From, log[0].To) msg = fmt.Sprintf("Change from %s to %s", log[0].From, log[0].To)
// for Readme // for Readme
//fmt.Println(msg) //fmt.Println(msg)
...@@ -91,7 +91,7 @@ func TestReadmeExample(t *testing.T) { ...@@ -91,7 +91,7 @@ func TestReadmeExample(t *testing.T) {
} }
func TestCangeOnChange(t *testing.T) { func TestChangeOnChange(t *testing.T) {
defaults := ConfigStruct2{ defaults := ConfigStruct2{
A: "", A: "",
......
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
</component> </component>
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/licenses" />
</content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
"devenv": { "devenv": {
"locked": { "locked": {
"dir": "src/modules", "dir": "src/modules",
"lastModified": 1690831896, "lastModified": 1692003204,
"narHash": "sha256-k4Cb2/Yx2kL8TFuVejwEk4R0J+5sxbydAj2IZBKZg7o=", "narHash": "sha256-gO2DXwXuArjpywgtRTDb3aKscWMbnI7YwFaqvV46yv0=",
"owner": "cachix", "owner": "cachix",
"repo": "devenv", "repo": "devenv",
"rev": "e91205acb792f6a49ea53ab04c04fbc2a85039cd", "rev": "ade3ae522baf366296598e232b7b063d81740bbb",
"type": "github" "type": "github"
}, },
"original": { "original": {
...@@ -74,16 +74,16 @@ ...@@ -74,16 +74,16 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1691188534, "lastModified": 1691950488,
"narHash": "sha256-oXjS9GrZar+sB8j2KYzWw3dW62jYFhnjOsnO5+D+B3s=", "narHash": "sha256-iUNEeudc4dGjx+HsHccnGiuZUVE/nhjXuQ1DVCsHIUY=",
"owner": "NixOS", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "5767e7b931f2e6ee7f582d564b8665095c059f3b", "rev": "720e61ed8de116eec48d6baea1d54469b536b985",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "nixos",
"ref": "nixpkgs-unstable", "ref": "nixos-23.05",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
...@@ -104,6 +104,21 @@ ...@@ -104,6 +104,21 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_2": {
"locked": {
"lastModified": 1691950488,
"narHash": "sha256-iUNEeudc4dGjx+HsHccnGiuZUVE/nhjXuQ1DVCsHIUY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "720e61ed8de116eec48d6baea1d54469b536b985",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-23.05",
"type": "indirect"
}
},
"pre-commit-hooks": { "pre-commit-hooks": {
"inputs": { "inputs": {
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
...@@ -115,11 +130,11 @@ ...@@ -115,11 +130,11 @@
"nixpkgs-stable": "nixpkgs-stable" "nixpkgs-stable": "nixpkgs-stable"
}, },
"locked": { "locked": {
"lastModified": 1691093055, "lastModified": 1691747570,
"narHash": "sha256-sjNWYpDHc6vx+/M0WbBZKltR0Avh2S43UiDbmYtfHt0=", "narHash": "sha256-J3fnIwJtHVQ0tK2JMBv4oAmII+1mCdXdpeCxtIsrL2A=",
"owner": "cachix", "owner": "cachix",
"repo": "pre-commit-hooks.nix", "repo": "pre-commit-hooks.nix",
"rev": "ebb43bdacd1af8954d04869c77bc3b61fde515e4", "rev": "c5ac3aa3324bd8aebe8622a3fc92eeb3975d317a",
"type": "github" "type": "github"
}, },
"original": { "original": {
...@@ -132,7 +147,8 @@ ...@@ -132,7 +147,8 @@
"inputs": { "inputs": {
"devenv": "devenv", "devenv": "devenv",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks" "pre-commit-hooks": "pre-commit-hooks",
"version": "version"
} }
}, },
"systems": { "systems": {
...@@ -149,6 +165,24 @@ ...@@ -149,6 +165,24 @@
"repo": "default", "repo": "default",
"type": "github" "type": "github"
} }
},
"version": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1690668568,
"narHash": "sha256-jzixQKFFW4oxO0S4GYqbkFCXzhBd6com6Z9+MtVKakU=",
"ref": "refs/heads/master",
"rev": "3838f03165b726e47d586c04a1821749375e1001",
"revCount": 37,
"type": "git",
"url": "https://gitlab.schukai.com/oss/utilities/version.git"
},
"original": {
"type": "git",
"url": "https://gitlab.schukai.com/oss/utilities/version.git"
}
} }
}, },
"root": "root", "root": "root",
......
{ pkgs, ... }: { pkgs, inputs, phps, lib, config, modulesPath,... }:
{ {
# https://devenv.sh/basics/
env.APP_NAME = "configuration";
# https://devenv.sh/packages/ # https://devenv.sh/packages/
packages = [ pkgs.git ]; packages = [
inputs.version.defaultPackage."${builtins.currentSystem}"
pkgs.git
pkgs.gcc12
pkgs.go-task
pkgs.blackbox
pkgs.blackbox-terminal
pkgs.jq
pkgs.delve
pkgs.gdlv
pkgs.wget
pkgs.glab
pkgs.unixtools.xxd
pkgs.libffi
pkgs.zlib
pkgs.procps
pkgs.php81Extensions.xdebug
pkgs.ranger
pkgs.meld
pkgs.gnused
pkgs.coreutils-full
pkgs.gnugrep
pkgs.gnumake
pkgs.util-linux
pkgs.httpie
pkgs.netcat
pkgs.memcached
pkgs.fd
];
# https://devenv.sh/languages/ # https://devenv.sh/languages/
languages.go.enable = true; # languages.nix.enable = true;
languages = {
go = { enable = true; };
};
difftastic.enable = true;
# This script is executed when the app is built
# You can use it to build the app
scripts.build-app.exec = ''
#!${pkgs.bash}/bin/bash
#set -euo pipefail
set -x
PATH="''${PATH}":${pkgs.coreutils}/bin
PATH="''${PATH}":${pkgs.findutils}/bin
PATH="''${PATH}":${pkgs.jq}/bin/
PATH="''${PATH}":${pkgs.rsync}/bin/
PATH="''${PATH}":${pkgs.bash}/bin/
PATH="''${PATH}":${pkgs.curl}/bin/
PATH="''${PATH}":${pkgs.moreutils}/bin/
PATH="''${PATH}":${pkgs.gnutar}/bin
PATH="''${PATH}":${pkgs.gzip}/bin/
PATH="''${PATH}":${pkgs.procps}/bin/
PATH="''${PATH}":${pkgs.exa}/bin/
PATH="''${PATH}":${pkgs.git}/bin/
PATH="''${PATH}":${pkgs.gnugrep}/bin/
PATH="''${PATH}":${inputs.version.defaultPackage."${builtins.currentSystem}"}/bin/
export -f PATH
task test
'';
# This scritp is used to deploy the app to the gitlab registry
# It is used by the gitlab-ci.yml file
# The environment variables are set in the gitlab project settings
scripts.deploy-app.exec = ''
#!${pkgs.bash}/bin/bash
PATH="''${PATH}":${pkgs.coreutils}/bin
PATH="''${PATH}":${pkgs.jq}/bin/
PATH="''${PATH}":${pkgs.curl}/bin/
PATH="''${PATH}":${pkgs.moreutils}/bin/
PATH="''${PATH}":${pkgs.gnutar}/bin
PATH="''${PATH}":${pkgs.gzip}/bin/
PATH="''${PATH}":${pkgs.exa}/bin/
PATH="''${PATH}":${pkgs.git}/bin/
PATH="''${PATH}":${inputs.version.defaultPackage."${builtins.currentSystem}"}/bin/
export PATH
if [[ -f .env-gitlab-ci ]]; then
source .env-gitlab-ci
rm .env-gitlab-ci
fi
set -x
## if $HOME not set, set it to current directory
if [[ -z "''${HOME}" ]]; then
HOME=$(pwd)
fi
export HOME
git config user.email "''${GITLAB_USER_EMAIL}"
git config user.name "''${GITLAB_USER_NAME:-"Gitlab CI"}"
git config pull.rebase true
git config http.sslVerify "false"
git remote set-url origin https://pad:''${GITLAB_TOKEN}@''${CI_REPOSITORY_URL#*@}
git fetch --all --tags --unshallow
git reset --hard origin/master
git checkout $CI_COMMIT_REF_NAME
git pull origin $CI_COMMIT_REF_NAME
if [ ! -z "''${CI_PROJECT_DIR}" ]; then
echo "CI_PROJECT_DIR is set, using it as project root."
project_root=$(realpath "''${CI_PROJECT_DIR}")/
elif [ ! -z "''${DEVENV_ROOT}" ]; then
echo "DEVENV_ROOT is set, using it as project root."
project_root=$(realpath "''${DEVENV_ROOT}")/
else
echo "Error: DEVENV_ROOT or CI_PROJECT_DIR environment variables are not set."
exit 1
fi
if [ ! -d "''${project_root}" ]; then
echo "Error: Project root directory does not seem to be valid."
echo "Check the DEVENV_ROOT or CI_PROJECT_DIR environment variables."
exit 1
fi
if [ -z "'CI_JOB_TOKEN" ]; then
echo "Error: CI_JOB_TOKEN variable is not set."
exit 1
fi
git --no-pager log --decorate=short --pretty=oneline
## the version should be the same as in the build task
if ! version auto --git --verbose
then
echo "ERROR: Could not update version."
exit 1
fi
git --no-pager log --decorate=short --pretty=oneline
gitVersion=v$(version predict)
git push -o ci.skip origin ''${CI_COMMIT_REF_NAME} --tags
echo "done"
# https://devenv.sh/pre-commit-hooks/ '';
# pre-commit.hooks.shellcheck.enable = true;
# https://devenv.sh/processes/
# processes.ping.exec = "ping example.com";
# See full reference at https://devenv.sh/reference/options/
} }
inputs: inputs:
nixpkgs: nixpkgs:
url: github:NixOS/nixpkgs/nixpkgs-unstable url: github:nixos/nixpkgs/nixos-23.05
version:
url: git+https://gitlab.schukai.com/oss/utilities/version.git
flake: true
...@@ -10,13 +10,13 @@ type ErrorHook interface { ...@@ -10,13 +10,13 @@ type ErrorHook interface {
Handle(event ErrorEvent) Handle(event ErrorEvent)
} }
// OnChange registers a hook that is called when the configuration changes. // OnError registers a hook that is called when the configuration changes.
func (s *Settings[C]) OnError(hook ErrorHook) *Settings[C] { func (s *Settings[C]) OnError(hook ErrorHook) *Settings[C] {
s.hooks.error = append(s.hooks.error, hook) s.hooks.error = append(s.hooks.error, hook)
return s return s
} }
// HasOnChangeHook returns true if there are registered hooks. // HasOnErrorHook returns true if there are registered hooks.
func (s *Settings[C]) HasOnErrorHook(hook ErrorHook) *Settings[C] { func (s *Settings[C]) HasOnErrorHook(hook ErrorHook) *Settings[C] {
for _, h := range s.hooks.error { for _, h := range s.hooks.error {
if h == hook { if h == hook {
...@@ -26,7 +26,7 @@ func (s *Settings[C]) HasOnErrorHook(hook ErrorHook) *Settings[C] { ...@@ -26,7 +26,7 @@ func (s *Settings[C]) HasOnErrorHook(hook ErrorHook) *Settings[C] {
return s return s
} }
// RemoveOnChangeHook removes a change hook from the list of hooks. // RemoveOnErrorHook removes a change hook from the list of hooks.
func (s *Settings[C]) RemoveOnErrorHook(hook ErrorHook) *Settings[C] { func (s *Settings[C]) RemoveOnErrorHook(hook ErrorHook) *Settings[C] {
for i, h := range s.hooks.error { for i, h := range s.hooks.error {
if h == hook { if h == hook {
......
...@@ -59,13 +59,13 @@ func TestAddRemoveErrorHook(t *testing.T) { ...@@ -59,13 +59,13 @@ func TestAddRemoveErrorHook(t *testing.T) {
s.OnError(h) s.OnError(h)
if len(s.hooks.error) != 1 { if len(s.hooks.error) != 1 {
t.Error("Expected 1 got ", len(s.hooks.change)) t.Error("Expected 1 got ", len(s.hooks.error))
} }
s.RemoveOnErrorHook(h) s.RemoveOnErrorHook(h)
if len(s.hooks.error) != 0 { if len(s.hooks.error) != 0 {
t.Error("Expected 0 got ", len(s.hooks.change)) t.Error("Expected 0 got ", len(s.hooks.error))
} }
} }
...@@ -69,14 +69,14 @@ func newUnsupportedTypeError(t reflect.Type) UnsupportedTypeError { ...@@ -69,14 +69,14 @@ func newUnsupportedTypeError(t reflect.Type) UnsupportedTypeError {
return UnsupportedTypeError(errors.New("type " + t.String() + " is not supported")) return UnsupportedTypeError(errors.New("type " + t.String() + " is not supported"))
} }
// At the reflect level, some types are not supported // UnsupportedReflectKindError At the reflect level, some types are not supported
type UnsupportedReflectKindError error type UnsupportedReflectKindError error
func newUnsupportedReflectKindError(t reflect.Type) UnsupportedReflectKindError { func newUnsupportedReflectKindError(t reflect.Type) UnsupportedReflectKindError {
return UnsupportedReflectKindError(errors.New("type " + t.String() + " is not supported")) return UnsupportedReflectKindError(errors.New("type " + t.String() + " is not supported"))
} }
// This error indicates that the flag is not found // FlagNotFoundError This error indicates that the flag is not found
type FlagNotFoundError error type FlagNotFoundError error
func newFlagNotFoundError(name string) FlagNotFoundError { func newFlagNotFoundError(name string) FlagNotFoundError {
......
...@@ -34,7 +34,7 @@ func (s *Settings[c]) HasFile(file string) bool { ...@@ -34,7 +34,7 @@ func (s *Settings[c]) HasFile(file string) bool {
return false return false
} }
// AddFiles adds a file to the list of files to import // AddFile adds a file to the list of files to import
func (s *Settings[C]) AddFile(file string, format ...Format) *Settings[C] { func (s *Settings[C]) AddFile(file string, format ...Format) *Settings[C] {
var f Format var f Format
...@@ -96,12 +96,12 @@ func initFileBackend(files *fileBackend) { ...@@ -96,12 +96,12 @@ func initFileBackend(files *fileBackend) {
files.fs = fs.FS(internalFS{}) files.fs = fs.FS(internalFS{})
} }
// Path returns the configuration directory // Directories returns the list of directories to search for configuration files
func (s *Settings[C]) Directories() []string { func (s *Settings[C]) Directories() []string {
return s.files.directories return s.files.directories
} }
// AddPath adds a directory to the configuration directory // AddDirectory adds a directory to the list of directories to search for configuration files
func (s *Settings[C]) AddDirectory(d string) *Settings[C] { func (s *Settings[C]) AddDirectory(d string) *Settings[C] {
s.Lock() s.Lock()
defer s.Unlock() defer s.Unlock()
...@@ -148,7 +148,7 @@ func (s *Settings[C]) sanitizeDirectories() { ...@@ -148,7 +148,7 @@ func (s *Settings[C]) sanitizeDirectories() {
} }
// Set all configuration directories // SetDirectories sets the list of directories to search for configuration files
func (s *Settings[C]) SetDirectories(d []string) *Settings[C] { func (s *Settings[C]) SetDirectories(d []string) *Settings[C] {
s.Lock() s.Lock()
defer s.Unlock() defer s.Unlock()
...@@ -158,7 +158,7 @@ func (s *Settings[C]) SetDirectories(d []string) *Settings[C] { ...@@ -158,7 +158,7 @@ func (s *Settings[C]) SetDirectories(d []string) *Settings[C] {
return s return s
} }
// Add the current working directory to the configuration directory // AddWorkingDirectory adds the current working directory to the list of directories to search for configuration files
func (s *Settings[C]) AddWorkingDirectory() *Settings[C] { func (s *Settings[C]) AddWorkingDirectory() *Settings[C] {
s.Lock() s.Lock()
defer s.Unlock() defer s.Unlock()
...@@ -181,7 +181,7 @@ func (s *Settings[C]) AddWorkingDirectory() *Settings[C] { ...@@ -181,7 +181,7 @@ func (s *Settings[C]) AddWorkingDirectory() *Settings[C] {
return s return s
} }
// Add the Unix etc directory to the configuration directory // AddEtcDirectory adds the /etc directory to the list of directories to search for configuration files
func (s *Settings[C]) AddEtcDirectory() *Settings[C] { func (s *Settings[C]) AddEtcDirectory() *Settings[C] {
s.Lock() s.Lock()
defer s.Unlock() defer s.Unlock()
...@@ -211,7 +211,7 @@ func (s *Settings[C]) AddEtcDirectory() *Settings[C] { ...@@ -211,7 +211,7 @@ func (s *Settings[C]) AddEtcDirectory() *Settings[C] {
return s return s
} }
// Add the user configuration directory to the configuration directory // AddUserConfigDirectory Add the user configuration directory to the configuration directory
// The mnemonic must be set for this function // The mnemonic must be set for this function
func (s *Settings[C]) AddUserConfigDirectory() *Settings[C] { func (s *Settings[C]) AddUserConfigDirectory() *Settings[C] {
...@@ -242,7 +242,7 @@ func (s *Settings[C]) AddUserConfigDirectory() *Settings[C] { ...@@ -242,7 +242,7 @@ func (s *Settings[C]) AddUserConfigDirectory() *Settings[C] {
return s return s
} }
// Add the current working directory, the user configuration directory // SetDefaultDirectories Add the current working directory, the user configuration directory
// and the Unix etc directory to the configuration directory // and the Unix etc directory to the configuration directory
func (s *Settings[C]) SetDefaultDirectories() *Settings[C] { func (s *Settings[C]) SetDefaultDirectories() *Settings[C] {
s.AddWorkingDirectory(). s.AddWorkingDirectory().
...@@ -269,7 +269,7 @@ func (s *Settings[C]) SetFileFormat(format Format) *Settings[C] { ...@@ -269,7 +269,7 @@ func (s *Settings[C]) SetFileFormat(format Format) *Settings[C] {
return s return s
} }
// Set the file name without extension // SetFileName sets the name of the configuration file
func (s *Settings[C]) SetFileName(name string) *Settings[C] { func (s *Settings[C]) SetFileName(name string) *Settings[C] {
errorCount := len(s.errors) errorCount := len(s.errors)
......
...@@ -71,6 +71,10 @@ golang.org/x/exp v0.0.0-20230307190834-24139beb5833 h1:SChBja7BCQewoTAU7IgvucQKM ...@@ -71,6 +71,10 @@ golang.org/x/exp v0.0.0-20230307190834-24139beb5833 h1:SChBja7BCQewoTAU7IgvucQKM
golang.org/x/exp v0.0.0-20230307190834-24139beb5833/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/exp v0.0.0-20230307190834-24139beb5833/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI= golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad h1:g0bG7Z4uG+OgH2QDODnjp6ggkk1bJDsINcuWmJN1iJU=
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA=
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b h1:tvrvnPFcdzp294diPnrdZZZ8XUt2Tyj7svb7X52iDuU= golang.org/x/net v0.0.0-20221014081412-f15817d10f9b h1:tvrvnPFcdzp294diPnrdZZZ8XUt2Tyj7svb7X52iDuU=
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
......
...@@ -18,3 +18,11 @@ type ErrorEventHandler struct { ...@@ -18,3 +18,11 @@ type ErrorEventHandler struct {
func (c *ErrorEventHandler) Handle(event ErrorEvent) { func (c *ErrorEventHandler) Handle(event ErrorEvent) {
c.Callback(event) c.Callback(event)
} }
type PostprocessingHandler struct {
Callback func(event PostprocessingEvent)
}
func (c *PostprocessingHandler) Handle(event PostprocessingEvent) {
c.Callback(event)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment