随笔分类 -  golang

摘要:https://xiazemin.github.io/MyBlog/golang/2020/04/13/statically.html go build -o release/main_linux_amd64 -ldflags '-linkmode "external" -extldflags "- 阅读全文
posted @ 2023-06-06 15:15 GPHPER 阅读(397) 评论(0) 推荐(0)
摘要:# Channel 定义 只能使用 `make` 进行初始化 ```go ch := make(chan int,0) ``` * 有缓存的channel和无缓存channel * channel 数据操作 1. 向channel 中添加数据 + `ch <- 数据` 2. 读取数据 + 直接读取 阅读全文
posted @ 2023-05-29 10:32 GPHPER
摘要:map中hash的 低B位确定桶的位置,高8位确定桶中的 key/value 位置 GC原理 https://www.cnblogs.com/cxy2020/p/16321884.html 题 https://blog.csdn.net/qq_41385137/article/details/127 阅读全文
posted @ 2023-04-20 18:01 GPHPER 阅读(30) 评论(0) 推荐(0)
摘要:排查程序突然崩溃的方法可是试试 coredump + dlv 阅读全文
posted @ 2023-03-08 10:13 GPHPER
摘要:package main import ( "fmt" "time" ) /* 有关Task任务相关定义及操作 */ //定义任务Task类型,每一个任务Task都可以抽象成一个函数 type Task struct { f func() error //一个无参的函数类型 } //通过NewTas 阅读全文
posted @ 2023-01-06 14:53 GPHPER 阅读(81) 评论(0) 推荐(0)
摘要:从文件中获取注释信息 package main import ( "go/ast" "go/parser" "go/token" "log" "path/filepath" ) type Visitor struct { fset *token.FileSet } func (v *Visitor) 阅读全文
posted @ 2022-12-13 14:51 GPHPER 阅读(583) 评论(0) 推荐(0)
摘要:结构体中字段类型的改变直接造成内存对齐结果的改变,是的占用内存空间也不一样 package main import ( "fmt" "unsafe" ) func main() { var xx struct { a bool b int32 c []int } var x struct { a i 阅读全文
posted @ 2022-11-13 14:58 GPHPER 阅读(30) 评论(0) 推荐(0)
摘要:package main import ( "fmt" "runtime" "time" ) //定义一个实现Job接口的数据 type Score struct { Num int } //定义对数据的处理 func (s *Score) Do() { fmt.Println("num:", s. 阅读全文
posted @ 2022-09-30 11:50 GPHPER 阅读(30) 评论(0) 推荐(0)
摘要:golang 安装程序为服务 package main import ( "context" "fmt" "io" "log" "net/http" "os" "path/filepath" "github.com/gin-gonic/gin" "github.com/kardianos/servi 阅读全文
posted @ 2022-09-21 13:11 GPHPER 阅读(110) 评论(0) 推荐(0)
摘要:在需要分步写入整条信息时做回滚操作时使用 /* * @Description: * @Author: gphper * @Date: 2021-11-06 20:11:56 */ package main import ( "fmt" "io" "log" "os" ) func main() { 阅读全文
posted @ 2022-03-20 12:24 GPHPER 阅读(466) 评论(0) 推荐(0)
摘要:基础知识(1) 基础知识(2) 函数 数据和切片 map类型 struct结构体 面向对象(方法) 面向对象(接口) 异常 字符串操作 json数据 文件操作 协程 Channel Channel select sync库 context库 阅读全文
posted @ 2021-06-19 10:24 GPHPER
摘要:package main import ( "github.com/golang/freetype" "image" "image/color" "image/png" "io/ioutil" "log" "os" ) func main() { //图片的宽度 srcWidth := 200 // 阅读全文
posted @ 2021-04-26 13:04 GPHPER 阅读(725) 评论(0) 推荐(0)
摘要:GinAdmin 这个项目是以Gin框架为基础搭建的后台管理平台,虽然很多人都认为go是用来开发高性能服务端项目的,但是也难免有要做web管理端的需求,总不能再使用别的语言来开发吧。所以整合出了GinAdmin项目,请大家多提意见指正! GitHub地址 https://github.com/gph 阅读全文
posted @ 2021-04-24 11:21 GPHPER 阅读(1344) 评论(0) 推荐(0)
摘要:WithCancel(主进程控制子协程关闭) package main import ( "context" "fmt" "sync" "time" ) var wg sync.WaitGroup func f(ctx context.Context) { defer wg.Done() LOOP: 阅读全文
posted @ 2021-03-06 11:59 GPHPER 阅读(165) 评论(0) 推荐(0)
摘要:sync.WaitGroup 优雅的同步执行协程 package main import ( "fmt" "math/rand" "sync" "time" ) func f1(i int) { defer wg.Done() rand.Seed(time.Now().UnixNano()) tim 阅读全文
posted @ 2021-03-05 21:24 GPHPER 阅读(160) 评论(0) 推荐(0)
摘要:select就是用来监听和channel有关的IO操作,当 IO 操作发生时,触发相应的动作 package main import ( "fmt" "time" ) func main() { ch := make(chan int) o := make(chan bool) go func() 阅读全文
posted @ 2021-03-05 20:57 GPHPER 阅读(81) 评论(0) 推荐(0)
摘要:Timer定时器 启动 package main import ( "fmt" "time" ) func main() { <-time.After(2 * time.Second) fmt.Println("延时两秒") } func main02() { time.Sleep(2 * time 阅读全文
posted @ 2021-03-03 21:15 GPHPER 阅读(111) 评论(0) 推荐(0)
摘要:Channel通道 无缓存通道 make(chan type类型) 注意:读和写都是阻塞执行的 package main import ( "fmt" "time" ) var ch = make(chan int) func Printer(str string) { for _, data := 阅读全文
posted @ 2021-03-02 21:38 GPHPER 阅读(90) 评论(0) 推荐(0)
摘要:当主协程退出后子协程也会退出 package main import ( "fmt" "time" ) func main() { go func() { i := 0 for { i++ fmt.Println("son i = ", i) time.Sleep(time.Second) } }( 阅读全文
posted @ 2021-03-02 20:57 GPHPER 阅读(127) 评论(0) 推荐(0)
摘要:标准设备文件操作 package main import ( "os" ) func main() { os.Stdout.WriteString("hello world") //相当于fmt.Println } 磁盘文件操作 package main import ( "bufio" "fmt" 阅读全文
posted @ 2021-03-02 20:24 GPHPER 阅读(112) 评论(0) 推荐(0)

TOP