Skip to content

Instantly share code, notes, and snippets.

View xmapst's full-sized avatar

小学课本的小明 xmapst

View GitHub Profile
@xmapst
xmapst / expiredmap.go
Last active February 22, 2023 00:53
带过期的内存kv缓存
package expiremap
import (
"sort"
"sync"
"time"
)
type val struct {
@xmapst
xmapst / rabbitmq.go
Last active February 22, 2023 00:53
消费者断线重连
package rabbitmq
import (
"encoding/json"
"errors"
"fmt"
"github.com/sirupsen/logrus"
"github.com/streadway/amqp"
"google.golang.org/protobuf/proto"
"time"
@xmapst
xmapst / snowflake.go
Last active February 22, 2023 00:53
雪花算法
package snowflake
import (
"encoding/base64"
"encoding/binary"
"errors"
"fmt"
"strconv"
"sync"
"time"
@xmapst
xmapst / ratelimit.go
Last active February 22, 2023 00:53
ratelimit 用于读写io流的限速
package ratelimit
import (
"io"
"time"
)
// New 创建一个限数器
// rate 速度,rate/每秒
func New(rate int64) *Limiter {