You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
1.8 KiB
Go
101 lines
1.8 KiB
Go
package fsm
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var (
|
|
l, _ = zap.NewProduction()
|
|
)
|
|
|
|
var CopyPost = Node{
|
|
State: "CopyPost",
|
|
Transitions: map[Event]*Transition{
|
|
"HasAttachments": &Transition{
|
|
Node: &HasAttachments,
|
|
Action: func(ctx context.Context) error {
|
|
return nil
|
|
},
|
|
},
|
|
"NoAttachments": &Transition{
|
|
Node: &NoAttachments,
|
|
Action: func(ctx context.Context) error {
|
|
return nil
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
var NoteFound = Node{
|
|
State: "NoteFound",
|
|
Transitions: map[Event]*Transition{
|
|
"CopyPost": &Transition{
|
|
Node: &CopyPost,
|
|
Action: func(ctx context.Context) error {
|
|
l = l.Named("NoteFound")
|
|
note := ctx.Value("note").(string)
|
|
l.Info("creating post from note", zap.String("filename", note))
|
|
// scan for attachments here
|
|
// if len() attachments > 0
|
|
//
|
|
return nil
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
var NoAttachments = Node{
|
|
State: "NoAttachments",
|
|
Transitions: map[Event]*Transition{
|
|
"Terminate": &Transition{
|
|
Node: &Terminate,
|
|
Action: func(ctx context.Context) error {
|
|
return nil
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
var HasAttachments = Node{
|
|
State: "HasAttachments",
|
|
Transitions: map[Event]*Transition{
|
|
"CopyAttachments": &Transition{
|
|
Node: &CopyAttachments,
|
|
Action: func(ctx context.Context) error {
|
|
return nil
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
var CopyAttachments = Node{
|
|
State: "CopyAttachments",
|
|
Transitions: map[Event]*Transition{
|
|
"SanitizeLinks": &Transition{
|
|
Node: &SanitizeLinks,
|
|
Action: func(ctx context.Context) error {
|
|
return nil
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
var SanitizeLinks = Node{
|
|
State: "SanitizeLinks",
|
|
Transitions: map[Event]*Transition{
|
|
"Terminate": &Transition{
|
|
Node: &Terminate,
|
|
Action: func(ctx context.Context) error {
|
|
return nil
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
var Terminate = Node{
|
|
State: "Terminate",
|
|
Transitions: map[Event]*Transition{},
|
|
}
|