-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdsend.go
60 lines (53 loc) · 1.6 KB
/
mdsend.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package mdsend
import (
"log"
"github.com/dkotik/mdsend/distributors"
"github.com/dkotik/mdsend/loaders"
"github.com/dkotik/mdsend/loggers"
"github.com/dkotik/mdsend/providers"
"github.com/dkotik/mdsend/renderers"
)
const Version = "dev"
// Options provide configuration to component execution.
type Options struct {
URI string // Credentials for provider API backend.
Verbose bool
Dryrun bool // Run the program without delivering or locking anything down.
YesOnPrompt bool // Automatically confirm all prompts.
Logger loggers.Logger
Loader loaders.Loader
Renderer renderers.Renderer
Provider providers.Provider
Distributor distributors.Distributor
}
// Send a message with default agents.
func Send(message *loaders.Message, o *Options) error {
if message.Subject == `` {
log.Fatal(`Message subject must be specified in the markdown file!`)
}
o.Logger.SetTotal(uint(len(*message.To) + len(*message.CC) + len(*message.BCC)))
o.Distributor.SetLogger(o.Logger)
o.Logger.Open("")
defer o.Logger.Close()
defer o.Distributor.Close()
// for i := 0; i < 1000; i++ {
// switch rand.Intn(5) {
// case 0:
// logger.LogSkip(`skip %d here we go`, i)
// case 1:
// logger.LogWarn(`warn %d here we go`, i)
// case 2:
// logger.LogInfo(`info %d here we go`, i)
// case 3:
// logger.LogTest(`test %d here we go`, i)
// default:
// logger.LogSent(`sent %d here we go`, i)
// }
// time.Sleep(time.Second / 10)
// }
err := o.Distributor.Send(message, o.Renderer, o.Provider, o.Dryrun)
if err != nil {
o.Logger.LogFail(err.Error() + ".")
}
return err
}