### Install GoPlantUML
Source: https://github.com/jfeliu007/goplantuml/blob/master/README.md
Installs the GoPlantUML parser and command-line tool. Ensure you have Go 1.17 or above installed.
```bash
go get github.com/jfeliu007/goplantuml/parser
go install github.com/jfeliu007/goplantuml/cmd/goplantuml@latest
```
--------------------------------
### PlantUML Class Diagram Specification
Source: https://github.com/jfeliu007/goplantuml/blob/master/README.md
This is an example of a PlantUML specification generated by goplantuml, detailing namespaces, classes, functions, and fields.
```plantuml
@startuml
namespace parser {
class Struct {
+ Functions []*Function
+ Fields []*Parameter
+ Type string
+ Composition []string
+ Extends []string
}
class LineStringBuilder {
+ WriteLineWithDepth(depth int, str string)
}
class ClassParser {
- structure map[string]map[string]*Struct
- currentPackageName string
- allInterfaces map[string]struct{}
- allStructs map[string]struct{}
- structImplementsInterface(st *Struct, inter *Struct)
- parsePackage(node ast.Node)
- parseFileDeclarations(node ast.Decl)
- addMethodToStruct(s *Struct, method *ast.Field)
- getFunction(f *ast.FuncType, name string)
- addFieldToStruct(s *Struct, field *ast.Field)
- addToComposition(s *Struct, fType string)
- addToExtends(s *Struct, fType string)
- getOrCreateStruct(name string)
- getStruct(structName string)
- getFieldType(exp ast.Expr, includePackageName bool)
+ Render()
}
class Parameter {
+ Name string
+ Type string
}
class Function {
+ Name string
+ Parameters []*Parameter
+ ReturnValues []string
}
}
strings.Builder *-- parser.LineStringBuilder
@enduml
```
--------------------------------
### GoPlantUML CLI Usage Help
Source: https://github.com/jfeliu007/goplantuml/blob/master/README.md
Displays detailed usage information for the goplantuml command-line tool, including all available flags and their descriptions.
```bash
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)
```
--------------------------------
### Basic Usage of GoPlantUML CLI
Source: https://github.com/jfeliu007/goplantuml/blob/master/README.md
Generates a PlantUML diagram from specified Go files or directories. The output can be redirected to a file.
```bash
goplantuml [-recursive] path/to/gofiles path/to/gofiles2
```
```bash
goplantuml [-recursive] path/to/gofiles path/to/gofiles2 > diagram_file_name.puml
```
--------------------------------
### Go code with Interface Implementation and Composition
Source: https://github.com/jfeliu007/goplantuml/blob/master/README.md
This Go code demonstrates interface implementation and type composition, which GoPlantUML can visualize in a UML diagram.
```go
package testingsupport
//MyInterface only has one method, notice the signature return value
type MyInterface interface {
foo() bool
}
//MyStruct1 will implement the foo() bool function so it will have an "extends" association with MyInterface
type MyStruct1 struct {
}
func (s1 *MyStruct1) foo() bool {
return true
}
//MyStruct2 will be directly composed of MyStruct1 so it will have a composition relationship with it
type MyStruct2 struct {
MyStruct1
}
//MyStruct3 will have a foo() function but the return value is not a bool, so it will not have any relationship with MyInterface
type MyStruct3 struct {
Foo MyStruct1
}
func (s3 *MyStruct3) foo() {
}
```
--------------------------------
### Generate PlantUML from Go package
Source: https://github.com/jfeliu007/goplantuml/blob/master/README.md
Use the goplantuml command-line tool to parse a Go package and generate a PlantUML diagram. The output is printed to standard output.
```bash
goplantuml $GOPATH/src/github.com/jfeliu007/goplantuml/parser
```
--------------------------------
### Generate PlantUML to file
Source: https://github.com/jfeliu007/goplantuml/blob/master/README.md
Redirect the output of goplantuml to a file to save the generated PlantUML specification. This is useful for version control or further processing.
```bash
goplantuml $GOPATH/src/github.com/jfeliu007/goplantuml/parser > ClassDiagram.puml
// Generates a file ClassDiagram.puml with the previous specifications
```
--------------------------------
### Versioning Convention
Source: https://github.com/jfeliu007/goplantuml/blob/master/CONTRIBUTING.md
Tags are cut from the master branch using the v{major}.{minor}.{patch} convention to indicate version changes.
```text
v{major}.{minor}.{patch}
```
--------------------------------
### Generated PlantUML Diagram from Go Code
Source: https://github.com/jfeliu007/goplantuml/blob/master/README.md
This PlantUML code represents the UML diagram generated from the preceding Go code, illustrating interface implementation and composition relationships.
```plantuml
@startuml
namespace testingsupport {
interface MyInterface {
- foo() bool
}
class MyStruct1 << (S,Aquamarine) >> {
- foo() bool
}
class MyStruct2 << (S,Aquamarine) >> {
}
class MyStruct3 << (S,Aquamarine) >> {
- foo()
+ Foo MyStruct1
}
}
testingsupport.MyStruct1 *-- testingsupport.MyStruct2
testingsupport.MyInterface <|-- testingsupport.MyStruct1
testingsupport.MyStruct3 o-- testingsupport.MyStruct1
@enduml
```
--------------------------------
### Regenerate Class Diagram
Source: https://github.com/jfeliu007/goplantuml/blob/master/CONTRIBUTING.md
Run this command to regenerate the ClassDiagram.puml file, ensuring diagrams are up-to-date with code changes.
```bash
./generate_diagram
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.