随笔分类 - Go
摘要:做个笔记,没有连数据库,没有存redis,只是demo package main import ( "errors" "fmt" "log" "net/http" "strings" "time" "github.com/dgrijalva/jwt-go/v4" "github.com/gin-go
阅读全文
摘要:1. 布尔类型 可比较 2. 整型 可比较 3. 浮点数 可比较 4. 复数 可比较 5. 字串 可比较 6. 指针值 可比较 var num1, num2 int num1 = 8 num2 = 8 pt1 := &num1 pt2 := &num1 pt3 := &num2 //定义一个空指针
阅读全文
摘要:参考 https://juejin.cn/post/6847902215575699464 package main import ( "fmt" "math/rand" "strconv" "strings" "time" ) type hand uint const ( NilHand hand
阅读全文
摘要:runtime包 package main import ( "bytes" "log" "os" "runtime" "strconv" "time" ) func getGoroutineID() uint64 { b := make([]byte, 64) b = b[:runtime.Sta
阅读全文
摘要:docker-compose安装RocketMQ docker-compose.yml version: '3.8' services: namesrv: image: apache/rocketmq:5.3.0 container_name: rmqnamesrv ports: - 9876:98
阅读全文
摘要:以下代码有一些是通过gpt生成的 普通模式 package main import "fmt" type Ints []int func (i Ints) Iterator() *Iterator { return &Iterator{ data: i, index: 0, } } type Ite
阅读全文
摘要:文档官网 https://www.golancet.cn 安装 使用 go1.18 及以上版本的用户,建议安装 v2.x.x。 因为 v2.x.x 应用 go1.18 的泛型重写了大部分函数。 go get github.com/duke-git/lancet/v2 使用 go1.18 以下版本的用
阅读全文
摘要:Lock.go package lock import ( "context" "crypto/tls" "crypto/x509" "fmt" "go.etcd.io/etcd/clientv3" "io" "io/ioutil" "sync" "time" ) type Mutex struct
阅读全文
摘要:go语言不像其他语言函数的参数可以设置默认值 以下是参考第三方库的写法 package main import "fmt" type User struct { name string age int id int } // Option 代表可选参数 type Option func(foo *U
阅读全文
摘要:package main import ( "fmt" "github.com/gin-gonic/gin" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheu
阅读全文
摘要:package main import ( "os" "text/template" ) const templateText = `package {{.PackageName}} type {{.StructName}} struct { Field1 string Field2 int } f
阅读全文
摘要:main.go package main import ( "log" "net/http" _ "net/http/pprof" "syscall" "github.com/gobwas/ws" "github.com/gobwas/ws/wsutil" ) var epoller *epoll
阅读全文
摘要:offer.go package main import ( "bufio" "encoding/base64" "encoding/json" "fmt" "github.com/pion/webrtc/v4" "log" "os" "strconv" "time" ) func main() {
阅读全文
摘要:电脑需要有摄像头 main.go //go:build !js // +build !js // sfu-ws is a many-to-many websocket based SFU package main import ( "encoding/json" "flag" "github.com
阅读全文
摘要:proto.go package proto import ( "bufio" "bytes" "encoding/binary" ) // Encode 将消息编码 func Encode(message string) ([]byte, error) { // 读取消息的长度,转换成int32类
阅读全文
摘要:package main import ( "fmt" "time" "github.com/go-redis/redis" ) func err_handler(err error) { fmt.Printf("err_handler, error:%s\n", err.Error()) pani
阅读全文
摘要:有个同事,之前一直写弱类型语言,连链表结构都不知道。。。。下面是gpt解释 链表是一种常见的数据结构,用于存储一系列元素。与数组不同,链表中的元素在内存中不是连续存放的,而是通过每个元素(称为节点)中的指针(或引用)连接起来。链表的结构具有以下特点: 节点:链表由一系列节点组成,每个节点通常包含两部
阅读全文
摘要:package main import ( "fmt" ) func array_trunk(m map[string]int, n int) []map[string]int { l := len(m) s := l / n if l%n != 0 { s += 1 } res := make([
阅读全文
摘要:使用mysql包的时候,发现链式调用很好用,看了源码很简单,其实就是方法返回指针 package main import ( "fmt" ) type Mysql struct { Db string Table string } func (p *Mysql) SetDb(db string) *
阅读全文
摘要:一些示例Go版本需>=1.18 读取文件 1、将文件整个读入内存 package main import ( "fmt" "io" "os" ) func main() { file, err := os.Open("../log.txt") if err != nil { panic(err) }
阅读全文

浙公网安备 33010602011771号