In Go, interface names are typically chosen based on their intended purpose and clarity, rather than strict adherence to specific conventions.
For interfaces that define a single method, the naming scheme often follows the format:
[Method Name]er
For example, an interface defining a Read method would be named Reader. However, there may be exceptions where using a pure English word or phrase makes more sense, such as StringBuilder or ByteReader.
When defining interfaces with multiple methods, it's crucial to choose a name that accurately reflects their purpose, such as net.Conn, http.ResponseWriter, or io.ReadWriter.
Regarding receiver names, it's advised to use concise one or two-letter abbreviations that reflect the type. For example, using client would be a suitable name for a receiver of type Client.
It's important to note that using prefixes like I or suffixes like er is generally not considered idiomatic in Go when naming interfaces. These conventions are more commonly associated with other programming languages.
In your specific case, suggested interface names include:
For a single interface with both methods, consider naming it RoleHelper or RoleChecker.
As for ServerSession, the name Session would be sufficient, or even Sessioner if desired. Avoid using verbose names like ServerSessioner.
The above is the detailed content of How should I name interfaces in Go?. For more information, please follow other related articles on the PHP Chinese website!