Comments (6)
@sjames-iberis I didn't want to customize the header because giving two templates as an input to gowrap is kinda too much and may confuse people. Why do you need it?
from gowrap.
Customising header template is not a big issue. I only raised it because it would have provided a way to use the package name in the body (for example, by declaring a constant that the body could reference).
We need the package name in the body because we have a number packages which have an interface with the same name and method signature.
The package name is needed to identify which variant of the method is being invoked, for example in logging.
from gowrap.
@sjames-iberis Thanks for the explanation, I got your point. Exposing source package metadata and destination package metadata to the body template is not a problem and can be done easily, however I was thinking about passing any kind of vars to the body template from the command line in the form of key/value pairs. So that way, the decorator struct name/constructor name can be passed from the command line too. I think it will be a more generic solution. Does it make sence to you?
from gowrap.
Although I would still prefer it if all properties of the source interface were automatically available to the template, being able to define key/value pairs from the command line is definitely a useful feature, and we could leverage it make the package name available.
Thanks!
from gowrap.
@sjames-iberis please check new -v flags for setting .Vars from the command line.
I also changed all templates in the repo so now they aware of .Vars.DecoratorName which can be set via -v
This is an example from the templates_tests/interface_with_log.go:
gowrap gen -d . -i TestInterface -t ../templates/log -o interface_with_log.go -v DecoratorName=TestInterfaceWithLogger
You can pass multiple vars to the templates by using -v flag multiple times.
Please close the issue if this approach works for you.
from gowrap.
Confirmed that -v option can be used to define package name.
from gowrap.
Related Issues (20)
- Add Go.mod file support to detect source/destination package names/import paths
- template/retry: do not use time.After HOT 1
- Prometheus metric is not registered HOT 2
- Plugin for goland or another IDE HOT 1
- Unable to generate if destination directory does not contain go files HOT 1
- Allowing specifying custom package HOT 6
- 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
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.