编程语言独立模型验证 [英] Programming Language independent Model Validation

查看:82
本文介绍了编程语言独立模型验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您在基础架构中使用了几种不同的编程语言和框架来处理大量流量等。

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

示例堆栈:


  1. 事件驱动的API服务器(使用Scala,node.js,Ruby EM)

  2. 标准的完整堆栈webapp(例如Rails)

  3. (也许更多技术)

当使用不同的语言和框架时,我通常最终会复制大多数模型验证的原因是每个客户入口点都需要验证其输入。这当然是一种保持同步的痛苦。

When using different languages and frameworks I usually end up duplicating most of the model validations because every "customer entry point" needs to validate its input. This is of course a pain to keep in sync.

如果没有像CORBA这样的东西你会如何处理?

How would you handle this without something like CORBA?

推荐答案

您最好的选择是允许您以与语言无关的格式(如JSON)指定模型验证的框架。您最终可能会得到各种类型的验证架构,例如:

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.

然而,这可能听起来很像CORBA / SOAP / Thrift / ProtocolBuffers /等。在此刻。那是因为它们是为解决这些类型的问题而编写的,如果你自己编写,你最终会重新发明一些轮子。

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.

这篇关于编程语言独立模型验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆