mirror of https://github.com/XTLS/Xray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
609 B
36 lines
609 B
package serial
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// ToString serialize an arbitrary value into string.
|
|
func ToString(v interface{}) string {
|
|
if v == nil {
|
|
return " "
|
|
}
|
|
|
|
switch value := v.(type) {
|
|
case string:
|
|
return value
|
|
case *string:
|
|
return *value
|
|
case fmt.Stringer:
|
|
return value.String()
|
|
case error:
|
|
return value.Error()
|
|
default:
|
|
return fmt.Sprintf("%+v", value)
|
|
}
|
|
}
|
|
|
|
// Concat concatenates all input into a single string.
|
|
func Concat(v ...interface{}) string {
|
|
builder := strings.Builder{}
|
|
for _, value := range v {
|
|
builder.WriteString(ToString(value))
|
|
}
|
|
return builder.String()
|
|
}
|