Closed TyVik closed 6 years ago
Or maybe more complicated logic should be used? Like parsing query params and encoding them to json.
Also this looks strange - Encode("Hello, World!")
. The result will be just []byte("Hello, World!")
.
I think more complicated behavior should be regulated by command line arguments.
JSON encoding is the most typical operation in REST services. I sure it should be here. And more: 1) .NET Core do it by default, i don't know how to disable that 🤣 2) I don't know how to do JSON encoding in Go in right way. Can u help me?
Atm I don't wanna add something more complicated like query params, arguments and so on. One request /api/test
, one JSON encoded answer with single string Hello, World!
. Do you disagree with me? For now we have 3 projects only, it's not a problem to change these structures.
I'm not familiar with java, but is it manual encoding?
return "[\"Hello, World!\"]";
By the way, json processing is additional task, which can may affect the main result. For example: http://artem.krylysov.com/blog/2015/09/29/benchmark-python-json-libraries/. There are 4 libraries for parsing json and results are very different.
I don't know how to do JSON encoding in Go in right way. Can u help me?
I mean, you should use an input that looks like json (map for example). Otherwise it doesn't make sense.
json.NewEncoder(w).Encode(map[string]string{"message": "Hello, World!"})
One more thing about json encoding: since encoding constant into json will always give the same result, isn't it possible that some smart enough compilers will do it only once at compile time?
I see. Okay, I'll remove JSON processing from all of projects. 👍
Done ☕️
https://github.com/binakot/Abstract-Rest-Service-Benchmark/blob/3608c5837d532a09e4d8a00010f0deb5c9b18c50/go-rest-service/main.go#L12
I think the test will be more accurate if you avoid encoding to json.