Asp.net core与golang web简单对比测试

发表于:2016-7-19 11:26

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:无名书生    来源:51Testing软件测试网采编

  最近因为工作需要接触了go语言,又恰好asp.net core发布RC2,就想简单做个对比测试
  下面是测试环境:
  CPU:E3-1230 v2
  内存:16G
  电脑有点不给力
  操作系统:Centos7.0(虚拟机单核2G内存)
  asp.net core rc2
  golang v1.7beta1
  下面是各自的代码:
package main
import (
"fmt"
"net/http"
)
func main() {
fmt.Println("This is webserver base!")
//第一个参数为客户端发起http请求时的接口名,第二个参数是一个func,负责处理这个请求。
http.HandleFunc("/login", loginTask)
//服务器要监听的主机地址和端口号
err := http.ListenAndServe("192.168.199.236:8081", nil)
if err != nil {
fmt.Println("ListenAndServe error: ", err.Error())
}
}
func loginTask(w http.ResponseWriter, req *http.Request) {
//获取客户端通过GET/POST方式传递的参数
req.ParseForm()
fmt.Fprint(w, "Hello World!")
}
  C#
public class MyHandlerMiddleware
{
// Must have constructor with this signature, otherwise exception at run time
public MyHandlerMiddleware(RequestDelegate next)
{
// This is an HTTP Handler, so no need to store next
}
public async Task Invoke(HttpContext context)
{
await context.Response.WriteAsync("Hello World!");
}
// ...
}
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
app.MapWhen(context => { return context.Request.Path.ToString().EndsWith("jjj.go"); }, ap =>
{
ap.UseMiddleware<MyHandlerMiddleware>();
});
}
}
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号