我已经这样设置了我的架构:
/products/:id/100x100/image.jpeg 的 GET 请求正在发送到 CloudFront。
如果已缓存,CloudFront 会将 100x100 尺寸的 image.jpeg 发送回客户端,否则它将调用 Origin,然后 Origin 将调用 Lambda 函数来调整图像大小。然后,通过 Lambda 函数调整大小的图像将被放入 S3 存储桶中并作为响应发回。
我已删除 ViewerRequest Lambda 函数。
这是我的 NodeJS 代码:
const AWS = require('aws-sdk');
const S3 = new AWS.S3({
signatureVersion: 'v4',
});
const Sharp = require('sharp');
const BUCKET = 'xBucket';
exports.handler = (event, context, callback) => {
let response = event.Records[0].cf.response;
//check if image is not present
if (response.status == 404) {
let request = event.Records[0].cf.request;
let path = request.uri;
let key …Run Code Online (Sandbox Code Playgroud) 我的 Rubocop 进攻告诉我我需要“使用条件的返回值进行变量赋值和比较”
当我尝试修复它时,它让我又一次冒犯了我的“方法线太长”。
我试过重构为另一种方法,但我的代码坏了。
如何缩短或重构此代码?
HSH = { 'a' => 'z', 'b' => 'y', 'c' => 'x', 'd' => 'w', 'e' => 'v', \
'f' => 'u', 'g' => 't', 'h' => 's', \
'i' => 'r', 'j' => 'q', 'k' => 'p', 'l' => 'o', 'm' => 'n' }.freeze
def encoder(str)
encoded_string = ''
str.chars.each do |char|
encoded_string = if HSH.key?(char) then encoded_string += HSH[char]
elsif HSH.invert.key?(char) then encoded_string += HSH.invert[char]
else encoded_string += char
end
end
encoded_string …Run Code Online (Sandbox Code Playgroud) 我目前正在阅读《Go 编程语言》一书,其中描述了字符串或子字符串的副本具有相似的内存地址。
s := "hello"
c := s
fmt.Println(&s, &c) // prints 0xc000010230 0xc000010240
Run Code Online (Sandbox Code Playgroud)
我的问题是,既然是精确的副本,就不应该&c相同吗?&sc
RAM
Address | Value
&s 0xc000010230 | "hello" <----- s
&c 0xc000010240 | "hello" <----- c
Run Code Online (Sandbox Code Playgroud) 我已经尝试了关于 stackoverflow 的所有答案,但仍然遇到相同的错误。
我尝试删除 node_modules、package-lock.json 和 npm install。但仍然得到同样的错误。
下面是我的 package.json
{
"name": "stadmin",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"serve": "ng serve",
"servehmr": "ng serve --hmr",
"start": "ng serve --port 8081",
"devstart": "ng serve --host 0.0.0.0 --port 3031 --disable-host-check",
"devstarthmr": "ng serve --hmr --configuration=hmr --host 0.0.0.0",
"build": "ng build",
"build_prod": "ng build --prod",
"build_dev": "ng build --configuration=dev",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"generate": "ng generate @vicoders/generator:angular_component",
"servelocal": "ng serve --port 4500 --configuration=local"
},
"private": …Run Code Online (Sandbox Code Playgroud)