Coder Social home page Coder Social logo

itrabbit / sieve Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 55 KB

GoLang Package for filtering fields models during serialization

License: MIT License

Go 100.00%
golang jms-serializer scopes serialization json filtering models entities exclude xml

sieve's Introduction

Build Status CodeCov GoDoc

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:

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

...

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: [email protected]

License

JUST is licensed under the MIT.

sieve's People

Contributors

legion-zver avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

shakahl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.