github.com/google/capslock@v0.2.3-0.20240517042941-dac19fc347c0/testpkgs/initfn/initfn.go (about)

     1  // Copyright 2023 Google LLC
     2  //
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file or at
     5  // https://developers.google.com/open-source/licenses/bsd
     6  
     7  // Package initfn is used for testing.
     8  package initfn
     9  
    10  import (
    11  	"net"
    12  	"os"
    13  	"reflect"
    14  	"runtime/debug"
    15  	"unsafe"
    16  )
    17  
    18  // init function
    19  func init() {
    20  	ips, err := net.LookupIP("localhost")
    21  	if err != nil {
    22  		println(err)
    23  	}
    24  	println(len(ips))
    25  }
    26  
    27  // another init function
    28  func init() {
    29  	debug.SetMaxThreads(123)
    30  }
    31  
    32  // X is initialized by a function call.
    33  var X int = os.Getpid()
    34  
    35  // UP is initialized with an unsafe.Pointer conversion.
    36  var UP *uint = (*uint)(unsafe.Pointer(&X))
    37  
    38  // The initialization of these variables copies a reflect.Value.
    39  var rv1 reflect.Value
    40  var rv2 = rv1