Development Guide#
Guide for contributing to lanup development.
Prerequisites#
- Go 1.22 or higher
- Git
- Make (optional, but recommended)
Getting Started#
Clone the Repository#
git clone https://github.com/raucheacho/lanup.git
cd lanupInstall Dependencies#
go mod downloadBuild#
# Build for current platform
make build
# Or use go directly
go build -o lanup .Run Tests#
# Run all tests
make test
# Or use go directly
go test ./...
# Run with coverage
make test-coverageProject Structure#
lanup/
├── cmd/ # Command implementations
│ ├── root.go # Root command
│ ├── init.go # Init command
│ ├── start.go # Start command
│ ├── expose.go # Expose command
│ ├── logs.go # Logs command
│ └── doctor.go # Doctor command
├── internal/ # Internal packages
│ ├── config/ # Configuration management
│ ├── net/ # Network detection
│ ├── env/ # Environment file management
│ ├── logger/ # Logging system
│ └── docker/ # Docker integration
├── pkg/ # Public packages
│ ├── errors/ # Error handling
│ └── utils/ # Utility functions
├── docs/ # Hugo documentation
├── main.go # Entry point
├── Makefile # Build scripts
└── README.md # Project READMEDevelopment Workflow#
1. Create a Feature Branch#
git checkout -b feature/my-feature2. Make Changes#
Follow Go best practices:
- Use
gofmtfor formatting - Add comments for exported functions
- Write tests for new features
- Keep functions small and focused
3. Run Tests#
make test4. Format Code#
make fmt5. Commit Changes#
git add .
git commit -m "Add my feature"6. Push and Create PR#
git push origin feature/my-featureThen create a Pull Request on GitHub.
Building#
Build for Current Platform#
make buildBuild for All Platforms#
make build-allThis creates binaries for:
- macOS (Intel and Apple Silicon)
- Linux (amd64)
- Windows (amd64)
Install Locally#
make installTesting#
Unit Tests#
# Run all tests
go test ./...
# Run specific package
go test ./internal/net/...
# Run with verbose output
go test -v ./...Integration Tests#
# Run integration tests
go test ./cmd/... -vCoverage#
# Generate coverage report
make test-coverage
# View coverage in browser
go tool cover -html=coverage.outCode Style#
Formatting#
Use gofmt for consistent formatting:
gofmt -w .Linting#
Use golangci-lint for linting:
golangci-lint runComments#
Add comments for exported functions:
// DetectLocalIP detects the local IP address of the machine.
// It returns the IP address, interface name, and interface type.
func DetectLocalIP() (*NetworkInfo, error) {
// Implementation
}Adding New Commands#
1. Create Command File#
// cmd/mycommand.go
package cmd
import (
"github.com/spf13/cobra"
)
func NewMyCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "mycommand",
Short: "Short description",
Long: "Long description",
RunE: func(cmd *cobra.Command, args []string) error {
// Implementation
return nil
},
}
return cmd
}
func init() {
RootCmd.AddCommand(NewMyCommand())
}2. Add Tests#
// cmd/mycommand_test.go
package cmd
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMyCommand(t *testing.T) {
// Test implementation
}3. Update Documentation#
Add documentation in docs/content/docs/commands.md.
Adding New Features#
1. Plan the Feature#
- Create an issue on GitHub
- Discuss the approach
- Get feedback from maintainers
2. Implement#
- Write code following project conventions
- Add tests
- Update documentation
3. Submit PR#
- Create a pull request
- Describe the changes
- Link to related issues
Release Process#
1. Update Version#
# Update version in main.go
version = "1.2.0"2. Create Tag#
git tag -a v1.2.0 -m "Release v1.2.0"
git push origin v1.2.03. Build Releases#
make build-all4. Create GitHub Release#
- Go to GitHub Releases
- Create new release
- Upload binaries
- Write release notes
Documentation#
Building Documentation#
cd docs
hugo serverVisit http://localhost:1313 to view the documentation.
Adding Documentation#
- Create new markdown file in
docs/content/docs/ - Add frontmatter with title and weight
- Write content in markdown
- Test locally with
hugo server
Contributing Guidelines#
Code of Conduct#
- Be respectful and inclusive
- Welcome newcomers
- Focus on constructive feedback
Pull Request Guidelines#
- One feature per PR
- Include tests
- Update documentation
- Follow code style
- Write clear commit messages
Commit Message Format#
type: subject
body
footerTypes:
feat: New featurefix: Bug fixdocs: Documentationtest: Testsrefactor: Code refactoringchore: Maintenance
Example:
feat: add watch mode for network changes
Implement watch mode that monitors network interfaces
and automatically updates environment files when the
IP address changes.
Closes #123Getting Help#
License#
MIT License - see LICENSE