Go Code Style
Formatting and Imports
All Go code must be formatted withgofmt and organized with goimports.
Format your code:
Linting with golangci-lint
Meshery usesgolangci-lint for comprehensive linting. All Go code must pass linting checks before being merged.
Run linting:
.github/.golangci.yml
Error Handling
Meshery uses MeshKit’s error utilities for consistent error handling across the codebase. Use MeshKit errors:./server/helpers and ensures consistency.
Package Structure
- Keep packages focused: Each package should have a single, well-defined responsibility
- Avoid cyclic dependencies: Structure packages to prevent circular imports
- Use internal packages: Use
internal/for packages that should not be imported externally - Follow Go project layout: Follow the Standard Go Project Layout
Testing
- File naming: Place tests in
*_test.gofiles alongside the code they test - Test naming: Use descriptive test names:
TestFunctionName_Scenario_ExpectedResult - Table-driven tests: Use table-driven tests for testing multiple scenarios
- Coverage: Aim for ≥70% coverage on business logic
Dependencies
- Go modules: Manage dependencies with Go modules
- Tidy regularly: Run
go mod tidyto clean up unused dependencies - Vendor directory: Not used in Meshery; rely on module cache
Naming Conventions
- Exported identifiers: Use PascalCase (e.g.,
GetKubeConfig) - Unexported identifiers: Use camelCase (e.g.,
parseConfig) - Acronyms: Keep acronyms uppercase (e.g.,
HTTPClient,APIURL) - Interfaces: Name interfaces with
-ersuffix when appropriate (e.g.,Reader,Writer)
JavaScript/React Code Style
ESLint Configuration
Meshery UI uses ESLint with Prettier for code formatting and linting. Run linting:ui/.eslintrc.js
Component Style
Use functional components with hooks:Styling
Prefer Sistent design system:State Management
Use Redux Toolkit for global state:API Integration
GraphQL via Relay:Schema-Driven Development
Use JSON schemas to define component props and validation:File Naming
- Components: PascalCase (e.g.,
WorkspaceFilter.js) - Utilities: camelCase (e.g.,
formatDate.js) - Hooks: camelCase with
useprefix (e.g.,useWorkspace.js) - Constants: UPPER_SNAKE_CASE (e.g.,
API_ENDPOINTS.js)
Import Organization
Organize imports in this order:Commit Messages
Format
Follow this format for all commit messages:Component Prefixes
[UI]– User interface changes[Server]– Backend changes[CLI]– mesheryctl changes[Docs]– Documentation updates[CI]– CI/CD workflow changes[Models]– MeshModel changes[Adapters]– Adapter-related changes
Examples
Good commit messages:Developer Certificate of Origin (DCO)
All commits must be signed with DCO:-s flag adds this line automatically:
Linking Issues
Reference issues in commit messages:Fixes #123Closes #123Resolves #123
Relates to #123References #123See #123
Git Workflow
Branching
Create feature branches frommaster:
feature/– New featuresfix/– Bug fixesdocs/– Documentation updatesrefactor/– Code refactoringtest/– Test additions or improvements
Keeping Your Branch Updated
Rebase on master regularly:Squashing Commits
Squash commits before merging to maintain a clean history:Documentation Style
Markdown
- Use ATX-style headers (
#syntax) - Use fenced code blocks with language identifiers
- Use tables for structured data
- Use lists for sequential or grouped items
| Component | Port | Description |
|---|---|---|
| Server | 9081 | REST/GraphQL API |
| UI | 3000 | Web interface |
Code Review Checklist
Before submitting a PR, ensure:- Code follows the style guide
- All tests pass locally
-
make golangcipasses (for Go code) -
make ui-lintpasses (for UI code) - Commit messages follow the format
- All commits are signed with DCO
- Documentation is updated (if applicable)
- No sensitive data (keys, tokens, passwords) is committed
- Breaking changes are documented
- New features have tests
Next Steps
Server Development
Learn about Go backend development
UI Development
Learn about React frontend development
CLI Development
Learn about mesheryctl development
Testing Guide
Learn how to test your changes