camelCase json for Golang struct tads

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

0
正式评论

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!

0

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

1

it doest not work for me

 

0

No luck to me also.

0

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

1

@Alexander Zolotov 

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

2
Avatar
Permanently deleted user

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

Hi @..., what was your previous GoLand version? Please see the corresponding post: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360006372139/comments/360003046240

0
Avatar
Permanently deleted user

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
Avatar
Permanently deleted user

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

0

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

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

0

请先登录再写评论。