Refactoring in vim - golang & graphql

Following will convert golang struct to a 99design graphql schema type.

1
2
3
4
5
6
    type Post struct {
      UserID int    `json:"userId"`
      ID     int    `json:"id"`
      Title  string `json:"title"`
      Body   string `json:"body"`
	}

If you want to change case on selected lines you can use following.

1
    :3,6s/`.*/

Above regular expression will remove the json tags from the line 3 to 6.

1
2
3
4
5
6
    type Post struct {
      UserID int    
      ID     int    
      Title  string 
      Body   string 
	}

Next two steps are field name to camel case and data type to be capitalize.

comments powered by Disqus