Giter Site home page Giter Site logo

Comments (12)

scottjbarr avatar scottjbarr commented on May 16, 2024 2

Ah, got it.

Yes, it would be bad to edit a generated file. For that reason I think it is worth writing a properly gofmt'ed file. It will play nicely for those that do gofmt checks in their build process.

from easyjson.

vstarodub avatar vstarodub commented on May 16, 2024 1

The issue is that bootstrapping code needs to import the package to do reflection on required structs and this doesn't quite work with main package.

I'll look into the options to make this case work.

As for gofmt, does this cause any trouble? The only case I can think of is when you edit it and gofmt will be run automatically, but it's generally a bad practice to manually edit an autogenerated file.

from easyjson.

TheSilvus avatar TheSilvus commented on May 16, 2024 1

@kmansoft Probably didn't explain myself well, sorry. I've only used this library and don't know about its internals, but wanted to suggest this limitation (at least until it's implemented) to be notes in the readme.

from easyjson.

ernado avatar ernado commented on May 16, 2024

And it will play nicely for those who use pre-commit git hooks with gofmt too.

from easyjson.

vstarodub avatar vstarodub commented on May 16, 2024

That's perfectly reasonable. I just wanted a use-case to be sure what scenario I am fixing. I've added 'gofmt -w' invocation, see #3.

Haven't gotten to fixing the main package yet, though.

from easyjson.

james-lawrence avatar james-lawrence commented on May 16, 2024

you could avoid the whole issue likely by using the AST packages instead of creating a executable and using reflection. would also make it possible to regenerate the json methods when you remove a field from a structure without having to delete the easyjson file.

from easyjson.

vstarodub avatar vstarodub commented on May 16, 2024

@james-lawrence Using AST would also be quite fast to generate. That's exactly what I tried doing at first. Unfortunately the code turned out to be more complex than I was willing to support. Maybe I was just using it the wrong way.

On the issue: it seems to be a rather rare scenario, so I didn't get to it yet. I'll have some time to experiment with it over this weekend, looks like it won't be too hard to fix.

from easyjson.

elwinar avatar elwinar commented on May 16, 2024

I'm having this problem too, on a small enough package that I don't want to split the pair of structs I need to play with to another package. Any news ?

from easyjson.

kmansoft avatar kmansoft commented on May 16, 2024

Any news on the AST parser approach?

The use case is as mentioned above by @elwinar - sometimes it's convenient to keep your structs in same source tree and not split into a separate package just because of EasyJSON.

from easyjson.

TheSilvus avatar TheSilvus commented on May 16, 2024

This should probably be noted in the Readme (for now?). It is a limitation of the library and will confuse people who try to use the library after reading through it.

from easyjson.

kmansoft avatar kmansoft commented on May 16, 2024

@TheSilvus I'm just saying that it would be nice to be able to parse local files (as opposed to having to reference external compile-able packages), which means taking the AST approach to generating metadata. I know this was in the plans at some point, but no actual progress.

Are you saying that the plans have changed, and this definitely won't be implemented?

from easyjson.

GoWebProd avatar GoWebProd commented on May 16, 2024

Fix of this was offered in #236

from easyjson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.