Chuỗi bài: Go
go
58 dòng
· Cập nhật 2026-04-18
main.go
Go/part1-language/examples/03_lexical/main.go
// Demonstrates lexical basics: package, imports, declarations, iota, zero values.
package main
import (
"fmt"
"strings"
)
const (
appName = "lexical-demo"
appVersion = "1.0.0"
)
type Weekday int
const (
Sunday Weekday = iota
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
)
func (w Weekday) String() string {
return [...]string{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}[w]
}
func main() {
var x int
var y = 3.14
z := "go"
a, b := 1, true
fmt.Println("zero int:", x)
fmt.Println("inferred float:", y)
fmt.Println("short decl:", z, a, b)
fmt.Printf("%s v%s on %s\n", appName, appVersion, strings.ToUpper("ready"))
for d := Sunday; d <= Saturday; d++ {
fmt.Printf("%d=%s ", d, d)
}
fmt.Println()
var (
s []int
m map[string]int
p *int
)
fmt.Println("nil slice len:", len(s))
fmt.Println("nil map ok read:", m["missing"])
fmt.Println("nil ptr:", p)
s = append(s, 10, 20, 30)
fmt.Println("after append:", s)
}
Bài viết liên quan
Go
go
Cập nhật 2026-04-18
main.go
main.go — go source code from the Go learning materials (Go/Baasid/cmd/hashpw/main.go).
Đọc bài viết →
Go
go
Cập nhật 2026-04-18
main.go
main.go — go source code from the Go learning materials (Go/Baasid/cmd/server/main.go).
Đọc bài viết →
Go
go
Cập nhật 2026-04-18
docs.go
docs.go — go source code from the Go learning materials (Go/Baasid/docs/docs.go).
Đọc bài viết →
Go
go
Cập nhật 2026-04-18
jwt.go
jwt.go — go source code from the Go learning materials (Go/Baasid/internal/auth/jwt.go).
Đọc bài viết →
Go
go
Cập nhật 2026-04-18
password.go
password.go — go source code from the Go learning materials (Go/Baasid/internal/auth/password.go).
Đọc bài viết →
Go
go
Cập nhật 2026-04-18
password_test.go
password_test.go — go source code from the Go learning materials (Go/Baasid/internal/auth/password_test.go).
Đọc bài viết →