Skip to content

Commit 8083dfe

Browse files
authored
Merge pull request #2 from jessp01/minor-fixes-and-ci
Minor fixes and ci
2 parents 5eab256 + 9e084c0 commit 8083dfe

File tree

5 files changed

+82
-6
lines changed

5 files changed

+82
-6
lines changed

.github/workflows/go.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will build a golang project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3+
4+
name: Go
5+
6+
on: [push, pull_request]
7+
8+
defaults:
9+
run:
10+
shell: 'bash -Eeuo pipefail -x {0}'
11+
12+
jobs:
13+
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v4
21+
with:
22+
go-version: '1.20'
23+
24+
- name: Build
25+
run: cd sequence && go build -v
26+
- name: Test
27+
run: |
28+
set -e
29+
go install github.com/go-critic/go-critic/cmd/gocritic@latest
30+
go install golang.org/x/tools/cmd/goimports@latest
31+
go install golang.org/x/lint/golint@latest
32+
go install github.com/gordonklaus/ineffassign@latest
33+
pip install pre-commit
34+
pre-commit install
35+
pre-commit run --all-files
36+
# go test -v
37+
38+
#- name: Test
39+
#run: go test -v

.pre-commit-config.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
repos:
2+
- repo: https://github.com/jessp01/pre-commit-golang.git
3+
rev: v0.5.4
4+
hooks:
5+
- id: go-fmt
6+
- id: go-imports
7+
#- id: go-vet
8+
- id: go-lint
9+
- id: go-critic
10+
- id: go-ineffassign
11+
- id: shellcheck

README.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
# go-uml
2+
3+
[![CI][badge-build]][build]
4+
[![GoDoc][go-docs-badge]][go-docs]
5+
[![GoReportCard][go-report-card-badge]][go-report-card]
6+
[![License][badge-license]][license]
7+
28
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
39
and you won't find some functionalities yet such as
410

511
- provide conditional flows
612

713
The generated diagram is saved as .PNG file
814

9-
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.
15+
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.
1016
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).
1117

12-
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
18+
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
1319

1420
# How to install
1521

@@ -26,7 +32,7 @@ first
2632

2733
# Example
2834

29-
```
35+
```go
3036
d := sequence.NewDiagram("user_starts_chatting")
3137

3238
client := "Client"
@@ -55,7 +61,7 @@ first
5561
d.Render()
5662

5763
```
58-
Result PNG file:
64+
Resulting PNG file:
5965
![Sequence Diagram generated based on above code](./examples/user_starts_chatting.png)
6066

6167
Some more examples:
@@ -65,3 +71,12 @@ Some more examples:
6571
## Warning - AI not welcome here
6672
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.
6773
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.
74+
75+
[license]: ./LICENSE
76+
[badge-license]: https://img.shields.io/github/license/MrIceman/go-uml.svg
77+
[go-docs-badge]: https://godoc.org/github.com/MrIceman/go-uml?status.svg
78+
[go-docs]: https://godoc.org/github.com/MrIceman/go-uml
79+
[go-report-card-badge]: https://goreportcard.com/badge/github.com/MrIceman/go-uml
80+
[go-report-card]: https://goreportcard.com/report/github.com/MrIceman/go-uml
81+
[badge-build]: https://github.com/MrIceman/go-uml/actions/workflows/go.yml/badge.svg
82+
[build]: https://github.com/MrIceman/go-uml/actions/workflows/go.yml

examples/main.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package main
33
import "github.com/mriceman/go-uml/sequence"
44

55
func main() {
6+
userStartsChatting()
7+
userBIsNotPartOfChat()
8+
userBIsPartOfChat()
69
userJoinsChat()
710
}
811

@@ -33,7 +36,7 @@ func userJoinsChat() {
3336
d.Render()
3437
}
3538

36-
func UserBIsPartOfChat() {
39+
func userBIsPartOfChat() {
3740
d := sequence.NewDiagram("on_new_message_for_user_b")
3841

3942
usrA := "User A"

sequence/diagram.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package sequence
22

33
import (
44
"fmt"
5-
"github.com/fogleman/gg"
65
"image/color"
76
"log"
7+
8+
"github.com/fogleman/gg"
89
)
910

1011
const (
@@ -21,6 +22,7 @@ const (
2122
height = 1000
2223
)
2324

25+
// Diagram represents a diagram
2426
type Diagram struct {
2527
participants []participant
2628
edges []edge
@@ -32,6 +34,7 @@ type Diagram struct {
3234
filename string
3335
}
3436

37+
// NewDiagram init function
3538
func NewDiagram(filename string) *Diagram {
3639
coordMap := make(map[string]participantCoord)
3740

@@ -41,6 +44,7 @@ func NewDiagram(filename string) *Diagram {
4144
}
4245
}
4346

47+
// Render generates an image from a `Diagram` object
4448
func (d *Diagram) Render() {
4549
d.dc = gg.NewContext(width, height)
4650
d.dc.DrawRectangle(0, 0, width, height)
@@ -188,6 +192,7 @@ func (d *Diagram) renderEdges() {
188192
}
189193
}
190194

195+
// AddParticipants sets the `participant` array on the Diagram object
191196
func (d *Diagram) AddParticipants(name ...string) {
192197
for _, n := range name {
193198
for i := range d.participants {
@@ -199,6 +204,7 @@ func (d *Diagram) AddParticipants(name ...string) {
199204
}
200205
}
201206

207+
// AddDirectionalEdge adds a connection (renders as an arrowed line) between two participants
202208
func (d *Diagram) AddDirectionalEdge(from, to string, label string) error {
203209
var fromPar *participant
204210
var toPar *participant
@@ -221,6 +227,7 @@ func (d *Diagram) AddDirectionalEdge(from, to string, label string) error {
221227
return nil
222228
}
223229

230+
// AddUndirectionalEdge adds a connection (renders as a line) between two participants
224231
func (d *Diagram) AddUndirectionalEdge(from, to string, label string) error {
225232
var fromPar *participant
226233
var toPar *participant
@@ -240,6 +247,7 @@ func (d *Diagram) AddUndirectionalEdge(from, to string, label string) error {
240247
return nil
241248
}
242249

250+
// SetTitle sets the diagram's title
243251
func (d *Diagram) SetTitle(s string) {
244252
d.title = s
245253
}

0 commit comments

Comments
 (0)