Top Related Projects
Calculate cyclomatic complexities of functions in Go source code.
errcheck checks that you checked errors.
Staticcheck - The advanced Go linter
Fast linters runner for Go
Go security checker
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Quick Overview
gocity is a tool that generates a city-like visualization of a Go project's source code. It provides a graphical representation of the project's structure, highlighting the relationships between packages and files.
Pros
- Visual Representation: gocity offers a unique way to visualize the structure of a Go project, making it easier to understand the codebase.
- Dependency Visualization: The tool highlights the dependencies between packages and files, providing valuable insights into the project's architecture.
- Customizable Output: gocity supports various output formats, including HTML, SVG, and PNG, allowing users to choose the most suitable format for their needs.
- Easy Integration: The tool can be easily integrated into a Go project's build process, making it a valuable addition to the development workflow.
Cons
- Limited Functionality: While gocity provides a visual representation of the project's structure, it does not offer advanced analysis or refactoring capabilities.
- Dependency on Graphviz: The tool relies on the Graphviz library for rendering the visualization, which may require additional setup and configuration.
- Potential Performance Issues: Generating the visualization for large projects may be resource-intensive and slow, especially on older or less powerful hardware.
- Lack of Interactive Features: The current version of gocity does not provide interactive features, such as zooming or panning, which could enhance the user experience.
Code Examples
Not applicable, as gocity is a command-line tool and not a code library.
Getting Started
To use gocity, follow these steps:
- Install the tool using the Go package manager:
go get github.com/rodrigo-brito/gocity
- Navigate to your Go project's directory and run the gocity command:
cd /path/to/your/go/project
gocity
This will generate a visualization of your project's structure in the current directory. By default, the output will be saved as an HTML file named gocity.html
.
- To customize the output format, use the
-o
flag followed by the desired file extension:
gocity -o gocity.svg
This will generate the visualization in SVG format.
- If you want to include the visualization in your project's documentation, you can use the generated file in your Markdown or HTML files:
![Go Project Visualization](gocity.svg)
- To integrate gocity into your project's build process, you can add a step to your CI/CD pipeline or a Makefile target:
.PHONY: gocity
gocity:
gocity -o gocity.svg
This will generate the visualization every time you run make gocity
.
Competitor Comparisons
Calculate cyclomatic complexities of functions in Go source code.
Pros of gocyclo
- Lightweight and focused solely on cyclomatic complexity analysis
- Provides a simple command-line interface for quick analysis
- Can be easily integrated into CI/CD pipelines for code quality checks
Cons of gocyclo
- Lacks visual representation of code complexity
- Does not offer a web-based interface for exploring results
- Limited to cyclomatic complexity analysis, without additional metrics
Code Comparison
gocyclo:
func Analyze(filename string, src interface{}) ([]Stat, error) {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, filename, src, parser.ParseComments)
if err != nil {
return nil, err
}
// ... (analysis logic)
}
gocity:
func (p *Project) ProcessFile(filename string) error {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, filename, nil, 0)
if err != nil {
return err
}
// ... (processing logic)
}
Both projects use the go/parser
package to parse Go source files, but gocity focuses on creating a visual representation of the codebase structure, while gocyclo specifically calculates cyclomatic complexity. gocity offers a more comprehensive analysis of the project structure, including package relationships and file sizes, presented in an interactive 3D visualization. gocyclo, on the other hand, provides a straightforward complexity score for each function, making it easier to identify specific areas of high complexity in the codebase.
errcheck checks that you checked errors.
Pros of errcheck
- Focused on error handling analysis, providing specific and targeted feedback
- Lightweight and fast, suitable for integration into CI/CD pipelines
- Supports custom error types and can be configured to ignore certain errors
Cons of errcheck
- Limited to error checking, lacking broader code visualization features
- May produce false positives in some cases, requiring manual review
- Less intuitive for non-technical stakeholders compared to visual representations
Code Comparison
errcheck:
if err := doSomething(); err != nil {
return err
}
gocity:
// No direct code comparison available as gocity focuses on visualization
// rather than error checking
Key Differences
- Purpose: errcheck focuses on error handling analysis, while gocity provides 3D visualization of Go code structure
- Output: errcheck generates text-based reports, whereas gocity creates interactive 3D city-like visualizations
- Use case: errcheck is primarily used for code quality and error handling improvement, while gocity is more suited for code exploration and architecture understanding
Conclusion
Both tools serve different purposes in the Go ecosystem. errcheck is a specialized tool for improving error handling practices, while gocity offers a unique approach to visualizing code structure. The choice between them depends on the specific needs of the project and team preferences.
Staticcheck - The advanced Go linter
Pros of go-tools
- Comprehensive suite of Go analysis tools and linters
- Actively maintained with frequent updates and bug fixes
- Widely used in the Go community, integrated with many IDEs and CI pipelines
Cons of go-tools
- More complex to set up and use compared to gocity's single-purpose visualization
- Requires more in-depth knowledge of Go and static analysis concepts
- May be overwhelming for beginners or those seeking quick project insights
Code comparison
gocity:
func (c *City) AddBuilding(b Building) {
c.Buildings = append(c.Buildings, b)
}
go-tools (example from staticcheck):
func (pass *Pass) Reportf(pos token.Pos, format string, args ...interface{}) {
pass.report(Diagnostic{Pos: pos, Message: fmt.Sprintf(format, args...)})
}
Summary
gocity is a focused tool for visualizing Go project structures, while go-tools is a comprehensive suite of analysis tools. gocity offers a unique 3D city metaphor for codebase visualization, making it intuitive for quick project overviews. go-tools, on the other hand, provides in-depth analysis and linting capabilities, making it more suitable for thorough code quality checks and enforcement of best practices. The choice between them depends on whether you need a quick visual overview (gocity) or detailed code analysis (go-tools).
Fast linters runner for Go
Pros of golangci-lint
- Comprehensive linting tool with support for multiple linters
- Highly configurable with options to enable/disable specific linters
- Faster execution due to parallel processing of linters
Cons of golangci-lint
- More complex setup and configuration compared to gocity
- Primarily focused on code quality and not visualization
- May produce overwhelming output for large codebases
Code comparison
gocity:
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
golangci-lint:
linters:
enable:
- gofmt
- golint
- govet
run:
deadline: 5m
gocity is a visualization tool for Go source code, presenting the codebase as a 3D city. It focuses on providing a unique perspective on code structure and complexity.
golangci-lint is a fast, extensible linter for Go. It integrates multiple linters and provides a unified interface for code analysis and quality checks.
While gocity offers a novel approach to code visualization, golangci-lint excels in identifying potential issues and enforcing coding standards. gocity may be more suitable for high-level code structure analysis, while golangci-lint is essential for maintaining code quality in Go projects.
Go security checker
Pros of gosec
- Focused on security analysis and vulnerability detection in Go code
- Integrates with CI/CD pipelines for automated security checks
- Provides detailed security reports with severity levels and recommendations
Cons of gosec
- Limited visualization capabilities compared to gocity's 3D representation
- Primarily command-line based, lacking a rich graphical interface
- Narrower scope, focusing solely on security aspects rather than overall code structure
Code comparison
gosec example:
package main
import "fmt"
func main() {
var password = "hardcoded_password" // gosec will flag this as a security issue
fmt.Println("Password:", password)
}
gocity doesn't have a direct code comparison, as it focuses on visualizing code structure rather than analyzing security. It generates 3D representations of Go projects based on their package structure and complexity.
Summary
gosec is a specialized tool for Go security analysis, offering robust vulnerability detection and integration with development workflows. gocity, on the other hand, provides a unique 3D visualization of Go projects, helping developers understand code structure and complexity. While gosec excels in security-focused analysis, gocity offers a more holistic view of code architecture through its innovative visual representation.
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Pros of goreporter
- Provides a comprehensive code quality report, including multiple metrics and analyses
- Offers a web-based interface for viewing reports
- Supports customizable rule sets and configurations
Cons of goreporter
- Less visually appealing output compared to gocity's 3D visualization
- May have a steeper learning curve due to its more complex feature set
- Requires more setup and configuration to get started
Code comparison
goreporter:
func (r *Reporter) RunReporters() {
for _, reporter := range r.Reporters {
reporter.Process(r.ProjectPath, r.ExceptPackages)
}
}
gocity:
func (c *City) Generate() error {
c.root = c.createBlock(c.pkgName, 0, 0, 0)
return c.processDir(c.root, c.pkgPath)
}
Both projects use Go and focus on code analysis, but goreporter emphasizes generating comprehensive reports, while gocity creates a 3D visualization of code structure. goreporter's code snippet shows its modular approach to running different reporters, while gocity's code demonstrates its focus on generating a visual representation of the codebase.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Available here: https://go-city.github.io
Research Paper: 26th International Conference on Software Analysis, Evolution and Reengineering (SANER)
PDF Version: ASERG Page
GoCity is an implementation of the Code City metaphor for visualizing source code. GoCity represents a Go program as a city, as follows:
- Folders are districts
- Files are buildings
- Structs are represented as buildings on the top of their files.
Structures Characteristics
- The Number of Lines of Source Code (LOC) represents the build color (high values makes the building dark)
- The Number of Variables (NOV) correlates to the building's base size.
- The Number of methods (NOM) correlates to the building height.
Installation
go install github.com/rodrigo-brito/gocity@latest
- Or just head to the releases page and download the latest version for you platform.
Usage:
- Online: https://go-city.github.io
- Commands
gocity server
- Start servergocity open <GITHUB_IMPORT>
- Open a specific Github project from githubgocity open ./my-project
- Open a local directory
UI / Front-end
The UI is built with React and uses babylon.js to plot 3D structures. The front-end source code is available in the front-end branch.
Related Works
This tool makes part of a scientific research developed at Federal University of Minas Gerais (UFMG)
Student: Rodrigo Brito
Advisor: Marco Tulio Valente
Top Related Projects
Calculate cyclomatic complexities of functions in Go source code.
errcheck checks that you checked errors.
Staticcheck - The advanced Go linter
Fast linters runner for Go
Go security checker
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot