mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-18 02:16:10 -05:00
44 lines
699 B
Go
44 lines
699 B
Go
package serial
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"v2ray.com/core/common/buf"
|
|
)
|
|
|
|
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()
|
|
case []byte:
|
|
return BytesToHexString(value)
|
|
default:
|
|
return fmt.Sprintf("%+v", value)
|
|
}
|
|
}
|
|
|
|
func Concat(v ...interface{}) string {
|
|
values := make([]string, len(v))
|
|
for i, value := range v {
|
|
values[i] = ToString(value)
|
|
}
|
|
return strings.Join(values, "")
|
|
}
|
|
|
|
func WriteString(s string) buf.Supplier {
|
|
return func(b []byte) (int, error) {
|
|
return copy(b, []byte(s)), nil
|
|
}
|
|
}
|