package multiaddrimport ()// Split returns the sub-address portions of a multiaddr.func ( Multiaddr) []Component {return}// Join returns a combination of addresses.// Note: This copies all the components from the input Multiaddrs. Depending on// your use case, you may prefer to use `append(leftMA, rightMA...)` instead.func ( ...Multiaddrer) Multiaddr { := make([]Multiaddr, len())for , := range {if == nil {continue } [] = .Multiaddr() } := 0for , := range { += len() }if == 0 {returnnil } := make([]Component, 0, )for , := range { = append(, ...) }return}// Cast re-casts a byte slice as a multiaddr. will panic if it fails to parse.func ( []byte) Multiaddr { , := NewMultiaddrBytes()if != nil {panic(fmt.Errorf("multiaddr failed to parse: %s", )) }return}// StringCast like Cast, but parses a string. Will also panic if it fails to parse.func ( string) Multiaddr { , := NewMultiaddr()if != nil {panic(fmt.Errorf("multiaddr failed to parse: %s", )) }return}// SplitFirst returns the first component and the rest of the multiaddr.func ( Multiaddr) (*Component, Multiaddr) {iflen() == 0 {returnnil, nil }iflen() == 1 {return &[0], nil }// defensive copy. Users can avoid by doing the split themselves. := [0]return &, [1:].copy()}// SplitLast returns the rest of the multiaddr and the last component.func ( Multiaddr) (Multiaddr, *Component) {iflen() == 0 {returnnil, nil }iflen() == 1 {// We want to explicitly return a nil slice if the prefix is now empty.returnnil, &[0] }// defensive copy. Users can avoid by doing the split themselves. := [len()-1]return [:len()-1].copy(), &}// SplitFunc splits the multiaddr when the callback first returns true. The// component on which the callback first returns will be included in the// *second* multiaddr.func ( Multiaddr, func(Component) bool) (Multiaddr, Multiaddr) {iflen() == 0 {returnnil, nil } := len()for , := range {if () { = break } } , := [:], [:]iflen() == 0 { = nil }iflen() == 0 { = nil }// defensive copy. Users can avoid by doing the split themselves.return .copy(), .copy()}// ForEach walks over the multiaddr, component by component.//// This function iterates over components.// Return true to continue iteration, false to stop.//// Prefer a standard for range loop instead// e.g. `for _, c := range m { ... }`func ( Multiaddr, func( Component) bool) {for , := range {if !() {return } }}type componentList []Componentfunc ( componentList) ( int) meg.Matchable {return &[]}func ( componentList) () int {returnlen()}func ( Multiaddr) ( ...meg.Pattern) (bool, error) { := meg.PatternToMatcher(...)returnmeg.Match(, componentList())}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.