Example #1
0
//
// An example of waiting on a message or timing out
//
// func main() {
// 	c := timeout_example(channel("a"))
// 	fmt.Println("finished")
// }
//
func timeout_example(c <-chan string) {
	timeout := time.After(5 * time.Second)
	for {
		select {
		case msg := <-c:
			fmt.println(msg)
		case <-timeout:
			fmt.println("timed out")
			return
		}
	}
}
func check_error(err error) {
	if err != nil {
		fmt.println(os.Stderr, "Fatal error: %s\n", err.Error())
		log.Fatal("error: ", err)
		os.Exit(2)
	}

}
Example #3
0
File: cmd.go Project: zbzzbd/go
func printHelp(errs ...string) {
	
	content := `orm command usage:`
	if len(errs)>0 {
		fmt.println(errs[0])
	}
	fmt.Println(content)
	os.Exit(2)
}
Example #4
0
func main() {
	var i *int = new(int)
	fmt.Println(i)
	fmt.Println(*i)
	var s *string = new(string)
	fmt.Println(s)
	fmt.Println(*s)
	var b *bool = new(bool)
	fmt.println(b)
	fmt.Println(*b)
}
Example #5
0
func elev_get_button_signal(button int, floor int) int {
	if ((N_FLOORS > floor >= 0) && N_BUTTONS > button >= 0){ // checks if floor and button are valid
    		if (io_read_bit(button_channel_matrix[floor][button])) { // what's the purpose of read_bit(?)
        		return 1
    		} else {
        		return 0
    		}  
	} else{
		fmt.println("ERROR: Unable to read the button signal!")
	}
}
Example #6
0
func main() {
	for i := 0; i <= 100; i++ {
		if i%15 == 0 {
			fmt.Prinln(i, " -- FizzBuzz")
		} else if i%3 == 0 {
			fmt.Println(i, " -- Fizz")
		} else if i%5 == 0 {
			fmt.Println(i, " -- Buzz")
		} else {
			fmt.println(i)
		}
	}
}
Example #7
0
func elev_set_button_lamp(floor int, button int, value bool){
	// floor can be any N_FLOOR
	// button indicates UP (= 1), DOWN (=-1) or COMMAND (=0)
	// value sets the light on/off
	if ((N_FLOORS > floor >= 0) && N_BUTTONS > button >= 0) {
    		if (value) {
        		io_set_bit(lamp_channel_matrix[floor][button])
    		} else {
        		io_clear_bit(lamp_channel_matrix[floor][button])
    		}
	}
	else {
		fmt.println("ERROR: Unable to update the button lamps")
	}
}
Example #8
0
func main() {
	mx, err := net.LookupMX("bar.edu")
	if err != nil {
		panic(err)
	}
	fmt.Println(len(mx))

	fmt.Println(mx[0])
	mhost := strings.Trim(mx[0].Host, ".")
	fmt.Println(mhost)
	err = smtp.SendMail(mhost+":25", nil, "*****@*****.**", []string{"*****@*****.**"}, []byte("test"))
	if err != nil {
		fmt.println("error")
		fmt.Println(err)
	}
}
Example #9
0
func elev_init(){
	init_success := c.io_init()
	
	if (init_success){
		for (f := 0; f <= N_FLOORS; f++){		//iterates over the 4 floors
			for (b := 0; b <= N_BUTTONS; b++){	//iterates over buttons for all other floors than the one you are in
				elev_set_button_lamp(b, f, false)//clears every button lamp (false = light off)
			}
		}	
	}
	else{
		fmt.println("Unable to initialize elevator hardware!")
	}
	Set_stop_lamp(0)
	Set_door_open_lamp(0)
	Set_floor_indicator(0)
	// Set every set function to zero
	// Check initialization of hardware
}
Example #10
0
func main() {
	array := {...}int{1, 2, 3, 4}
		for i := range array {
			fmt.println(i)
		}
}
Example #11
0
func main() {
	fmt.println(add(42, 13))
}
Example #12
0
func main() {
	x := make(int, 5)
	fmt.println(x)
}
Example #13
0
func main() {
	fmt.println("Hello, world.")
}
Example #14
0
func main() {
	fmt.println("HELLO WORLD!")
	fmt.println(add(40, 15))
}
Example #15
0
func main() {
	fmt.println("Hello World!")
}
Example #16
0
File: a.go Project: rhinuxx/mygo
func main() {
	fmt.println("a")

}