Giter VIP home page Giter VIP logo

repogen's People

Contributors

hhow09 avatar sunboyy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

repogen's Issues

Repository Interface and destination in different packages from Model

Nice generator package!

Is your feature request related to a problem? Please describe.
With dependency injection pattern, it's common that controller package defines the repository interface and accept it as input. However current implementation requires that repository interface and model type located within the same package.

Describe the solution you'd like
It would be nice if it could support the setup like this.

examples/ref_exp
├── ctrl
│   └── ctrl.go
├── repo
│   └── user_repo.go // generated
└── user.go
// ctrl.go
package ctrl

//go:generate repogen -pkg=.. -dest=../repo/user_repo.go -model=UserModel -repo=UserRepository

// UserRepository is an interface that describes the specification of querying
// user data in the database.
type UserRepository interface {
	// InsertOne stores userModel into the database and returns inserted ID
	// if insertion succeeds and returns error if insertion fails.
	InsertOne(ctx context.Context, userModel *ref_exp.UserModel) (interface{}, error)
	// FindByUsername queries user by username. If a user with specified
	// username exists, the user will be returned. Otherwise, error will be
	// returned.
	FindByUsername(ctx context.Context, username string) (*ref_exp.UserModel, error)

        ...
}

func NewController(userRepo UserRepository ... )...

Additional context
Just play around the code base. For this feature these might be related:

  • Package ID of where Model located. (to be used in RepositoryGenerator.Imports() )
  • in interfaceMethodParser there are some operation mode checking. And about the type comparison. Not sure how to allow imported types like *ref_exp.UserModel in args and return. (Currently it will check with p.StructModel).

generated repository should return concrete type instead of interface

Is your feature request related to a problem? Please describe.
generated repository should return concrete type instead of interface

currently NewUserRepository in example is returning interface.
However as suggestion in go codereview

Go interfaces generally belong in the package that uses values of the interface type, not the package that implements those values. The implementing package should return concrete (usually pointer or struct) types 1

*UserRepositoryMongo should be returned.

btw you can assert the implementation in test file

// user_repo_test.go
var _ UserRepository  = (*UserRepositoryMongo)(nil)

Describe the solution you'd like
return concrete type

Footnotes

  1. https://go.dev/wiki/CodeReviewComments#interfaces

Detect model automatically based on model data in interface

Just found this great generator but missing one thing to use it in our project with data model generated by other tool (OpenAPI spec generator)

Is your feature request related to a problem? Please describe.

I'm using model from pkg auto-generated from OpenAPI spec so would not want to copy it everytime into file where interface is.

Describe the solution you'd like

Ignore -model flag, just detect it in from the interface methods definitions (copy the same?) during generation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.