Standard library / net

net.IP.Mask()

Apply the mask to the address; incompatible lengths may return nil. Expected stdout: '192.0.2.0\n'.

Formal Syntax & Structure

go syntaxgo
func (ip IP) Mask(mask IPMask) IP

Parameters & Attributes

NameTypeDescription
maskIPMaskBitmask selecting network bits.

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("192.0.2.7").Mask(net.CIDRMask(24, 32))) }
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