Golang设计模式之原型模式

Jackey Golang 1,825 次浏览 0 评论 , ,
package main import "fmt" // 原型对象需要实现的接口 // copy 原有的对象 type Cloneable interface { Clone() Cloneable } // 原型的类 type PrototypeManager struct { prototypes map[string]Cloneable ...

Golang设计模式之单例

Jackey Golang 1,997 次浏览 0 评论 , ,
package main import ( "fmt" "sync" ) type Single struct { Data int } var singleton *Single var once sync.Once // 内核信号,时时刻刻只能运行一个 func GetInterface() *Single { once.Do(...

Golang设计模式之抽象工厂

Jackey Golang 1,816 次浏览 0 评论 , ,
创建DAOFactory.go package AbstractFactory // mysql // sqlserver // oracle // 订单 // 订单报表 type OrderMainDAO interface { // 订单记录 SaveOrderMain() // 保存 //DeleteOrderMain() //SearchOrd...

Golang设计模式之工厂

Jackey Golang 1,986 次浏览 0 评论 , ,
新建 OperatorFactory.go package factory // 实际运行类的接口 type Operator interface { SetLeft(int) SetRight(int) Result() int } // 工厂接口 type OperatorFactory interface { Create() Opera...

Golang 接口与多态

Jackey Golang 2,576 次浏览 0 评论 , ,
package main import ( "fmt" ) type A interface { Get() } type B struct { } func (b *B) Get () { fmt.Println("b") } type C struct { } func (c *C) Get () { fmt.Println("c") } f...

IDEA 利用 go mod 管理 beego 项目

Jackey Golang 3,808 次浏览 0 评论 ,
项目名称:test mkdir goproject cd goproject mkdir src mkdir test 进入IDEA, 打开到 test项目,然后配置IDEA的gopath和代理网址: 说明:配置gopath是为了找到bee命令,配置代理网址:https://goproxy.cn,是为...

Golang 利用redis加并发锁

Jackey Golang, Redis 4,350 次浏览 3 评论 ,
package main import ( "fmt" "github.com/go-redis/redis" "time" ) // 定义redis链接池 var RedisTest *redis.Client // 初始化redis链接池 func init() { RedisTest = redis.NewClient(&redis.Options...

Golang mac编译linux、windows可执行程序

Jackey Golang 2,739 次浏览 1 评论
mac下编译Linux, Windows平台的64位可执行程序: $ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build test.go $ CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build test.go

Golang 比较两个版本号

Jackey Golang 6,517 次浏览 1 评论 ,
要求 比较两个版本号 version1 和 version2。 如果 version1 > version2 返回 1,如果 version1 < version2 返回 -1, 除此之外返回 0。 你可以假设版本字符串非空,并且只包含数字和 . 字符。 . 字符不代表小数点,而...
Go