zeromicro / go-zero

A cloud-native Go microservices framework with cli tool for productivity.
https://go-zero.dev
MIT License
29.31k stars 3.96k forks source link

Is it possible to support interface in goctl? #4125

Open Linde7777 opened 6 months ago

Linde7777 commented 6 months ago

Is your feature request related to a problem? Please describe. I need to write unit-test, which need gomock, and it need interface

Describe the solution you'd like

package logic

type UserLogic interface {
    UserCreate(in *user.UserReq) (*user.UserResp, error)
    UserDelete(in *user.UserReq) (*user.UserResp, error)
}

type UserLogicV1 struct {
    UserRepo repository.UserRepository
}

// compile-time checking if UserLogicV1 implement UserLogic interface
var _ UserLogic = (*UserLogicV1)(nil)

// return the concrete implementation instead of interface, as Go style suggests
func NewUserLogicV1(userRepo repository.UserRepository) *UserLogicV1 {
    return &UserLogicV1{
        UserRepo: userRepo,
    }
}

Describe alternatives you've considered currently no

Additional context currently no

kesonan commented 6 months ago

not support yet, and no plan to support, define a template in logic.tpl maybe a good choice.