\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{char1010101010} \pdfinfo{ /Title (go.pdf) /Creator (Cheatography) /Author (char1010101010) /Subject (Go Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{000000} \definecolor{LightBackground}{HTML}{F7F7F7} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Go Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{char1010101010} via \textcolor{DarkBackground}{\uline{cheatography.com/183653/cs/38233/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}char1010101010 \\ \uline{cheatography.com/char1010101010} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 16th April, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{WaitGroups}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{func generateRandomNumber(ch chan\textless{}- int, id int, wg *sync.WaitGroup) \{ \newline defer wg.Done() \newline \newline \seqsplit{rand.Seed(time.Now().UnixNano()} + int64(id)) \newline randomNumber := rand.Intn(100) \newline \newline ch \textless{}- randomNumber \newline \} \newline \newline func main() \{ \newline var wg sync.WaitGroup \newline ch := make(chan int, 100) \newline \newline runtime.GOMAXPROCS(3) \newline \newline for i := 1; i \textless{}= 100; i++ \{ \newline wg.Add(1) \newline go generateRandomNumber(ch, i, \&wg) \newline \} \newline \newline go func() \{ \newline wg.Wait() \newline close(ch) \newline \}() \newline \newline for randomNumber := range ch \{ \newline \seqsplit{fmt.Println(randomNumber)} \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Arrays}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{func mean(tab {[}5{]}int) (meanVal float64) \{ \newline // for index, value := range collection \newline for \_, value := range tab \{ \newline meanVal+= (float64)(value) \newline \} \newline meanVal /= (float64)(len(tab)) \newline return \newline \} \newline \newline func main() \{ \newline var table = {[}5{]}int\{3, 4, 8, 9, 2\} \newline m := mean(table) // pass by value \newline fmt.Printf("result= \%f\textbackslash{}n", m) \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Maps}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{func main() \{ \newline m := make(map{[}string{]}int) \newline \newline m{[}"k1"{]} = 7 \newline m{[}"k2"{]} = 13 \newline \newline fmt.Println("map:", m) //map: map{[}k1:7 k2:13{]} \newline \newline v1 := m{[}"k1"{]} \newline fmt.Println("v1:", v1) //v1: 7 \newline \newline v3 := m{[}"k3"{]} \newline fmt.Println("v3:", v3) //v3: 0 \newline \newline fmt.Println("len:", len(m)) //len: 2 \newline \newline delete(m, "k2") \newline fmt.Println("map:", m) //map: map{[}k1:7{]} \newline \newline \_, prs := m{[}"k2"{]} //second return val to see if key is present \newline fmt.Println("prs:", prs) //prs: false \newline \newline n := map{[}string{]}int\{"foo": 1, "bar": 2\} \newline fmt.Println("map:", n) //map: map{[}bar:2 foo:1{]} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Method}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{func (pt {\emph{Point) norm() float64 \{ \newline return math.Sqrt(pt.x}}pt.x + pt.y*pt.y) \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Range}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{for i, num := range nums \{ \newline fmt.Println("index: ", i, " num: ", num) \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Range}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{for i, num := range nums \{ \newline fmt.Println("index: ", i, " num: ", num) \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Iota}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{const ( \newline ON = iota \newline OFF = iota // optional here \newline OTHER = iota \newline ) \newline fmt.Println(ON, OFF, OTHER) // Will print: 0 1 2} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Functions as Parameters}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{func main() \{ \newline a := Point\{2.,4.\} \newline b := Point\{5.,9.\} \newline dist := calc(a,b,Distance) \newline fmt.Printf("result= \%f\textbackslash{}n", dist) \newline dist = calc(a,b, \newline func(p Point, q Point)float64\{ \newline return \seqsplit{math.Abs(p.x-q.x)+math.Abs(p.y-q.y)} \newline \}) \newline fmt.Printf("result= \%f\textbackslash{}n", dist) \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Pointers and Structs}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{type Point struct \{ \newline x int \newline y int \newline \} \newline \newline func main() \{ \newline pt := Point\{8, 1\} \newline complement(\&pt) \newline fmt.Printf("Result= \%d and \%d\textbackslash{}n", pt.x , pt.y) \newline \} \newline \newline func complement(p *Point) \{ \newline p.x, p.y = -p.y, -p.x \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Slices}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{func main() \{ \newline s := make({[}{]}string, 3) \newline fmt.Println("emp:", s) //emp: {[} {]} \newline \newline s{[}0{]} = "a" \newline s{[}1{]} = "b" \newline s{[}2{]} = "c" \newline fmt.Println("set:", s) //set: {[}a b c{]} \newline fmt.Println("get:", s{[}2{]}) //get: c \newline \newline fmt.Println("len:", len(s)) //len: 3 \newline \newline s = append(s, "d") \newline s = append(s, "e", "f") \newline fmt.Println("apd:", s) //apd: {[}a b c d e f{]} \newline \newline c := make({[}{]}string, len(s)) \newline copy(c, s) \newline fmt.Println("cpy:", c) //cpy: {[}a b c d e f{]} \newline \newline l := s{[}2:5{]} \newline fmt.Println("sl1:", l) //sl1: {[}c d e{]} \newline \newline l = s{[}:5{]} \newline fmt.Println("sl2:", l) //sl2: {[}a b c d e{]} \newline \newline l = s{[}2:{]} \newline fmt.Println("sl3:", l) //sl3: {[}c d e f{]} \newline \newline t := {[}{]}string\{"g", "h", "i"\} \newline fmt.Println("dcl:", t) //dcl: {[}g h i{]} \newline \newline twoD := make({[}{]}{[}{]}int, 3) \newline for i := 0; i \textless{} 3; i++ \{ \newline innerLen := i + 1 \newline twoD{[}i{]} = make({[}{]}int, innerLen) \newline for j := 0; j \textless{} innerLen; j++ \{ \newline twoD{[}i{]}{[}j{]} = i + j \newline \} \newline \} \newline fmt.Println("2d: ", twoD) //2d: {[}{[}0{]} {[}1 2{]} {[}2 3 4{]}{]} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}