go-service-conventionslisted
Install: claude install-skill saturngfish/go-claude-skill
# Go service conventions
Apply these rules whenever you write, edit, review or scaffold Go code for a service.
## 1. Code formatting
### Rules
1. **Blank line before `return`** when the `return` follows one or more statements inside the same block.
2. **Guard return** (an early exit that is the only line inside an `if`) is written **without** a blank line. The body of the condition already isolates it.
3. **Logical blocks** inside a function (declaration → computation → return) are separated by blank lines.
4. One-line wrapper functions (`func X() T { return ... }`) are fine and stay on one line.
### Good
```go
func EncodeBattle(id int64) string { return Encode(Battle, id) }
func EncodeItem(id int64) string { return Encode(Item, id) }
if resp.IsError() {
if resp.Error != nil && resp.Error.Message == msgNotEnoughFunds {
return true, nil
}
return false, types.NewServiceError(types.ErrorServerError, "WITHDRAW_FAILED")
}
func isUsdStablecoin(symbol string) bool {
_, ok := usdStablecoins[strings.ToUpper(strings.TrimSpace(symbol))]
return ok
}
func ConvertUsdToActiveCrypto(priceUsd float64, targetSymbol string) (float64, error) {
// ...other code
result, err := prices.Default.Convert(ctx, decimal.NewFromFloat(priceUsd), "USD", targetSymbol)
if err != nil {
return 0, err
}
f, _ := result.Float64()
return f, nil
}
func Roll(serverSeed, clientSeed string, nonce int64) uint64 {
h := hmac.New(sha256.New, []byte(serverSeed))
h.Write([]byte(clientSeed))