Читать книгу Practical Go - Amit Saha - Страница 57
Listing 2.5: Custom error values
Оглавление// chap2/sub-cmd-arch/cmd/errors.gopackage cmd import "errors" var ErrNoServerSpecified = errors.New("You have to specify the remote server.")
In the cmd
subdirectory, save Listing 2.5 as errors.go
. You will end up with a source tree structure that looks like the following:
. |____cmd | |____grpcCmd.go | |____httpCmd.go | |____errors.go |____go.mod |____main.go
From the root directory of the module, build the application:
$ go build -o application
Try running the build
application with different arguments, starting with -help
or -h
:
$ ./application --help Usage: mync [http|grpc] -h http: A HTTP client. http: <options> server Options: -verb string HTTP method (default "GET") grpc: A gRPC client. grpc: <options> server Options: -body string Body of request -method string Method to call
Before we move on, let's make sure that we have unit tests for the functionality implemented by the main
and cmd
packages.