-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprovider.go
More file actions
46 lines (41 loc) · 1 KB
/
provider.go
File metadata and controls
46 lines (41 loc) · 1 KB
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
package main
import (
"fmt"
"os"
"github.com/emersion/go-vcard"
)
// ContextProvider returns lines of context about a contact.
type ContextProvider interface {
Name() string
GetContext(card vcard.Card) ([]string, error)
}
// initProviders creates providers based on config.
func initProviders(cfg Config) []ContextProvider {
var providers []ContextProvider
for _, svc := range cfg.jmapServices() {
p, err := newJMAPProvider(svc)
if err != nil {
fmt.Fprintf(os.Stderr, "jmap provider: %v\n", err)
} else {
providers = append(providers, p)
}
}
return providers
}
// collectContext gathers context from all providers for a given card.
func collectContext(providers []ContextProvider, card vcard.Card) []string {
var all []string
for _, p := range providers {
lines, err := p.GetContext(card)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %v\n", p.Name(), err)
continue
}
if len(lines) == 0 {
continue
}
all = append(all, p.Name()+":")
all = append(all, lines...)
}
return all
}