The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
f1ren2es

请教一下 go orm 字段复用问题

  •  
  •   f1ren2es · May 26, 2019 · 3069 views
    This topic created in 2578 days ago, the information mentioned may be changed or developed.
    刚刚接触 go, 发现写 orm 时存在一个问题, 要复用 orm 定义的字段不能如 java / py 一样直接继承父类字段到子类, 例如初始化时需要先初始化子类内嵌的父类,然后再初始化子类,想问下有没有比较优雅的技巧实现重复字段的复用
    4 replies    2019-06-13 07:27:38 +08:00
    leon0903
        1
    leon0903  
       May 26, 2019
    谁说不能复用的。。。
    struct A
    {
    }

    struct B{
    A
    ....
    }
    这就是复用
    Vegetable
        2
    Vegetable  
       May 27, 2019
    polebug
        3
    polebug  
       May 27, 2019 via Android
    lz 先学习一下继承?
    1800x
        4
    1800x  
       Jun 13, 2019 via Android
    怎样才能叫优雅?
    下面的如何?

    type A struct{
    Num int
    }
    type B struct {
    A
    }

    func NewB(num int) *B{
    b := &B{}
    b.Num = num
    return b
    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1020 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 22:12 · PVG 06:12 · LAX 15:12 · JFK 18:12
    ♥ Do have faith in what you're doing.