diff --git a/api/Dockerfile b/api/Dockerfile index 7139fb5..656736e 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.11.2 +FROM golang:1.14.3 WORKDIR /go/src/app COPY . . diff --git a/api/main.go b/api/main.go index f6d93e1..b8e3d0e 100644 --- a/api/main.go +++ b/api/main.go @@ -17,19 +17,18 @@ type Response struct { } func main() { - http.HandleFunc("/data", func(w http.ResponseWriter, r *http.Request) { - rsp := Response{ - Id: "id_" + strconv.Itoa(rand.Int()), - Name: "name_" + strconv.Itoa(rand.Int()), - Time: time.Now().Unix(), - } - - js, err := json.Marshal(rsp) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + rsp := Response{ + Id: "id_" + strconv.Itoa(rand.Int()), + Name: "name_" + strconv.Itoa(rand.Int()), + Time: time.Now().Unix(), + } + js, err := json.Marshal(rsp) + if err != nil { + panic(err) + return + } + http.HandleFunc("/data", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") if _, err := w.Write(js); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/go/Dockerfile b/go/Dockerfile index ab069be..81d8510 100644 --- a/go/Dockerfile +++ b/go/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.11.2 +FROM golang:1.14.3 WORKDIR /go/src/app COPY . . diff --git a/netcore/Dockerfile b/netcore/Dockerfile index 3c08ab0..f0cf255 100644 --- a/netcore/Dockerfile +++ b/netcore/Dockerfile @@ -1,4 +1,4 @@ -FROM microsoft/dotnet:2.2-sdk +FROM mcr.microsoft.com/dotnet/core/sdk:3.1 WORKDIR /dotnetapp diff --git a/netcore/Program.cs b/netcore/Program.cs index edb55bc..dcc1f95 100644 --- a/netcore/Program.cs +++ b/netcore/Program.cs @@ -1,17 +1,11 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; +using Utf8Json; class Program { @@ -37,7 +31,7 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) { } } -class Response +public struct Response { public string Id { get; set; } public string Name { get; set; } @@ -60,22 +54,16 @@ private static void HandleTest(IApplicationBuilder app) { app.Run(async ctx => { - using (var rsp = await _http.GetAsync("/data")) - { - var str = await rsp.Content.ReadAsStringAsync(); + await using var rsp = await _http.GetStreamAsync("/data"); - // deserialize - var obj = JsonConvert.DeserializeObject(str); + // deserialize + var obj = await JsonSerializer.DeserializeAsync(rsp); - // serialize - var json = JsonConvert.SerializeObject(obj); - - ctx.Response.ContentType = "application/json"; - await ctx.Response.WriteAsync(json); - } + // serialize + ctx.Response.ContentType = "application/json"; + await JsonSerializer.SerializeAsync(ctx.Response.Body, obj); }); } - public void Configure(IApplicationBuilder app) { app.Map("/test", HandleTest); diff --git a/netcore/netcore.csproj b/netcore/netcore.csproj index f95ae55..d060f8b 100644 --- a/netcore/netcore.csproj +++ b/netcore/netcore.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp3.1 @@ -9,12 +9,11 @@ - - + - +