camelCase json for Golang struct tads 关注 A Kolkov 创建于 2018年05月11日 10:31 Hi! How to convert SomeValue `json:"some_value"` auto completion to SomeValue `json:"someValue"?
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.
Thanks! camelCase(fieldName()) work as expected for me!
I have as you suggested, and now it does not autocomplete anymore with the name field
it doest not work for me
No luck to me also.
You need to change both of `json` live template. Likely you changed one but use another.
Thanks. After setup new tag rule at Live Template/GO/json & Live Template/Go Struct Tags/json. It works as expected
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
Hi Orlando Vargas, what was your previous GoLand version? Please see the corresponding post: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360006372139/comments/360003046240
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$`
Sorry, my mistake, it is working only if it is the first tag, the problem is related to the ticket to filed.
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
Daniil Maslov thanks a lot, I was about to bang my head to the desk then I read your message :)