- 博客(223)
- 资源 (2)
- 收藏
- 关注
原创 Python指定函数参数和返回值的类型
函数注解本质上是Python语言中特殊的注释语法,可以提供更好的代码可读性和明确度,但并不会进行类型检查。在函数内部,仍然可以传递任何类型的参数和返回任何类型的值。(Function Annotation)来指定函数参数和返回值的类型。函数注解是Python 3引入的一种语法,允许。如果要进行类型检查,可以在函数中使用isinstance或其他类型检查函数来验证函数的参数和返回值是否符合预期类型。来指定函数参数和返回值的类型, 但这并不会影响函数的行为。
2023-07-05 11:24:35 1470
原创 国密sm2不同平台对接
4.如go对应的tjfoc/gmsm/sm2库加解密的密文前是添加了04的,如果要解密 https://webencrypt.org/sm2samplecryptjs/ 这里加密的密文,需要在密文前添加04。2.如这里的 https://webencrypt.org/sm2samplecryptjs/ 公钥前添加了04,但是密文前没有04.1.对不同的平台(语言)国密接口对接时,需要检查开始位,如公钥前加0x04、密文前加0x04,其实04代表未压缩。)加密的数据,到go服务程序解密,会出现。
2023-06-05 14:41:17 745 1
原创 国密SM4——golang的实现
SM4算法使用32轮的非线性迭代结构。SM4在最后一轮非线性迭代之后加上了一个反序变换,因此SM4中只要解密密钥是加密密钥的逆序,它的解密算法与加密算法就可以保持一致。1. CBC分组模式(Cipher Block Chaining ,密码分组链模式)以上代码中,SM4用到的库为:github.com/tjfoc/gmsm。SM4算法是我国商用密码标准,其前身是SMS4算法。整体逻辑结构如图所示,经过32轮变换把明文变换为密文。SM4算法类似于国际密码算法AES。,分组长度和密钥长度均。
2023-05-08 14:51:19 2024 1
原创 国密SM3——golang的实现
SM3密码杂凑算法是中国国家密码管理局2010年公布的中国商用密码杂凑算法标准。SM3适用于商用密码应用中的数字签名和验证,是在[]基础上改进实现的一种算法,其。
2023-05-08 14:37:49 636
原创 国密SM2——golang的实现
由于 RSA 算法和 ECC 算法这一明显不同,使得 ECC 算法的单位安全强度高于 RSA算 法。由于SM2是基于椭圆曲线的公钥加密算法,与RSA一样都是非对称密码算法。SM2是国家密码管理局于2010年12月17日发布的。也就是说,要达到同样的安全强度,
2023-05-08 14:28:31 2152
原创 Golang中json.Marshal避坑
1、介绍Golang库自带了json序列化与反序列化方法,type Marshalertype Marshaler interface { MarshalJSON() ([]byte, error)}实现了Marshaler接口的类型可以将自身序列化为合法的json描述。type Unmarshalertype Unmarshaler interface { UnmarshalJSON([]byte) error}实现了Unmarshaler接口的对象可
2022-04-22 17:53:13 11457
原创 Python列表生成式
列表生成式是一种基于其他iterable(如集合、元组、其他列表等)创建列表的方法。它还可以用更简单、更吸引人的语法表示for和if循环。列表生成式比for循环要快得多。列表生成式的基本结构如下:List=[ expression for item in iterable (if conditional) ]示例:if __name__ == '__main__': print('+++++++++++++++++ 简单用法 ++++++++++++++++') wo.
2022-04-13 10:39:05 973
原创 RSA no_padding加密(modulus、exponent构造公钥)
RSA no_padding加密(modulus、exponent构造公钥)
2022-01-26 15:42:18 7419 1
原创 Go语言(Golang)超时机制
机制1:select+time.After通过select+time.After方法实现超时机制,示例代码如下:package mainimport ( "context" "fmt" "runtime" "time")func main() { timeout1() println("Goroutine数量:",runtime.NumGoroutine()) time.Sleep(time.Second*10) println("Goroutine数量:",runtim
2021-11-21 22:51:47 2319
原创 设计模式——Go语言(Golang)版:24_迭代器模式
示例代码:package mainimport ( "fmt")//迭代器接口type Iterator interface { First() IsDone() bool Next() interface{}}//迭代的数据集type Aggregate interface { Iterator() Iterator}type Numbers struct { start, end int}//实现迭代器接口对应的功能type NumbersIterator s
2021-04-08 09:08:28 320
原创 设计模式——Go语言(Golang)版:23_访问者模式
示例代码:package mainimport "fmt"type Customer interface { Accept(visitor Visitor)}type Visitor interface { Visit(customer Customer)}//客户群type CustomerCol struct { customers []Customer}func (c *CustomerCol) Add(customer Customer) { c.custom
2021-04-08 09:08:03 378 1
原创 设计模式——Go语言(Golang)版:22_命令模式
示例代码:package mainimport "fmt"type Command interface { Execute()}type MotherBoard struct{}func (*MotherBoard) Start() { fmt.Println("系统启动中...")}func (*MotherBoard) Reboot() { fmt.Println("系统重启中...")}//====启动命令=====type StartCommand struc
2021-04-08 09:07:31 235
原创 设计模式——Go语言(Golang)版:21_备忘录模式
示例代码:package mainimport "fmt"//备忘录模式用于保存程序内部状态到外部,又不希望暴露内部状态的情形。type Memento interface{}type gameMemento struct { hp, mp int}type Game struct { hp, mp int}func (g *Game) Play(mpDelta, hpDelta int) { g.hp += hpDelta g.mp += mpDelta}func (
2021-04-08 09:07:03 209
原创 设计模式——Go语言(Golang)版:20_策略模式
示例代码:package mainimport "fmt"//支付环境type PaymentContext struct { Name ,CardId string Money int}//支付策略type PaymentStrategy interface { Pay(ctx *PaymentContext)}//支付type Payment struct { Context *PaymentContext Strategy PaymentStrategy}f
2021-04-08 09:06:30 520
原创 设计模式——Go语言(Golang)版:19_中介模式
示例代码:package mainimport ( "fmt" "strings")type CDDriver struct { Data string}func (c *CDDriver) ReadData() { //c.Data = "音乐、图片" fmt.Println("CD驱动器正在读取:", c.Data)}type CPUDriver struct { Video string Sound string}func (c *CPUDriver)
2021-04-07 09:24:26 180
原创 设计模式——Go语言(Golang)版:18_模板模式
示例代码:package mainimport "fmt"type DownLoader interface { Download(uri string)}//具体实施type implement interface { download() save()}//模板type template struct { implement uri string}func (t *template) Download(uri string) { t.uri = uri fm
2021-04-07 09:24:03 344 1
原创 设计模式——Go语言(Golang)版:17_状态模式
示例代码:package mainimport "fmt"//状态模式用于分离状态和行为。//周一 至 周日 时间之间的切换type Week interface { Today() Next(ctx *DayContext)}type DayContext struct { today Week}func (dc *DayContext)Today() { dc.today.Today() //调用父类(接口)的方法,具体实现是在对应的类(结构体)中}func
2021-04-07 09:23:35 229
原创 设计模式——Go语言(Golang)版:16_解释器模式
示例代码:package mainimport ( "fmt" "strconv" "strings")//解释器接口type Node interface { Interpret() int //解释方法}//数据节点type ValNode struct { val int}func (vn *ValNode) Interpret() int { return vn.val}//=============加法节点=============type Ad
2021-04-07 09:23:13 471
原创 设计模式——Go语言(Golang)版:15_观察者模式
示例代码:package mainimport "fmt"type Observer interface { Update(subject *Subject)}type Subject struct { observers []Observer msg string}//添加观察者func (s *Subject) Attach(o Observer) { s.observers = append(s.observers, o)}//通知信息到观察者fu
2021-04-07 09:22:44 296
原创 设计模式——Go语言(Golang)版:14_责任链模式
示例代码:package mainimport "fmt"type Manager interface { HaveRight(money int)bool //有权做 HandleFeeRequest(name string,money int)bool //处理费用请求}type RequestChain struct { Manager successor *RequestChain //后续者(链式结构,链表)}func (rc *RequestChain)HaveR
2021-04-07 09:22:22 331
原创 设计模式——Go语言(Golang)版:13_享元模式
示例代码:package mainimport "fmt"//轻量级图片type ImageFlyweight struct { data string}func (i *ImageFlyweight) Data() string { return i.data}func NewImageFlyweight(fileName string) *ImageFlyweight { d := fmt.Sprintf("image data:%s", fileName) retur
2021-04-07 09:21:51 159
原创 设计模式——Go语言(Golang)版:12_装饰器模式
示例代码:package mainimport "fmt"type Component interface { Calc() int}type ConcreteComponent struct{}func (*ConcreteComponent) Calc() int { return 0}//乘法修饰器type MulDecorator struct { Component num int}func (d *MulDecorator) Calc() int {
2021-04-07 09:21:22 350
原创 设计模式——Go语言(Golang)版:11_桥接模式
示例代码:package mainimport "fmt"//发送信息的具体实现(操作)type MessageImplementer interface { send(test, to string)}//发送SMStype MessageSMS struct{}func (*MessageSMS) send(test, to string) { fmt.Printf("SMS信息:[%v];发送到:[%v]\n", test, to)}func ViaSMS() *Mes
2021-04-07 09:20:40 253
原创 设计模式——Go语言(Golang)版:10_外观模式
示例代码:package mainimport "fmt"func NewAPI() API { return &apiImpl{ a: NewAModuleAPI(), b: NewBModuleAPI(), }}//API is facade interface of facade packagetype API interface { Test() string}//facade implementtype apiImpl struct { a A
2021-04-07 09:19:51 183
原创 设计模式——Go语言(Golang)版:09_代理模式
示例代码:package mainimport "fmt"type Subject interface { Do() string}type RealSubject struct{}func (r *RealSubject) Do() string { return "执行以太坊智能合约"}type ProxySubject struct { RealSubject money int}func (p *ProxySubject) Do() string { if
2021-04-06 17:38:29 167
原创 设计模式——Go语言(Golang)版:08_组合模式
示例代码:package mainimport "fmt"type Component interface { Parent() Component SetParent(Component) Name() string SetName(string) AddChild(Component) Print(string)}const ( LeafNode = iota CompositeNode)func NewComponent(kind int, name strin
2021-04-06 17:37:21 220
原创 设计模式——Go语言(Golang)版:07_适配器模式
示例代码:package mainimport "fmt"//================1.被适配对象================//被适配的接口type Adapter interface { SpecRequest(int, int) string}//接口载体type AdapterImpl struct{}func (ap *AdapterImpl) SpecRequest(int, int) string { return "目标对象:SpecReque
2021-04-06 17:34:41 261
原创 设计模式——Go语言(Golang)版:06_建造者模式
示例代码:package mainimport "fmt"//================1.建造者接口==============//Builder 是生成器接口type Builder interface { Part1() Part2() Part3()}//===============2.建造者对象及操作===============type Director struct { builder Builder //建造者的接口}//创建接口func N
2021-04-06 17:33:25 248
原创 设计模式——Go语言(Golang)版:05_原型模式
示例代码:package mainimport "fmt"//1.原型对象需要实现的接口type Cloneable interface { Clone() Cloneable}//2.原型对象的类type PrototypeManager struct { prototypes map[string]Cloneable}//3.原型对象操作func NewPrototypeManger() *PrototypeManager { return &Prototy
2021-04-06 17:32:08 253
原创 设计模式——Go语言(Golang)版:04_单例模式
示例代码:package mainimport ( "fmt" "sync")type SingleData struct { data interface{}}var data *SingleDatavar once sync.Once //通过该类型可以实现单例模式,虽然是多次赋值,但是只执行一次(一个对象多次实例化,但是只有一个,共享对象地址)func getInstance(i int) *SingleData { once.Do(func() { data
2021-04-06 17:28:21 205
原创 设计模式——Go语言(Golang)版:03_抽象工厂模式
示例代码:package mainimport "fmt"//OrderMainDAO 为订单主记录type OrderMainDAO interface { SaveOrderMain()}//OrderDetailDAO 为订单详情纪录type OrderDetailDAO interface { SaveOrderDetail()}//DAOFactory DAO 抽象模式工厂接口type DAOFactory interface { CreateOrderMain
2021-04-06 17:26:50 495
原创 设计模式——Go语言(Golang)版:02_工厂方法模式
示例代码:package main//==============2.工厂模式===================//Operator 是被封装的实际类接口type Operator interface { SetA(int) SetB(int) Result() int}//OperatorFactory 是工厂接口type OperatorFactory interface { Create() Operator}//OperatorBase 是Operator 接口
2021-04-06 17:25:00 359
原创 设计模式——Go语言(Golang)版:01_简单工厂模式
示例代码:package mainimport "fmt"//===============1.定义简单接口=================type SimpleAPI interface { Say(content string) string}//===============2.实现对应的接口===============//对象1type Chinese struct {}func (c *Chinese) Say(content string) string {
2021-04-06 17:22:51 433
Go 学习笔记 第四版.pdf
2018-10-07
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人