My first time participating in a half horse race
This weekend, I’m going to a half marathon with my girlfriend. The scenery on the west coast of Qingdao is really beautiful, and the newly paved roads are spacious. Traffic control started around 7 o’clock, so we can only take a taxi to the nearby area and walk thereThe competition venue was very lively, and as someone with no culture, I could only say one sentence at the venue. There were so many people and the atmosphere was really good. I didn’t dare to sign up for a half horse race for my fi ...
JS Flying Animation, Accelerated Animation, Swap In and Out Effects
JS Flying Animation, Accelerated Animation, Swap In and Out Effects
Performance Optimization and Memory Usage Reduction by Sorting Fields in Go Structs
By rearranging the fields in the struct from the first example to the second one, performance can be improved and memory usage reduced by sorting fields in Go structs.
type BadStruct struct { age uint8 IdCardNumber uint64 DateOfBirth uint16}type GoodStruct struct { age uint8 DateOfBirth uint16 IdCardNumber uint64}
Go ioutil Package Deprecated Starting from 1.16, Use io Package Instead
In October 2020, Go’s lead Russ Cox proposed to deprecate the ioutil package[1]. The reason for deprecation is: io/ioutil, like most things with util in the name, has turned out to be a poorly defined and hard to understand collection of things.
Subsequent code submissions have confirmed this. Starting from Go 1.16, the ioutil package will be deprecated, and its functionality will be moved to the io or os package.
Related link: https://github.com/go-critic/go-critic/issues/1019
For example, ...
go sha256 with RSA signature base64
Generate key file GenerateRSAKey(2048) // Simulate sender // Message to be sent msg := []byte("hello world") // Generate signature sign := GetSign(msg, "private.pem") fmt.Println("signlen lenlen", string(sign)) // Simulate receiver // Received message acceptmsg := []byte("hello world") // Received signature acceptsign := sign // Verify signature result := VerifySign(acceptmsg, acceptsign, "public.pem") fmt.Println("Verification result:", result)
Issue with Second Body Retrieval in Go
After using the os.ReadAll(r.Body) method, it is necessary to execute the following method to rewrite the body:
ctx.Request.Body = io.NopCloser(bytes.NewBuffer(signStrByte)) // Rewrite the body back, otherwise it cannot be retrieved elsewhere
It has been observed in practice that using gin.Context.Bindxxx related methods also requires executing the above method to rewrite the body.
golang gin interface signature sign
golang gin interface signature sign
gin.Default().Group("").Use(xxx.CheckSign()){ // Register routes that need to be signed gin.Default().Group("testrouter").POST("dotest", func(ctx *gin.Context) { response.Result(401, gin.H{}, "hello", ctx) }) }
sign.go signature verification
package xxximport ( "crypto/sha256" "encoding/hex" "fmt" "github.com/flipped-aurora/gin-vue-admin/server/model/comm ...