Renames Fields type to Entries and updates comments

This commit is contained in:
sloumdrone 2019-07-03 14:49:49 -07:00
parent 27261a6f6c
commit f95b2b5f84
1 changed files with 12 additions and 13 deletions

View File

@ -19,13 +19,12 @@ import (
// contain options for various keys (test, view, edit, etc).
type Entry map[string]string
// Fields is a slice of entries that gets used as a part of the Cap type
type Fields []Entry
// Entries is a slice of entries that gets used as a part of the Cap type
type Entries []Entry
// Cap is a map of Fields (itself a slice of Entries) and represents
// each mimetype and a slice of the various entries (programs) available
// for that mimetype.
type Cap map[string]Fields
// Cap is a map of Entries and represents each mimetype and a slice of the
// various entries (programs) available for that mimetype.
type Cap map[string]Entries
// Mailcap is the main struct to interact with. It contains a Cap, as
// caps, that represents the full mailcap db for the system. It has a
@ -42,12 +41,12 @@ func NewMailcap() *Mailcap {
return &mc
}
// Returns Fields for a given mimetype and an error or nil.
func (m *Mailcap) GetAllMime(mime string) (Fields, error) {
// Returns Entries for a given mimetype and an error or nil.
func (m *Mailcap) GetAllMime(mime string) (Entries, error) {
if v, ok := m.Caps[mime]; ok {
return v, nil
}
return make(Fields, 0), fmt.Errorf("Cannot find %s\n", mime)
return make(Entries, 0), fmt.Errorf("Cannot find %s\n", mime)
}
// Retrieves an Entry for a given mimetype and key.
@ -134,8 +133,8 @@ func (e Entry) SetAction(action string) error {
// Look up all of the Entry types available for
// a given mime and key. Returns an Entry slice (Fields)
func (m *Mailcap) lookup(mime, key string) Fields {
f := make(Fields, 0, 5)
func (m *Mailcap) lookup(mime, key string) Entries {
f := make(Entries, 0, 5)
if val, ok := m.Caps[mime]; ok {
f = append(f, val...)
}
@ -144,7 +143,7 @@ func (m *Mailcap) lookup(mime, key string) Fields {
if val, ok := m.Caps[catchAllMime]; ok && mime != catchAllMime {
f = append(f, val...)
}
output := make(Fields, 0, len(f))
output := make(Entries, 0, len(f))
for _, v := range f {
if _, ok := v[key]; ok {
output = append(output, v)
@ -249,7 +248,7 @@ func readMailcapFile(f *os.File,ln int) (Cap, int) {
if _, ok := caps[key]; ok {
caps[key] = append(caps[key], fields)
} else {
caps[key] = make(Fields,0,10)
caps[key] = make(Entries,0,10)
caps[key] = append(caps[key], fields)
}
}