Getting started with Go — Continued

import "fmt"
import "time"
import (
"fmt"
"time"
)
var (name stringage intaddress stringmarried bool)
package main import "fmt"const (
name string = "Matthew"
)
func main(){
fmt.Println(name)
}
func HelloWorld(){fmt.Println("hello, world!")
}
  • Notice the capitalisation of the function name, this means that the function is exported, this is similar to the premise of public and private methods. If the variable / function starts with a lower case, then it is a private method and can only be used in that package. However, if it is a capitalised name, like HelloWorld, we can use this else where.
func incrementByOne(number int){    number += 1    fmt.Println(number)}
func incrementByOne(number int) int{    number += 1    return number}
func incrementByOne(number, test int) (int, int) {    number += 1    return number, test}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matthew Boyd

Matthew Boyd

Learning, and posting my findings!