Help us shape the future of Go! Take the 2026 Go Developer Survey

serviceconfig

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2025 License: MIT Imports: 11 Imported by: 0

README

Service config manager

This golang package manages service configuration files in YAML format.

Tags that control the behaviour.

  • yaml:"name" overrides field names
  • comment:"My comment" adds a comment above the field
  • line-comment:"My comment" adds a comment at the end of the line

Example

See example/example.go for implementation examples.

Installation

go get github.com/utvecklat/version

Config file location

If there is no path given for the configuration file the default is to place the configuration file in the same folder as the program.

If the service application is located in /opt/ FHS 3.0 suggests that the configuration should be located under /etc/opt/ such as /etc/opt/<provider>/<service>.

Provide the full path name to place config file in a folder different from the application binary.

License and Code of Conduct

This package is released under the MIT License. Please follow the code of conduct when you interact with the project contributors.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFile = errors.New("config file is not a regular file")
View Source
var ErrInvalidFileName = errors.New("invalid file name")

Functions

This section is empty.

Types

type Manager

type Manager[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any](defaults *T, file string) (c *Manager[T], err error)

func (*Manager[T]) Config

func (c *Manager[T]) Config() *T

Config thread safe fetch of config, use this if using the watcher or to make sure that the parser is done after a change.

func (*Manager[T]) Filename

func (c *Manager[T]) Filename() string

Filename returns the full path to the file.

func (*Manager[T]) Load

func (c *Manager[T]) Load() (changed bool, err error)

Load loads the configuration from disk. If Watch is set up the file will be automatically be loaded if updated.

func (*Manager[T]) Save

func (c *Manager[T]) Save() (err error)

Save saves the config to the configured filename. Does not trigger the watch function.

func (*Manager[T]) Watch

func (c *Manager[T]) Watch(f func(err error))

Watch calls the function f when the config file have been changed from an external program. Calling Save does not trigger this watcher. If the file saved but not changed will not trigger this watcher.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL