Go use error properly
This blog investigates the error types in golang and summerizes a best practice for using errors.
');--md-admonition-icon--abstract:url('data:image/svg+xml;charset=utf-8,');--md-admonition-icon--info:url('data:image/svg+xml;charset=utf-8,');--md-admonition-icon--tip:url('data:image/svg+xml;charset=utf-8,');--md-admonition-icon--success:url('data:image/svg+xml;charset=utf-8,');--md-admonition-icon--question:url('data:image/svg+xml;charset=utf-8,');--md-admonition-icon--warning:url('data:image/svg+xml;charset=utf-8,');--md-admonition-icon--failure:url('data:image/svg+xml;charset=utf-8,');--md-admonition-icon--danger:url('data:image/svg+xml;charset=utf-8,');--md-admonition-icon--bug:url('data:image/svg+xml;charset=utf-8,');--md-admonition-icon--example:url('data:image/svg+xml;charset=utf-8,');--md-admonition-icon--quote:url('data:image/svg+xml;charset=utf-8,');}
This blog investigates the error types in golang and summerizes a best practice for using errors.
This page is next to the client side details, Request Sending Precedures in GRPC Client Side. There are more details in it, which means this page will much more brief than previous one. Still, I focus on the core logic, ignoring like interceptors.
In cpp, there are concepts of reference
, value
, right value
and left value
. The go is very similar with some idolisms of C++, for example we cannot copy the iostream
in cpp
, as the same io
in go always passed by reference with the help of interface
.
However, go doesn’t have reference
acurrately, as it only has concepts about value
and pointer
. The reference in title should be called pointer
also.
C++ has a dilicated way to control what happened when copying and moving, but golang doesn’t have such concepts, which means the complexities are hidden in the compiler and runtime.
Let’s focus on the copy behavior of basic types in golang, we can see that when copying, map
, chan
and context
are treated as reference, the origin one and copied one share the same one. It’s worthy to know why some types are copied by reference instead of value.
In go, there are some cases when we need to check functions in some cases:
However, function
type in Go is not addressable and not comparable.
It’s common to run and wish to get results. As the command is executed in a forked child process, how results are passed back? This blog investigates how output is passed to parent process in command.Output
.