
A picture is worth a thousand words.
If you agree that nothing paints a better picture of your software project like a well maintained UML class diagram, then this post is for you.
Motivation
I have been fascinated with Golang because of the versatility of the language. I wanted to take advantage of the Golang parser and a great software called PlantUML (http://plantuml.com/) to create a program that will translate my Golang code into a neat class diagram.
After a weekend of fun coding and Jazz Listening, GoPlantUML was born.
https://github.com/jfeliu007/goplantuml
What can you do?
GoPlantUML can help you turn this:
package goisawesome import "strings" type Foo struct { field int PublicField bool *strings.Builder } type MyInterface interface { GetValue() bool } func (f *Foo) myPrivateFunction() int { return 3 } func (f *Foo) GetValue() bool { return true } func (f *Foo) MyPublicFunction() bool { return true }
Into this:
@startuml namespace goisawesome { class Foo { - field int + PublicField bool - myPrivateFunction() + GetValue() + MyPublicFunction() } interface MyInterface { + GetValue() } } strings.Builder *-- goisawesome.Foo goisawesome.MyInterface <|-- goisawesome.Foo @enduml
And by the magic of PlantUML you can turn it into this:


Why PlantUML?
As the Plant UML states in their website:
PlantUML is used to draw UML diagrams, using a simple and human readable text description.
www.plantuml.com
But the best part is that it is a text file. And text files are easily versioned on git or any other versioning system. Which means they will be easier to maintain. Moreover, you get the benefit of the different versions of the file.
Conclusion
PlantUML is great to generate UML diagrams that can be versioned in your versioning system. They could be a nuisance to complete, but with GoPlantUML https://github.com/jfeliu007/goplantuml you can easily generate PlantUML files from your golang projects.
I hope this helps you understand your projects better as well as explain them to others as needed.
Don’t forget to star my project if you like it!
Happy coding,