我有一个非常简单的服务器可以玩:
import * as http from 'http';
import * as Koa from "koa";
import { Request, Response, Context } from "koa";
import * as Router from "koa-router";
import * as bodyParser from "koa-bodyparser";
const HTTPPORT = 3000;
var app:Koa = new Koa();
var router:Router = new Router();
app.use(async (ctx:Context, next)=> {
console.log(ctx);
return await next();
});
router.get('/', function (ctx) {
ctx.body = "hello world";
console.log("success")
});
app
.use(bodyParser)
.use(router.routes())
.use(router.allowedMethods());
const httpServer = http.createServer(app.callback());
//listen on provided port
httpServer.listen(HTTPPORT, () …Run Code Online (Sandbox Code Playgroud) 我正在使用 Cloudformation 模板创建一个堆栈,包括 IoT 车队配置模板,并根据 文档,IoT 配置模板主体应该是字符串类型。
我有这样的物联网车队配置模板:
{
"Parameters": {
"SerialNumber": {
"Type": "String"
},
"AWS::IoT::Certificate::Id": {
"Type": "String"
}
},
"Resources": {
"certificate": {
"Properties": {
"CertificateId": {
"Ref": "AWS::IoT::Certificate::Id"
},
"Status": "Active"
},
"Type": "AWS::IoT::Certificate"
},
"policy": {
"Properties": {
"PolicyName": "mypolicy"
},
"Type": "AWS::IoT::Policy"
},
"thing": {
"OverrideSettings": {
"AttributePayload": "MERGE",
"ThingGroups": "REPLACE",
"ThingTypeName": "REPLACE"
},
"Properties": {
"AttributePayload": {
"SerialNumber": {
"Ref": "SerialNumber"
}
},
"ThingName": {
"Ref": "SerialNumber"
}
},
"Type": "AWS::IoT::Thing"
} …Run Code Online (Sandbox Code Playgroud) 除了这个之外,还有更好(更精简)的方式来表达我自己:
#[derive(Serialize, Deserialize, Debug, Default]
pub struct PagingObject {
#[serde(skip_serializing_if = "Option::is_none")]
offsetId: Option<String>, // offset expressed as element id (uuid)
#[serde(skip_serializing_if = "Option::is_none")]
offset: Option<i32>, // offset expressed as index (numeric)
#[serde(skip_serializing_if = "Option::is_none")]
total: Option<i32>, // total number of elements
#[serde(skip_serializing_if = "Option::is_none")]
totalPages: Option<i32>, // total number of pages based on limit
#[serde(skip_serializing_if = "Option::is_none")]
previous: Option<String>, // link to previous page
#[serde(skip_serializing_if = "Option::is_none")]
next: Option<String>, // link to next page
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<i32> …Run Code Online (Sandbox Code Playgroud) 我想在AWS lambda上构建适当的打字稿项目。
现在,我有以下定义:
export type HttpResponse = {
statusCode: number;
headers: {};
body: string;
}
export async function readCollection (event, context, callback): Promise<HttpResponse>{
console.log(event); // Contains incoming request data (e.g., query params, headers and more)
const data = [
{
id: "a7b5bf50-0b5b-11e9-bc65-6bfc39f23288",
name: "some thing",
uri: `/notifications/a7b5bf50-0b5b-11e9-bc65-6bfc39f23288`
}
]
const response = {
statusCode: 200,
headers: {
},
body: JSON.stringify({
status: "ok",
data: data
})
};
return response;
};
Run Code Online (Sandbox Code Playgroud)
但
除了使用自定义HttpResponse类型,我还想使用一个官方定义。
但是我要导入和返回哪种正式类型?
如何将字符串的值限制为 Rust 中的某个集合?
\n// string literal union type with\n// values of "admin", "owner", "user"\ntype Roles = "admin" | "owner" | "user";\n\n// use the type "Roles" for the "role" variable\nlet role: Roles;\n\n// assing a value other than "admin", "owner", "user"\nrole = "Hello World!"; // \xe2\x9d\x8c not allowed. Type \'"Hello World!"\' is not assignable to type \'Roles\'\n\n// assign a valid string value\nrole = "admin"; // \xe2\x9c\x85 allowed.\nRun Code Online (Sandbox Code Playgroud)\n锈的等价物是什么
\n如何删除iOS7中的状态栏?
我有一个iOS6的全屏应用程序没有状态栏,上iOS7显示半透明sytle新的状态栏.
rust ×2
typescript ×2
aws-lambda ×1
cordova ×1
ios7 ×1
iot ×1
javascript ×1
json ×1
koa ×1
koa-router ×1
node.js ×1
serde ×1
string ×1