ok-lets-go | Three Approaches to Structuring Go Code | Dataset library
kandi X-RAY | ok-lets-go Summary
kandi X-RAY | ok-lets-go Summary
Three Approaches to Structuring Go Code
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- NewPermissionStorage returns a new instance of PermissionStorage
- InitPermissions initializes Permissions
- initPermissions initializes the Permissions
- The http server
- UserPermissionsByID retrieves a list of permissions by ID
- RolePermissions returns the permissions for a given role
ok-lets-go Key Features
ok-lets-go Examples and Code Snippets
Community Discussions
Trending Discussions on ok-lets-go
QUESTION
Recently, I stumbled upon an interesting article regarding the organization of Go code.
I was highly interested in the third approach: 'Independent Packages'. It's said packages should NOT depend on each other, but defines their own interface to interact with other packages.
Now, I face a problem with the approach.
I'm building a CLI applications that's able to execute various commands, one after each other. It's important that these commands can share data.
First, I have built a contain in which I can register commands.
This resides in the package: commands
.
ANSWER
Answered 2020-Nov-29 at 22:47This will not work because the function signatures don't match. You can do:
- Make Context a shared interface, so every package can use it. This does not necessarily introduce dependencies between packages using it.
- Use context.Context, and expect to see the key in there. This is essentially the same as #1 but using a known predefined type
- Use interface{} instead of context, and use type assertion to convert it to the local context type.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ok-lets-go
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