现在我在我的项目中有大量的常量字符串和枚举.从一开始我就使用以下方法(伪php示例代码):
class Constants implements iStatuses, iEmailTypes {
}
interface iStatuses {
const STATUS_NEW = 1;
cosnt STATUS_UPDATED =2;
...
}
interface iEmailTypes {
const EMAIL_TYPE_NEW = 1;
const EMAIL_TYPE_UPDATED =2;
...
}
Run Code Online (Sandbox Code Playgroud)
这种方法允许我在代码中的任何地方以下列方式获取常量,因为我在index.php中包含了"常量"类.
$this->sendEmailByType(CONSTANTS::EMAIL_TYPE_NEW);
Run Code Online (Sandbox Code Playgroud)
但是,我完全可以看到这种方法的缺点:
由于我的项目现在变得越来越大,我们需要将它与另一个项目的代码合并,因此需要更改类Constants方法.但是,我根据该类获得了太多依赖项.我应该如何重新构造该方法,以免破坏使用常量类值的旧代码.
请分享您的想法和建议,如何改进我的"常数"方法,或确认它是不错的,我应该支持它.
先感谢您.
我的 Azure 函数带有 CosmosDB 触发器,它使用租用收集机制侦听集合。此功能托管在消费计划上。
我注意到,在重负载下,我倾向于以越来越大的延迟更新我的函数。阅读文档后,我没有找到如何改进设置扩展的方法。有办法吗?
我有一个简单的服务器有这个方法
app.post('/', function (req, res) {
res.sendfile(path.resolve(req.files.image.path));
});
Run Code Online (Sandbox Code Playgroud)
如何在客户端的 Image 对象中获取数据?这是我的 ajax.success 方法,至少我尝试过......
success: function (res) {
console.log(res);
var canvas = document.getElementById("mainCanvas");
var ctx = canvas.getContext("2d");
var img = new Image();
img.onload = function () {
ctx.drawImage(img,0,0);
}
img.src=res
}
Run Code Online (Sandbox Code Playgroud)
真的已经寻找答案两天了......尝试了很多方法,但没有奏效。我什至不确定我从服务器收到的是什么 - 是字节数组吗?
解决方案: 所以,我发现post请求不需要发回文件,Image.src将自己的get请求发送到服务器
app.post('/', function (req, res) {
res.send(path.basename(req.files.image.path));
});
/* serves all the static files */
app.get(/^(.+)$/, function(req, res){
console.log('static file request : ' + req.params);
res.sendfile( __dirname + req.params[0]);
});
Run Code Online (Sandbox Code Playgroud)
客户:
success: function (res) {
var …Run Code Online (Sandbox Code Playgroud)