-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.go
30 lines (26 loc) · 1.19 KB
/
services.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
package gowords
import (
"github.com/saleh-rahimzadeh/go-words/core"
"github.com/saleh-rahimzadeh/go-words/internal"
)
//──────────────────────────────────────────────────────────────────────────────────────────────────
// GetBy a helper to search for a name by suffix and using Words object,
// then return value if found, else return empty string.
// Also return empty string if suffix is invalid.
func GetBy(w Words, name string, suffix core.Suffix) string {
strsuffix, ok := internal.ValidationSuffix(string(suffix))
if !ok {
return internal.Empty
}
return w.Get(name + strsuffix)
}
// FindBy a helper to search for a name by suffix and using Words object,
// then return value and `true` if found, else return empty string and `false`.
// Also return empty string and `false` if suffix is invalid.
func FindBy(w Words, name string, suffix core.Suffix) (string, bool) {
strsuffix, ok := internal.ValidationSuffix(string(suffix))
if !ok {
return internal.Empty, false
}
return w.Find(name + strsuffix)
}