Programming Language independent Model Validation

前端 未结 4 500
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 18:05

Let\'s say you use several different programming languages and frameworks in your infrastructure to handle large amounts of traffic etc.

Example Stack:

4条回答
  •  再見小時候
    2021-01-12 18:52

    I would go on a "dictionary" of Regular Expressions. Regular Expressions are supported by all the languages you counted - and - translating their string representation from one language to another can be done by a passing the expressions themselves through regular expressions...

    To my observation - it's a lot less work then composing a parse and execute mechanism for each language...

    Like advised before - you can save this "dictionary" of Reg-Exps in an agnostic format, such as JSON. This narrows down the duplicated work to -

    • one source file of validation expressions that you maintain
    • per programming language:
      • converter from the main file to the format of the target language
      • thin mechanism of
        1. reading the JSON,
        2. selecting from it the configured checks
        3. executing them
      • edge cases (if any)

    Have fun :)

提交回复
热议问题