1 Star 0 Fork 0

wordgao / StudyNotbook

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
README.md 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
wordgao 提交于 2020-10-24 10:04 . 添加chan说明

Golang 程序学习代码片段 相关笔记

[TOC]

BasicsCode Golang 基础知识

基础知识 代码片段
- Assertion 断言使用
- chan 通道
- InterFace 接口使用

chan

// idx := 0
// cn :=make(chan int)
// cn <- idx  //数字idx 写入通道cn
// <-cn 读取通道数据
// cn chan<- int 函数 只能写不能读
// cn <-chan int 函数 只能读不能写
// 将二维数组的切片连接起来,返回一个一维数组
TwoBytes:=[][]byte{
    Uint64ToByte(block.Version),
    block.PrevHash,
    block.MerkelRoot,
    Uint64ToByte(block.TimeStamp),
    Uint64ToByte(block.Difficulty),
    Uint64ToByte(block.Nonce),
    block.Data,
    }
blockInfo:=bytes.Join(TwoBytes,[]byte{})

· 字符串转换 将uint64转成[]byte

// 实现一个辅助函数,实现功能 将uint64转成[]byte
func Uint64ToByte(num uint64) []byte{
    var buffer bytes.Buffer
    err:=binary.Write(&buffer, binary.BigEndian,num)
    if err != nil{
        panic(err)
    }
    return buffer.Bytes()
}

· gob进行序列化 比上面的 binary.Write 更稳定


EncryptionAndDecryption

MD4 MD5 SHA1 SHA2 DES AES 加解密等片段
-- 加密推荐模式 CBC CTR
--  AES_Encrypt AES加密
--  DES_Encrypt DES加密
--  DigitalSignature  RSA签名和认证
--  EllipticDSA 椭圆曲线签名和认证
--  GenericMsgAuthHMAC 消息认证码
--  MD5orSHA MD4 MD5 SHA1 SHA2 计算散列值
--  RSAEncryptionAndDecryption RSA加解密
--  base64 编码解码 以及URL编码和解码

HttpClientRequests Golang HTTP 的请求方法

请求方式
cookie 
porxy
GET
POST
FROM
持久
下载
登陆认证
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/cshare/studynotbook.git
git@gitee.com:cshare/studynotbook.git
cshare
studynotbook
StudyNotbook
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891