camelCase json for Golang struct tads

Hi! How to convert SomeValue `json:"some_value"` auto completion to SomeValue `json:"someValue"?

13 comments
Comment actions Permalink
Official comment

Please go to "Settings | Editor | Live Templates | Go Struct Tags" and either edit or duplicate the existing "json", then click on "Edit variables" button and select how the field should be transformed, by default it is "snakeCase(fieldName())" but you can use something like "capitalize(fieldName())" instead or anything from the available list of transformations.

Please see https://www.jetbrains.com/help/go/2018.1/edit-template-variables-dialog.html for a list of available transformations and how they work.

 

Edit: Provided the correct IDE link.

Comment actions Permalink

Thanks! camelCase(fieldName()) work as expected for me!

0
Comment actions Permalink

I have as you suggested, and now it does not autocomplete anymore with the name field

1
Comment actions Permalink

it doest not work for me

 

0
Comment actions Permalink

No luck to me also.

0
Comment actions Permalink

You need to change both of `json` live template. Likely you changed one but use another.

1
Comment actions Permalink

@Alexander Zolotov 

Thanks. After setup new tag rule at Live Template/GO/json & Live Template/Go Struct Tags/json. It works as expected 

2
Comment actions Permalink

Hi, I configured the tag rule in both places and it worked fine, but after upgrading it, it stops working, I have 2021.1.2

0
Comment actions Permalink

I don't remember the version I had when it was working but with the last two upgrades at least I started to notice the issue. My configuration was like the one you posted, but with the $END$ variable, I just removed it, and now is working again.

Originally I had `json:"$FIELD_NAME$"$END$`

Now 

`json:"$FIELD_NAME$"`

Thanks

0
Comment actions Permalink

Sorry, my mistake, it is working only if it is the first tag, the problem is related to the ticket to filed.

0
Comment actions Permalink

Please follow GO-11005 to autodetect field name style in the struct tags. Note that you should invoke json abbreviation without backticks if you configured a template like in my previous message. Templates inside backticks always produce struct tags with snake_case and there is no way to configure it yet.

Also, pay attention that you can change the style of the field name for all tags in one click: https://www.jetbrains.com/go/whatsnew/#working-with-json

3
Comment actions Permalink

Daniil Maslov thanks a lot, I was about to bang my head to the desk then I read your message :)

0

Please sign in to leave a comment.