@@ -31,7 +31,7 @@ type AddTypeOption struct {
3131}
3232
3333// AddType adds a new type stype to scaffolded app by using optional type fields. 
34- func  (s  * Scaffolder ) AddType (addTypeOptions  AddTypeOption , moduleName  string , stype  string , fields  ... string ) error  {
34+ func  (s  * Scaffolder ) AddType (addTypeOptions  AddTypeOption , moduleName  string , typeName  string , fields  ... string ) error  {
3535	version , err  :=  s .version ()
3636	if  err  !=  nil  {
3737		return  err 
@@ -54,18 +54,18 @@ func (s *Scaffolder) AddType(addTypeOptions AddTypeOption, moduleName string, st
5454		return  fmt .Errorf ("the module %s doesn't exist" , moduleName )
5555	}
5656
57- 	// Ensure the type name is not a Go reserved name,  it would generate an incorrect code 
58- 	if  isGoReservedWord ( stype ) {
59- 		return  fmt .Errorf ("%s can't be used as a type name" , stype )
57+ 	// Ensure the type name is valid, otherwise  it would generate an incorrect code 
58+ 	if  isForbiddenComponentName ( typeName ) {
59+ 		return  fmt .Errorf ("%s can't be used as a type name" , typeName )
6060	}
6161
6262	// Check type is not already created 
63- 	ok , err  =  isTypeCreated (s .path , moduleName , stype )
63+ 	ok , err  =  isTypeCreated (s .path , moduleName , typeName )
6464	if  err  !=  nil  {
6565		return  err 
6666	}
6767	if  ok  {
68- 		return  fmt .Errorf ("%s type is already added" , stype )
68+ 		return  fmt .Errorf ("%s type is already added" , typeName )
6969	}
7070
7171	// Parse provided field 
@@ -81,7 +81,7 @@ func (s *Scaffolder) AddType(addTypeOptions AddTypeOption, moduleName string, st
8181			ModulePath : path .RawPath ,
8282			ModuleName : moduleName ,
8383			OwnerName :  owner (path .RawPath ),
84- 			TypeName :   stype ,
84+ 			TypeName :   typeName ,
8585			Fields :     tFields ,
8686			Legacy :     addTypeOptions .Legacy ,
8787		}
@@ -208,20 +208,6 @@ func isTypeCreated(appPath, moduleName, typeName string) (isCreated bool, err er
208208	return 
209209}
210210
211- // isMsgServerDefined checks if the module uses the MsgServer convention for transactions 
212- // this is checked by verifying the existence of the tx.proto file 
213- func  isMsgServerDefined (appPath , moduleName  string ) (bool , error ) {
214- 	txProto , err  :=  filepath .Abs (filepath .Join (appPath , "proto" , moduleName , "tx.proto" ))
215- 	if  err  !=  nil  {
216- 		return  false , err 
217- 	}
218- 
219- 	if  _ , err  :=  os .Stat (txProto ); os .IsNotExist (err ) {
220- 		return  false , nil 
221- 	}
222- 	return  true , err 
223- }
224- 
225211// isForbiddenTypeField returns true if the name is forbidden as a field name 
226212func  isForbiddenTypeField (name  string ) bool  {
227213	switch  name  {
@@ -234,53 +220,3 @@ func isForbiddenTypeField(name string) bool {
234220
235221	return  isGoReservedWord (name )
236222}
237- 
238- func  isGoReservedWord (name  string ) bool  {
239- 	// Check keyword or literal 
240- 	if  token .Lookup (name ).IsKeyword () {
241- 		return  true 
242- 	}
243- 
244- 	// Check with builtin identifier 
245- 	switch  name  {
246- 	case 
247- 		"panic" ,
248- 		"recover" ,
249- 		"append" ,
250- 		"bool" ,
251- 		"byte" ,
252- 		"cap" ,
253- 		"close" ,
254- 		"complex" ,
255- 		"complex64" ,
256- 		"complex128" ,
257- 		"uint16" ,
258- 		"copy" ,
259- 		"false" ,
260- 		"float32" ,
261- 		"float64" ,
262- 		"imag" ,
263- 		"int" ,
264- 		"int8" ,
265- 		"int16" ,
266- 		"uint32" ,
267- 		"int32" ,
268- 		"int64" ,
269- 		"iota" ,
270- 		"len" ,
271- 		"make" ,
272- 		"new" ,
273- 		"nil" ,
274- 		"uint64" ,
275- 		"print" ,
276- 		"println" ,
277- 		"real" ,
278- 		"string" ,
279- 		"true" ,
280- 		"uint" ,
281- 		"uint8" ,
282- 		"uintptr" :
283- 		return  true 
284- 	}
285- 	return  false 
286- }
0 commit comments