Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • oss/libraries/go/application/configuration
1 result
Select Git revision
Show changes
Commits on Source (3)
## Configuration
## Installation
```shell
go get gitlab.schukai.com/oss/libraries/go/application/configuration
```
**Note:** This library uses [Go Modules](https://github.com/golang/go/wiki/Modules) to manage dependencies.
## What do this library?
This library provides a simple way to load configuration from different sources.
......@@ -23,6 +15,15 @@ It supports:
* [x] Properties
* [x] Configuration from a struct
* [x] HTTP API (get and set configuration)
* [x] Monitor File changes
## Installation
```shell
go get gitlab.schukai.com/oss/libraries/go/application/configuration
```
**Note:** This library uses [Go Modules](https://github.com/golang/go/wiki/Modules) to manage dependencies.
## Usage
......@@ -228,9 +229,6 @@ returns a bool channel on which the status of the watch is reported.
If the watch has ended, a true is sent over the channel. If an error occurs, a false is sent.
```go
#### Streams
The configuration can also be loaded from a stream. This is useful if you want to
......
......@@ -28,7 +28,7 @@ func newPathAlreadyExistsError(path string) PathAlreadyExistsError {
return PathAlreadyExistsError(errors.New("files " + path + " already exists"))
}
// PathDoesNotExistError is returned when a files does not exist
// PathDoesNotExistError is returned when a files do not exist
type PathDoesNotExistError error
func newPathDoesNotExistError(path string) PathDoesNotExistError {
......@@ -59,7 +59,7 @@ func (s *setting[C]) ResetErrors() *setting[C] {
// At the reflect level, some types are not supported
type UnsupportedReflectKindError error
func newUnsupportedReflectKindError(t reflect.Type) UnsupportedTypeError {
func newUnsupportedReflectKindError(t reflect.Type) UnsupportedReflectKindError {
return UnsupportedReflectKindError(errors.New("type " + t.String() + " is not supported"))
}
......
package configuration
import (
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)
func TestResetErrors(t *testing.T) {
defaults := ConfigStruct2{
A: "Hello!",
}
c := New(defaults)
assert.False(t, c.HasError())
c.SetDefaultDirectories()
assert.True(t, c.HasError())
c.ResetErrors()
assert.False(t, c.HasError())
}
func TestNewFlagDoesNotExistError(t *testing.T) {
err := newFlagDoesNotExistError("flag")
_, ok := err.(FlagDoesNotExistError)
assert.True(t, ok)
}
func TestNewPathAlreadyExistsError(t *testing.T) {
err := newPathAlreadyExistsError("flag")
_, ok := err.(PathAlreadyExistsError)
assert.True(t, ok)
}
func TestNewPathDoesNotExistError(t *testing.T) {
err := newPathDoesNotExistError("flag")
_, ok := err.(PathDoesNotExistError)
assert.True(t, ok)
}
func TestNewFormatNotSupportedError(t *testing.T) {
err := newFormatNotSupportedError(Yaml)
_, ok := err.(FormatNotSupportedError)
assert.True(t, ok)
}
func TestNewUnsupportedTypeError(t *testing.T) {
x := reflect.TypeOf("string")
err := newUnsupportedTypeError(x)
_, ok := err.(UnsupportedTypeError)
assert.True(t, ok)
}
func TestNewUnsupportedReflectKindError(t *testing.T) {
x := reflect.TypeOf("string")
err := newUnsupportedReflectKindError(x)
_, ok := err.(UnsupportedReflectKindError)
assert.True(t, ok)
}
func TestNewFlagNotFoundError(t *testing.T) {
err := newFlagNotFoundError("flag")
_, ok := err.(FlagNotFoundError)
assert.True(t, ok)
}
func TestNewMismatchedTypeError(t *testing.T) {
x := reflect.TypeOf("string")
err := newMismatchedTypeError(x, x)
_, ok := err.(MismatchedTypeError)
assert.True(t, ok)
}
{"version":"1.0.0"}
{"version":"1.0.1"}