cheekybits / genny

Elegant generics for Go
MIT License
1.71k stars 167 forks source link

generic.Type support function definition ? #80

Open achilsh opened 1 year ago

achilsh commented 1 year ago

i want to define function with generic.Type define. for example: define template_demo.go :

  1. type ModelType generic.Type

func registerModelType() { MngCreater = append(MngCreater, ModelType(GlobalmgDb)) }

  1. then run genny command:

input_file="./template_res_register.go" out_file="res_register_1.go" ## real_type="RegisterSignDailyFortuneMg,RegisterSecretChitchatWork" ###RegisterSecretChitchatWork pkg_name="common_res" genny -in ${input_file} -out ${out_file} -pkg ${pkg_name} gen "ModelType=${real_type}"

  1. then generated codes:

func registerRegisterSecretChitchatWork() { MngCreater = append(MngCreater, RegisterSecretChitchatWork(GlobalmgDb)) }

  1. when i build project, error happen . show defined template file err:

cannot use ModelType(GlobalmgDb) (value of type ModelType) as data_cache.CreateRes value in argument to append: ModelType does not implement data_cache.CreateRes (missing method Create)