Skip to content

Go

cotrVarBool

Go Create Boolean Variable

var ${1:variableName} bool = ${2:variableValue}

cotrGenList

Go Generate Array

var ${1:arrayName} = []${2:arrayType}{
${3:value1},
${4:value2}
}

cotrTernary

Go Ternary Operator

${1:condition} ? ${2:trueValue} : ${3:falseValue}

cotrPrintMulti

Go Print Multi

fmt.Println(`
${1:Line 1}
${2:Line 2}
${3:Line 3}
`)

cotrEntry

Go Entry Point

// Go Entry Point
// To run this program, use: `go run filename.go`
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}

cotrTypesNum

Go Float Type

float64

cotrInterpolate

Go Interpolate String

`${1:string}`

cotrVarList

Go Create List Variable

var ${1:variableName} = []${2:variableType}{
${3:value1},
${4:value2}
}

cotrConst

Go Create Constant

const ${1:variableName} ${2:variableType} = ${3:variableValue}

cotrForRangeLoop

Go For…Range Loop

for ${1:index}, ${2:value} := range ${3:iterable} {
${4:// Your code here}
}

cotrIfElse

Go If Else Statement

if ${1:condition} {
${2:// Your code here}
} else if ${3:condition} {
${4:// Your code here}
} else {
${5:// Your code here}
}

cotrTypeCompare

Go Type Comparison

// Check if two variables have the same type:
if reflect.TypeOf(${1:variable1}) == reflect.TypeOf(${2:variable2}) {
// Your code here
}

cotrTypes

Go Types

$BLOCK_COMMENT_START
Go is a statically typed language.
Types in Go include:
- int, int8, int16, int32, int64: Signed integers
- uint, uint8, uint16, uint32, uint64: Unsigned integers
- float32, float64: Floating-point numbers
- complex64, complex128: Complex numbers
- byte: Alias for uint8
- rune: Alias for int32 (represents a Unicode code point)
- string: String
- bool: Boolean
- [10]int: Array of integers with fixed size 10
- []int: Slice of integers
- map[K]V: Map with key type K and value type V
- struct { Field1 int; Field2 string; }: Custom data structure with named fields
- interface{}: Interface type representing any type
- chan int: Channel for sending and receiving integers
- func(int) string: Function type taking an int and returning a string
- error: Interface type for error handling
$BLOCK_COMMENT_END

cotrTypesDateNow

Go Date Now

time.Now()

cotrConcat

Go Concatenate Strings

${1:string1} + ${2:string2}

cotrFuncArgs

Go Function Args

// In Go, functions do not support default argument values in definitions.
func ${2:MyFunction}(${3:arg1} ${4:type1}, ${5:arg2} ${6:type2}) ${1:void} {
${7:// Your code here}
}

cotrTypesInt

Go Integer Type

int

cotrTypesList

Go List Type

[]${1:type}

cotrTypesDynamic

Go Dynamic Type

interface{}

cotrEnum

Go Iota

const (
${1:variable1} = iota
${2:variable2}
${3:variable3}
// Add more variables here
)

cotrTypeCheck

Go Type Check

fmt.Printf("%T", ${1:variable})

cotrVar

Go Create Variable

var ${1:variableName} ${2:variableType} = ${3:variableValue}

cotrVarDate

Go Create Date Variable

// import "time"
var ${1:myDate} = time.Date(${2:year}, time.${3:Month}, ${4:day}, ${5:0}, ${6:0}, ${7:0}, ${8:0}, time.UTC)

cotrWhileLoop

Go While Loop

for ${1:condition} {
${2:// Your code here}
}

cotrFuncSyntax

Go Function Syntax

// Go Function Syntax
// Basic function: func FunctionName(parameters) returnType { ... }
// Function with arguments: func FunctionName(arg1 type1, arg2 type2, ...) returnType { ... }
// Note: Go does not support named arguments in function definitions.

cotrVarInt

Go Create Integer Variable

var ${1:variableName} int = ${2:variableValue}

cotrPrint

Go Print

fmt.Println(${1:message})

cotrFuncAnon

Go Anonymous Function

var ${1:myFunc} = func(${2:parameters}) ${3:returnType} {
${4:// Your code here}
return ${5:value}
}
// Usage
${1:myFunc}(${6:arguments})

cotrTypeConvert

Go Type Conversion

// Go Type Conversion:
// Explicit conversions (using type assertion):
// - targetType(variable) // Type assertion (can panic if conversion fails)
// Conversion functions:
// - strconv.Itoa(int) // Converts int to string
// - strconv.Atoi(string) // Converts string to int
// - ... (Various conversion functions in strconv and other packages)
// Note:
// - Be cautious with type assertions, as they can lead to panics if the conversion is not valid.

cotrTypesString

Go String Type

string

cotrTypesMap

Go Map Type

map[${1:keyType}]${2:valueType}

cotrTypesNull

Go Null Type

nil

cotrVarNullable

Go Create Nullable Variable

var ${1:myVar} *${2:Type} = $3

cotrTypesBoolFalse

Go Boolean False

false

cotrStructure

Go Project Structure (High-Level)

// Recommended High-Level Go Project Structure:
// - cmd/
// - Contains the main applications for the project.
// - Each application has its own subdirectory.
// - For example, if your project has two main applications, 'webserver' and 'datasync',
// you might have cmd/webserver/ and cmd/datasync/ directories.
// - pkg/
// - Contains library code that's ok to use by external applications.
// - Other projects will import these libraries.
// - internal/
// - Contains private application and library code.
// - The code here is not intended to be used by other applications.
// - api/
// - Contains the API definitions for the project.
// - For example, OpenAPI/Swagger specs, Protocol Buffers files.
// - web/
// - Contains web application specific components: static files, templates, etc.
// - scripts/
// - Contains scripts that perform various build, install, analysis, etc operations.
// - configs/
// - Contains configuration files.
// - deployments/
// - Contains configuration and scripts for deploying the application.
// - test/
// - Contains additional external test apps and test data.
// - It might also include test utilities.
// Note:
// - This structure is particularly common in larger projects or projects that produce
// multiple executables.
// - Smaller projects might have a simpler structure.

cotrVarMultiString

Go Create Multi-line String Variable

var ${1:variableName} = `
${2:Line 1}
${3:Line 2}
${4:Line 3}
`

cotrSwitch

Go Switch Statement

switch ${1:variable} {
case ${2:value1}:
${3:// Your code here}
break
case ${4:value2}:
${5:// Your code here}
break
default:
${6:// Your code here}
}

cotrFuncArgsNamed

Go Function Named Args

// Go does not support named arguments in function definitions.

cotrOperatorsBool

Go Boolean Operators

// Go Boolean Operators:
// Logical AND: &&
// Logical OR: ||
// Logical NOT: !
// Equality: ==
// Inequality: !=
// Greater than: >
// Less than: <
// Greater than or equal to: >=
// Less than or equal to: <=

cotrVarTyped

Go Create Typed Variable

var ${1:myVar} ${2:Type} = $3

cotrVarString

Go Create String Variable

var ${1:variableName} string = ${2:variableValue}

cotrInfo

Go Info

Typing: Statically typed
Paradigm: Multi-paradigm: procedural, concurrent
Compilation: Compiled
Concurrency: Built-in support for concurrency with goroutines and channels

cotrGenMap

Go Generate Map

var ${1:mapName} = make(map[${2:keyType}]${3:valueType})
${1:mapName}[${4:key1}] = ${5:value1}
${1:mapName}[${6:key2}] = ${7:value2}

cotrThrow

Go Throw Exception

panic('Your message here')

cotrNotEqual

Go Not Equal To

!=

cotrTypesBool

Go Boolean Type

bool

cotrTypesDate

Go Date Type

time.Time

cotrForLoop

Go For Loop

for ${1:i} := ${2:0}; $1 < ${3:10}; $1++ {
${4:// Your code here}
}

cotrCommentMulti

Go Multi-line Comment

/*
* ${1:comment}
*/

cotrTryCatch

Go Try Catch

defer func() {
if r := recover(); r != nil {
${1:// Your code here}
}
}()
${2:// Your code here}

cotrOperators

Go Mathematical Operators

// Go Mathematical Operators:
// Addition: +
// Subtraction: -
// Multiplication: *
// Exponentiation: **
// Division: /
// Modulus: %
// Increment: ++
// Decrement: --
// Assignment: =
// Addition assignment: +=
// Subtraction assignment: -=
// Multiplication assignment: *=
// Division assignment: /=
// Modulus assignment: %=

cotrEqual

Go Equal To

==

cotrVarSyntax

Go Variable Declaration Syntax

// Go Variable Declaration Syntax:
// - var: (Scope: Block or Package)
// - Explicitly declare the variable's type.
// - Can be declared without initialization (zero value is assigned).
// - :=: (Scope: Block)
// - Short variable declaration and type inference.
// - Requires initialization.
// - const: (Scope: Package)
// - Cannot be reassigned or redeclared.
// - Use for values that should remain constant.
// Note:
// - Use 'var' for package-level variables or when explicit type declaration is desired.
// - Use ':=' for most variable declarations within blocks.
// - Use 'const' for values that are known at compile time.

cotrClass

Go Struct

type ${1:MyStruct} struct {
${2:field1} ${3:type1}
${4:field2} ${5:type2}
// Add more fields here
}

cotrVarMap

Go Create Map Variable

var ${1:mapName} = map[${2:keyType}]${3:valueType}{
${4:key1}: ${5:value1},
${6:key2}: ${7:value2}
}

cotrFunc

Go Function

func ${2:MyFunction}(${3:parameters}) ${1:void} {
${4:// Your code here}
}

cotrIf

Go If Statement

if ${1:condition} {
${2:// Your code here}
}

cotrTypesBoolTrue

Go Boolean True

true

cotrVarNum

Go Create Float Variable

var ${1:variableName} float64 = ${2:variableValue}

cotrComment

Go Comment

// ${1:comment}