diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..a5911cb --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,39 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go + +on: [push, pull_request] + +defaults: + run: + shell: 'bash -Eeuo pipefail -x {0}' + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: Build + run: cd sequence && go build -v + - name: Test + run: | + set -e + go install github.com/go-critic/go-critic/cmd/gocritic@latest + go install golang.org/x/tools/cmd/goimports@latest + go install golang.org/x/lint/golint@latest + go install github.com/gordonklaus/ineffassign@latest + pip install pre-commit + pre-commit install + pre-commit run --all-files + # go test -v + + #- name: Test + #run: go test -v diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..162e192 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +repos: + - repo: https://github.com/jessp01/pre-commit-golang.git + rev: v0.5.4 + hooks: + - id: go-fmt + - id: go-imports + #- id: go-vet + - id: go-lint + - id: go-critic + - id: go-ineffassign + - id: shellcheck diff --git a/README.md b/README.md index 0e27ea5..844dcc2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ # go-uml + +[![CI][badge-build]][build] +[![GoDoc][go-docs-badge]][go-docs] +[![GoReportCard][go-report-card-badge]][go-report-card] +[![License][badge-license]][license] + Just a little tool to create UML Diagrams built in Go. You can use it already to build simple sequence diagrams, however, this project is still under development and you won't find some functionalities yet such as @@ -6,10 +12,10 @@ and you won't find some functionalities yet such as The generated diagram is saved as .PNG file -So far, you can create only sequence diagrams and add Participants, directional and undirectional Edges, labels for Edges and set a Title for the diagram. +So far, you can create only sequence diagrams and add Participants, directional and non-directional Edges, labels for Edges and set a Title for the diagram. I'll be updating this repository whenever I need the tool to support more functionality, feel free to create an Issue with a feature request. Since I just started this project, contributing should also be quite easy (I appreciate any contribution). -You don't need to download any dependencies such as plantUML or Graphviz, which is what most of the tools out there require and what was also my motivation to start this project. go-uml is using a 2D graphics engine written 100% in Go https://github.com/fogleman/gg +You don't need to download any dependencies such as plantUML or Graphviz, which is what most of the tools out there require and what was also my motivation to start this project. go-uml is using a [2D graphics engine](https://github.com/fogleman/gg) written 100% in Go # How to install @@ -26,7 +32,7 @@ first # Example -``` +```go d := sequence.NewDiagram("user_starts_chatting") client := "Client" @@ -55,7 +61,7 @@ first d.Render() ``` -Result PNG file: +Resulting PNG file: ![Sequence Diagram generated based on above code](./examples/user_starts_chatting.png) Some more examples: @@ -65,3 +71,12 @@ Some more examples: ## Warning - AI not welcome here Because of my own personal philosophy regarding technology and AI, all the code in this repository that was written by me - I wrote 100% on my own. There is and will be no usage of Github Co-Pilot or any other AI tool. I became a software developer because of my passion for our craft - Software Engineering. I build this tool because I enjoy programming. Every single line of code you'll read in this repo, that was written by me, is produced first in my mind and then manifested into reality through my hands. I encourage any contributor to follow the same principle, though I can't and don't want to put any restrictions on this. Just like people stopped walking because they commute by cars and trains, which caused an increase in obesity and illness, I believe that the massive usage of AI will cause people to stop thinking and using their minds and the resulting havoc is unthinkable. + +[license]: ./LICENSE +[badge-license]: https://img.shields.io/github/license/MrIceman/go-uml.svg +[go-docs-badge]: https://godoc.org/github.com/MrIceman/go-uml?status.svg +[go-docs]: https://godoc.org/github.com/MrIceman/go-uml +[go-report-card-badge]: https://goreportcard.com/badge/github.com/MrIceman/go-uml +[go-report-card]: https://goreportcard.com/report/github.com/MrIceman/go-uml +[badge-build]: https://github.com/MrIceman/go-uml/actions/workflows/go.yml/badge.svg +[build]: https://github.com/MrIceman/go-uml/actions/workflows/go.yml diff --git a/examples/main.go b/examples/main.go index 28505f0..70f11a1 100644 --- a/examples/main.go +++ b/examples/main.go @@ -3,6 +3,9 @@ package main import "github.com/mriceman/go-uml/sequence" func main() { + userStartsChatting() + userBIsNotPartOfChat() + userBIsPartOfChat() userJoinsChat() } @@ -33,7 +36,7 @@ func userJoinsChat() { d.Render() } -func UserBIsPartOfChat() { +func userBIsPartOfChat() { d := sequence.NewDiagram("on_new_message_for_user_b") usrA := "User A" diff --git a/sequence/diagram.go b/sequence/diagram.go index 5065625..184abac 100644 --- a/sequence/diagram.go +++ b/sequence/diagram.go @@ -2,9 +2,10 @@ package sequence import ( "fmt" - "github.com/fogleman/gg" "image/color" "log" + + "github.com/fogleman/gg" ) const ( @@ -21,6 +22,7 @@ const ( height = 1000 ) +// Diagram represents a diagram type Diagram struct { participants []participant edges []edge @@ -32,6 +34,7 @@ type Diagram struct { filename string } +// NewDiagram init function func NewDiagram(filename string) *Diagram { coordMap := make(map[string]participantCoord) @@ -41,6 +44,7 @@ func NewDiagram(filename string) *Diagram { } } +// Render generates an image from a `Diagram` object func (d *Diagram) Render() { d.dc = gg.NewContext(width, height) d.dc.DrawRectangle(0, 0, width, height) @@ -188,6 +192,7 @@ func (d *Diagram) renderEdges() { } } +// AddParticipants sets the `participant` array on the Diagram object func (d *Diagram) AddParticipants(name ...string) { for _, n := range name { for i := range d.participants { @@ -199,6 +204,7 @@ func (d *Diagram) AddParticipants(name ...string) { } } +// AddDirectionalEdge adds a connection (renders as an arrowed line) between two participants func (d *Diagram) AddDirectionalEdge(from, to string, label string) error { var fromPar *participant var toPar *participant @@ -221,6 +227,7 @@ func (d *Diagram) AddDirectionalEdge(from, to string, label string) error { return nil } +// AddUndirectionalEdge adds a connection (renders as a line) between two participants func (d *Diagram) AddUndirectionalEdge(from, to string, label string) error { var fromPar *participant var toPar *participant @@ -240,6 +247,7 @@ func (d *Diagram) AddUndirectionalEdge(from, to string, label string) error { return nil } +// SetTitle sets the diagram's title func (d *Diagram) SetTitle(s string) { d.title = s }