Maintain a clean and logical code structure by properly organizing code according to its functionality and purpose: 1. Group related functionality into dedicated packages based on domain logic (e.g., `pkg/ssh` for SSH-related code)
Maintain a clean and logical code structure by properly organizing code according to its functionality and purpose:
pkg/ssh
for SSH-related code)Example of proper import organization:
// Good: Organized import section
import (
"context"
"crypto/tls"
"fmt"
"github.com/fatedier/frp/models/transport"
)
Example of improving complex parameter patterns with structured types:
// Before
func NewVhostMuxer(listener net.Listener, vhostFunc muxFunc, authFunc httpAuthFunc,
successFunc successFunc, rewriteFunc hostRewriteFunc, timeout time.Duration) {
// ...
}
// After
type MuxerOptions struct {
VhostFunc muxFunc
AuthFunc httpAuthFunc
SuccessFunc successFunc
RewriteFunc hostRewriteFunc
Timeout time.Duration
}
func NewVhostMuxer(listener net.Listener, options MuxerOptions) {
// ...
}
This organization improves code maintainability, makes navigation easier for developers, and establishes a consistent project structure that scales with codebase growth.
Enter the URL of a public GitHub repository