github.com/mdempsky/go@v0.0.0-20151201204031-5dd372bd1e70/misc/cgo/testcarchive/src/libgo/libgo.go (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"os"
    10  	"syscall"
    11  	"time"
    12  
    13  	_ "p"
    14  )
    15  
    16  import "C"
    17  
    18  var initCh = make(chan int, 1)
    19  var ranMain bool
    20  
    21  func init() {
    22  	// emulate an exceedingly slow package initialization function
    23  	time.Sleep(100 * time.Millisecond)
    24  	initCh <- 42
    25  }
    26  
    27  func main() { ranMain = true }
    28  
    29  //export DidInitRun
    30  func DidInitRun() bool {
    31  	select {
    32  	case x := <-initCh:
    33  		if x != 42 {
    34  			// Just in case initCh was not correctly made.
    35  			println("want init value of 42, got: ", x)
    36  			syscall.Exit(2)
    37  		}
    38  		return true
    39  	default:
    40  		return false
    41  	}
    42  }
    43  
    44  //export DidMainRun
    45  func DidMainRun() bool { return ranMain }
    46  
    47  //export CheckArgs
    48  func CheckArgs() {
    49  	if len(os.Args) != 3 || os.Args[1] != "arg1" || os.Args[2] != "arg2" {
    50  		fmt.Printf("CheckArgs: want [_, arg1, arg2], got: %v\n", os.Args)
    51  		os.Exit(2)
    52  	}
    53  }