Standard library / net

net.ParseIP()

Parse IPv4 or IPv6 text; malformed input returns nil, not an error. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func ParseIP(s string) IP

Parameters & Attributes

NameTypeDescription
sstringTextual address or prefix to parse.

Return Value

IP

Operation result; check errors and validity indicators when returned.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net")
func main() { fmt.Println(net.ParseIP("bad") == nil) }
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference