Programming Language independent Model Validation

前端 未结 4 499
隐瞒了意图╮
隐瞒了意图╮ 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 19:01

    Your best bet would be a framework that allows you to specify model validation in a language agnostic format, like JSON. You might end up with a validation schema of sorts, say:

    {
      "name": [
        {
          "validate": "length",
          "minLength": 6,
          "maxLength": 10
        },
        ...
      ],
      ...
    }
    

    You would then have language-specific validators that could parse this format. The validators only need to be written once, and then you maintain a single schema for each model.

    However, this is probably sounding a lot like CORBA/SOAP/Thrift/ProtocolBuffers/etc. at this point. That's because they were written to solve these types of problems, and you'll end up reinventing a few wheels if you write it yourself.

提交回复
热议问题