Jorgen's blog Jorgen's blog
首页
  • 平台架构
  • 混合式开发记录
  • 推送服务
  • 数据分析
  • 实时调度
  • 架构思想

    • 分布式
  • 编程框架工具

    • 编程语言
    • 框架
    • 开发工具
  • 数据存储与处理

    • 数据库
    • 大数据
  • 消息、缓存与搜索

    • 消息队列
    • 搜索与日志分析
  • 前端与跨端开发

    • 前端技术
    • Android
  • 系统与运维

    • 操作系统
    • 容器化与 DevOps
  • 物联网与安全

    • 通信协议
    • 安全
    • 云平台
newland
  • 关于我
  • 终身学习
  • 关于时间的感悟
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

jorgen

Love it, make mistakes, learn, keep grinding.
首页
  • 平台架构
  • 混合式开发记录
  • 推送服务
  • 数据分析
  • 实时调度
  • 架构思想

    • 分布式
  • 编程框架工具

    • 编程语言
    • 框架
    • 开发工具
  • 数据存储与处理

    • 数据库
    • 大数据
  • 消息、缓存与搜索

    • 消息队列
    • 搜索与日志分析
  • 前端与跨端开发

    • 前端技术
    • Android
  • 系统与运维

    • 操作系统
    • 容器化与 DevOps
  • 物联网与安全

    • 通信协议
    • 安全
    • 云平台
newland
  • 关于我
  • 终身学习
  • 关于时间的感悟
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • Go学习指南
  • Golang入门
    • Go youtube booking-app
      • Basic Info
    • first code
      • hello world
    • Variable
      • printf
    • Data Types
    • Get user input
    • Array
    • Slice
    • Loops
    • Condition
    • Functions
    • goroutine
    • Waitgroup
  • DS&A
  • 算法碎碎念
  • 编程语言范式:理解编程的思维模式
  • 并发编程模型 - 现代软件开发的核心能力
  • 并发编程模型-跨越语言的并行艺术
  • 类型系统-编程语言的骨架与灵魂
  • 类型系统探秘:编程语言的灵魂架构
  • 类型系统探秘:编程语言的骨架与灵魂
  • 编程语言的内存管理与垃圾回收机制
  • 编程语言类型系统-类型背后的哲学
  • 编程语言设计原理 - 构建高效表达的工具
  • 编程语言设计原理与实现 - 从想法到代码的艺术
  • 编程语言设计原理与实现 - 构建你自己的语言
  • 编程语言选择指南:找到最适合你的技术栈
  • 静态类型与动态类型:编程语言的两条路
  • 编程语言解释器与编译器原理-从源码到执行的旅程
  • 函数式编程范式-编程中的数学思维
  • 编程语言的测试与调试技术-构建可靠软件的基石
  • 编程语言的语法设计与解析技术-构建优雅表达的艺术
  • 元编程与反射机制-编程语言的自我审视与重塑艺术
  • 编程语言学习方法与认知过程-掌握多语言思维的钥匙
  • 编程语言的互操作性-跨越语言边界的无缝协作
  • 编程语言的错误处理机制-从异常到错误码的哲学思考
  • 编程语言的性能优化技术-从代码到执行的效率革命
  • 渐进式类型系统-静态与动态的完美融合
  • 编程语言的包管理与依赖系统-构建现代软件开发的基石
  • 编程语言的演化历史与未来趋势-从机器码到AI时代的语言革命
  • 编程语言的异步编程模型-现代应用开发的加速器
  • programming_languages
Jorgen
2023-12-31
目录

Golang入门

# Go youtube booking-app

# Basic Info

  1. 2007 google 2009 open source

go

  1. use cases

    1. for performant applications
    2. runing on scaled distributed systems
  2. characterics

    1. simple syntax, Easy to learn read and write code
    2. fast build time start up and run
    3. require fewer resources
    4. faster than interpreted languages like python
    5. consistent across different os
  3. install

  4. vscode:go extension Go team at Google

# first code

# hello world

  1. init module go mod init <module path>
  2. all our code must belong to **packages — the first statement in Go file must be ‘package…’**
  3. the “main function” is the entrypoint of a Go program
  4. A program can only have 1 main function because you can only have 1 entrypoint
  5. Go packages:
    1. Go programs are organized into packages
    2. Go’s standard library, provides different core packages for us to use
    3. ‘fmt’ is one of these, which you can use by importing it
    4. a package is a collection of source files
  6. go run <file name> = compiles and runs the code

# Variable

  1. Variable must be used
  2. Constants are like variables, except their values cannot be changed.

# printf

pkg.go.dev/fmt:print formatted data

  • It takes a template string that contains the text that need be formatted.
  • plus some annotation verbs(placeholder) that tells the fmt functions how to format the variable passed in.

# Data Types

Go is a statically typed language

  • you need to tell go compiler, the data type when declaring the variable
  • Type Inference: BUT Go can infer the type when you assign a value
Go Java
int8 byte
int16 short
int32 int
int64 long

sytactic suger in Programming

  • a term to describe a feature in a language that let you do smth more easily
  • make the language ‘sweeter’ to human use
  • But doesn’t add any new functionality that it didn’t already have

# Get user input

fmt → formatted Input and Output(I/O)

  • Print Messages
  • Collect User Input
  • Write into a File

Pointer

  • A pointer is a variable that points to the memory address of another variable
  • a special variable

# Array

  • Fixed Size how many elements the array can hold
  • Only the same data type can be stored.
var variable_name [size]data_type
1

# Slice

  • Slice is an abstraction of the array
  • Slices are more flexible and powerful: variable-length or get an sub-array of its own
  • Slices are also index-based and have a size, but is resized when needed

append

  • Adds the element at the end of the slice
  • Grows the slice if a greater capacity is needed and return the updated slice value

# Loops

  • In general, Languages provide various control structures to control the application flow
  • a loop statement allows us to execute code multiple times, in a loop
  • only have ‘for’ loop

Range

  • Range iterates over elements for different data structures (so not only arrays and slices)
  • For arrays ans slices, range provides the index and value for each element.

string.Fields()

  • Splits the string with white space as separator
  • And return a slice with the split elements

Blank identifier

  • to ignore a variable you don’t want to use
  • So with Go you need to make unused variables explicit

# Condition

if statement {}

break statement

  • Terminate the for loop
  • And continues with the code right after the for loop

continue statement

  • Cause loop to skip the remainder of its body
  • And immediately retesting its condition

switch statement

  • allows a variable to be tested for equality against a list of values
  • default handle the case, if not match is found

# Functions

  • Encapsulate code into own container which logically belong together

  • Like variable name, you should give a funtion a descriptive name

  • call the function by its name, whenever you want to execute this block of code

  • every program has at least one funtion, which is the main() function

  • Funtion is only executed when called

  • you can call a function as many times you want

  • so funtion is also used to reduce code duplication

parameters

  • information can be passed into funtions as parameters
  • parameters are also call arguments

Mutiple packages

exporting a variable

  • make it avaiable for all packages in the app
  • Capitalize first letter

3 level of scope

local

  • declaration within function → can be used only with that function
  • declaration within block → can be used only within that block

package

  • declaration outside all funtions → can be used everywhere in the same package

global

  • declaration outside all functions & uppercase first letter → can be used everywhere across all packages

variable scope

scope is the region of a program, where a defined variable can be accessed

maps

  • maps unique keys to values
  • you can retrieve the value by using its key later
  • all keys have same data types — all values have same data types

struct

the type keyword creates a new type, with the name you specify

In fact, you can create a type based on every other data type like int, string etc

# goroutine

concurrency

go keyword

  • “go…” starts a new goroutine
  • A goroutine is a lightweight thread managed by Go runtime

# Waitgroup

  • wait for the launched goroutine to finish
  • Package “sync” provides basic synchronization functionality
  • Add: sets the number of goroutines to wait for (increases the counter by the provided number)
  • Wait: Blocks until the WaitGroup counter is 0
  • Done: decrements the WaitGroup counter by 1 so this is called by the goroutine to indicate that its finished

built-in functionality for goroutine to talk with one another

comparison to other languages

| writing concurrent code | writing concurrent code is more complex

more overhead
Threads vs Goroutines
heavyweight and needs more hardware resources

why? what is the different?

#go
上次更新: 2026/01/28, 13:30:02
Go学习指南
DS&A

← Go学习指南 DS&A→

最近更新
01
LLM
01-30
02
intro
01-30
03
intro
01-30
更多文章>
Theme by Vdoing | Copyright © 2019-2026 Jorgen | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式