0% found this document useful (0 votes)
71 views

Notes Golang Part 1

The document provides instructions for setting up a Go module, running Go code, importing packages, declaring and assigning variables, printing variables, and converting variables between types. It explains how to initialize a Go module, import packages for formatting text and retrieving quotes, run code using go run, see Go commands with go help, download external packages with go mod tidy, declare and assign variables, print variables using printf, and convert an int to a string using strconv.Itoa().

Uploaded by

Ender Troller
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Notes Golang Part 1

The document provides instructions for setting up a Go module, running Go code, importing packages, declaring and assigning variables, printing variables, and converting variables between types. It explains how to initialize a Go module, import packages for formatting text and retrieving quotes, run code using go run, see Go commands with go help, download external packages with go mod tidy, declare and assign variables, print variables using printf, and convert an int to a string using strconv.Itoa().

Uploaded by

Ender Troller
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

write line in your directory on command prompt

$ go mod init moduleName


__________________________________________________

Declare package main to able to import all go package

import "fmt" contains functions for formatting text

__________________________________________________

To run code write line in terminal


$ go run .

__________________________________________________

To see all the go command write line in terminal


$ go help

__________________________________________________

importing external package resc.io/quote is


for beautifying printed message

run line to download external package


$ go mod tidy

___________________________________________________

Declaring variable

var var_name var_type

ex

var x int

___________________________________________________

Assign variable in declaration

var x int = 2

Shortcut to assign variable value and declaration


at once

x := 2

___________________________________________________

Printing with printf

x := 2
fmt.Printf("%v, %T", x, x)

notes
%v = value of the variable
%T = type of the variable

___________________________________________________
Converting int to string

import "strconv" libraries

use "strconv.Itoa()" functions

i := 32
var j string
j = strconv.Itoa(i)

You might also like