# StudyNotbook **Repository Path**: cshare/studynotbook ## Basic Information - **Project Name**: StudyNotbook - **Description**: golang 学习笔记 以及部分代码片段备份 - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-10-03 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Golang 程序学习代码片段 相关笔记 [TOC] ## BasicsCode Golang 基础知识 ##### 基础知识 代码片段 - Assertion 断言使用 - chan 通道 - InterFace 接口使用 ## chan ```cassandraql // idx := 0 // cn :=make(chan int) // cn <- idx //数字idx 写入通道cn // <-cn 读取通道数据 // cn chan<- int 函数 只能写不能读 // cn <-chan int 函数 只能读不能写 ``` ```go // 将二维数组的切片连接起来,返回一个一维数组 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 ```go // 实现一个辅助函数,实现功能 将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 持久 下载 登陆认证