Keepers 3d170c5b66
follow-up refinements to m365/api (#3461)
some renaming, mostly refactoring the configuration (select and header declaration for each query) by combining the consts.go and query_param.go file into config.go, and making a more composable set of funcs and consts.

---

#### Does this PR need a docs update or release note?

- [x]  No

#### Type of change

- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)

* #1996

#### Test Plan

- [x]  Unit test
- [x] 💚 E2E
2023-05-22 18:37:01 +00:00

59 lines
937 B
Go

package str
import (
"fmt"
"strconv"
"github.com/alcionai/clues"
"github.com/alcionai/corso/src/internal/common/ptr"
)
// parseBool returns the bool value represented by the string
// or false on error
func ParseBool(v string) bool {
s, err := strconv.ParseBool(v)
if err != nil {
return false
}
return s
}
func AnyValueToString(k string, m map[string]any) (string, error) {
if len(m) == 0 {
return "", clues.New("missing entry").With("map_key", k)
}
return AnyToString(m[k])
}
func AnyToString(a any) (string, error) {
if a == nil {
return "", clues.New("missing value")
}
sp, ok := a.(*string)
if ok {
return ptr.Val(sp), nil
}
s, ok := a.(string)
if ok {
return s, nil
}
return "", clues.New(fmt.Sprintf("unexpected type: %T", a))
}
// First returns the first non-zero valued string
func First(vs ...string) string {
for _, v := range vs {
if len(v) > 0 {
return v
}
}
return ""
}