gocontracts | A tool for design-by-contract in Go | Blockchain library
kandi X-RAY | gocontracts Summary
kandi X-RAY | gocontracts Summary
[godoc] gocontracts is a tool for [design-by-contract] in Go. It generates pre- and post-condition checks from the function descriptions so that the contracts are included in the documentation and automatically reflected in the code. (If you need invariants, please let us know by commenting on this issue:
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- ToCondition converts text to a Condition .
- Process parses a function declaration and returns the updated function updates .
- parseContract parses a contract definition .
- commonWhitespacePrefix finds the longest common whitespace prefix in the given lines .
- Main entry point for diff
- parsePreconditions parses preconditions for preconditions .
- update returns the function code for the given function updates .
- generateCode generates code for the given contract
- ProcessInPlace processes a file in a place
- validateNoStmts validates that the function declaration is valid .
gocontracts Key Features
gocontracts Examples and Code Snippets
Community Discussions
Trending Discussions on gocontracts
QUESTION
By analogy with this question about tags I note that there are several uses of comments in go beyond pure commentary.
Examples:
- go:generate can be used for code generation.
- godoc uses the function name to indicate comments it should interpret
- build constraints
Are there any others I've missed?
Is there a definitive list somewhere?
Some third party packages like gocontracts and go-swagger use them as well. How can they avoid conflicting with each other?
...ANSWER
Answered 2018-Dec-04 at 15:50As noted comments are directives in go not just comments.
There is at the time of writing no definitive list. This as logged as an golang issue 28532.
Therefore I propose using this answer to make one.
Uses in the go core language and tools themselves:
- go:generate can be used for code generation.
- godoc uses the function name to indicate comments it should interpret
- Examples - document the expected output of a test (thanks @Butuzov)
- build constraints (starting with '// +build')
- Import comments e.g. 'package math // import "path"'
Notable uses in third party packages
- gocontracts - specify preconditions as comments
- go-swagger - document a ReST API using swagger
- golangci e.g. //nolint[:linter1,linter2,...]
How can they avoid conflicting with each other?
If you are developing a tool that really needs to treat comments as attributes and wish to avoid conflict with other similar uses prefix your comments with a namespace like "{mytool}: "
There are some conscious attempts at namespacing. Magic comments built into go use the "go: " prefix as in "go:generate" (except where they don't)
go-swagger uses "swagger: "
However you still need to approach this with caution and check the list here or any other source you can find.
Also consider whether comments are the best or only approach rather than using functions instead. Compare for instance (gocontracts):
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install gocontracts
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page