Standard library / net/netip
netip.Addr.WithZone()
Return a copy with the requested IPv6 zone; IPv4 is unchanged. Expected stdout: 'fe80::1%demo\n'.
Formal Syntax & Structure
go syntaxgo
func (ip Addr) WithZone(zone string) AddrParameters & Attributes
| Name | Type | Description |
|---|---|---|
| zone | string | IPv6 scope zone identifier; empty removes it. |
Return Value
Addr
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/netip")
func main() { fmt.Println(netip.MustParseAddr("fe80::1").WithZone("demo")) }
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) }}