Golang Expr不完全指南

安装 库的说明 Expr package provides an engine that can compile and evaluate expressions. An expression is a one-liner that returns a value (mostly, but not limited to, booleans). It is designed for simplicity, speed and safety. The purpose of the package is to allow users to use expressions inside configuration for more complex logic. It is a perfect candidate for the foundation of a business rule engine. 安装 go get -u github....

July 13, 2022 · 9 min · czyt

Golang DSL参考

ANTLR 4 图书 The definitive ANTLR 4 reference (2014) 英文版下载 中文版下载 文章 使用ANTLR和Go实现DSL入门 手把手教你使用ANTLR和Go实现一门DSL语言part1 part2part3part4part5 Parsing with ANTLR 4 and Go 实例代码 bilibili gengine link go-zero link grule-rule-engine https://github.com/kulics-works/feel-go windows 环境配置 配置好Java环境,然后将下面的批处理加入系统环境变量: antlr.cmd @echo off java -classpath %~dp0antlr-4.12.0-complete.jar org.antlr.v4.Tool %* grun.cmd @echo off java -classpath %~dp0antlr-4.12.0-complete.jar org.antlr.v4.gui.TestRig %* Others 图书 Writing A Compiler In Go Writing an Interpreter in Go µGo语言实现——从头开发一个迷你Go语言编译器 文章 Build your own DSL with Go & HCL...

July 11, 2022 · 1 min · czyt

Vue 相关资源

Vue - The Complete Guide (incl. Router & Composition API) The Vue.js 3 Masterclass TypeScript Friendly Vue 3 Vue.js Fundamentals

June 30, 2022 · 1 min · czyt

Golang io.Pipe 使用

介绍 // Pipe creates a synchronous in-memory pipe. // It can be used to connect code expecting an io.Reader // with code expecting an io.Writer. // // Reads and Writes on the pipe are matched one to one // except when multiple Reads are needed to consume a single Write. // That is, each Write to the PipeWriter blocks until it has satisfied // one or more Reads from the PipeReader that fully consume // the written data....

June 24, 2022 · 3 min · czyt

go embed 使用小记

​ go embed 是go 1.16 开始添加的特性,允许嵌入文件及文件夹,在Go程序中进行使用。官方还为此添加了embed.FS的对象。下面将常用的使用场景进行简单列举: 嵌入单个文件 官方的例子 嵌入文件并绑定到字符串变量 import _ "embed" //go:embed hello.txt var s string print(s) 嵌入文件并绑定到字节变量 import _ "embed" //go:embed hello.txt var b []byte print(string(b)) 嵌入文件并绑定到文件对象 import "embed" //go:embed hello.txt var f embed.FS data, _ := f.ReadFile("hello.txt") print(string(data)) 嵌入目录 嵌入时,可以在多行或者一行输入要嵌入的文件和文件夹。 package server import "embed" // content holds our static web server content. //go:embed image/* template/* //go:embed html/index.html var content embed.FS 在匹配文件夹时,embed会嵌入包括子目录下的所有除.和_开头的文件(递归),所以上面的代码大致等价于下面的代码: // content is our static web server content....

June 23, 2022 · 1 min · czyt

Git小技巧

Windows下GIT的几个小技巧 记住git密码 使用下面命令可以设置记住git密码,但推荐使用ssh进行操作。 git config credential.helper store 设置换行符转换 在windows下开发时,迁出的代码是CRLF会导致编译的sh脚本不能正确执行: git config --global core.autocrlf false Git推送到多个服务器 要实现一次push到多个远程仓库 本机git仓库A https://aaaaa.git 要同步push的远程git仓库B https://bbbbb.git 通过git remote add添加 先使用git remote -v查看远程仓库的情况 ,然后添加一个git仓库 git remote add b https://bbbbb.git 再次查看远程仓库情况,如果需要push,则需要push两次 通过git remote set-url 添加 如果按上面添加过remote分支,需要先git remote rm b,使用下面命令添加即可。 git remote set-url --add a https://bbbbb.git 查看远程仓库情况,看看是否已经是两个push地址了 。这个只需push一次就行了 修改配置文件 打开 .git/config 找到 [remote “github”],添加对应的 url 即可,效果如下。这种方法其实和方法二是一样的。 [remote "a"] url = https://aaaaa.git fetch = +refs/heads/*:refs/remotes/a/* url = https://bbbbb.git 参考链接 ● 一个项目push到多个远程Git仓库 https://segmentfault....

June 17, 2022 · 2 min · czyt

Golang nocopy check

目的 实现nocopy的目的在于,golang在进行参数传递时,都是传递副本的方式。但是某些情况,我们是需要进行传递对象的引用的(特别是一些指针对象,可能会导致多个指针的副本的操作造成程序陷入恐慌),为了杜绝调用者的复制,只能指针传递全局唯一对象。那么就可以通过添加nocopy来实现对go vet参数支持的no copy 检查。 实现 golang里面最常用的sync.WaitGroup就是通过nocopy实现的。参考定义 // A WaitGroup must not be copied after first use. type WaitGroup struct { noCopy noCopy // 64-bit value: high 32 bits are counter, low 32 bits are waiter count. // 64-bit atomic operations require 64-bit alignment, but 32-bit // compilers do not ensure it. So we allocate 12 bytes and then use // the aligned 8 bytes in them as state, and the other 4 as storage // for the sema....

June 17, 2022 · 1 min · czyt

golang正则校验支付宝微信支付授权码

参考sdk定义 package main import ( "fmt" "regexp" ) // wechat pay 用户付款码条形码规则:18位纯数字,以10、11、12、13、14、15开头 // alipay 支付授权码,25~30开头的长度为16~24位的数字,实际字符串长度以开发者获取的付款码长度为准 func main() { // wechat regwechat:=regexp.MustCompile("^(1[0-5])\\d{16}$") matchwechat := regwechat.MatchString("154658833119096245") fmt.Println(matchwechat) // alipay regalipay:=regexp.MustCompile("^(2[5-9]|30)\\d{14,22}$") matchalipay := regalipay.MatchString("307573774583867517336") fmt.Println(matchalipay) } 参考 微信 支付宝

June 17, 2022 · 1 min · czyt

Linux环境下Perl提权

事故起因 我们公司的应用程序部署目录有个bin目录,手误,删除的时候输入的是/bin 事故现象 ● SSH 不能登陆进来了 ● ls、chmod等常用命令都不能使用了 ● wget 还能用 事故解决 通过查找谷歌,发现有个perl带有提权的功能,简单来说就是 perl -e "chmod 0777, '/bin/ls'" 通过这个方式可以对指定的文件进行权限的修改。于是从另外的机器上打包了一个/bin目录,放到网上,wget 下载到本地wget bin.tar.gz ​ 本机开外网ssh转发,scp 拷贝tar文件到目录,执行 perl -e "chmod 0777, './tar'" ,再使用tar进行文件解压./tar xvzf bin.tar.gz -C /,然后再给chmod执行文件赋予执行权限 perl -e "chmod 0777, '/bin/chmod'" 然后再通过chmod 执行 chmod -R +x /bin/给/bin目录下的可执行程序文件授予执行权限。至此,完成事故修复。 参考连接 ● https://perldoc.perl.org/functions/chmod.html

June 17, 2022 · 1 min · czyt

ebpf Golang参考

整理一个列表,持续更新。 理论 ebf官网 B站视频 eBPF 和 Go,超能力组合 实践 Tracing Go Functions with eBPF part1 part2 Getting Started with eBPF and Go Linux中基于eBPF的恶意利用与检测机制 如何用eBPF分析Golang应用 使用BPF, 将Go网络程序的吞吐提升8倍 使用ebpf跟踪rpcx微服务 BPF MAP机制 一种通用数据结构,可以存储不同类型数据的通用数据结构 Andrii Nakryiko 抽象数据容器(abstract data container) bpf系统调用的说明 《使用C语言从头开发一个Hello World级别的eBPF程序》 《Linux Observability with BPF》 《揭秘BPF map前生今世》 bpf系统调用说明 官方bpf map参考手册 bpftool参考手册 《Building BPF applications with libbpf-bootstrap》 https://github.com/DavadDi/bpf_study https://github.com/mikeroyal/eBPF-Guide#go-development golang 包 https://github.com/cilium/ebpf

June 11, 2022 · 1 min · czyt