Naming, layout and comments: descriptive full-word names, one item per line in wrapped calls and literals, and doc comments on exported names
Short and single-letter names in application code become full words (tests keep theirs). Wrapped calls, signatures and composite literals put one item per line, and one-line function bodies are expanded. Exported names and groups of constants get doc comments, and comments refer to the renamed identifiers.
This commit is contained in:
1 parent
043e307663
commit
465358609a
78 files changed
+2374
-1402
No files matched your search
@@ -37,28 +37,36 @@ type Envelope struct {
|
||||
// Envelope types. TypeEvent, TypeRequest and TypeAck are reserved: nothing
|
||||
// sends or handles them yet.
|
||||
const (
|
||||
// TypeWelcome is sent to a client when it connects, with its client ID.
|
||||
TypeWelcome = "welcome"
|
||||
TypePing = "ping"
|
||||
TypePong = "pong"
|
||||
TypeEcho = "echo"
|
||||
TypeEvent = "event"
|
||||
// TypePing asks the server for a TypePong.
|
||||
TypePing = "ping"
|
||||
// TypePong answers a TypePing, with the server's time.
|
||||
TypePong = "pong"
|
||||
// TypeEcho is sent back to the client with the same ID and payload.
|
||||
TypeEcho = "echo"
|
||||
// TypeEvent is reserved for events pushed to clients.
|
||||
TypeEvent = "event"
|
||||
// TypeRequest is reserved for requests from clients.
|
||||
TypeRequest = "request"
|
||||
TypeAck = "ack"
|
||||
TypeError = "error"
|
||||
// TypeAck is reserved for acknowledging a request.
|
||||
TypeAck = "ack"
|
||||
// TypeError reports an error, with the ID of the message it answers.
|
||||
TypeError = "error"
|
||||
)
|
||||
|
||||
// mustRaw returns v as raw JSON: v itself if it is already json.RawMessage,
|
||||
// nil if v is nil or can't be marshalled.
|
||||
func mustRaw(v any) json.RawMessage {
|
||||
if v == nil {
|
||||
// mustRaw returns value as raw JSON: value itself if it is already
|
||||
// json.RawMessage, nil if value is nil or can't be marshalled.
|
||||
func mustRaw(value any) json.RawMessage {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
if raw, ok := v.(json.RawMessage); ok {
|
||||
if raw, ok := value.(json.RawMessage); ok {
|
||||
return raw
|
||||
}
|
||||
b, err := json.Marshal(v)
|
||||
encoded, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return b
|
||||
return encoded
|
||||
}
|
||||
Reference in new issue
Block a user