github.com/blend/go-sdk@v1.20220411.3/webutil/port_bind_addr.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package webutil 9 10 import ( 11 "strconv" 12 "strings" 13 ) 14 15 // PortFromBindAddr returns a port number as an integer from a bind addr. 16 func PortFromBindAddr(bindAddr string) (port int32) { 17 if len(bindAddr) == 0 { 18 return 0 19 } 20 parts := strings.SplitN(bindAddr, ":", 2) 21 if len(parts) == 0 { 22 return 0 23 } 24 if len(parts) < 2 { 25 output, _ := strconv.ParseInt(parts[0], 10, 64) 26 port = int32(output) 27 return 28 } 29 output, _ := strconv.ParseInt(parts[1], 10, 64) 30 port = int32(output) 31 return 32 }