This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- handler.lua | |
| local BasePlugin = require "kong.plugins.base_plugin" | |
| local kong = kong | |
| local CustomHandler = BasePlugin:extend() | |
| CustomHandler.VERSION = "1.0.0" | |
| CustomHandler.PRIORITY = 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- ---------------------------- | |
| -- 下面cache的key为PK或者uniq字段 | |
| -- ---------------------------- | |
| -- 查表从数据库中取出 | |
| local function load_{tablename}_by_{filedname}(var_filedname) | |
| local row, err = kong.db.{tablename}:select_by_{filedname}(var_filedname) -- 3. cache中没有时从db中获取数据 | |
| if err then | |
| return nil, err |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // Companion code to https://medium.com/statuscode/pipeline-patterns-in-go-a37bb3a7e61d | |
| // | |
| // To run: | |
| // go get github.com/pkg/errors | |
| // go run -race pipeline_demo.go | |
| // | |
| package main | |
| import ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "os" | |
| "os/signal" | |
| "syscall" | |
| ) | |
| func main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "io/ioutil" | |
| "os/exec" | |
| ) | |
| func main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "time" | |
| ) | |
| func main() { | |
| requests := make(chan int, 5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| // 多生成,多消费者;注意下面的注意事项 | |
| // https://www.toutiao.com/a6506067818100818445/ | |
| import ( | |
| "fmt" | |
| "math/rand" | |
| "sync" | |
| "time" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 一个循环里只从一个工作channel里读数据 | |
| go func(in <-chan int) { | |
| for x := range in { // 当channel "in"被关闭时会结束循环 | |
| fmt.Printf("Process %d\n", x) | |
| } | |
| }(inCh) | |
| // 一个循环里需要从一个工作channel里读数据,同时还需响应控制channel | |
| go func() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Package main implements a client for Greeter service. | |
| package main | |
| import ( | |
| "context" | |
| "log" | |
| "os" | |
| "time" | |
| "google.golang.org/grpc" |