github.com/OrigamiWang/msd/micro@v0.0.0-20240229032328-b62246268db9/util/strings.go (about)

     1  package util
     2  
     3  import "encoding/json"
     4  
     5  func ReflectToString(obj interface{}, args ...interface{}) string {
     6  	if obj == nil {
     7  		return "<nil>"
     8  	}
     9  	switch v := obj.(type) {
    10  	case string:
    11  		return v
    12  	case []byte:
    13  		return string(v)
    14  	default:
    15  		result, err := json.Marshal(obj)
    16  		if err != nil {
    17  			return err.Error()
    18  		} else {
    19  			return string(result)
    20  		}
    21  	}
    22  
    23  }