github.com/hyperledger/aries-framework-go@v0.3.2/pkg/internal/didcommutil/util.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package didcommutil
     8  
     9  // GetServiceType will return service type if service type is a string or first service type if it is an array.
    10  func GetServiceType(serviceType interface{}) string {
    11  	val := ""
    12  
    13  	switch t := serviceType.(type) {
    14  	case string:
    15  		val = t
    16  	case []string:
    17  		if len(t) > 0 {
    18  			val = t[0]
    19  		}
    20  	case []interface{}:
    21  		if len(t) > 0 {
    22  			if str, ok := t[0].(string); ok {
    23  				val = str
    24  			}
    25  		}
    26  	}
    27  
    28  	return val
    29  }