gitee.com/h79/goutils@v1.22.10/thrift/thriftutil/target.go (about) 1 package thriftutil 2 3 import ( 4 "gitee.com/h79/goutils/thrift/resolver" 5 "strings" 6 ) 7 8 // split2 returns the values from strings.SplitN(s, sep, 2). 9 // If sep is not found, it returns ("", "", false) instead. 10 func split2(s, sep string) (string, string, bool) { 11 spl := strings.SplitN(s, sep, 2) 12 if len(spl) < 2 { 13 return "", "", false 14 } 15 return spl[0], spl[1], true 16 } 17 18 // ParseTarget splits target into a resolver.Target struct containing scheme, 19 // authority and endpoint. 20 // 21 // If target is not a valid scheme://authority/endpoint, it returns {Endpoint: 22 // target}. 23 func ParseTarget(target string) (ret resolver.Target) { 24 var ok bool 25 ret.Scheme, ret.Endpoint, ok = split2(target, "://") 26 if !ok { 27 return resolver.Target{Endpoint: target} 28 } 29 ret.Authority, ret.Endpoint, ok = split2(ret.Endpoint, "/") 30 if !ok { 31 return resolver.Target{Endpoint: target} 32 } 33 return ret 34 }