### Basic Gin Web Server Example (Go) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/gin-gonic/gin/README.md A minimal Go program demonstrating how to initialize a Gin router, define a simple GET route (`/ping`), handle the request by returning a JSON response, and start the server listening on the default port (8080). Requires the `net/http` and `github.com/gin-gonic/gin` packages. ```Go package main import ( "net/http" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.GET("/ping", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ "message": "pong" }) }) r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080") } ``` -------------------------------- ### Install and Get Help for tomll Tool (Shell) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md Provides the shell commands necessary to install the `tomll` command-line tool using `go install` and then display its help message to understand its usage and options. ```Shell $ go install github.com/pelletier/go-toml/v2/cmd/tomll@latest $ tomll --help ``` -------------------------------- ### Install and Get Help for jsontoml Tool (Shell) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md Provides the shell commands necessary to install the `jsontoml` command-line tool using `go install` and then display its help message to understand its usage and options. ```Shell $ go install github.com/pelletier/go-toml/v2/cmd/jsontoml@latest $ jsontoml --help ``` -------------------------------- ### Install and Get Help for tomljson Tool (Shell) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md Provides the shell commands necessary to install the `tomljson` command-line tool using `go install` and then display its help message to understand its usage and options. ```Shell $ go install github.com/pelletier/go-toml/v2/cmd/tomljson@latest $ tomljson --help ``` -------------------------------- ### Running the Gin Example Server (Shell) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/gin-gonic/gin/README.md The command used to compile and execute the `example.go` program, which starts the Gin web server. After running this command, the server will be accessible, typically at `http://localhost:8080`. ```Shell $ go run example.go ``` -------------------------------- ### Installing Gin Package (Shell) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/gin-gonic/gin/README.md Provides the command-line instruction to download and install the Gin web framework using the Go module system or traditional `go get`. This makes the package available for import in Go projects. ```Shell $ go get -u github.com/gin-gonic/gin ``` -------------------------------- ### Install cpuid Go Package Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/klauspost/cpuid/v2/README.md Installs the cpuid Go package using the `go get` command with module support. This command fetches the latest version of the v2 module. ```sh go get -u github.com/klauspost/cpuid/v2 ``` -------------------------------- ### Install cpuid Command-Line Binary Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/klauspost/cpuid/v2/README.md Installs the cpuid command-line tool from the source code using the `go install` command, specifying the latest version. ```sh go install github.com/klauspost/cpuid/v2/cmd/cpuid@latest ``` -------------------------------- ### Installing go-isatty Library (Shell) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/mattn/go-isatty/README.md This command uses the Go module system to download and install the `go-isatty` library from its GitHub repository. ```Shell $ go get github.com/mattn/go-isatty ``` -------------------------------- ### Install cpuid Binary from Source (Command Line) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/klauspost/cpuid/v2/README.md Provides the command to install the `cpuid` command-line binary directly from the Go source code repository using `go install`. ```sh go install github.com/klauspost/cpuid/v2/cmd/cpuid@latest ``` -------------------------------- ### Installing json-iterator/go library Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/json-iterator/go/README.md This command shows how to download and install the json-iterator/go package using the Go module system's 'go get' command. This makes the library available for use in your Go projects. ```Shell go get github.com/json-iterator/go ``` -------------------------------- ### Install universal-translator Go package Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/go-playground/universal-translator/README.md Use the standard `go get` command to download and install the universal-translator library into your Go workspace, making it available for use in your projects. ```shell go get github.com/go-playground/universal-translator ``` -------------------------------- ### Installing mimetype package (Bash) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/gabriel-vasile/mimetype/README.md Use the standard Go command to fetch and install the mimetype package into your project's dependencies. ```Bash go get github.com/gabriel-vasile/mimetype ``` -------------------------------- ### Sample Usage of Codec Package in Go Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/ugorji/go/codec/README.md Demonstrates how to create and configure codec handles (Binc, Msgpack, Cbor), set up extensions, and use NewDecoder/NewEncoder for reading/writing data. Includes examples for both byte slices and io.Reader/Writer. Also shows how to integrate with the standard net/rpc package for both server and client sides. ```Go // create and configure Handle var ( bh codec.BincHandle mh codec.MsgpackHandle ch codec.CborHandle ) mh.MapType = reflect.TypeOf(map[string]interface{}(nil)) // configure extensions // e.g. for msgpack, define functions and enable Time support for tag 1 // mh.SetExt(reflect.TypeOf(time.Time{}), 1, myExt) // create and use decoder/encoder var ( r io.Reader w io.Writer b []byte h = &bh // or mh to use msgpack ) dec = codec.NewDecoder(r, h) dec = codec.NewDecoderBytes(b, h) err = dec.Decode(&v) enc = codec.NewEncoder(w, h) enc = codec.NewEncoderBytes(&b, h) err = enc.Encode(v) //RPC Server go func() { for { conn, err := listener.Accept() rpcCodec := codec.GoRpc.ServerCodec(conn, h) //OR rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, h) rpc.ServeCodec(rpcCodec) } }() //RPC Communication (client side) conn, err = net.Dial("tcp", "localhost:5555") rpcCodec := codec.GoRpc.ClientCodec(conn, h) //OR rpcCodec := codec.MsgpackSpecRpc.ClientCodec(conn, h) client := rpc.NewClientWithCodec(rpcCodec) ``` -------------------------------- ### Installing Go Playground Validator Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/go-playground/validator/v10/README.md Command to download and install the Go Playground Validator package using `go get`. This makes the package available for use in your Go projects. ```Shell go get github.com/go-playground/validator/v10 ``` -------------------------------- ### Install locales Go Library Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/go-playground/locales/README.md Use the Go package manager to download and install the locales library. ```shell go get github.com/go-playground/locales ``` -------------------------------- ### Install cpuid via Homebrew Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/klauspost/cpuid/v2/README.md Installs the cpuid command-line tool on macOS or Linux using the Homebrew package manager. ```sh $ brew install cpuid ``` -------------------------------- ### Importing Gin Package (Go) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/gin-gonic/gin/README.md Shows the standard Go import statement required to use the Gin web framework in a Go project. This is the first step after installing the package. ```Go import "github.com/gin-gonic/gin" ``` -------------------------------- ### Basic CPU Information Example (Go) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/klauspost/cpuid/v2/README.md Demonstrates how to use the `cpuid` package in Go to print basic CPU information such as brand name, core counts, cache sizes, and supported features. It also shows how to check for specific features like SSE and SSE2. ```Go package main import ( "fmt" "strings" . "github.com/klauspost/cpuid/v2" ) func main() { // Print basic CPU information: fmt.Println("Name:", CPU.BrandName) fmt.Println("PhysicalCores:", CPU.PhysicalCores) fmt.Println("ThreadsPerCore:", CPU.ThreadsPerCore) fmt.Println("LogicalCores:", CPU.LogicalCores) fmt.Println("Family", CPU.Family, "Model:", CPU.Model, "Vendor ID:", CPU.VendorID) fmt.Println("Features:", strings.Join(CPU.FeatureSet(), ",")) fmt.Println("Cacheline bytes:", CPU.CacheLine) fmt.Println("L1 Data Cache:", CPU.Cache.L1D, "bytes") fmt.Println("L1 Instruction Cache:", CPU.Cache.L1I, "bytes") fmt.Println("L2 Cache:", CPU.Cache.L2, "bytes") fmt.Println("L3 Cache:", CPU.Cache.L3, "bytes") fmt.Println("Frequency", CPU.Hz, "hz") // Test if we have these specific features: if CPU.Supports(SSE, SSE2) { fmt.Println("We have Streaming SIMD 2 Extensions") } } ``` -------------------------------- ### Run tomljson Tool via Docker (Shell) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md Demonstrates how to execute the `tomljson` tool using a Docker container, piping the content of an example TOML file as standard input to the tool. ```Shell docker run -i ghcr.io/pelletier/go-toml:v2 tomljson < example.toml ``` -------------------------------- ### Demonstrate locales Library Usage in Go Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/go-playground/locales/README.md This example shows how to initialize a locale (en_CA) and use its methods for formatting dates, times, numbers, currencies, percentages, and retrieving plural rules. ```go package main import ( "fmt" "time" "github.com/go-playground/locales/currency" "github.com/go-playground/locales/en_CA" ) func main() { loc, _ := time.LoadLocation("America/Toronto") datetime := time.Date(2016, 02, 03, 9, 0, 1, 0, loc) l := en_CA.New() // Dates fmt.Println(l.FmtDateFull(datetime)) fmt.Println(l.FmtDateLong(datetime)) fmt.Println(l.FmtDateMedium(datetime)) fmt.Println(l.FmtDateShort(datetime)) // Times fmt.Println(l.FmtTimeFull(datetime)) fmt.Println(l.FmtTimeLong(datetime)) fmt.Println(l.FmtTimeMedium(datetime)) fmt.Println(l.FmtTimeShort(datetime)) // Months Wide fmt.Println(l.MonthWide(time.January)) fmt.Println(l.MonthWide(time.February)) fmt.Println(l.MonthWide(time.March)) // ... // Months Abbreviated fmt.Println(l.MonthAbbreviated(time.January)) fmt.Println(l.MonthAbbreviated(time.February)) fmt.Println(l.MonthAbbreviated(time.March)) // ... // Months Narrow fmt.Println(l.MonthNarrow(time.January)) fmt.Println(l.MonthNarrow(time.February)) fmt.Println(l.MonthNarrow(time.March)) // ... // Weekdays Wide fmt.Println(l.WeekdayWide(time.Sunday)) fmt.Println(l.WeekdayWide(time.Monday)) fmt.Println(l.WeekdayWide(time.Tuesday)) // ... // Weekdays Abbreviated fmt.Println(l.WeekdayAbbreviated(time.Sunday)) fmt.Println(l.WeekdayAbbreviated(time.Monday)) fmt.Println(l.WeekdayAbbreviated(time.Tuesday)) // ... // Weekdays Short fmt.Println(l.WeekdayShort(time.Sunday)) fmt.Println(l.WeekdayShort(time.Monday)) fmt.Println(l.WeekdayShort(time.Tuesday)) // ... // Weekdays Narrow fmt.Println(l.WeekdayNarrow(time.Sunday)) fmt.Println(l.WeekdayNarrow(time.Monday)) fmt.Println(l.WeekdayNarrow(time.Tuesday)) // ... var f64 float64 f64 = -10356.4523 // Number fmt.Println(l.FmtNumber(f64, 2)) // Currency fmt.Println(l.FmtCurrency(f64, 2, currency.CAD)) fmt.Println(l.FmtCurrency(f64, 2, currency.USD)) // Accounting fmt.Println(l.FmtAccounting(f64, 2, currency.CAD)) fmt.Println(l.FmtAccounting(f64, 2, currency.USD)) f64 = 78.12 // Percent fmt.Println(l.FmtPercent(f64, 0)) // Plural Rules for locale, so you know what rules you must cover fmt.Println(l.PluralsCardinal()) fmt.Println(l.PluralsOrdinal()) // Cardinal Plural Rules fmt.Println(l.CardinalPluralRule(1, 0)) fmt.Println(l.CardinalPluralRule(1.0, 0)) fmt.Println(l.CardinalPluralRule(1.0, 1)) fmt.Println(l.CardinalPluralRule(3, 0)) // Ordinal Plural Rules fmt.Println(l.OrdinalPluralRule(21, 0)) // 21st fmt.Println(l.OrdinalPluralRule(22, 0)) // 22nd fmt.Println(l.OrdinalPluralRule(33, 0)) // 33rd fmt.Println(l.OrdinalPluralRule(34, 0)) // 34th // Range Plural Rules fmt.Println(l.RangePluralRule(1, 0, 1, 0)) // 1-1 fmt.Println(l.RangePluralRule(1, 0, 2, 0)) // 1-2 fmt.Println(l.RangePluralRule(5, 0, 8, 0)) // 5-8 } ``` -------------------------------- ### Getting Standard CPU Information with cpuid Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/klauspost/cpuid/v2/README.md Demonstrates the default output of the `cpuid` command, providing a human-readable summary of CPU specifications including vendor, core counts, cache sizes, and supported features. ```Shell λ cpuid Name: AMD Ryzen 9 3950X 16-Core Processor Vendor String: AuthenticAMD Vendor ID: AMD PhysicalCores: 16 Threads Per Core: 2 Logical Cores: 32 CPU Family 23 Model: 113 Features: ADX,AESNI,AVX,AVX2,BMI1,BMI2,CLMUL,CLZERO,CMOV,CMPXCHG8,CPBOOST,CX16,F16C,FMA3,FXSR,FXSROPT,HTT,HYPERVISOR,LAHF,LZCNT,MCAOVERFLOW,MMX,MMXEXT,MOVBE,NX,OSXSAVE,POPCNT,RDRAND,RDSEED,RDTSCP,SCE,SHA,SSE,SSE2,SSE3,SSE4,SSE42,SSE4A,SSSE3,SUCCOR,X87,XSAVE Microarchitecture level: 3 Cacheline bytes: 64 L1 Instruction Cache: 32768 bytes L1 Data Cache: 32768 bytes L2 Cache: 524288 bytes L3 Cache: 16777216 bytes ``` -------------------------------- ### Installing the Google UUID Package Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/google/uuid/README.md This command uses the Go module system to download and install the latest version of the github.com/google/uuid package into your Go environment, making it available for use in your projects. ```Shell go get github.com/google/uuid ``` -------------------------------- ### Getting CPU Information as JSON with cpuid Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/klauspost/cpuid/v2/README.md Shows how to use the `--json` flag to obtain CPU details in a structured JSON format, suitable for parsing and automated processing. ```Shell λ cpuid --json { "BrandName": "AMD Ryzen 9 3950X 16-Core Processor", "VendorID": 2, "VendorString": "AuthenticAMD", "PhysicalCores": 16, "ThreadsPerCore": 2, "LogicalCores": 32, "Family": 23, "Model": 113, "CacheLine": 64, "Hz": 0, "BoostFreq": 0, "Cache": { "L1I": 32768, "L1D": 32768, "L2": 524288, "L3": 16777216 }, "SGX": { "Available": false, "LaunchControl": false, "SGX1Supported": false, "SGX2Supported": false, "MaxEnclaveSizeNot64": 0, "MaxEnclaveSize64": 0, "EPCSections": null }, "Features": [ "ADX", "AESNI", "AVX", "AVX2", "BMI1", "BMI2", "CLMUL", "CLZERO", "CMOV", "CMPXCHG8", "CPBOOST", "CX16", "F16C", "FMA3", "FXSR", "FXSROPT", "HTT", "HYPERVISOR", "LAHF", "LZCNT", "MCAOVERFLOW", "MMX", "MMXEXT", "MOVBE", "NX", "OSXSAVE", "POPCNT", "RDRAND", "RDSEED", "RDTSCP", "SCE", "SHA", "SSE", "SSE2", "SSE3", "SSE4", "SSE42", "SSE4A", "SSSE3", "SUCCOR", "X87", "XSAVE" ], "X64Level": 3 } ``` -------------------------------- ### Checking CPU Microarchitecture Level Support Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/klauspost/cpuid/v2/README.md Illustrates using the `--check-level` flag to verify if a specific microarchitecture level is supported by the CPU, showing examples for both a supported and an unsupported level and their respective exit codes. ```Shell λ cpuid --check-level=3 2022/03/18 17:04:40 AMD Ryzen 9 3950X 16-Core Processor 2022/03/18 17:04:40 Microarchitecture level 3 is supported. Max level is 3. Exit Code 0 λ cpuid --check-level=4 2022/03/18 17:06:18 AMD Ryzen 9 3950X 16-Core Processor 2022/03/18 17:06:18 Microarchitecture level 4 not supported. Max level is 3. Exit Code 1 ``` -------------------------------- ### Searching JSON AST with Sonic Go Get/Index Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/bytedance/sonic/README.md Demonstrates how to navigate and search a JSON Abstract Syntax Tree (AST) using sonic.Get with paths and ast.Node methods like Get and Index. Highlights the performance benefit of Index. ```Go import "github.com/bytedance/sonic" input := []byte(`{"key1":[{},{"key2":{"key3":[1,2,3]}}]}`) // no path, returns entire json root, err := sonic.Get(input) raw := root.Raw() // == string(input) // multiple paths root, err := sonic.Get(input, "key1", 1, "key2") sub := root.Get("key3").Index(2).Int64() // == 3 ``` -------------------------------- ### Instantiating NetSceneBaseEx for WxaApp Get Share Info in C++ Source: https://github.com/nsky99/wechatclient/blob/main/docs/netscene.txt Declares and defines the NetSceneBaseEx template class specialized for WxaAppGetShareInfoRequest and WxaAppGetShareInfoResponse messages, inheriting from NetSceneBase and InstanceCounter. ```C++ NetSceneBaseEx NetSceneBaseEx: NetSceneBase, InstanceCounter; ``` -------------------------------- ### Instantiating NetSceneBaseEx for WxaApp Get Public Lib Info in C++ Source: https://github.com/nsky99/wechatclient/blob/main/docs/netscene.txt Declares and defines the NetSceneBaseEx template class specialized for WxaAppGetPublicLibInfoRequest and WxaAppGetPublicLibInfoResponse messages, inheriting from NetSceneBase and InstanceCounter. ```C++ NetSceneBaseEx NetSceneBaseEx: NetSceneBase, InstanceCounter; ``` -------------------------------- ### Instantiating NetSceneBaseEx for WxaApp Get Auth Info in C++ Source: https://github.com/nsky99/wechatclient/blob/main/docs/netscene.txt Declares and defines the NetSceneBaseEx template class specialized for WxaAppGetAuthInfoReq and WxaAppGetAuthInfoResp messages, inheriting from NetSceneBase and InstanceCounter. ```C++ NetSceneBaseEx NetSceneBaseEx: NetSceneBase, InstanceCounter; ``` -------------------------------- ### Sorting JSON Keys with Sonic Go Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/bytedance/sonic/README.md Explains how to enable key sorting in Sonic for compatibility or specific needs, despite the performance cost. Shows examples using encoder.SortMapKeys option and the SortKeys method on an AST node. ```Go import "github.com/bytedance/sonic" import "github.com/bytedance/sonic/encoder" // Binding map only m := map[string]interface{}{} v, err := encoder.Encode(m, encoder.SortMapKeys) // Or ast.Node.SortKeys() before marshal var root := sonic.Get(JSON) err := root.SortKeys() ``` -------------------------------- ### Marshaling a Go Struct to TOML using go-toml v2 Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md This example illustrates how to use `toml.Marshal` to convert a Go struct (`MyConfig`) into a TOML formatted byte slice. It shows how to create an instance of the struct, marshal it, handle errors, and print the resulting TOML string. Requires the `MyConfig` struct definition and the `go-toml/v2` library. ```Go cfg := MyConfig{ Version: 2, Name: "go-toml", Tags: []string{"go", "toml"}, } b, err := toml.Marshal(cfg) if err != nil { panic(err) } fmt.Println(string(b)) // Output: // Version = 2 // Name = 'go-toml' // Tags = ['go', 'toml'] ``` -------------------------------- ### Using concurrent.Executor for Cancellable Goroutines in Go Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/modern-go/concurrent/README.md This example illustrates how to create an UnboundedExecutor, launch a goroutine using Go that listens for cancellation via a context.Context, and stop the executor using StopAndWaitForever. It shows how to manage the lifecycle of a goroutine and handle cancellation. ```Go executor := concurrent.NewUnboundedExecutor() executor.Go(func(ctx context.Context) { everyMillisecond := time.NewTicker(time.Millisecond) for { select { case <-ctx.Done(): fmt.Println("goroutine exited") return case <-everyMillisecond.C: // do something } } }) time.Sleep(time.Second) executor.StopAndWaitForever() fmt.Println("executor stopped") ``` -------------------------------- ### Search and Index Sonic Ast.Node (Go) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/bytedance/sonic/README_ZH_CN.md Demonstrates how to use `sonic.Get` to obtain an `ast.Node` from JSON input and how to navigate the tree using `Get` with string keys and `Index` with integer indices. ```go import "github.com/bytedance/sonic" input := []byte(`{"key1":[{},{"key2":{"key3":[1,2,3]}}]}`) // no path, returns entire json root, err := sonic.Get(input) raw := root.Raw() // == string(input) // multiple paths root, err := sonic.Get(input, "key1", 1, "key2") sub := root.Get("key3").Index(2).Int64() // == 3 ``` -------------------------------- ### Defining a Go Struct for TOML Mapping Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md This Go struct `MyConfig` is defined to demonstrate how Go types can be structured to map to TOML data. It includes fields for an integer version, a string name, and a slice of strings for tags, which are used in the marshaling and unmarshaling examples. ```Go type MyConfig struct { Version int Name string Tags []string } ``` -------------------------------- ### Handling Generic JSON Data with Sonic ast.Node (Go) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/bytedance/sonic/README.md This example illustrates using `sonic.GetFromString` to obtain the root `ast.Node` of a JSON document and then navigating it using methods like `GetByPath` to access nested elements. `ast.Node` provides efficient indexing and lazy-loading, making it suitable for handling generic or unknown JSON structures without fully parsing everything into maps or interfaces. Note that `ast.Node` requires explicit loading (`Load`/`LoadAll`) for concurrent use. ```Go import "github.com/bytedance/sonic" root, err := sonic.GetFromString(_TwitterJson) user := root.GetByPath("statuses", 3, "user") // === root.Get("status").Index(3).Get("user") err = user.Check() // err = user.LoadAll() // only call this when you want to use 'user' concurrently... go someFunc(user) ``` -------------------------------- ### Run Go Benchmarks Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/ugorji/go/codec/README.md Executes benchmarks in the current directory ('.') using the 'go test' command, enabling memory allocation statistics ('-benchmem') and setting the minimum benchmark execution time to 1 second ('-benchtime 1s'). ```Shell go test -bench . -benchmem -benchtime 1s ``` -------------------------------- ### Run Full Go Test Suite with Tags Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/ugorji/go/codec/README.md Runs the complete test suite by specifying the 'alltests' build tag and filtering tests to run the 'Suite'. ```Shell go test -tags alltests -run Suite ``` -------------------------------- ### Running Go Benchmarks Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/pelletier/go-toml/v2/CONTRIBUTING.md Executes the Go benchmark tests for all packages in the current module. The `-bench=.` flag runs all benchmarks, and `-count=10` repeats each benchmark 10 times to reduce noise and improve reliability of results. ```Go go test ./... -bench=. -count=10 ``` -------------------------------- ### Run Full Go Test Suite with Multiple Tags (Safe Mode) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/ugorji/go/codec/README.md Runs the complete test suite by specifying both 'alltests' and 'codec.safe' build tags and filtering tests to run the 'Suite'. ```Shell go test -tags "alltests codec.safe" -run Suite ``` -------------------------------- ### Defining Example Go Struct for JSON Decoding Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/goccy/go-json/README.md Defines a simple Go struct `T` with fields `A`, `B`, and `C` tagged for JSON decoding from keys `a`, `b`, and `c`. This struct is used as an example target for the JSON decoding process discussed. ```Go type T struct { A int `json:"a"` B int `json:"b"` C int `json:"c"` } ``` -------------------------------- ### Run Old Build System mkall.sh (GOOS != linux) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/golang.org/x/sys/unix/README.md Executes the mkall.sh script to generate Go files for the current OS and architecture using the old build system. This process relies on the C header files present on the system where the script is run. Requires bash and go. ```bash mkall.sh ``` -------------------------------- ### Parsing Partial JSON Schema with Sonic Get and Unmarshal (Go) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/bytedance/sonic/README.md This snippet shows how to extract a specific part of a JSON string using `sonic.GetFromString` to get an `ast.Node`, and then unmarshal that node's raw content into a Go struct (`User`) representing a partial schema. This approach is useful when you only need to parse a subset of a large JSON document. ```Go import "github.com/bytedance/sonic" node, err := sonic.GetFromString(_TwitterJson, "statuses", 3, "user") var user User // your partial schema... err = sonic.UnmarshalString(node.Raw(), &user) ``` -------------------------------- ### Run Basic Go Tests Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/ugorji/go/codec/README.md Executes the standard Go tests within the current package directory. ```Shell go test ``` -------------------------------- ### Preview Old Build System mkall.sh Commands (GOOS != linux) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/golang.org/x/sys/unix/README.md Runs the mkall.sh script with the -n flag to display the commands that would be executed by the old build system without actually running them. Useful for inspecting the build process. Requires bash and go. ```bash mkall.sh -n ``` -------------------------------- ### Handling Sonic Go Syntax Errors Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/bytedance/sonic/README.md Illustrates how to catch and handle decoder.SyntaxError when unmarshaling invalid JSON. Shows how to get a concise error message with Error() and a pretty-printed message with Description(). ```Go import "github.com/bytedance/sonic" import "github.com/bytedance/sonic/decoder" var data interface{} err := sonic.UnmarshalString("[[[}]]", &data) if err != nil { /* One line by default */ println(e.Error()) // "Syntax error at index 3: invalid char\n\n\t[[[}]]\n\t...^..\n" /* Pretty print */ if e, ok := err.(decoder.SyntaxError); ok { /*Syntax error at index 3: invalid char [[[}]] ...^.. */ print(e.Description()) } else if me, ok := err.(*decoder.MismatchTypeError); ok { // decoder.MismatchTypeError is new to Sonic v1.6.0 print(me.Description()) } } ``` -------------------------------- ### Change Directory to Benchmarks Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/ugorji/go/codec/README.md Navigates into the 'bench' subdirectory to access benchmark files. ```Shell cd bench ``` -------------------------------- ### Preview New Build System mkall.sh Commands (GOOS == linux) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/golang.org/x/sys/unix/README.md Runs the mkall.sh script with the -n flag to display the commands that would be executed by the new container-based build system without actually running them. Requires bash, go, and docker on an amd64/Linux system. ```bash mkall.sh -n ``` -------------------------------- ### Run New Build System mkall.sh (GOOS == linux) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/golang.org/x/sys/unix/README.md Executes the mkall.sh script to generate Go files for all supported GOOS/GOARCH pairs using the new container-based build system. This system uses Docker to ensure reproducible builds from source checkouts. Requires bash, go, and docker on an amd64/Linux system. ```bash mkall.sh ``` -------------------------------- ### Defining NetSceneBaseEx Specialization for GetBizJsApiRedirectUrl - C++ Source: https://github.com/nsky99/wechatclient/blob/main/docs/netscene.txt Defines a specialized NetSceneBaseEx class for getting the redirect URL for a business JS API. It inherits from NetSceneBase and uses InstanceCounter for tracking instances. ```C++ NetSceneBaseEx NetSceneBaseEx: NetSceneBase, InstanceCounter; ``` -------------------------------- ### Using Colorize Option for JSON Encoding in Go Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/goccy/go-json/CHANGELOG.md This snippet demonstrates how to use the json.Colorize option with json.MarshalWithOption to produce colored JSON output. It applies a specified color scheme (DefaultColorScheme in this example) to the encoded JSON byte slice. ```go b, err := json.MarshalWithOption(v, json.Colorize(json.DefaultColorScheme)) if err != nil { ... } fmt.Println(string(b)) // print colored json ``` -------------------------------- ### Using Flags for CPU Detection (Go) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/klauspost/cpuid/v2/README.md Illustrates how to use the `cpuid.Flags()` and `cpuid.Detect()` functions to incorporate command-line flags into the CPU detection process. `Flags()` must be called before `flag.Parse()`, and `Detect()` must be called after. ```Go package main import ( "flag" "fmt" "strings" "github.com/klauspost/cpuid/v2" ) func main() { cpuid.Flags() flag.Parse() cpuid.Detect() // Test if we have these specific features: if cpuid.CPU.Supports(cpuid.SSE, cpuid.SSE2) { fmt.Println("We have Streaming SIMD 2 Extensions") } } ``` -------------------------------- ### Setting Value with Type Checking using reflect2 in Go Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/modern-go/reflect2/README.md This example illustrates how to set the value of a variable (`i`) using `reflect2.Type.Set`. This method performs type checking and operates on pointers to the values. After execution, the value of `i` will be updated to the value of `j`. ```Go valType := reflect2.TypeOf(1) i := 1 j := 10 valType.Set(&i, &j) // i will be 10 ``` -------------------------------- ### Tagging a New Git Release Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/pelletier/go-toml/v2/CONTRIBUTING.md Sequence of Git commands to prepare for and tag a new release version. It switches to the `v2` branch, pulls the latest changes, creates a local tag `v2.2.0`, and then pushes the new tag to the remote repository. ```Git git checkout v2 git pull git tag v2.2.0 git push --tags ``` -------------------------------- ### Using concurrent.Map in Go Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/modern-go/concurrent/README.md This snippet demonstrates how to create a new concurrent.Map, store a key-value pair, and load a value by its key. It shows the basic Store and Load operations, useful for Go versions below 1.9. ```Go m := concurrent.NewMap() m.Store("hello", "world") elem, found := m.Load("hello") // elem will be "world" // found will be true ``` -------------------------------- ### Parsing RFC 2141 URN with Parse function in Go Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/leodido/go-urn/README.md This example shows how to parse a RFC 2141 URN string using the simpler `urn.Parse()` function with a byte slice input. It includes basic error checking using `panic` and prints the URN's ID and SS components. ```go package main import ( "fmt" "github.com/leodido/go-urn" ) func main() { var uid = "URN:foo:a123,456" // Parse the input string as a RFC 2141 URN only u, ok := urn.Parse([]byte(uid)) if !ok { panic("error parsing urn") } fmt.Println(u.ID) fmt.Println(u.SS) // Output: // foo // a123,456 } ``` -------------------------------- ### Getting Type by Name with reflect2 in Go Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/modern-go/reflect2/README.md This snippet shows how to retrieve a type using its fully qualified name string via `reflect2.TypeByName`. It's similar to Java's `Class.forName`. Note that types not used elsewhere in the code may be optimized away by the compiler and thus not discoverable at runtime. ```Go // given package is github.com/your/awesome-package type MyStruct struct { // ... } // will return the type reflect2.TypeByName("awesome-package.MyStruct") // however, if the type has not been used // it will be eliminated by compiler, so we can not get it in runtime ``` -------------------------------- ### Defining FinderCreateLivePrepare Network Scene Class (C++) Source: https://github.com/nsky99/wechatclient/blob/main/docs/netscene.txt Defines the NetSceneBaseEx class specialized for handling FinderCreateLivePrepare requests and responses. It inherits from NetSceneBase and uses InstanceCounter for tracking. ```C++ NetSceneBaseEx NetSceneBaseEx: NetSceneBase, InstanceCounter; ``` -------------------------------- ### Sonic Go SAX-style JSON Preorder Traversal API Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/bytedance/sonic/README.md Presents the `Preorder` function and the `Visitor` interface provided by Sonic's ast package. This API allows for a SAX-style, preorder traversal of a JSON Abstract Syntax Tree (AST), enabling developers to process JSON data incrementally using a custom visitor implementation. ```Go func Preorder(str string, visitor Visitor, opts *VisitorOptions) error type Visitor interface { OnNull() error OnBool(v bool) error OnString(v string) error OnInt64(v int64, n json.Number) error OnFloat64(v float64, n json.Number) error OnObjectBegin(capacity int) error OnObjectKey(key string) error OnObjectEnd() error OnArrayBegin(capacity int) error OnArrayEnd() error } ``` -------------------------------- ### Reusing Buffers with sync.Pool in Go Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/goccy/go-json/README.md Demonstrates how to use `sync.Pool` to reuse byte slices for JSON encoding results, reducing memory allocations and improving performance. It shows getting a buffer from the pool, using its data, copying the result, updating the buffer's data, and putting it back. ```go type buffer struct { data []byte } var bufPool = sync.Pool{ New: func() interface{} { return &buffer{data: make([]byte, 0, 1024)} }, } buf := bufPool.Get().(*buffer) data := encode(buf.data) // reuse buf.data newBuf := make([]byte, len(data)) copy(newBuf, buf) buf.data = data bufPool.Put(buf) ``` -------------------------------- ### Go System Call Dispatch Entry Points Source: https://github.com/nsky99/wechatclient/blob/main/vendor/golang.org/x/sys/unix/README.md Defines the three primary function signatures implemented in the hand-written assembly file (asm_${GOOS}_${GOARCH}.s) for dispatching system calls in Go. Syscall and Syscall6 are standard entry points, while RawSyscall is a low-level variant used by ForkExec that bypasses scheduler notification. ```go func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr) func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr) ``` -------------------------------- ### Defining Custom Types for Codec Extensions (Go) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/ugorji/go/codec/README.md These are examples of custom Go types (slice alias, primitive alias, struct) that can be registered with the codec library's extension mechanism. Registering an extension allows users to define custom encoding and decoding logic for these types, overriding the default behavior. ```Go type BisSet []int type BitSet64 uint64 type UUID string type MyStructWithUnexportedFields struct { a int; b bool; c []int; } type GifImage struct { ... } ``` -------------------------------- ### Example Go Struct for Bitmap False Hit Scenario Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/goccy/go-json/README.md Provides a Go struct `T` with a single field `X` tagged with a longer JSON key `abc`. This struct is used to illustrate a potential 'false hit' scenario in the bitmap lookup when the input key is shorter than the target field key. ```Go type T struct { X int `json:"abc"` } ``` -------------------------------- ### Benchmark Results for Go Web Framework Static Routes Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/gin-gonic/gin/BENCHMARKS.md This output displays the performance metrics obtained from running benchmarks on various Go web frameworks for handling static routes. The columns typically represent the number of iterations, time per operation (ns/op), bytes allocated per operation (B/op), and allocations per operation (allocs/op). Lower values for ns/op, B/op, and allocs/op indicate better performance. ```Shell BenchmarkGin_StaticAll 62169 19319 ns/op 0 B/op 0 allocs/op BenchmarkAce_StaticAll 65428 18313 ns/op 0 B/op 0 allocs/op BenchmarkAero_StaticAll 121132 9632 ns/op 0 B/op 0 allocs/op BenchmarkHttpServeMux_StaticAll 52626 22758 ns/op 0 B/op 0 allocs/op BenchmarkBeego_StaticAll 9962 179058 ns/op 55264 B/op 471 allocs/op BenchmarkBear_StaticAll 14894 80966 ns/op 20272 B/op 469 allocs/op BenchmarkBone_StaticAll 18718 64065 ns/op 0 B/op 0 allocs/op BenchmarkChi_StaticAll 10000 149827 ns/op 67824 B/op 471 allocs/op BenchmarkDenco_StaticAll 211393 5680 ns/op 0 B/op 0 allocs/op BenchmarkEcho_StaticAll 49341 24343 ns/op 0 B/op 0 allocs/op BenchmarkGocraftWeb_StaticAll 10000 126209 ns/op 46312 B/op 785 allocs/op BenchmarkGoji_StaticAll 27956 43174 ns/op 0 B/op 0 allocs/op BenchmarkGojiv2_StaticAll 3430 370718 ns/op 205984 B/op 1570 allocs/op BenchmarkGoJsonRest_StaticAll 9134 188888 ns/op 51653 B/op 1727 allocs/op BenchmarkGoRestful_StaticAll 706 1703330 ns/op 613280 B/op 2053 allocs/op BenchmarkGorillaMux_StaticAll 1268 924083 ns/op 153233 B/op 1413 allocs/op BenchmarkGowwwRouter_StaticAll 63374 18935 ns/op 0 B/op 0 allocs/op BenchmarkHttpRouter_StaticAll 109938 10902 ns/op 0 B/op 0 allocs/op BenchmarkHttpTreeMux_StaticAll 109166 10861 ns/op 0 B/op 0 allocs/op BenchmarkKocha_StaticAll 92258 12992 ns/op 0 B/op 0 allocs/op BenchmarkLARS_StaticAll 65200 18387 ns/op 0 B/op 0 allocs/op BenchmarkMacaron_StaticAll 5671 291501 ns/op 115553 B/op 1256 allocs/op BenchmarkMartini_StaticAll 807 1460498 ns/op 125444 B/op 1717 allocs/op BenchmarkPat_StaticAll 513 2342396 ns/op 602832 B/op 12559 allocs/op BenchmarkPossum_StaticAll 10000 128270 ns/op 65312 B/op 471 allocs/op BenchmarkR2router_StaticAll 16726 71760 ns/op 22608 B/op 628 allocs/op BenchmarkRivet_StaticAll 41722 28723 ns/op 0 B/op 0 allocs/op BenchmarkTango_StaticAll 7606 205082 ns/op 39209 B/op 1256 allocs/op BenchmarkTigerTonic_StaticAll 26247 45806 ns/op 7376 B/op 157 allocs/op BenchmarkTraffic_StaticAll 550 2284518 ns/op 754864 B/op 14601 allocs/op BenchmarkVulcan_StaticAll 10000 131343 ns/op 15386 B/op 471 allocs/op ``` -------------------------------- ### Example Translation File Format (JSON) Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/go-playground/universal-translator/README.md Illustrates the basic structure for a single translation entry within a JSON file used by the universal-translator library. It includes fields for locale, translation key, the translated text, translation type (like Cardinal, Ordinal), the specific plural rule, and an optional override flag. ```json { "locale": "en", "key": "days-left", "trans": "You have {0} day left.", "type": "Cardinal", "rule": "One", "override": false } ``` -------------------------------- ### Defining LaunchWxaApp Network Scene in C++ Source: https://github.com/nsky99/wechatclient/blob/main/docs/netscene.txt This line defines a specific network scene for launching Wxa (Mini) apps using the NetSceneBaseEx template. It associates the micromsg::LaunchWxaAppRequest and micromsg::LaunchWxaAppResponse types with the base NetSceneBase and an InstanceCounter. ```C++ NetSceneBaseEx NetSceneBaseEx: NetSceneBase, InstanceCounter; ``` -------------------------------- ### Defining NetSceneBaseEx for InitiateBizChatReq and InitiateBizChatResp in C++ Source: https://github.com/nsky99/wechatclient/blob/main/docs/netscene.txt Defines a specific instantiation of the NetSceneBaseEx template class for handling micromsg::InitiateBizChatReq requests and micromsg::InitiateBizChatResp responses. It inherits from NetSceneBase and uses InstanceCounter for tracking instances, limited to 100. ```C++ NetSceneBaseEx: NetSceneBase, InstanceCounter; ``` -------------------------------- ### Unmarshaling TOML into a Go Struct using go-toml v2 Source: https://github.com/nsky99/wechatclient/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md This example demonstrates how to use `toml.Unmarshal` to parse a TOML string (`doc`) and populate a Go struct (`MyConfig`). It shows how to handle potential errors and access the data stored in the struct after successful unmarshaling. Requires the `MyConfig` struct definition and the `go-toml/v2` library. ```Go doc := ` version = 2 name = "go-toml" tags = ["go", "toml"] ` var cfg MyConfig err := toml.Unmarshal([]byte(doc), &cfg) if err != nil { panic(err) } fmt.Println("version:", cfg.Version) fmt.Println("name:", cfg.Name) fmt.Println("tags:", cfg.Tags) // Output: // version: 2 // name: go-toml // tags: [go toml] ``` -------------------------------- ### Defining ExtDeviceOpLog Network Scene Class (C++) Source: https://github.com/nsky99/wechatclient/blob/main/docs/netscene.txt Defines the NetSceneBaseEx class specialized for handling ExtDeviceOpLog requests and responses. It inherits from NetSceneBase and uses InstanceCounter for tracking. ```C++ NetSceneBaseEx NetSceneBaseEx: NetSceneBase, InstanceCounter; ``` -------------------------------- ### Instantiating NetSceneBaseEx for VoIP Sync in C++ Source: https://github.com/nsky99/wechatclient/blob/main/docs/netscene.txt Declares and defines the NetSceneBaseEx template class specialized for VoipSyncReq and VoipSyncResp messages, inheriting from NetSceneBase and InstanceCounter. ```C++ NetSceneBaseEx NetSceneBaseEx: NetSceneBase, InstanceCounter; ```