Golang: Function declaration and how to Call


Golang has unique way to declare and call function, here is my example regarding Basic Golang Function Declaration and Call (link) :

package main

import (
    "fmt"
)

var (
    function1 = func() {
        fmt.Println("Hello function1")
    }

    function2 = func() {
        fmt.Println("Hello function2")
    }
)

var function3 = func() {
    fmt.Println("Hello function3")
}

func function4() {
    fmt.Println("Hello function4")
}

func main () {
    function5 := func() {
        fmt.Println("Hello function5")

        crazy := func() {
            fmt.Println("Crazy function")

            superCrazy := func() {
                fmt.Println("Super Crazy function")
            }

            superCrazy()
        }

    crazy()

    }

    function1()
    function2()
    function3()
    function4()
    function5()
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s