sequence

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 5 Imported by: 1

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

Examples

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

func NewDiagram(w io.Writer, opts ...Option) *Diagram

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

func (d *Diagram) Activate(participant string) *Diagram

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

func (d *Diagram) Actor(actor string) *Diagram

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

func (d *Diagram) AltElse(description string) *Diagram

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

func (d *Diagram) AltEnd() *Diagram

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

func (d *Diagram) AltStart(description string) *Diagram

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

func (d *Diagram) AsyncRequest(from, to, message string) *Diagram

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

func (d *Diagram) AsyncRequestWithActivation(from, to, message string) *Diagram

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

func (d *Diagram) AsyncRequestf(from, to, format string, args ...any) *Diagram

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

func (d *Diagram) AsyncRequestfWithActivation(from, to, format string, args ...any) *Diagram

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

func (d *Diagram) AsyncResponse(from, to, message string) *Diagram

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

func (d *Diagram) AsyncResponseWithActivation(from, to, message string) *Diagram

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

func (d *Diagram) AsyncResponsef(from, to, format string, args ...any) *Diagram

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

func (d *Diagram) AsyncResponsefWithActivation(from, to, format string, args ...any) *Diagram

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

func (d *Diagram) AutoNumber() *Diagram

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

func (d *Diagram) BoxEnd() *Diagram

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

func (d *Diagram) BoxStart(participant []string) *Diagram

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

func (d *Diagram) BreakEnd() *Diagram

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

func (d *Diagram) BreakStart(description string) *Diagram

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

func (d *Diagram) Build() error

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

func (d *Diagram) CreateActor(actor string) *Diagram

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

func (d *Diagram) CreateParticipant(participant string) *Diagram

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

func (d *Diagram) CriticalEnd() *Diagram

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

func (d *Diagram) CriticalOption(description string) *Diagram

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

func (d *Diagram) CriticalStart(description string) *Diagram

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

func (d *Diagram) Deactivate(participant string) *Diagram

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

func (d *Diagram) DestroyActor(actor string) *Diagram

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

func (d *Diagram) DestroyParticipant(participant string) *Diagram

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

func (d *Diagram) Error() 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

func (d *Diagram) LF() *Diagram

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

func (d *Diagram) LoopEnd() *Diagram

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

func (d *Diagram) LoopStart(description string) *Diagram

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

func (d *Diagram) NoteLeftOf(participant, message string) *Diagram

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

func (d *Diagram) NoteOver(participant, message string) *Diagram

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

func (d *Diagram) NoteRightOf(participant, message string) *Diagram

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

func (d *Diagram) OptEnd() *Diagram

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

func (d *Diagram) OptStart(description string) *Diagram

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

func (d *Diagram) ParallelAnd(description string) *Diagram

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

func (d *Diagram) ParallelEnd() *Diagram

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

func (d *Diagram) ParallelStart(description string) *Diagram

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

func (d *Diagram) Participant(participant string) *Diagram

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

func (d *Diagram) RequestError(from, to, message string) *Diagram

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

func (d *Diagram) RequestErrorf(from, to, format string, args ...any) *Diagram

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

func (d *Diagram) ResponseError(from, to, message string) *Diagram

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

func (d *Diagram) ResponseErrorf(from, to, format string, args ...any) *Diagram

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

func (d *Diagram) String() 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

func (d *Diagram) SyncRequest(from, to, message string) *Diagram

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

func (d *Diagram) SyncRequestWithActivation(from, to, message string) *Diagram

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

func (d *Diagram) SyncRequestf(from, to, format string, args ...any) *Diagram

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

func (d *Diagram) SyncRequestfWithActivation(from, to, format string, args ...any) *Diagram

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

func (d *Diagram) SyncResponse(from, to, message string) *Diagram

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

func (d *Diagram) SyncResponseWithActivation(from, to, message string) *Diagram

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

func (d *Diagram) SyncResponsef(from, to, format string, args ...any) *Diagram

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

func (d *Diagram) SyncResponsefWithActivation(from, to, format string, args ...any) *Diagram

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

func WithActorFontFamily(actorFontFamily string) Option

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

func WithActorFontSize(actorFontSize uint) Option

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

func WithActorFontWeight(actorFontWeight string) Option

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

func WithBottomMariginAdjustment(bottomMariginAdjustment uint) Option

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

func WithMessageFontFamily(messageFontFamily string) Option

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

func WithMessageFontSize(messageFontSize uint) Option

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

func WithMessageFontWeight(messageFontWeight string) Option

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

func WithMirrorActors(mirrorActors bool) Option

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

func WithNoteAlign(noteAlign string) Option

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

func WithNoteFontFamily(noteFontFamily string) Option

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

func WithNoteFontSize(noteFontSize uint) Option

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

func WithNoteFontWeight(noteFontWeight string) Option

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?

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL