Documentation
¶
Overview ¶
Package sequence is mermaid sequence diagram builder.
Errors are recorded rather than returned from every call: the chain runs to the end and the error surfaces from Build. A nil writer and a writer that refuses the diagram are both reported rather than causing a panic, and String returns the diagram without needing a writer at all.
Index ¶
- type Diagram
- func (d *Diagram) Activate(participant string) *Diagram
- func (d *Diagram) Actor(actor string) *Diagram
- func (d *Diagram) AltElse(description string) *Diagram
- func (d *Diagram) AltEnd() *Diagram
- func (d *Diagram) AltStart(description string) *Diagram
- func (d *Diagram) AsyncRequest(from, to, message string) *Diagram
- func (d *Diagram) AsyncRequestWithActivation(from, to, message string) *Diagram
- func (d *Diagram) AsyncRequestf(from, to, format string, args ...any) *Diagram
- func (d *Diagram) AsyncRequestfWithActivation(from, to, format string, args ...any) *Diagram
- func (d *Diagram) AsyncResponse(from, to, message string) *Diagram
- func (d *Diagram) AsyncResponseWithActivation(from, to, message string) *Diagram
- func (d *Diagram) AsyncResponsef(from, to, format string, args ...any) *Diagram
- func (d *Diagram) AsyncResponsefWithActivation(from, to, format string, args ...any) *Diagram
- func (d *Diagram) AutoNumber() *Diagram
- func (d *Diagram) BoxEnd() *Diagram
- func (d *Diagram) BoxStart(participant []string) *Diagram
- func (d *Diagram) BreakEnd() *Diagram
- func (d *Diagram) BreakStart(description string) *Diagram
- func (d *Diagram) Build() error
- func (d *Diagram) CreateActor(actor string) *Diagram
- func (d *Diagram) CreateParticipant(participant string) *Diagram
- func (d *Diagram) CriticalEnd() *Diagram
- func (d *Diagram) CriticalOption(description string) *Diagram
- func (d *Diagram) CriticalStart(description string) *Diagram
- func (d *Diagram) Deactivate(participant string) *Diagram
- func (d *Diagram) DestroyActor(actor string) *Diagram
- func (d *Diagram) DestroyParticipant(participant string) *Diagram
- func (d *Diagram) Error() error
- func (d *Diagram) LF() *Diagram
- func (d *Diagram) LoopEnd() *Diagram
- func (d *Diagram) LoopStart(description string) *Diagram
- func (d *Diagram) NoteLeftOf(participant, message string) *Diagram
- func (d *Diagram) NoteOver(participant, message string) *Diagram
- func (d *Diagram) NoteRightOf(participant, message string) *Diagram
- func (d *Diagram) OptEnd() *Diagram
- func (d *Diagram) OptStart(description string) *Diagram
- func (d *Diagram) ParallelAnd(description string) *Diagram
- func (d *Diagram) ParallelEnd() *Diagram
- func (d *Diagram) ParallelStart(description string) *Diagram
- func (d *Diagram) Participant(participant string) *Diagram
- func (d *Diagram) RequestError(from, to, message string) *Diagram
- func (d *Diagram) RequestErrorf(from, to, format string, args ...any) *Diagram
- func (d *Diagram) ResponseError(from, to, message string) *Diagram
- func (d *Diagram) ResponseErrorf(from, to, format string, args ...any) *Diagram
- func (d *Diagram) String() string
- func (d *Diagram) SyncRequest(from, to, message string) *Diagram
- func (d *Diagram) SyncRequestWithActivation(from, to, message string) *Diagram
- func (d *Diagram) SyncRequestf(from, to, format string, args ...any) *Diagram
- func (d *Diagram) SyncRequestfWithActivation(from, to, format string, args ...any) *Diagram
- func (d *Diagram) SyncResponse(from, to, message string) *Diagram
- func (d *Diagram) SyncResponseWithActivation(from, to, message string) *Diagram
- func (d *Diagram) SyncResponsef(from, to, format string, args ...any) *Diagram
- func (d *Diagram) SyncResponsefWithActivation(from, to, format string, args ...any) *Diagram
- type NotePosition
- type Option
- func WithActorFontFamily(actorFontFamily string) Option
- func WithActorFontSize(actorFontSize uint) Option
- func WithActorFontWeight(actorFontWeight string) Option
- func WithBottomMariginAdjustment(bottomMariginAdjustment uint) Option
- func WithMessageFontFamily(messageFontFamily string) Option
- func WithMessageFontSize(messageFontSize uint) Option
- func WithMessageFontWeight(messageFontWeight string) Option
- func WithMirrorActors(mirrorActors bool) Option
- func WithNoteAlign(noteAlign string) Option
- func WithNoteFontFamily(noteFontFamily string) Option
- func WithNoteFontSize(noteFontSize uint) Option
- func WithNoteFontWeight(noteFontWeight string) Option
Examples ¶
- Diagram
- Diagram.Activate
- Diagram.Actor
- Diagram.AltElse
- Diagram.AltEnd
- Diagram.AltStart
- Diagram.AsyncRequest
- Diagram.AsyncRequestWithActivation
- Diagram.AsyncRequestf
- Diagram.AsyncRequestfWithActivation
- Diagram.AsyncResponse
- Diagram.AsyncResponseWithActivation
- Diagram.AsyncResponsef
- Diagram.AsyncResponsefWithActivation
- Diagram.AutoNumber
- Diagram.AutoNumber (Second)
- Diagram.BoxEnd
- Diagram.BoxStart
- Diagram.BreakEnd
- Diagram.BreakStart
- Diagram.Build
- Diagram.CreateActor
- Diagram.CreateParticipant
- Diagram.CriticalEnd
- Diagram.CriticalOption
- Diagram.CriticalStart
- Diagram.Deactivate
- Diagram.DestroyActor
- Diagram.DestroyParticipant
- Diagram.Error
- Diagram.LF
- Diagram.LoopEnd
- Diagram.LoopStart
- Diagram.NoteLeftOf
- Diagram.NoteOver
- Diagram.NoteRightOf
- Diagram.OptEnd
- Diagram.OptStart
- Diagram.ParallelAnd
- Diagram.ParallelEnd
- Diagram.ParallelStart
- Diagram.Participant
- Diagram.RequestError
- Diagram.RequestErrorf
- Diagram.ResponseError
- Diagram.ResponseErrorf
- Diagram.String
- Diagram.SyncRequest
- Diagram.SyncRequestWithActivation
- Diagram.SyncRequestf
- Diagram.SyncRequestfWithActivation
- Diagram.SyncResponse
- Diagram.SyncResponseWithActivation
- Diagram.SyncResponsef
- Diagram.SyncResponsefWithActivation
- NewDiagram
- NotePosition
- Option
- WithActorFontFamily
- WithActorFontSize
- WithActorFontWeight
- WithBottomMariginAdjustment
- WithMessageFontFamily
- WithMessageFontSize
- WithMessageFontWeight
- WithMirrorActors
- WithNoteAlign
- WithNoteFontFamily
- WithNoteFontSize
- WithNoteFontWeight
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Diagram ¶
type Diagram struct {
// contains filtered or unexported fields
}
Diagram is a sequence diagram builder.
Example ¶
ExampleDiagram skips this test on Windows. The newline codes in the comment section where the expected values are written are represented as '\n', causing failures when testing on Windows.
package main
import (
"os"
md "github.com/nao1215/markdown"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
diagram := sequence.NewDiagram(os.Stdout).
Participant("Sophia").
Participant("David").
Participant("Subaru").
LF().
SyncRequest("Sophia", "David", "Please wake up Subaru").
SyncResponse("David", "Sophia", "OK").
LF().
LoopStart("until Subaru wake up").
SyncRequest("David", "Subaru", "Wake up!").
SyncResponse("Subaru", "David", "zzz").
SyncRequest("David", "Subaru", "Hey!!!").
BreakStart("if Subaru wake up").
SyncResponse("Subaru", "David", "......").
BreakEnd().
LoopEnd().
LF().
SyncResponse("David", "Sophia", "wake up, wake up").
String()
_ = md.NewMarkdown(os.Stdout).
H2("Sequence Diagram").
CodeBlocks(md.SyntaxHighlightMermaid, diagram).
Build()
}
Output: ## Sequence Diagram ```mermaid sequenceDiagram participant Sophia participant David participant Subaru Sophia->>David: Please wake up Subaru David-->>Sophia: OK loop until Subaru wake up David->>Subaru: Wake up! Subaru-->>David: zzz David->>Subaru: Hey!!! break if Subaru wake up Subaru-->>David: ...... end end David-->>Sophia: wake up, wake up ```
func NewDiagram ¶
NewDiagram returns a new Diagram. Currently, there is no option (method) provided to change the configuration.
Example ¶
ExampleNewDiagram shows the shape every sequence diagram has: a writer, the participants, the messages between them, and Build.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
Participant("Alice").
Participant("Bob").
SyncRequest("Alice", "Bob", "How are you?").
SyncResponse("Bob", "Alice", "Fine, thanks").
Build()
}
Output: sequenceDiagram participant Alice participant Bob Alice->>Bob: How are you? Bob-->>Alice: Fine, thanks
func (*Diagram) Activate ¶
Activate add a participant to the sequence diagram.
Example ¶
ExampleDiagram_Activate turns a participant's activation bar on, which shows it doing something rather than waiting.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
SyncRequest("Alice", "Bob", "How are you?").
Activate("Bob").
SyncResponse("Bob", "Alice", "Fine, thanks").
Deactivate("Bob").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you? activate Bob Bob-->>Alice: Fine, thanks deactivate Bob
func (*Diagram) Actor ¶
Actor add a participant to the sequence diagram.
Example ¶
ExampleDiagram_Actor declares someone taking part, drawn as a stick figure rather than a box.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
Actor("Alice").
Participant("Bob").
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram actor Alice participant Bob Alice->>Bob: How are you?
func (*Diagram) AltElse ¶
AltElse add a alt to the sequence diagram.
Example ¶
ExampleDiagram_AltElse begins an alternative path.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
AltStart("is logged in").
AltElse("is not").
AltEnd().
Build()
}
Output: sequenceDiagram alt is logged in else is not end
func (*Diagram) AltEnd ¶
AltEnd add a alt to the sequence diagram.
Example ¶
ExampleDiagram_AltEnd closes the choice AltStart opened.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
AltStart("is logged in").
AltEnd().
Build()
}
Output: sequenceDiagram alt is logged in end
func (*Diagram) AltStart ¶
AltStart add a alt to the sequence diagram.
Example ¶
ExampleDiagram_AltStart opens a choice between paths. AltElse begins each alternative and AltEnd closes the whole thing.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
AltStart("is logged in").
SyncResponse("Bob", "Alice", "Here you are").
AltElse("is not").
SyncResponse("Bob", "Alice", "Please log in").
AltEnd().
Build()
}
Output: sequenceDiagram alt is logged in Bob-->>Alice: Here you are else is not Bob-->>Alice: Please log in end
func (*Diagram) AsyncRequest ¶
AsyncRequest add a async request to the sequence diagram.
Example ¶
ExampleDiagram_AsyncRequest draws a call that does not wait for a reply.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
AsyncRequest("Alice", "Bob", "Start the job").
Build()
}
Output: sequenceDiagram Alice->)Bob: Start the job
func (*Diagram) AsyncRequestWithActivation ¶
AsyncRequestWithActivation add a async request to the sequence diagram.
Example ¶
ExampleDiagram_AsyncRequestWithActivation draws an asynchronous call that turns the bar on.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
AsyncRequestWithActivation("Alice", "Bob", "Start the job").
Build()
}
Output: sequenceDiagram Alice->>+Bob: Start the job
func (*Diagram) AsyncRequestf ¶
AsyncRequestf add a async request to the sequence diagram.
Example ¶
ExampleDiagram_AsyncRequestf draws the same from a format string.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
AsyncRequestf("Alice", "Bob", "Start job %d", 7).
Build()
}
Output: sequenceDiagram Alice->)Bob: Start job 7
func (*Diagram) AsyncRequestfWithActivation ¶
AsyncRequestfWithActivation add a async request to the sequence diagram.
Example ¶
ExampleDiagram_AsyncRequestfWithActivation draws the same from a format string.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
AsyncRequestfWithActivation("Alice", "Bob", "Start job %d", 7).
Build()
}
Output: sequenceDiagram Alice->>+Bob: Start job 7
func (*Diagram) AsyncResponse ¶
AsyncResponse add a async response to the sequence diagram.
Example ¶
ExampleDiagram_AsyncResponse draws a reply to a call that was not waiting.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
AsyncResponse("Bob", "Alice", "Job finished").
Build()
}
Output: sequenceDiagram Bob--)Alice: Job finished
func (*Diagram) AsyncResponseWithActivation ¶
AsyncResponseWithActivation add a async response to the sequence diagram.
Example ¶
ExampleDiagram_AsyncResponseWithActivation draws an asynchronous reply that turns the bar off.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
AsyncResponseWithActivation("Bob", "Alice", "Job finished").
Build()
}
Output: sequenceDiagram Bob-->>-Alice: Job finished
func (*Diagram) AsyncResponsef ¶
AsyncResponsef add a async response to the sequence diagram.
Example ¶
ExampleDiagram_AsyncResponsef draws the same from a format string.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
AsyncResponsef("Bob", "Alice", "Job %d finished", 7).
Build()
}
Output: sequenceDiagram Bob--)Alice: Job 7 finished
func (*Diagram) AsyncResponsefWithActivation ¶
AsyncResponsefWithActivation add a async response to the sequence diagram.
Example ¶
ExampleDiagram_AsyncResponsefWithActivation draws the same from a format string.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
AsyncResponsefWithActivation("Bob", "Alice", "Job %d finished", 7).
Build()
}
Output: sequenceDiagram Bob-->>-Alice: Job 7 finished
func (*Diagram) AutoNumber ¶
AutoNumber add auto number to the sequence diagram.
Example ¶
ExampleDiagram_AutoNumber numbers the messages, so a discussion can refer to one of them by number.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
AutoNumber().
SyncRequest("Alice", "Bob", "How are you?").
SyncResponse("Bob", "Alice", "Fine, thanks").
Build()
}
Output: sequenceDiagram autonumber Alice->>Bob: How are you? Bob-->>Alice: Fine, thanks
Example (Second) ¶
ExampleDiagram_AutoNumber_second shows that numbering is a call rather than an option, so it can be turned on partway through a chain.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
AutoNumber().
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram autonumber Alice->>Bob: How are you?
func (*Diagram) BoxEnd ¶
BoxEnd add a box to the sequence diagram.
Example ¶
ExampleDiagram_BoxEnd closes the box BoxStart opened.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
BoxStart([]string{"Alice"}).
Participant("Alice").
BoxEnd().
Build()
}
Output: sequenceDiagram box Alice participant Alice end
func (*Diagram) BoxStart ¶
BoxStart add a box to the sequence diagram.
Example ¶
ExampleDiagram_BoxStart draws a box around several participants, which is how a diagram says which of them belong to one system.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
BoxStart([]string{"Alice", "Bob"}).
Participant("Alice").
Participant("Bob").
BoxEnd().
Build()
}
Output: sequenceDiagram box Alice & Bob participant Alice participant Bob end
func (*Diagram) BreakEnd ¶
BreakEnd add a break to the sequence diagram.
Example ¶
ExampleDiagram_BreakEnd closes the block BreakStart opened.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
BreakStart("the request is invalid").
BreakEnd().
Build()
}
Output: sequenceDiagram break the request is invalid end
func (*Diagram) BreakStart ¶
BreakStart add a break to the sequence diagram.
Example ¶
ExampleDiagram_BreakStart opens a block that stops the flow when it happens.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
BreakStart("the request is invalid").
SyncResponse("Bob", "Alice", "400 Bad Request").
BreakEnd().
Build()
}
Output: sequenceDiagram break the request is invalid Bob-->>Alice: 400 Bad Request end
func (*Diagram) Build ¶
Build writes the sequence diagram body to the output destination.
Example ¶
ExampleDiagram_Build writes the diagram and reports the error the chain recorded.
package main
import (
"fmt"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
err := sequence.NewDiagram(nil).
SyncRequest("Alice", "Bob", "How are you?").
Build()
fmt.Println("error:", err)
}
Output: error: output writer must not be nil
func (*Diagram) CreateActor ¶
CreateActor add a participant to the sequence diagram.
Example ¶
ExampleDiagram_CreateActor brings an actor into being partway through.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
Participant("System").
CreateActor("Reviewer").
SyncRequest("System", "Reviewer", "Please review").
Build()
}
Output: sequenceDiagram participant System create actor Reviewer System->>Reviewer: Please review
func (*Diagram) CreateParticipant ¶
CreateParticipant add a participant to the sequence diagram.
Example ¶
ExampleDiagram_CreateParticipant brings a participant into being partway through, which is how a diagram shows something being started rather than having been there all along.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
Participant("Alice").
CreateParticipant("Worker").
SyncRequest("Alice", "Worker", "Start").
Build()
}
Output: sequenceDiagram participant Alice create participant Worker Alice->>Worker: Start
func (*Diagram) CriticalEnd ¶
CriticalEnd add a critical to the sequence diagram.
Example ¶
ExampleDiagram_CriticalEnd closes the block CriticalStart opened.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
CriticalStart("connect to the database").
CriticalEnd().
Build()
}
Output: sequenceDiagram critical connect to the database end
func (*Diagram) CriticalOption ¶
CriticalOption add a critical opiton to the sequence diagram.
Example ¶
ExampleDiagram_CriticalOption begins what happens instead when the critical block cannot go ahead.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
CriticalStart("connect to the database").
CriticalOption("the network is down").
CriticalEnd().
Build()
}
Output: sequenceDiagram critical connect to the database option the network is down end
func (*Diagram) CriticalStart ¶
CriticalStart add a critical to the sequence diagram.
Example ¶
ExampleDiagram_CriticalStart opens a block that has to happen, with CriticalOption for each thing that can go wrong instead.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
CriticalStart("connect to the database").
SyncRequest("Service", "Database", "Connect").
CriticalOption("the network is down").
SyncRequest("Service", "Operator", "Page").
CriticalEnd().
Build()
}
Output: sequenceDiagram critical connect to the database Service->>Database: Connect option the network is down Service->>Operator: Page end
func (*Diagram) Deactivate ¶
Deactivate add a participant to the sequence diagram.
Example ¶
ExampleDiagram_Deactivate turns the bar off again.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
Activate("Bob").
Deactivate("Bob").
Build()
}
Output: sequenceDiagram activate Bob deactivate Bob
func (*Diagram) DestroyActor ¶
DestroyActor add a participant to the sequence diagram.
Example ¶
ExampleDiagram_DestroyActor ends an actor.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
Actor("Reviewer").
DestroyActor("Reviewer").
Build()
}
Output: sequenceDiagram actor Reviewer destroy Reviewer
func (*Diagram) DestroyParticipant ¶
DestroyParticipant add a participant to the sequence diagram.
Example ¶
ExampleDiagram_DestroyParticipant ends a participant, drawn with a cross.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
Participant("Alice").
Participant("Worker").
SyncRequest("Alice", "Worker", "Stop").
DestroyParticipant("Worker").
Build()
}
Output: sequenceDiagram participant Alice participant Worker Alice->>Worker: Stop destroy Worker
func (*Diagram) Error ¶
Error returns the error that occurred during the sequence diagram building.
Example ¶
ExampleDiagram_Error reports the same error Build does, for code that wants to look before writing anything.
package main
import (
"fmt"
"io"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
d := sequence.NewDiagram(io.Discard).SyncRequest("Alice", "Bob", "How are you?")
fmt.Println("error:", d.Error())
}
Output: error: <nil>
func (*Diagram) LF ¶
LF add a line feed to the sequence diagram.
Example ¶
ExampleDiagram_LF adds a blank line to the diagram body.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
SyncRequest("Alice", "Bob", "How are you?").
LF().
SyncResponse("Bob", "Alice", "Fine, thanks").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you? Bob-->>Alice: Fine, thanks
func (*Diagram) LoopEnd ¶
LoopEnd add a loop to the sequence diagram.
Example ¶
ExampleDiagram_LoopEnd closes the block LoopStart opened.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
LoopStart("every minute").
SyncRequest("Alice", "Bob", "Still there?").
LoopEnd().
Build()
}
Output: sequenceDiagram loop every minute Alice->>Bob: Still there? end
func (*Diagram) LoopStart ¶
LoopStart add a loop to the sequence diagram.
Example ¶
ExampleDiagram_LoopStart opens a block that repeats, and LoopEnd closes it.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
LoopStart("every minute").
SyncRequest("Alice", "Bob", "Still there?").
LoopEnd().
Build()
}
Output: sequenceDiagram loop every minute Alice->>Bob: Still there? end
func (*Diagram) NoteLeftOf ¶
NoteLeftOf add a note to the sequence diagram.
Example ¶
ExampleDiagram_NoteLeftOf puts a note to the left of a participant.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
NoteLeftOf("Alice", "Alice is waiting").
Build()
}
Output: sequenceDiagram note left of Alice: Alice is waiting
func (*Diagram) NoteOver ¶
NoteOver add a note to the sequence diagram.
Example ¶
ExampleDiagram_NoteOver puts a note across one or more participants. Two named with a comma between them is a note spanning both.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
NoteOver("Alice", "Thinking it over").
NoteOver("Alice,Bob", "Both are waiting").
Build()
}
Output: sequenceDiagram note over Alice: Thinking it over note over Alice,Bob: Both are waiting
func (*Diagram) NoteRightOf ¶
NoteRightOf add a note to the sequence diagram.
Example ¶
ExampleDiagram_NoteRightOf puts a note to the right of a participant.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
NoteRightOf("Bob", "Bob is busy").
Build()
}
Output: sequenceDiagram note right of Bob: Bob is busy
func (*Diagram) OptEnd ¶
OptEnd add a opt to the sequence diagram.
Example ¶
ExampleDiagram_OptEnd closes the block OptStart opened.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
OptStart("if the cache is cold").
OptEnd().
Build()
}
Output: sequenceDiagram opt if the cache is cold end
func (*Diagram) OptStart ¶
OptStart add a opt to the sequence diagram.
Example ¶
ExampleDiagram_OptStart opens a block that may or may not happen, which is a choice with only one path.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
OptStart("if the cache is cold").
SyncRequest("Bob", "Database", "Fetch").
OptEnd().
Build()
}
Output: sequenceDiagram opt if the cache is cold Bob->>Database: Fetch end
func (*Diagram) ParallelAnd ¶
ParallelAnd add a parallel to the sequence diagram.
Example ¶
ExampleDiagram_ParallelAnd begins another path running at the same time.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
ParallelStart("lint").
ParallelAnd("test").
ParallelEnd().
Build()
}
Output: sequenceDiagram par lint and test end
func (*Diagram) ParallelEnd ¶
ParallelEnd add a parallel to the sequence diagram.
Example ¶
ExampleDiagram_ParallelEnd closes the paths ParallelStart opened.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
ParallelStart("lint").
ParallelEnd().
Build()
}
Output: sequenceDiagram par lint end
func (*Diagram) ParallelStart ¶
ParallelStart add a parallel to the sequence diagram.
Example ¶
ExampleDiagram_ParallelStart opens paths that run at the same time. ParallelAnd begins each one after the first and ParallelEnd closes them.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
ParallelStart("lint").
SyncRequest("CI", "Linter", "Run").
ParallelAnd("test").
SyncRequest("CI", "Tester", "Run").
ParallelEnd().
Build()
}
Output: sequenceDiagram par lint CI->>Linter: Run and test CI->>Tester: Run end
func (*Diagram) Participant ¶
Participant add a participant to the sequence diagram.
Example ¶
ExampleDiagram_Participant declares someone taking part, drawn as a box. Declaring one is what fixes the order they appear in; a participant a message names is drawn anyway, at the point it is first mentioned.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
Participant("Bob").
Participant("Alice").
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram participant Bob participant Alice Alice->>Bob: How are you?
func (*Diagram) RequestError ¶
RequestError add a request error to the sequence diagram.
Example ¶
ExampleDiagram_RequestError draws a call that failed, drawn with a cross at the end.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
RequestError("Alice", "Bob", "Timed out").
Build()
}
Output: sequenceDiagram Alice-xBob: Timed out
func (*Diagram) RequestErrorf ¶
RequestErrorf add a request error to the sequence diagram.
Example ¶
ExampleDiagram_RequestErrorf draws the same from a format string.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
RequestErrorf("Alice", "Bob", "Timed out after %ds", 30).
Build()
}
Output: sequenceDiagram Alice-xBob: Timed out after 30s
func (*Diagram) ResponseError ¶
ResponseError add a response error to the sequence diagram.
Example ¶
ExampleDiagram_ResponseError draws a reply that failed.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
ResponseError("Bob", "Alice", "Refused").
Build()
}
Output: sequenceDiagram Bob--xAlice: Refused
func (*Diagram) ResponseErrorf ¶
ResponseErrorf add a response error to the sequence diagram.
Example ¶
ExampleDiagram_ResponseErrorf draws the same from a format string.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
ResponseErrorf("Bob", "Alice", "Refused with %d", 503).
Build()
}
Output: sequenceDiagram Bob--xAlice: Refused with 503
func (*Diagram) String ¶
String returns the sequence diagram body.
Example ¶
ExampleDiagram_String returns the diagram without needing a writer, which is how it is handed to a markdown code block.
package main
import (
"io"
"os"
md "github.com/nao1215/markdown"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
diagram := sequence.NewDiagram(io.Discard).
SyncRequest("Alice", "Bob", "How are you?").
String()
_ = md.NewMarkdown(os.Stdout).
CodeBlocks(md.SyntaxHighlightMermaid, diagram).
Build()
}
Output: ```mermaid sequenceDiagram Alice->>Bob: How are you? ```
func (*Diagram) SyncRequest ¶
SyncRequest add a request to the sequence diagram.
Example ¶
ExampleDiagram_SyncRequest draws a solid arrow with a filled head, the ordinary call.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?
func (*Diagram) SyncRequestWithActivation ¶
SyncRequestWithActivation add a request to the sequence diagram.
Example ¶
ExampleDiagram_SyncRequestWithActivation draws a call that also turns the receiver's activation bar on.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
SyncRequestWithActivation("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>+Bob: How are you?
func (*Diagram) SyncRequestf ¶
SyncRequestf add a request to the sequence diagram.
Example ¶
ExampleDiagram_SyncRequestf draws the same from a format string.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
SyncRequestf("Alice", "Bob", "Retry %d of %d", 2, 3).
Build()
}
Output: sequenceDiagram Alice->>Bob: Retry 2 of 3
func (*Diagram) SyncRequestfWithActivation ¶
SyncRequestfWithActivation add a request to the sequence diagram.
Example ¶
ExampleDiagram_SyncRequestfWithActivation draws the same from a format string.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
SyncRequestfWithActivation("Alice", "Bob", "Retry %d", 2).
Build()
}
Output: sequenceDiagram Alice->>+Bob: Retry 2
func (*Diagram) SyncResponse ¶
SyncResponse add a response to the sequence diagram.
Example ¶
ExampleDiagram_SyncResponse draws a dashed arrow with a filled head, the ordinary reply.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
SyncResponse("Bob", "Alice", "Fine, thanks").
Build()
}
Output: sequenceDiagram Bob-->>Alice: Fine, thanks
func (*Diagram) SyncResponseWithActivation ¶
SyncResponseWithActivation add a response to the sequence diagram.
Example ¶
ExampleDiagram_SyncResponseWithActivation draws a reply that also turns the bar off.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
SyncResponseWithActivation("Bob", "Alice", "Fine, thanks").
Build()
}
Output: sequenceDiagram Bob-->>-Alice: Fine, thanks
func (*Diagram) SyncResponsef ¶
SyncResponsef add a response to the sequence diagram.
Example ¶
ExampleDiagram_SyncResponsef draws the same from a format string.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
SyncResponsef("Bob", "Alice", "%d items", 7).
Build()
}
Output: sequenceDiagram Bob-->>Alice: 7 items
func (*Diagram) SyncResponsefWithActivation ¶
SyncResponsefWithActivation add a response to the sequence diagram.
Example ¶
ExampleDiagram_SyncResponsefWithActivation draws the same from a format string.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout).
SyncResponsefWithActivation("Bob", "Alice", "%d items", 7).
Build()
}
Output: sequenceDiagram Bob-->>-Alice: 7 items
type NotePosition ¶
type NotePosition string
NotePosition is a note position.
Example ¶
ExampleNotePosition shows where a note can be placed. The constants are used by the note methods rather than passed to them, and WithNoteAlign takes the same wording as a string.
package main
import (
"fmt"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
fmt.Println(sequence.NotePositionOver)
fmt.Println(sequence.NotePositionLeft)
fmt.Println(sequence.NotePositionRight)
}
Output: over left of right of
const ( // NotePositionOver is a note position. NotePositionOver NotePosition = "over" // NotePositionRight is a note position. NotePositionRight NotePosition = "right of" // NotePositionLeft is a note position. NotePositionLeft NotePosition = "left of" )
type Option ¶ added in v0.2.0
type Option func(*config)
Option sets the options for the Diagram struct.
Example ¶
ExampleOption shows what an Option is: a function that changes how the diagram is written, passed to NewDiagram.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
options := []sequence.Option{
sequence.WithMirrorActors(true),
sequence.WithActorFontSize(18),
}
_ = sequence.NewDiagram(os.Stdout, options...).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?
func WithActorFontFamily ¶ added in v0.2.0
WithActorFontFamily sets the actorFontFamily configuration.
Example ¶
ExampleWithActorFontFamily sets the typeface of the actor names.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout, sequence.WithActorFontFamily("Helvetica")).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?
func WithActorFontSize ¶ added in v0.2.0
WithActorFontSize sets the actorFontSize configuration.
Example ¶
ExampleWithActorFontSize sets the size of the actor names.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout, sequence.WithActorFontSize(18)).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?
func WithActorFontWeight ¶ added in v0.2.0
WithActorFontWeight sets the actorFontWeight configuration.
Example ¶
ExampleWithActorFontWeight sets the weight of the actor names.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout, sequence.WithActorFontWeight("bold")).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?
func WithBottomMariginAdjustment ¶ added in v0.2.0
WithBottomMariginAdjustment sets the bottomMariginAdjustment configuration.
Example ¶
ExampleWithBottomMariginAdjustment adds space below the diagram.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout, sequence.WithBottomMariginAdjustment(10)).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?
func WithMessageFontFamily ¶ added in v0.2.0
WithMessageFontFamily sets the messageFontFamily configuration.
Example ¶
ExampleWithMessageFontFamily sets the typeface of the message text.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout, sequence.WithMessageFontFamily("Helvetica")).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?
func WithMessageFontSize ¶ added in v0.2.0
WithMessageFontSize sets the messageFontSize configuration.
Example ¶
ExampleWithMessageFontSize sets the size of the message text.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout, sequence.WithMessageFontSize(14)).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?
func WithMessageFontWeight ¶ added in v0.2.0
WithMessageFontWeight sets the messageFontWeight configuration.
Example ¶
ExampleWithMessageFontWeight sets the weight of the message text.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout, sequence.WithMessageFontWeight("bold")).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?
func WithMirrorActors ¶ added in v0.2.0
WithMirrorActors sets the mirrorActors configuration.
Example ¶
ExampleWithMirrorActors draws the actors along the bottom as well as the top, which a long diagram wants so a reader does not have to scroll back.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout, sequence.WithMirrorActors(true)).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?
func WithNoteAlign ¶ added in v0.2.0
WithNoteAlign sets the noteAlign configuration.
Example ¶
ExampleWithNoteAlign sets which way the note text is aligned.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout, sequence.WithNoteAlign("center")).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?
func WithNoteFontFamily ¶ added in v0.2.0
WithNoteFontFamily sets the noteFontFamily configuration.
Example ¶
ExampleWithNoteFontFamily sets the typeface of the note text.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout, sequence.WithNoteFontFamily("Helvetica")).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?
func WithNoteFontSize ¶ added in v0.2.0
WithNoteFontSize sets the noteFontSize configuration.
Example ¶
ExampleWithNoteFontSize sets the size of the note text.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout, sequence.WithNoteFontSize(12)).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?
func WithNoteFontWeight ¶ added in v0.2.0
WithNoteFontWeight sets the noteFontWeight configuration.
Example ¶
ExampleWithNoteFontWeight sets the weight of the note text.
package main
import (
"os"
"github.com/nao1215/markdown/mermaid/sequence"
)
func main() {
_ = sequence.NewDiagram(os.Stdout, sequence.WithNoteFontWeight("bold")).
SyncRequest("Alice", "Bob", "How are you?").
Build()
}
Output: sequenceDiagram Alice->>Bob: How are you?