Comments (10)
The idea is that calc.go
implements the service package which lives at the root. The service can be instantiated by the command line but that's not the only option. For example there could be multiple services instantiated in a single executable. This follows the clean architecture pattern where the service implements the business logic, the gen
directory contains the transport logic and cmd
configures and puts everything together. I've used this same structure at scale (hundreds of services) and it works very well.
from goa.
from goa.
Hello!
Goa does generate both server and client code for all services defined in the design. The CLI generator takes advantage of the generated client package to build a tool on top. The weather
example in the clue is probably a good place to look at what implementing a service client looks like, see the forecaster service client for example. In particular the New
function which instantiates the client by leveraging the generated client package.
The calc.go
in the root folder contains the actual business logic. Goa takes care of generating the transport code (both server and client side) as well as the endpoints layer. The user takes advantage of that code to create the actual servers and business logic.
The goa example
command provides an example of a main
but it certainly isn't the only way to write a main. The actual implementation will depend on a lot of other factors like other downstream dependencies that need to be instantiated (databases, cloud services etc.), the observability stack and other non-Goa dependencies. The same weather example shows an alternative implementation of a main package. At the end of the day the main
package doesn't have to be modified much when the design changes. It only needs to be updated when new services are added or services are removed.
The source code for the website is located at https://github.com/goadesign/goa.design - please feel free to submit a PR with any clarification you think would help newcomers like you. I'd be happy to review and merge any submission!
from goa.
Thanks. I will definitely make a pull request to clarify the docs if I manage to understand it myself and get it working.
So in the Getting Started calc example - which file would I use on a client to get started? (Not a CLI command, but an actual file in the /gen or /cmd that calls the server)
from goa.
The code that needs to make calls to the Goa service would import the generated client, for example: https://github.com/goadesign/clue/blob/main/example/weather/services/front/clients/forecaster/client.go#L11.
It then takes advantage of the generated NewClient function to instantiate a client endpoint "factory" object. The signature of the NewClient
function depends on the underlying transport (HTTP or gRPC). For HTTP it takes an encoder and decoder which can be set to the default Goa encoder and decoder. This object exposes one method for each service method that returns an endpoint. The endpoint can then be called and/or wrapped as needed.
from goa.
Another confusion about your structure.
- Your starting point is
/design
. - Your definitions is
/gen
. - Your implementation is
/cmd
.
All good. Your server implementation is in cmd/calc/main.go
. This makes sense, as /cmd
holds all the placeholder implementation code, and calc
is the API name.
But why then is calc.go
sitting in the root folder by itself? It's a placeholder implementation of a service, so surely it belongs next to, or below, the placeholder implementation of the API. In other words, in /cmd/calc/calc.go
or /cmd/calc/services/calc.go
.
from goa.
I've finished writing an article for Speakeasy with Goa that we'll publish soon. If you can see anything wrong with what I've said about Goa, please let me know - https://github.com/ritza-co/speakeasy-docs/blob/goa-guide/web/packages/marketing-site/src/pages/docs/api-frameworks/goa.mdx
I'll try to make a pull request to your docs for anything I think can be clearer soon. I still don't understand why service implementations are kept in the root, bu thank you for trying to explain.
from goa.
Awesome! looking forward to checking it out however I don't seem to have access to the link above (getting a 404).
from goa.
Ah, sorry, they made the repository private. Here's another version - ritza-co/speakeasy-goa-example@b802da7. Load diff will show it.
Otherwise the final article will soon appear under - https://www.speakeasyapi.dev/docs/api-frameworks/goa
from goa.
Thanks for the link, the article looks awesome! Will have to checkout speakeasy :)
from goa.
Related Issues (20)
- can't set cookie 'SameSite' attribute HOT 2
- How to get the native *http.Request from the payload? HOT 2
- Missing schemas in OpenAPI spec when using union types HOT 3
- Declare POST request contain an array of object HOT 2
- Bumping goa.design/plugins/v3 from 3.14.0 to 3.14.1 is causing my client generation to fail HOT 3
- Generated code for nested inline attributes doesn't compile HOT 2
- Deprecated Code in Generated http.go using goa example
- meta for externalDocs and deprecated? HOT 4
- Map as Query Param not working? HOT 2
- Using Param() to map path parameters to attributes results in a runtime error HOT 5
- Panic in main HOT 2
- Goa panics when query params have unclosed square brackets HOT 2
- Goa panics when a user provides an explicit `null` where a `Map` is expected, if it's a nested structure HOT 2
- Middleware in design? HOT 6
- Goa generating uncompilable code while using views on types that contain OneOf union type
- Goa generating invalid code when OneOf types is a user defined type
- Example generation failed in the latest version HOT 3
- Generated server code parses query parameters repeatedly HOT 1
- Getting the Raw Query? HOT 1
- Allow implementing `io.WriterTo` for `SkipResponseBodyEncodeDecode` responses. HOT 1
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 goa.