随笔分类 - Go
摘要:1.for循环里被关闭的通道 package main import ( "fmt" "time" ) func main() { c := make(chan int) go func() { time.Sleep(time.Second) c <- 10 close(c) }() for { s
阅读全文
摘要:package main import ( "fmt" "time" ) func batchProcessor(ch <-chan string, batchSize int, flushInterval time.Duration) { var batch []string timer := t
阅读全文
摘要:package main import ( "container/heap" "fmt" ) // IntHeap 是一个包含整数的切片,它实现了 heap.Interface 接口。 type IntHeap []int // Len 方法返回堆中的元素数量。 func (h IntHeap) L
阅读全文
摘要:package main import ( "crypto/rand" "crypto/rsa" "crypto/x509" "encoding/base64" "encoding/pem" "errors" "fmt" ) // 私钥生成 // openssl genrsa -out rsa_pr
阅读全文
摘要:方式1 package main import ( "fmt" "github.com/antlabs/timer" "time" ) type CurstomTest struct { count int } // 只要实现Next接口就行 func (c *CurstomTest) Next(n
阅读全文
摘要:+ func main() { s1 := "hello" s2 := "word" s3 := s1 + s2 fmt.Print(s3) //s3 = "helloword" } sprintf s1 := "hello" s2 := "word" s3 := fmt.Sprintf("%s%s
阅读全文
摘要:main.go package main import "fmt" // 指针(任何类型的指针)、slice和map作为返回值 // 当带有指针的返回值被赋给外部变量或者作为参数传递给其他函数时, 编译器无法确定该变量何时停止使用 // 因此,为了确保安全性和正确性,它必须将该数据分配在堆上,并使其
阅读全文
摘要:fifo的文件需要提前建立好,或者用程序处理 php <?php $fifoName = "my_fifo"; // 打开命名管道进行读取 $fifo = fopen($fifoName, "r+"); if ($fifo false) { die("Unable to open FIFO: $fi
阅读全文
摘要:先搭建nats集群 -js 代表开启stream,这个时候必须起名字。如果节点不加入集群,那就不用配置--routes,以及-js version: "3.5" services: nats: image: nats ports: - "8222:8222" - "4222:4222" - "622
阅读全文
摘要:hello.proto syntax="proto3"; package pb; option go_package = "./pb"; service Greeter { rpc SayHello(HelloRequest) returns(HelloReply){} } message Hell
阅读全文
摘要:结构体 type Context interface { // 标识deadline是否已经设置了,没有设置时,ok的值是false,并返回初始的time.Time Deadline() (deadline time.Time, ok bool) // 返回一个channel, 当返回关闭的chan
阅读全文
摘要:固定窗口 package main import ( "fmt" "sync" "sync/atomic" "time" ) // 定义限流结构体 type RateLimiter struct { interval time.Duration // 时间窗口 tokens int32 // 令牌总
阅读全文
摘要:padding的填充方式可以根据自己需要修改 php $key = 'a7gE3fH9jKmN1pQ2rS4tU6vY8zW9xL0'; $iv = '7hJ3kQxZW45mNpR'; $data = '123456'; $encrypted = openssl_encrypt($data, 'A
阅读全文
摘要:package main import ( "encoding/json" "fmt" "github.com/gin-gonic/gin" "github.com/natefinch/lumberjack" "go.uber.org/zap" "go.uber.org/zap/zapcore" "
阅读全文
摘要:没用singleflight之前 package main import ( "fmt" "sync" "time" ) var ( mx sync.Mutex wg sync.WaitGroup cacheData = make(map[string]string, 0) ) func main(
阅读全文
摘要:生产者 package main import ( "context" "fmt" "github.com/apache/rocketmq-client-go/v2" "github.com/apache/rocketmq-client-go/v2/primitive" "github.com/ap
阅读全文
摘要:注意,当前使用的不是grpc协议 生产者 package main import ( "context" "fmt" "github.com/apache/rocketmq-client-go/v2" "github.com/apache/rocketmq-client-go/v2/primitiv
阅读全文
摘要:index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>upload file</title> </head> <body id="app"> <h1 style="text-align: ce
阅读全文
摘要:upload.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>upload file</title> </head> <body> <form method="post" enctype="mult
阅读全文
摘要:package main import ( "fmt" "net/http" "time" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.GET("/", func(c *gin.Context) { w := c.W
阅读全文

浙公网安备 33010602011771号