Go는 Google에서 개발한 단순하고 효율적인 프로그래밍 언어입니다. 강력한 동시성 지원과 빠른 컴파일 속도로 클라우드 인프라와 백엔드 개발에 널리 사용됩니다.
Go is a simple and efficient programming language developed by Google. It's widely used for cloud infrastructure and backend development due to its powerful concurrency support and fast compilation.
기본 구조 Basic Structure
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}
변수와 타입 Variables and Types
var name string = "Go"
var age int = 15
// 짧은 선언 (:=)
count := 10
isActive := true
// 상수
const Pi = 3.14159
var name string = "Go"
var age int = 15
// Short declaration (:=)
count := 10
isActive := true
// Constants
const Pi = 3.14159
Goroutine과 Channel Goroutine and Channel
Go의 가장 강력한 기능인 동시성 프로그래밍입니다.
goroutine은 경량 스레드이고, channel은 goroutine 간 통신 수단입니다.
Go's most powerful feature for concurrent programming.
goroutine is a lightweight thread, and channel is for communication
between goroutines.
go doWork()
// Channel 생성
ch := make(chan int)
// Channel로 데이터 전송
go func() {
ch <- 42
}()
// Channel에서 데이터 수신
result := <-ch
go doWork()
// Channel 생성
ch := make(chan int)
// Channel로 데이터 전송
go func() {
ch <- 42
}()
// Channel에서 데이터 수신
result := <-ch
에러 처리 Error Handling
Go는 예외 대신 명시적인 에러 반환을 사용합니다.
Go uses explicit error returns instead of exceptions.
if b == 0 {
return 0, errors.New("division by zero")
}
return a / b, nil
}
result, err := divide(10, 2)
if err != nil {
fmt.Println("Error:", err)
return
}
if b == 0 {
return 0, errors.New("division by zero")
}
return a / b, nil
}
result, err := divide(10, 2)
if err != nil {
fmt.Println("Error:", err)
return
}
구조체와 인터페이스 Struct and Interface
type User struct {
ID int
Name string
}
// 메서드
func (u User) Greet() string {
return "Hello, " + u.Name
}
// 인터페이스
type Greeter interface {
Greet() string
}
type User struct {
ID int
Name string
}
// Method
func (u User) Greet() string {
return "Hello, " + u.Name
}
// Interface
type Greeter interface {
Greet() string
}
💡 Go 타자 연습 팁 💡 Go Typing Practice Tips
Go의 독특한 문법인 :=, <-, func,
go
키워드에 익숙해지세요.
특히 goroutine과 channel 패턴을 반복 연습하면 동시성 코드를 더 빠르게 작성할 수 있습니다.
Get familiar with Go's unique syntax like :=,
<-,
func, and go keywords.
Practicing goroutine and channel patterns helps write concurrent code
faster.
