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
| type printId interface { | |
| print(id int) | |
| } | |
| type BufferWrapper struct { | |
| buffer *bytes.Buffer | |
| } | |
| func NewBufferWrapper() *BufferWrapper { | |
| return &BufferWrapper{} | |
| } |
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 lock_free | |
| import ( | |
| "sync" | |
| "sync/atomic" | |
| "unsafe" | |
| ) | |
| type StackInterface interface { | |
| Push(any) |
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
| func (gjt *GoJoseToken) GetRSAToken() (string, error) { | |
| // Generate ED25519 key pair | |
| data, err := os.ReadFile("ec_public.pem") | |
| if err != nil { | |
| log.Fatalf("Failed to read public key: %v", err) | |
| } | |
| pub, err := LoadPublicKey(data) | |
| if err != nil { | |
| log.Fatalf("Failed to load public key: %v", 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
| import ( | |
| "blog-example/lib/jwt/inf" | |
| "fmt" | |
| "github.com/golang-jwt/jwt/v5" | |
| "time" | |
| ) | |
| type V5Token struct { | |
| User inf.UserInfo | |
| jwt.RegisteredClaims |
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
| func main() { | |
| Demo1() | |
| runtime.GC() | |
| time.Sleep(1 * time.Second) | |
| exit() | |
| } | |
| func exit() { | |
| fmt.Println("Saving heap profile...") | |
| // create a heap profile | |
| f, err := os.Create("heap.pprof") |
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 limit_alg | |
| import ( | |
| "sync" | |
| ) | |
| // UserQuota | |
| type UserQuota struct { | |
| Quanity int | |
| Limit int |
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
| // UserQuota | |
| type UserQuota struct { | |
| Quanity int | |
| Limit int | |
| mutex sync.Mutex | |
| } | |
| // QuotaManager Managing user credits | |
| type QuotaManager struct { | |
| users map[string]*UserQuota |
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 limit_alg | |
| import ( | |
| "context" | |
| "fmt" | |
| "github.com/go-redis/redis/v8" | |
| "time" | |
| ) | |
| type RedisTokenBucket struct { |
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 limit_alg | |
| import ( | |
| "sync" | |
| "time" | |
| ) | |
| type TokenBucket struct { | |
| mu sync.Mutex | |
| bucketSize int |
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
| type TokenBucket struct { | |
| mu sync.Mutex | |
| bucketSize int | |
| capacity chan struct{} | |
| interval time.Duration | |
| refillRate int | |
| } | |
| func NewTokenBucket(capacity int, refillRate int, interval time.Duration) *TokenBucket { | |
| tl := &TokenBucket{ |
NewerOlder