• ly
    2023-02-10 来自贵州
    goos: darwin goarch: arm64 pkg: goup BenchmarkDirect-10 473992540 2.476 ns/op BenchmarkInterface-10 483796916 2.479 ns/op BenchmarkInterfacePointer-10 483879259 2.483 ns/op PASS ok goup 4.484s go1.20的测试...

    作者回复: Go的编译器越来越好了哈

    
    1
  • 青鹿
    2023-02-09 来自上海
    请问,代码项目地址有吗?

    作者回复: https://github.com/dreamerjackson/crawler

    
    
  • 牙小木
    2023-08-16 来自北京
    trade的部分,大概是这个意思 ``` package main import ( "context" "github.com/go-xorm/xorm" "gorm.io/gorm" ) //声明一个统一的insert接口 type DBer interface { InsertRow(ctx context.Context, instance ...interface{}) } type XormDB struct { db *xorm.Session } func (xorm *XormDB) InsertRow(ctx context.Context, instance ...interface{}) { xorm.db.Context(ctx).Insert(instance) } type GormDB struct { db *gorm.DB } func (gorm *GormDB) InsertRow(ctx context.Context, value ...interface{}) { gorm.db.Create(value) } //定义业务统一操作 type Trade struct { db DBer } func (t *Trade) AddDB(db DBer) { t.db = db } func (t *Trade) AddTrade(ctx context.Context, instance ...interface{}) { t.db.InsertRow(ctx, instance) } func main() { //dber:=&XormDB{} orm := &GormDB{} t := &Trade{db: orm} ctx := context.Background() t.AddTrade(ctx, "xiaoming,28") } ```
    展开
    
    
  • 牙小木
    2023-08-16 来自北京
    cpu: Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz BenchmarkDirect-4 412734510 2.860 ns/op BenchmarkInterface-4 331038409 3.693 ns/op BenchmarkInterfacePointer-4 327338402 3.640 ns/op PASS
    
    
  • 爱编程的运维
    2023-04-12 来自广东
    老师,你上面的代码怎么测试啊? 我新建了一个test.go文件,然后把代码复制进去,再在命令行执行: go test -gcflags "-N -l" -bench=. 提示:? gitee.com/qiankai_git/crawler.git [no test files]
    共 1 条评论
    
  • Geek_8ed998
    2023-02-23 来自上海
    这个接口不是实现的insert方法吗,怎么又可以调用creat阿
    
    