MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / ValueToStringArray

Function ValueToStringArray

base/util.go:694–715  ·  view source on GitHub ↗

Convert string or array into a string array, otherwise return nil. If the input slice contains entries of mixed type, all string entries would be collected and returned as a slice and non-string entries as another.

(value interface{})

Source from the content-addressed store, hash-verified

692// the input slice contains entries of mixed type, all string entries would
693// be collected and returned as a slice and non-string entries as another.
694func ValueToStringArray(value interface{}) ([]string, []interface{}) {
695 var nonStrings []interface{}
696 switch valueType := value.(type) {
697 case string:
698 return []string{valueType}, nil
699 case []string:
700 return valueType, nil
701 case []interface{}:
702 result := make([]string, 0, len(valueType))
703 for _, item := range valueType {
704 if str, ok := item.(string); ok {
705 result = append(result, str)
706 } else {
707 nonStrings = append(nonStrings, item)
708 }
709 }
710 return result, nonStrings
711 default:
712 nonStrings = append(nonStrings, valueType)
713 return nil, nonStrings
714 }
715}
716
717// SanitizeRequestURL will return a sanitised string of the URL by:
718// - Tagging mux path variables.

Callers 4

getJWTClaimAsSetFunction · 0.92
ottoValueToStringArrayFunction · 0.92
getChannelsAndAccessMethod · 0.92
TestValueToStringArrayFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestValueToStringArrayFunction · 0.68