javascript - 如何使用 GO 自动生成 JavaScript 代码
问题描述
我需要根据输入的规则集在 GO 中自动生成 JS 代码。例如,假设我在 GO 中有一个应用程序,它接收包含一组规则的 Json:
{
"enabled": true,
"rulesLimit": 3,
"Rules": [
{
"name": "Not Dave or Ted",
"enabled": true,
"id": 1,
"trigger": {
"operator": "AND",
"conditions": [
{
"operator": "NOT EQUAL",
"value": "Dave"
},
{
"operator": "NOT EQUAL",
"value": "Ted"
}
]
}
},
{
"name": "Only from home",
"enabled": true,
"id": 2,
"trigger": {
"conditions": [
{
"operator": "EQUAL",
"urlValue": "Home"
}
]
}
}
]
}
该应用程序需要自动生成一个包含请求规则的函数的 JS 代码:
function applyRules(){
if (person[name] === "Dave" || person[name] === "Ted") {
return
}
if (person[address] !== "Home") {
return
}
}
applyRules();
我目前正在研究什么是处理它的最佳方法。起初我考虑使用Go Template将模板与占位符一起使用,但是当我开始实现它时,复杂性有点高。有没有我可以研究的其他方法、工具或方法可以满足我的需要?谢谢
解决方案
推荐阅读
- javascript - 如何根据其他输入值显示和隐藏输入 - 没有 JQuery
- python - 爬入csv(python)
- c# - 使用 Automapper 基于 List c# 和 linq 中的 List 有效过滤
- android - Android Volley request 将 Recycler 视图文本作为参数发布时出错
- arrays - 如何在 React Native 中访问关键状态?
- android - 尝试 GoogleNetHTTPTransport 时出现“未找到 JKS”
- php - PHP致命错误:require():打开失败需要'/mnt/web112/c3/44/58344944/htdocs/WordPress_SecureMode_01/wp-includes/random_c
- angular-ngselect - ng-select angular 5 在悬停时更改选项列表中项目的背景颜色
- javascript - 为地址生成所有组合的有效方法 - Javascript
- c# - WebRequest.在 DMZ 服务器上创建异常