Comments (6)
Well, Gowrap is not supposed to generate tests. Package name is either "guessed" if the directory of the destination file is empty and doesn't contain any *.go files or loaded from the actual package via standard go/packages
package. I don't think it's good idea to introduce special flag for that.
However you can use -v
option of the gen
command to pass the desired package name to the template (which you also have to modify to use passed variable).
The example can be found in any template in this repo:
{{ $decorator := (or .Vars.DecoratorName (printf "%sWithRateLimit" .Interface.Name)) }}
So if you pass -v DecoratorName=CustomDecoratorName
to gowrap then CustomDecoratorName
will be uses as a struct name of the decorator.
The only problem here is that the header template that generates package name is hardcoded so maybe I have to introduce some magic variable like PackageName to use approach I described above. WDYT?
from gowrap.
@despondency most of the templates now have hardcoded import statements. And gowrap runs goimports and hope that all imports will be resolved correctly. Sometimes it might lead to the cases like you described. You can simply update template and use {{.Import}}
template helper rather than import ()
statement and use latest version of gowrap.
I'll update all common templates to use {{.Import}}
soon.
from gowrap.
Hi @Varriount
Thanks for posting this issue.
There are two options to provide a package:
- Point gowrap to the directory relative to your project, i.e.
-p ./pkg/storage
- Point gowrap to the full import path of the package, i.e.
github.com/pkg/errors
Regarding the destination file/package Gowrap should use package name that is used for the destination package.
What option you have troubles with? Can you please provide an example.
Also you mentioned tests are you having troubles with minimock and not gowrap itself?
Can you please provide some code/samples for me to be able to reproduce your issue?
from gowrap.
I think there might be some confusion here.
I am using gowrap to generate test code for a project I am working on. Since the file gowrap generates is a test file, it resides in the same directory as the implementation code being tested. The test code should have a package name that is the same as the implementation code, but with "_test" at the end, similar to this.
This is because, as far as I can tell, gowrap uses the parent directory name is the name of the package for generated files. There is no way to override this behavior that I can see.
from gowrap.
Regarding the packages, we have the following problem : Original file uses google.UUID and when it undergoes templating the wrapped file uses gofrs UUID which is clearly incorrect. Should we explicitly put this in the import statement, or there is a way to make it more generic in which package to import?
from gowrap.
Worked like a charm, thank you @hexdigest
from gowrap.
Related Issues (20)
- Plugin for goland or another IDE HOT 1
- Unable to generate if destination directory does not contain go files HOT 1
- Wrong position of package comment if template has no own `import` HOT 2
- Imports of modules with custom names are not included into generated code HOT 8
- Cannot iterate over m.Params names HOT 1
- comments on the top of generated file HOT 2
- Unable to install this package HOT 3
- Add Masterminds/sprig template functions HOT 1
- method.Declaration does not add package names in argument types and return types HOT 5
- gowrap version cmd
- .Interface.Methods no longer contains nested methods HOT 2
- Appear in Nixpkgs HOT 1
- Add support for build tags HOT 1
- Add support for internal packages HOT 2
- template path in generated code uses OS specific path separators HOT 1
- Method.ReturnsError is not a proper interface/implements check
- Merge generated file with existing instead of overwriting
- Can't loading template during the gen
- "Redeclared as the imported package name" error when main module and one of dependencies have the same last part HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gowrap.