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
  • master
  • v1.0.0
  • v1.0.1
  • v1.1.0
  • v1.10.0
  • v1.11.0
  • v1.11.1
  • v1.11.2
  • v1.11.3
  • v1.11.4
  • v1.12.0
  • v1.13.0
  • v1.14.0
  • v1.15.0
  • v1.16.0
  • v1.17.1
  • v1.17.2
  • v1.17.3
  • v1.17.4
  • v1.17.5
  • v1.17.6
  • v1.17.7
  • v1.18.0
  • v1.18.1
  • v1.18.2
  • v1.18.3
  • v1.19.0
  • v1.2.0
  • v1.20.0
  • v1.20.1
  • v1.20.2
  • v1.20.3
  • v1.20.4
  • v1.20.5
  • v1.21.0
  • v1.22.0
  • v1.22.1
  • v1.22.3
  • v1.22.4
  • v1.22.5
  • v1.22.6
  • v1.22.7
  • v1.22.8
  • v1.22.9
  • v1.3.0
  • v1.4.0
  • v1.4.1
  • v1.4.2
  • v1.4.3
  • v1.5.0
  • v1.6.0
  • v1.7.0
  • v1.7.1
  • v1.8.0
  • v1.9.0
55 results

Target

Select target project
  • oss/libraries/go/application/configuration
1 result
Select Git revision
  • master
  • v1.0.0
  • v1.0.1
  • v1.1.0
  • v1.10.0
  • v1.11.0
  • v1.11.1
  • v1.11.2
  • v1.11.3
  • v1.11.4
  • v1.12.0
  • v1.13.0
  • v1.14.0
  • v1.15.0
  • v1.16.0
  • v1.17.1
  • v1.17.2
  • v1.17.3
  • v1.17.4
  • v1.17.5
  • v1.17.6
  • v1.17.7
  • v1.18.0
  • v1.18.1
  • v1.18.2
  • v1.18.3
  • v1.19.0
  • v1.2.0
  • v1.20.0
  • v1.20.1
  • v1.20.2
  • v1.20.3
  • v1.20.4
  • v1.20.5
  • v1.21.0
  • v1.22.0
  • v1.22.1
  • v1.22.3
  • v1.22.4
  • v1.22.5
  • v1.22.6
  • v1.22.7
  • v1.22.8
  • v1.22.9
  • v1.3.0
  • v1.4.0
  • v1.4.1
  • v1.4.2
  • v1.4.3
  • v1.5.0
  • v1.6.0
  • v1.7.0
  • v1.7.1
  • v1.8.0
  • v1.9.0
55 results
Show changes
Commits on Source (3)
<a name="v1.8.0"></a>
## [v1.8.0] - 2022-10-17
### Add Features
- feat add the posibility to recognise the filetype, add HasFile and RemoveFile
<a name="v1.7.1"></a>
## [v1.7.1] - 2022-10-15
### Bug Fixes
......@@ -78,6 +84,7 @@
<a name="v1.0.0"></a>
## v1.0.0 - 2022-09-18
[v1.8.0]: https://gitlab.schukai.com/oss/libraries/go/application/configuration/compare/v1.7.1...v1.8.0
[v1.7.1]: https://gitlab.schukai.com/oss/libraries/go/application/configuration/compare/v1.7.0...v1.7.1
[v1.7.0]: https://gitlab.schukai.com/oss/libraries/go/application/configuration/compare/v1.6.0...v1.7.0
[v1.6.0]: https://gitlab.schukai.com/oss/libraries/go/application/configuration/compare/v1.5.0...v1.6.0
......
......@@ -41,6 +41,8 @@ func (s *Settings[C]) SetMnemonic(mnemonic string) *Settings[C] {
}
// Config() returns the configuration
// Remember that the configuration is a copy of the original configuration.
// Changes to the configuration will not be reflected in the original configuration.
func (s *Settings[C]) Config() C {
return s.config
}
......@@ -4,7 +4,7 @@
package configuration
import (
"github.com/magiconair/properties/assert"
"github.com/stretchr/testify/assert"
"testing"
)
......
......@@ -4,7 +4,7 @@
package configuration
import (
"github.com/magiconair/properties/assert"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
......
......@@ -89,3 +89,9 @@ type MismatchedTypeError error
func newMismatchedTypeError(expected, actual reflect.Type) MismatchedTypeError {
return MismatchedTypeError(errors.New("expected type " + expected.String() + " but got " + actual.String()))
}
type UnknownFileExtensionError error
func newUnknownFileExtensionError(extension, filename string) UnknownFileExtensionError {
return UnknownFileExtensionError(errors.New("unknown file extension " + extension + " for file " + filename))
}
......@@ -8,6 +8,7 @@ import (
"io/fs"
"os"
"path"
"path/filepath"
)
type files struct {
......@@ -23,9 +24,60 @@ type fileBackend struct {
fs fs.FS
}
func (s *Settings[c]) HasFile(file string) bool {
for _, f := range s.files.files {
if f.path == file {
return true
}
}
return false
}
// AddFiles adds a file to the list of files to import
func (s *Settings[C]) AddFile(file string, format Format) *Settings[C] {
s.files.files = append(s.files.files, files{file, format})
func (s *Settings[C]) AddFile(file string, format ...Format) *Settings[C] {
var f Format
f = RecogniseFormat
if len(format) <= 1 {
f = format[0]
} else {
panic("too many arguments")
}
if f == RecogniseFormat {
ext := filepath.Ext(file)
switch ext {
case ".yaml":
f = Yaml
case ".json":
f = Json
case ".toml":
f = Toml
case ".properties":
f = Properties
default:
if ext != "" {
s.errors = append(s.errors, newUnknownFileExtensionError(ext, file))
return s
}
f = s.files.format
}
}
s.files.files = append(s.files.files, files{file, f})
return s
}
func (s *Settings[C]) RemoveFile(file string) *Settings[C] {
for i, f := range s.files.files {
if f.path == file {
s.files.files = append(s.files.files[:i], s.files.files[i+1:]...)
return s
}
}
return s
}
......
......@@ -5,7 +5,7 @@ package configuration
import (
"bytes"
"github.com/magiconair/properties/assert"
"github.com/stretchr/testify/assert"
"io"
"io/fs"
"os"
......@@ -510,6 +510,54 @@ func TestSettingAddFile(t *testing.T) {
}
func TestRemoveFile(t *testing.T) {
cfg := ConfigStruct2{}
f, err := os.CreateTemp("", "watch_test")
if err != nil {
t.Error(err)
return
}
defer os.Remove(f.Name())
f.WriteString("A: \"from file\"")
c := New(cfg)
c.AddFile(f.Name(), Yaml)
assert.Equal(t, c.Config().A, "")
c.Import()
assert.Equal(t, c.Config().A, "from file")
assert.True(t, c.HasFile(f.Name()))
c.RemoveFile(f.Name())
assert.False(t, c.HasFile(f.Name()))
}
func TestSettingAddFileWithRecognise(t *testing.T) {
cfg := ConfigStruct2{}
f, err := os.CreateTemp("", "watch_test")
if err != nil {
t.Error(err)
return
}
defer os.Remove(f.Name())
f.WriteString("A: \"from file\"")
c := New(cfg)
c.AddFile(f.Name(), RecogniseFormat)
assert.Equal(t, c.Config().A, "")
c.Import()
assert.Equal(t, c.Config().A, "from file")
}
func TestSetConfigName(t *testing.T) {
cfg := ConfigStruct2{}
......
......@@ -8,7 +8,7 @@ import (
"os"
"testing"
"github.com/magiconair/properties/assert"
"github.com/stretchr/testify/assert"
)
// Example for README
......
......@@ -6,7 +6,8 @@ package configuration
type Format int
const (
Yaml Format = iota
RecogniseFormat = -1
Yaml Format = iota
Json
Toml
Properties
......
......@@ -4,7 +4,7 @@
package configuration
import (
"github.com/magiconair/properties/assert"
"github.com/stretchr/testify/assert"
"testing"
)
......
......@@ -4,7 +4,7 @@
package configuration
import (
"github.com/magiconair/properties/assert"
"github.com/stretchr/testify/assert"
"testing"
)
......
{"version":"1.7.1"}
{"version":"1.8.0"}
......@@ -4,7 +4,7 @@
package configuration
import (
"github.com/magiconair/properties/assert"
"github.com/stretchr/testify/assert"
"os"
"testing"
"time"
......