github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/managed_node_address.go (about) 1 package hedera 2 3 /*- 4 * 5 * Hedera Go SDK 6 * 7 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 */ 22 23 import ( 24 "fmt" 25 "regexp" 26 "strconv" 27 ) 28 29 var hostAndPort = regexp.MustCompile(`^(\S+):(\d+)$`) 30 31 type _ManagedNodeAddress struct { 32 address *string 33 port uint32 34 } 35 36 func _ManagedNodeAddressFromString(str string) (*_ManagedNodeAddress, error) { 37 hostAndPortMatch := hostAndPort.FindStringSubmatch(str) 38 39 if len(hostAndPortMatch) > 1 { 40 port, err := strconv.ParseUint(hostAndPortMatch[2], 10, 64) 41 if err != nil { 42 return nil, err 43 } 44 45 return &_ManagedNodeAddress{ 46 address: &hostAndPortMatch[1], 47 port: uint32(port), 48 }, nil 49 } 50 51 return nil, fmt.Errorf("failed to parse node address") 52 } 53 54 func (address *_ManagedNodeAddress) _IsTransportSecurity() bool { 55 return address.port == 50212 || address.port == 443 56 } 57 58 func (address *_ManagedNodeAddress) _ToInsecure() *_ManagedNodeAddress { 59 if address.port == 50212 { 60 address.port = uint32(50211) 61 } 62 63 return address 64 } 65 66 func (address *_ManagedNodeAddress) _ToSecure() *_ManagedNodeAddress { 67 if address.port == 50211 { 68 address.port = uint32(50212) 69 } 70 return address 71 } 72 73 func (address *_ManagedNodeAddress) _Equals(comp _ManagedNodeAddress) bool { //nolint 74 if address.address != nil && address.address == comp.address { 75 if address.port == comp.port { 76 return true 77 } 78 } 79 80 return false 81 } 82 83 func (address *_ManagedNodeAddress) _String() string { 84 if address.address != nil { 85 return *address.address + ":" + strconv.FormatInt(int64(address.port), 10) 86 } 87 88 return "" 89 }