-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from goreflect/issue_14
Issue 14 Solved
- Loading branch information
Showing
17 changed files
with
1,453 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,86 @@ | ||
# Gostructor [![Actions Status](https://github.com/goreflect/gostructor/workflows/CI_dev/badge.svg)](https://github.com/goreflect/gostructor/actions?query=workflow%3ACI_dev) [![Go Report Card](https://goreportcard.com/badge/github.com/goreflect/gostructor)](https://goreportcard.com/report/github.com/goreflect/gostructor) [![codecov](https://codecov.io/gh/goreflect/gostructor/branch/master/graph/badge.svg)](https://codecov.io/gh/goreflect/gostructor) | ||
____ | ||
### Version: 0.1.2 | ||
### Version: 0.4.1 | ||
|
||
hocon current configuration configuration library | ||
Universal configuration library by tags | ||
|
||
## Current supporting input formats | ||
|
||
- hocon | ||
- hocon values | ||
- default values | ||
- environment variables | ||
|
||
## Current supporting types | ||
|
||
- int32, int64 | ||
- int, int8, int16, int32, int64 | ||
- float32, float64 | ||
- string | ||
- bool | ||
- map[string\int]string\int\float32\float64 | ||
- slices of any types from (int32, int64, int, string, bool, float32, float64) | ||
|
||
## Tags | ||
### Tags | ||
|
||
In current library using any of this tags: | ||
- [x] cf_hocon - setup value for this field from hocon | ||
- [x] cf_default - setup default value for this field | ||
- [x] cf_env - setup value from env variable by name in this tag | ||
- [ ] cf_yaml - setup value for this field from yaml (version > 0.6) | ||
- [ ] cf_json - setup value for this field from json (version > 0.5) | ||
- [ ] cf_server - setup value from configuration server like spring cloud config server or others (version>0.7) | ||
- [ ] cf_vault - setup secret for this field from hashi corp vault (version>0.8) | ||
|
||
1. cf_hocon - setup value for this field from hocon | ||
2. cf_default - setup default value for this field | ||
3. cf_env - setup value from env variable by name in this tag | ||
4. cf_yaml - setup value for this field from yaml (version > 0.2) | ||
5. cf_json - setup value for this field from json (version > 0.3) | ||
6. cf_server - setup value from configuration server like spring cloud config server or others (version>0.4) | ||
7. cf_vault - setup secret for this field from hashi corp vault (version>0.5) | ||
## Running configuring by smart variant | ||
|
||
## Validation(optional version > 0.6) | ||
For Run configuration by smart variant autostart analysing of using tags. library will start configuring your structure by pipeline with all founded tags. | ||
|
||
If you have validate your data you should write in source tag validate after comma and after : you can choose validation type: | ||
- phoneNumber8 | ||
|
||
## Menu | ||
|
||
- [Reserved Tags](https://github.com/goreflect/gostructor/blob/master/tags) | ||
- [Specifications](https://github.com/goreflect/gostructor/blob/master/specifications) | ||
|
||
## Running configuring by easy way | ||
|
||
For easy way you can chose gostructor.ConfigureEasy(). And if you have use one of file sources like: json, hocon, yaml, txt your files should ended by type (if your file not ended of type, this source will be ignored by function chainer) | ||
```go | ||
type Test struct { | ||
MyValue1 string `cf_default:"turur" cf_hocon:"mySourceValue1"` | ||
MySlice1 []bool `cf_default:"true,false,false,true" cf_env:"MY_SIGNALS"` | ||
} | ||
|
||
## Running configuring by setup way | ||
// in this example do use 3 tags: cf_default (using default values which setup inline tag) | ||
// cf_env - using environment variable | ||
// cf_hocon - using hocon source file | ||
|
||
For this way you should set up chain functions will used in configuring pipeline. For example: | ||
`test.hocon` | ||
```hocon | ||
Examples = { | ||
FieldExample = test1 | ||
//.... | ||
|
||
ExampleType = { | ||
Field1 = test2 | ||
func myConfigurator() { | ||
myStruct, errConfiguring := gostructir.ConfigureSmart(&Test{}, "testhocon.hocon") | ||
// check errConfiguring for any errors | ||
if errConfiguring != nil { | ||
/// action for error | ||
} | ||
} | ||
``` | ||
|
||
```golang | ||
type ExampleType struct { | ||
fieldTest1 string `cf_hocon:"Examples.FieldExample"` | ||
Field1 string `cf_default:"tururutest"` | ||
} | ||
... | ||
value, err := gostructor.ConfigureSetup(&ExampleType{}, "test.hocon", []pipeline.FuncType{ | ||
pipeline.FunctionSetupHocon, | ||
pipeline.FunctionSetupDefault, | ||
}) | ||
// cast interface{} into Test structure | ||
myValues := myStruct.(*Test) | ||
// now, u structure already filled | ||
} | ||
|
||
``` | ||
|
||
Where Value is Interface therefore you should cast to your type with Pointer like this: | ||
```golang | ||
value.(*ExampleType) | ||
``` | ||
## Running configuring by setup | ||
|
||
You can also setting configuring pipeline like this: | ||
|
||
## Many examples | ||
```go | ||
type Test struct { | ||
MyValue1 string `cf_default:"turur" cf_hocon:"mySourceValue1"` | ||
MySlice1 []bool `cf_default:"true,false,false,true" cf_env:"MY_SIGNALS"` | ||
} | ||
|
||
In this section will added any examples of using this library | ||
func myConfigurator() { | ||
myStruct, errConfiguring := gostructir.ConfigureSetup(&Test{}, "testhocon.hocon", []infra.FuncType{ | ||
infra.FunctionSetupEnvironment, | ||
})// you should setup only by order configure | ||
// check errConfiguring for any errors | ||
if errConfiguring != nil { | ||
/// action for error | ||
} | ||
|
||
## TODO | ||
// cast interface{} into Test structure | ||
myValues := myStruct.(*Test) | ||
// now, u structure already filled | ||
} | ||
|
||
1. Implement self converters for all sources | ||
2. Write unit tests for any cases | ||
3. Move getFieldName methods for any source func parsers because in any of source have available any naming sources | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package pipeline | ||
|
||
import "testing" | ||
|
||
func Test_checkFileAccessibility(t *testing.T) { | ||
type args struct { | ||
filename string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "check permission denied", | ||
args: args{ | ||
filename: "../test_configs/testFile", | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "check derivet string is dir", | ||
args: args{ | ||
filename: "../test_configs", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "check completed", | ||
args: args{ | ||
filename: "../test_configs/testmap.hocon", | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := checkFileAccessibility(tt.args.filename); (err != nil) != tt.wantErr { | ||
t.Errorf("checkFileAccessibility() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.