Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marshal function #8

Open
Caledfwlch1 opened this issue Jul 9, 2020 · 7 comments
Open

Marshal function #8

Caledfwlch1 opened this issue Jul 9, 2020 · 7 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Caledfwlch1
Copy link

Please take the next step: Marshal function ...

@muhammadmuzzammil1998
Copy link
Owner

Yeah... You know what? I'll look into it. Thanks!
Any suggestions for how the comments should be structured?

@muhammadmuzzammil1998 muhammadmuzzammil1998 self-assigned this Jul 9, 2020
@muhammadmuzzammil1998 muhammadmuzzammil1998 added enhancement New feature or request help wanted Extra attention is needed labels Jul 9, 2020
@Caledfwlch1
Copy link
Author

maybe put in tags?

@muhammadmuzzammil1998
Copy link
Owner

Yes it has to be done with tags but how would the syntax be? Just like jsonc:"key" anything here will be considered a comment or have a specific syntax?

PS: I haven't worked with tags yet. Will have to take a look on how they work to finalize a syntax. Thanks for your interest 😊.

@Caledfwlch1
Copy link
Author

Caledfwlch1 commented Jul 11, 2020

Please look at that tag. This is not difficult. :) This will reduce a speed, but comments are usually needed in the configuration file, in which case this is not critical. I liked your idea!
structure{ Field string 'json:"field" comment:"this field...."' }

@muhammadmuzzammil1998
Copy link
Owner

Thanks! But could you please tell:

  1. Should this support only jsonc tag or both jsonc and json tag? I don't see why it shouldn't. What do you think?

  2. Where do you think the comments should be placed?

{
  "key": "value" // comment here (my preference)
}

OR

{
  // comment here
  "key": "value" 
}

@Caledfwlch1
Copy link
Author

  1. I think you should not overload the JSON tag. If you are not using the JSONC tag now, then it's time. :)
  2. I also like the first example.

@marco-sacchi
Copy link

I know I'm late, but just around this time I wrote a go module that does exactly what you need and its MIT licensed.

It is not based on tags, but on parsing the abstract syntax tree of the go source.

Distinguishes both documentation blocks and inline comments, and reads any default values specified in a method with a specific signature (see the readme).

If you think it could be useful, use it freely and let me know what you think: https://github.com/marco-sacchi/go2jsonc

Note that go2jsonc is a static analysis / generator tool and its not reflection based, so you need to specify the package path and type name, not the package import string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants