mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-06 05:17:38 +03:00
16 lines
272 B
Go
16 lines
272 B
Go
package common
|
|
|
|
type WithUpstream interface {
|
|
Upstream() any
|
|
}
|
|
|
|
func Cast[T any](obj any) (T, bool) {
|
|
if c, ok := obj.(T); ok {
|
|
return c, true
|
|
}
|
|
if u, ok := obj.(WithUpstream); ok {
|
|
return Cast[T](u.Upstream())
|
|
}
|
|
var defaultValue T
|
|
return defaultValue, false
|
|
}
|