> For the complete documentation index, see [llms.txt](https://openai.gitbook.io/code-cheatsheets/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openai.gitbook.io/code-cheatsheets/all/go.md).

# README

## Go

Playground: [play.golang.org](https://github.com/jsfuentes/Code-Cheatsheet/tree/cfa54859c01d276d596fdd857a971a04980468a2/Go/play.goland.org)

### Overview

* Compiled exec OS specific and have statically linked runtime(contains all needed libs)
* Custom types can implement interfaces and have methods
* Custom structs have member fields
* GO's class with no inheritance, no constructors, no generics(operator overloading), no exception handling, no implicit numeric conversions
* Next-gen succient C&#x20;
* Garbage Collection, mem reclaimed when objects out of scope of set to nil very fast
* Scopes to blocks&#x20;
* Great concurrency(Goroutine, channel, select)&#x20;

#### CLI

`go run [file]`

`go build [file]`

`godoc [package]` ie. `godoc fmt` gives you all exported functions and comments

`gofmt -w [file]` To override and format file

### Hello World

```go
package main

import(
  "fmt"
  "strings"
)

func main() {
  fmt.Println("Hello from Go!")
  fmt.Println(strings.ToUpper("Hello really loud"))
}
```

Exported fts and fields have initial upper-case character

starting brace must be on same line

*builtin* package

## Workspace

Needed to have multi-files and install libs

### Setup

Make the following dir struct:

\[folder]

​ bin #for exec

​ pkg #for intermediate

​ src

​ \[package name]

​ \[filename].go

Then `export GOPATH=[folder path]`

Startup file has `package main` at top and a `func main`

Now `go install` in the \[package name] folder will create stuff in bin

`go install [package name]` will work anywhere and install package

### Packages

All files in a package must use the same *name*

under src>stringutil>stringutil.go

```go
package stringutil

func FullName(s, l) {
    //....
}
```

In other package

```go
package main

import (
    "stringutil"
)

func main() {
    author := stringutil.FullName("Jorge", "Fuentes")
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://openai.gitbook.io/code-cheatsheets/all/go.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
