Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Configuration
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Go
Application
Configuration
Compare revisions
v1.11.3 to v1.11.4
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
oss/libraries/go/application/configuration
Select target project
No results found
v1.11.4
Select Git revision
Branches
master
Tags
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
Swap
Target
oss/libraries/go/application/configuration
Select target project
oss/libraries/go/application/configuration
1 result
v1.11.3
Select Git revision
Branches
master
Tags
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
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (3)
fix the prefix of the env function now works
· 06ee56ee
Volker Schukai
authored
2 years ago
Verified
06ee56ee
Bump version to 1.11.4
· c86e8c30
Volker Schukai
authored
2 years ago
Verified
c86e8c30
Update changelog
· 87d00532
Volker Schukai
authored
2 years ago
Verified
87d00532
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+7
-0
7 additions, 0 deletions
CHANGELOG.md
env.go
+7
-0
7 additions, 0 deletions
env.go
env_test.go
+26
-2
26 additions, 2 deletions
env_test.go
release.json
+1
-1
1 addition, 1 deletion
release.json
with
41 additions
and
3 deletions
CHANGELOG.md
View file @
87d00532
<a
name=
"v1.11.4"
></a>
## [v1.11.4] - 2022-10-23
### Bug Fixes
-
fix the prefix of the env function now works
<a
name=
"v1.11.3"
></a>
## [v1.11.3] - 2022-10-23
### Bug Fixes
...
...
@@ -131,6 +137,7 @@
<a
name=
"v1.0.0"
></a>
## v1.0.0 - 2022-09-18
[
v1.11.4
]:
https://gitlab.schukai.com/oss/libraries/go/application/configuration/compare/v1.11.3...v1.11.4
[
v1.11.3
]:
https://gitlab.schukai.com/oss/libraries/go/application/configuration/compare/v1.11.2...v1.11.3
[
v1.11.2
]:
https://gitlab.schukai.com/oss/libraries/go/application/configuration/compare/v1.11.1...v1.11.2
[
v1.11.1
]:
https://gitlab.schukai.com/oss/libraries/go/application/configuration/compare/v1.11.0...v1.11.1
...
...
This diff is collapsed.
Click to expand it.
env.go
View file @
87d00532
...
...
@@ -7,6 +7,7 @@ import (
"os"
"reflect"
"strconv"
"strings"
)
func
(
s
*
Settings
[
C
])
InitFromEnv
(
prefix
string
)
*
Settings
[
C
]
{
...
...
@@ -21,12 +22,18 @@ func (s *Settings[C]) InitFromEnv(prefix string) *Settings[C] {
}
}()
if
prefix
!=
""
{
prefix
=
strings
.
ToUpper
(
prefix
)
+
"_"
}
err
:=
runOnTags
(
&
s
.
config
,
[]
string
{
envTagKey
},
func
(
k
string
,
field
reflect
.
Value
)
{
if
!
field
.
CanSet
()
{
return
}
k
=
prefix
+
strings
.
ToUpper
(
k
)
v
,
found
:=
os
.
LookupEnv
(
k
)
if
!
found
{
return
// env not found
...
...
This diff is collapsed.
Click to expand it.
env_test.go
View file @
87d00532
...
...
@@ -20,6 +20,7 @@ func TestReadmeExample2(t *testing.T) {
// Set value
os
.
Setenv
(
"HOST"
,
"www.example.com"
)
defer
os
.
Unsetenv
(
"HOST"
)
s
:=
New
(
config
)
//fmt.Println(s.Config().Host) // localhost
...
...
@@ -31,6 +32,27 @@ func TestReadmeExample2(t *testing.T) {
}
func
TestWithPrefix
(
t
*
testing
.
T
)
{
config
:=
struct
{
Host
string
`env:"HOST"`
}{
Host
:
"localhost"
,
}
// Set value
os
.
Setenv
(
"XYZ_HOST"
,
"www.example.com"
)
defer
os
.
Unsetenv
(
"XYZ_HOST"
)
s
:=
New
(
config
)
//fmt.Println(s.Config().Host) // localhost
assert
.
Equal
(
t
,
s
.
Config
()
.
Host
,
"localhost"
)
s
.
InitFromEnv
(
"XYZ"
)
// no prefix
//fmt.Println(s.Config().Host) // www.example.com
assert
.
Equal
(
t
,
s
.
Config
()
.
Host
,
"www.example.com"
)
}
func
TestFromEnvNotSet
(
t
*
testing
.
T
)
{
config
:=
ConfigStruct6
{
IA
:
1234
,
...
...
@@ -43,6 +65,7 @@ func TestFromEnvNotSet(t *testing.T) {
// Value not set
s
.
InitFromEnv
(
"VALUE_IB"
)
defer
os
.
Unsetenv
(
"VALUE_IB"
)
if
s
.
Config
()
.
IA
!=
1234
{
t
.
Errorf
(
"Expected 1234, got %d"
,
s
.
Config
()
.
IA
)
...
...
@@ -61,7 +84,7 @@ func TestFromEnv(t *testing.T) {
s
:=
New
(
config
)
// Value not set
s
.
InitFromEnv
(
"
VALUE_IB
"
)
s
.
InitFromEnv
(
"
NIX
"
)
if
s
.
Config
()
.
IA
!=
1234
{
t
.
Errorf
(
"Expected 1234, got %d"
,
s
.
Config
()
.
IA
)
...
...
@@ -69,7 +92,8 @@ func TestFromEnv(t *testing.T) {
// Set value
os
.
Setenv
(
"VALUE_IB"
,
"i-am-b"
)
s
.
InitFromEnv
(
"VALUE_IB"
)
defer
os
.
Unsetenv
(
"VALUE_IB"
)
s
.
InitFromEnv
(
""
)
if
s
.
Config
()
.
IB
!=
"i-am-b"
{
t
.
Errorf
(
"Expected i-am-b, got %s"
,
s
.
Config
()
.
IB
)
...
...
This diff is collapsed.
Click to expand it.
release.json
View file @
87d00532
{
"version"
:
"1.11.
3
"
}
{
"version"
:
"1.11.
4
"
}
This diff is collapsed.
Click to expand it.