Contributing Code Conventions - osama1998H/Moca GitHub Wiki

Code Conventions

Package structure, naming, error handling, and PR process.

Package Structure

  • pkg/ -- Public packages (importable by apps)
  • internal/ -- Private packages (framework internals only)
  • cmd/ -- Binary entry points (thin main.go files)

Naming

  • Packages: lowercase, single word (meta, document, orm)
  • Files: snake_case (query_builder.go, meta_type.go)
  • Types: PascalCase (MetaType, DynamicDoc)
  • Functions: PascalCase for exported, camelCase for internal
  • Constants: PascalCase (FieldTypeData, EventBeforeSave)

Error Handling

  • Return errors, don't panic
  • Wrap errors with context: fmt.Errorf("failed to load MetaType %s: %w", name, err)
  • Use sentinel errors for expected conditions

Testing

  • Unit tests co-located with source files
  • Integration tests use //go:build integration tag
  • Test file naming: *_test.go

Linting

golangci-lint v2 with: govet, errcheck, staticcheck, unused.

PR Process

  • Branch from main
  • Keep PRs focused (one feature/fix per PR)
  • Tests must pass in CI
  • Run make lint before pushing

Related