GoPlantUML Documentation

repository·master·Indexed 24 days ago

https://github.com/jfeliu007/goplantuml

GoPlantUML is a tool that parses Go source code to automatically generate PlantUML diagrams. It allows developers to visualize package dependencies, struct compositions, and interface implementations. The tool provides a CLI to scan directories and customize output via flags for hiding fields, methods, or connections, and for controlling recursive traversal and output paths.

Tokens
2K
Snippets
4
Records
6
Agent score
35%

What's inside GoPlantUML

  1. Understand GoPlantUML relationship types

    master

    GoPlantUML identifies two primary types of relationships in Go code:

    1. Interface Implementation: When a struct implements all methods of an interface with matching signatures, an extends association (represented by <|-- in PlantUML) is created.
    2. Type Composition: When a struct contains another type as a field, a composition or aggregation relationship is created (represented by *-- or o-- in PlantUML).

    Example Logic:

    • MyStruct1 implements MyInterface $\rightarrow$ MyInterface <|-- MyStruct1 (extends).
    • MyStruct2 contains MyStruct1 as an embedded field $\rightarrow$ MyStruct1 *-- MyStruct2 (composition).
    • MyStruct3 contains MyStruct1 as a named field $\rightarrow$ MyStruct3 o-- MyStruct1 (aggregation/association).
  2. Install GoPlantUML

    master

    To use the goplantuml CLI tool, you need Go 1.17 or above. Install the parser library and the command-line tool using the following commands:

    go get github.com/jfeliu007/goplantuml/parser
    go install github.com/jfeliu007/goplantuml/cmd/goplantuml@latest

    This will install the goplantuml binary in your $GOPATH/bin folder.

  3. Use the goplantuml CLI

    master

    The goplantuml command generates PlantUML syntax from Go source files. You can output the result to standard output or to a specific file.

    Basic Syntax:

    goplantuml [-recursive] path/to/gofiles path/to/gofiles2 > diagram_file_name.puml

    Example: To generate a class diagram from a specific directory and save it to ClassDiagram.puml:

    goplantuml $GOPATH/src/github.com/jfeliu007/goplantuml/parser > ClassDiagram.puml
  4. Use the goplantuml CLI to generate PlantUML diagrams

    master

    goplantuml is a command-line tool that parses Go source code and generates PlantUML class diagrams. You can specify one or more directories to scan, control the depth of package nesting, and customize which elements (fields, methods, connections, etc.) are rendered in the output.

    Basic Usage

    To generate a diagram for a directory and print it to standard output:

    goplantuml ./path/to/your/go/code

    To save the output to a specific file:

    goplantuml -output diagram.puml ./path/to/your/go/code
    goplantuml <DIR>
  5. Reference goplantuml CLI flags

    master

    The following flags are available to customize the generated PlantUML diagram:

    FlagDescription
    -aggregate-private-membersShow aggregations for private members. Ignored if -show-aggregations is not used.
    -hide-connectionsHides all connections in the diagram
    -hide-fieldsHides fields
    -hide-methodsHides methods
    -ignore stringComma separated list of folders to ignore
    -notes stringComma separated list of notes to be added to the diagram
    -output stringOutput file path. If omitted, defaults to standard output
    -recursiveWalk all directories recursively
    -show-aggregationsRenders public aggregations even when -hide-connections is used
    -show-aliasesShows aliases even when -hide-connections is used
    -show-compositionsShows compositions even when -hide-connections is used
    -show-connection-labelsShows labels in the connections to identify connection types (e.g. extends, implements, aggregates, alias of)
    -show-implementationsShows implementations even when -hide-connections is used
    -show-options-as-noteShow a note in the diagram with the non-evident options ran with this CLI
    -title stringTitle of the generated diagram
    -hide-private-membersHides all private members (fields and methods)
    Usage of goplantuml:
      -aggregate-private-members
            Show aggregations for private members. Ignored if -show-aggregations is not used.
      -hide-connections
            hides all connections in the diagram
      -hide-fields
            hides fields
      -hide-methods
            hides methods
      -ignore string
            comma separated list of folders to ignore
      -notes string
            Comma separated list of notes to be added to the diagram
      -output string
            output file path. If omitted, then this will default to standard output
      -recursive
            walk all directories recursively
      -show-aggregations
            renders public aggregations even when -hide-connections is used (do not render by default)
      -show-aliases
            Shows aliases even when -hide-connections is used
      -show-compositions
            Shows compositions even when -hide-connections is used
      -show-connection-labels
            Shows labels in the connections to identify the connections types (e.g. extends, implements, aggregates, alias of
      -show-implementations
            Shows implementations even when -hide-connections is used
      -show-options-as-note
            Show a note in the diagram with the none evident options ran with this CLI
      -title string
            Title of the generated diagram
      -hide-private-members
            Hides all private members (fields and methods)
  6. goplantuml CLI flags reference

    master

    The following flags control how the Go source code is traversed and how the PlantUML diagram is rendered.

    Traversal Flags

    FlagDescription
    -recursiveWalk all directories recursively
    -ignore=<DIRLIST>Comma separated list of folders to ignore
    -max-depth=<INT>Maximum nesting depth for packages (0 = unlimited)

    Rendering Flags

    FlagDescription
    -title=<STRING>Title of the generated diagram
    -notes=<STRING>Comma separated list of notes to be added to the diagram
    -output=<PATH>Output file path (defaults to stdout if omitted)
    -show-options-as-noteShow a note in the diagram with the non-evident options used with this CLI
    -show-connection-labelsShows labels in the connections to identify connection types (e.g. extends, implements, aggregates, alias of)
    -hide-fieldsHides fields
    -hide-methodsHides methods
    -hide-connectionsHides all connections in the diagram
    -show-aggregationsRenders public aggregations even when -hide-connections is used
    -show-compositionsShows compositions even when -hide-connections is used
    -show-implementationsShows implementations even when -hide-connections is used
    -show-aliasesShows aliases even when -hide-connections is used
    -aggregate-private-membersShow aggregations for private members (requires -show-aggregations)
    -hide-private-membersHide private fields and methods