https://github.com/itrabbit/sieve
GoLang Package for filtering fields models during serialization
https://github.com/itrabbit/sieve
entities exclude filtering golang jms-serializer json models scopes serialization xml yml
Last synced: 5 months ago
JSON representation
GoLang Package for filtering fields models during serialization
- Host: GitHub
- URL: https://github.com/itrabbit/sieve
- Owner: itrabbit
- License: mit
- Created: 2018-04-11T19:15:42.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-22T16:46:30.000Z (almost 8 years ago)
- Last Synced: 2024-11-15T22:12:04.304Z (over 1 year ago)
- Topics: entities, exclude, filtering, golang, jms-serializer, json, models, scopes, serialization, xml, yml
- Language: Go
- Size: 53.7 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 
[](https://travis-ci.org/itrabbit/sieve)
[](https://codecov.io/gh/itrabbit/sieve)
[](https://godoc.org/github.com/itrabbit/sieve)
GoLang Package for filtering fields models during serialization
**Support:**
- Scopes filtration fields structures
- Exclude strategy (equal fieldValue, equal value)
- Export values of higher level
**Plans**:
- Add version for fields
- Add code generation for fast serialization
- Add support XML, YML serializers
### Tag options
- `s`, `scopes` - for the pane fields in structures;
- `ns`, `nextScopes` - next scopes in the attachment;
- `k`, `exportKeys` - exported field or value from the structure fields;
- `ef`, `eef`, `excludeEqualField` - exclusion rule field (comparison with another field);
- `ev`, `eev`, `excludeEqualValue` - exclusion rule field (comparison with value);
- `e.any` - if you are using multiple conditions, exceptions, if specified, is triggered when any condition.
**Example:**
```go
type A struct {
Status string `sieve:"ev:unknown;ev:null;e.any"
CreatedAt time.Time `sieve:"s:private"`
UpdatedAt time.Time `sieve:"s:private,admin;ef:CreatedAt"`
}
```
## Example
```go
...
type Option struct {
Name string `json:"name"`
Value string `json:"value"`
}
type Object struct {
idx uint64
Name string `json:"name" sieve:"s:*"`
FullName string `json:"full_name" sieve:"s:private"`
CreatedAt uint64 `json:"created_at"`
UpdatedAt uint64 `json:"updated_at" sieve:"ef:CreatedAt"`
Options []Option `json:"options" sieve:"k:Name"`
}
...
func main() {
obj := Object{
100,
"One",
"Full",
100,
100,
[]Option{
Option{"1", "Cool"},
Option{"2", "Great"},
Option{"3", "Best"},
},
}
if b, err := json.Marshal(Sieve(&obj, "public")); err == nil {
fmt.Println(string(b))
// -> {"created_at":100,"name":"One","options":["1","2","3"]}
}
if b, err := json.Marshal(Sieve(&obj, "private")); err == nil {
fmt.Println(string(b))
// -> {"created_at":100,"full_name":"Full","name":"One","options":["1","2","3"]}
}
}
```
# Donation to development
`BTC: 1497z5VaY3AUEUYURS5b5fUTehVwv7wosX`
`DASH: XjBr7sqaCch4Lo1A7BctQz3HzRjybfpx2c`
`XRP: rEQwgdCr8Jma3GY2s55SLoZq2jmqmWUBDY`
`PayPal / Yandex Money: garin1221@yandex.ru`
## License
JUST is licensed under the [MIT](LICENSE).