Skip to content

walterfan/kata-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kata-go

Kata should be called "routine" in Chinese. The secret of practicing martial arts is to master various routines.

First, you must learn from the strengths of hundreds of schools and be familiar with the routines of various schools in the world. Only then can you integrate them and achieve the state of no moves being better than moves.

Dave Thomas - the author of "The Pragmatic Programmer", proposed the idea of ​​Code Kata. Dave also collected a small practice project on his website (http://codekata.com/).

As a professional programmer, I hope to practice some routines that can be often used in work, such as some small routines for file modification, image cutting, and network sending and receiving, so I will organize and collect some routines here.

Kata

  1. cron-service.go: demostration of how to implement cron job
  2. encoding_tool: demostrate how to implement encoding command line tool by cobra library
  3. ds_web_console: demostrate how to call deep seek api and provide a web console by gin library
  4. ata-auth: demostrate how to implement a simple auth system by casbin
  5. list_files.go: demostrate how to list files in a directory
  6. links.go: demostrate how to use http client to get links from a web page
  7. llm-agent-go: demostrate how to implement a simple llm agent by gin and vue.js
  8. prompt_service: demostrate how to implement a simple prompt management service by gin and gorm with sqlite db
  9. prompt_service_v2: add login and metrics endpoint for prompt management service
  10. service-monitor: demostrate how to monitor a backend service with prometheus exportor
  11. simple-ai-agent: demostrate how to use function calling and tools of openai
  12. unix_socket: demostrate how to use unix socket to communicate with backend service

Cheat sheet of golang

Go tutorial

Go Tools

build and run

go build xxx.go
go run xxx.go

check dependency

go list, go get, go mod xxx

go mod init my_project
go mod tidy

format code

go fmt, gofmt

Debug

dlv debug main.go

documentation

go doc, godoc

go install github.com/swaggo/swag/cmd/swag@latest
swag init

unit test

# Run all tests with verbose output for entire project
go test -v ./...

# Run tests in specific package with verbose output
go test -v ./internal/cmd

# Run specific test function
go test -v ./internal/cmd -run Test_Metrics

# Run tests matching a pattern
go test -v ./internal/cmd -run "Test.*eks.*"

# Run tests with regex pattern
go test -v ./internal/cmd -run "^TestMonitor.*"

# Skip specific tests
go test -v ./internal/cmd -skip "TestFileSync"

# Skip multiple test patterns
go test -v ./internal/cmd -skip "TestFileSync|TestMetrics"

# Run tests but skip long-running ones
go test -v ./internal/cmd -short

static analysis

go vet, golangci-lint

e.g.

brew install golangci-lint
golangci-lint run ./...

performance profile

go tool pprof, go tool trace

go tool pprof http://localhost:6060/debug/pprof/profile

go run main.go
go tool trace trace.out

upgrade

go tool fix

bug report

go bug

go with vscode

  • install go extensions and delve
  • configuration of go debug in vscode
 {
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug file",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${file}"
        },
        {
            "name": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}"
        }
    ]
}

Reference

About

kata of golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published