Standard library / net

net.Interface

Metadata for a network interface: local Index, MTU, Name, HardwareAddr and Flags. These values describe a host interface, not a remote endpoint. Expected stdout: 'true true\n'.

Formal Syntax & Structure

go syntaxgo
type Interface struct {  Index        int  MTU          int  Name         string  HardwareAddr HardwareAddr  Flags        Flags}

Working Example

Example Snippetgo
package main
import (  "fmt"  "net")
func main() {  all := must(net.Interfaces())  var loop net.Interface  for _, x := range all {    if x.Flags&net.FlagLoopback != 0 {      loop = x      break    }  }  if loop.Index == 0 {    panic("no loopback interface")  }  fmt.Println(loop.Index > 0, loop.Flags&net.FlagLoopback != 0)}
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