golang的SQL脱敏代码示例

package main

import (
	"fmt"
	"hash/crc32"

	"github.com/pingcap/tidb/parser"
) 

func main() {
	sts := "select * from table where id = 10"
	sts1 := "select * from table where id = 12"
	sql := parser.Normalize(sts)
	fmt.Println(sql)
	crc_result := crc32.ChecksumIEEE([]byte(sql))
	crc64data := int64(crc_result)
	fmt.Println(crc64data)
	sql = parser.Normalize(sts1)
	fmt.Println(sql)
	crc_result = crc32.ChecksumIEEE([]byte(sql))
	crc64data = int64(crc_result)
	fmt.Println(crc_result, crc64data)
}

配置go.mod文件:

...()
require github.com/pingcap/tidb/parser v0.0.0-20211124132551-4a1b2e9fe5b5
...()

输出:

select * from table where `id` = ?
523556088
select * from table where `id` = ?
523556088 523556088

你可能感兴趣的:(golang,sql,开发语言)