This is a creation in Article, where the information may have evolved or changed.
1 Anonymous declaration.
Tests: = []struct {
Key, Val string
OK bool
}{
{"Имя", "V", false},//key must be ASCII
{"Name", "Валю", true},//value May NON-ASCII
{"", "V", false},//key must be non-empty
{"K", "", true},//value may empty
}
This pattern is commonly used. Define a constant table, the format of the table can be used in this place.
2 Collective statement:
Type (
Echo is the top-level framework instance.
Echo struct {
Server engine. Server
Premiddleware []middlewarefunc
Middleware []middlewarefunc
Maxparam *int
Notfoundhandler Handlerfunc
Httperrorhandler Httperrorhandler
Binder Binder
Renderer renderer
Pool sync. Pool
debug bool
Router *router
Logger log. Logger
}
Route contains a handler and information for matching against requests.
Route struct {
Method string
Path string
Handler string
}
Httperror represents an error, occurred while handling a request.
Httperror struct {
Code int
Message string
}
**************
)
than a single type XXX struct province things up. The Golang is not verbose.
The similar things are:
Import, Var, and const statements. This reduces the noise signal in the middle of the program.
For example, this is the case with Python, Java. Write an import every time.
Import Email.parser
Import Email.message
Import http
Import IO
Import OS
Import re
Import socket
Import Collections
From Urllib.parse import Urlsplit
This seemingly small thing is actually very useful.