Golang Flashcards

1
Q

What is GO

A

Statically typed, compiled language. (Code is translated directly into machine code resulting in fast execution and performance)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

GO Key Features

A
  • Concurrency
  • Garbage collection
  • Strong standard library
  • Cross platform
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

GO: Garbage Collection

A

Automatically manages memory, freeing developers from manual memory management tasks and reducing the risk of memory leaks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

GO Standard Library

A

Includes packages for handling common tasks like I/O operations, web servers, and data serialization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

SQLC

A

Generates type safe GO code from SQL queries

  • Works by taking SQL queriers written by dev and converts it to Go code which includes methods to execute those queries
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

pgx

A

PostgreSQL driver and toolkit for GO

  • PostgreSQL client library for Go
  • provides functionalities for low level and high level interactions
  • allows you to connect to postgreSQL DB and execute a query
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Gin

A

Web framework in Go used to build high performance HTTP web apps and APIs

  • known for its speed and efficiency which can handle large number of requests with minimal overhead
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

tx

A

Abbreviation for transaction

  • represents an instance of a DB transaction
  • allows for grouping multiple DB operations into a single unit of work that can be committed or rolled back as a while
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

BindJSON

A

Binds JSON data from an HTTP request body to a GO struct

  • it reads the JSON payload from the request and populates the fields of the provided struct with the corresponding data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Key features of Gin

A
  • fast performance
  • routing (provides flexible routing system)
  • middleware (allows you to execute code before or after request handling)
  • JSON handling (binding JSON request payloads to GO structs and rendering JSON responses)
  • Error handling
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

GO Struct

A

Data type that groups together variables (fields) under a single name

  • Each field can have a diff type and are used to represent a collection of related data
  • Purpose: represent real world entities by grouping related data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

GO Interface

A

A type that specifies a contract of methods that a type must implement to satisfy the interface. It doesn’t hold data but describes behavior.

  • Purpose: defines a set of methods that a type MUST implement allowing diff types to be used interchangeably if they satisfy the interface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How SQLC works

A
  1. Write SQL
  2. Generate code, where go types, structs and query functions are created
  3. Use in Go
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

go_struct_tags

A

referenced in sqlc.yaml file

  • Allows you to customize the Go struct tags for fields generated by sqlc
  • Control how struct fields are processed when encoding, decoding or interacting with DBs

ex: you might want tags for DB column mapping, JSON serialization etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Interface

A

A type that defines a set of methods (behavior) but doesn’t provide the implementation for the methods

  • Defines what methods a type must have to satisfy the interface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

*gin.Context

A

in Gin is used to manage HTTP requests and responses, route parameters and middleware in web apps

17
Q

Parameterized Queries

A

Technique used when interacting with DBs to prevent SQL injection vulnerabilities

Instead of directly embedding user provided values into SQL query strings placeholders are used.

These placeholders are then replaced with the actual values at runtime by the DB driver

18
Q

GO modules

A

A collection of related GO packages that are versioned together as a single unit

standard way to manage dependencies in GO

19
Q

go.mod

A

defines the module and its dependencies

  • the main config file for go modules
  • the first line specifies the module name

ex: like package.json

** manually edited or via go mod commands

20
Q

go.sum

A

this file ensures the integrity and security of dependencies

  • it contains checksums (hashes) of module versions listed in the go.mod file

ex: like yarn.lock

** automatically managed by go

21
Q

fmt.Errorf

A

Function that allows you to create formatted error messages
- Returns an error with the formatted message