goa-cellar

所属分类:collect
开发工具:GO
文件大小:0KB
下载次数:0
上传日期:2018-01-05 00:00:37
上 传 者sh-1993
说明:  果阿酒窖示例服务,
(goa winecellar example service,)

文件列表:
.travis.yml (837, 2018-01-04)
LICENSE (1080, 2018-01-04)
Makefile (1547, 2018-01-04)
app.yaml (71, 2018-01-04)
app.yaml.vm (283, 2018-01-04)
app/ (0, 2018-01-04)
app/contexts.go (37357, 2018-01-04)
app/controllers.go (24410, 2018-01-04)
app/hrefs.go (966, 2018-01-04)
app/media_types.go (14439, 2018-01-04)
app/test/ (0, 2018-01-04)
app/test/account_testing.go (36584, 2018-01-04)
app/test/bottle_testing.go (53032, 2018-01-04)
app/test/health_testing.go (2343, 2018-01-04)
app/test/js_testing.go (251, 2018-01-04)
app/test/public_testing.go (255, 2018-01-04)
app/test/swagger_testing.go (256, 2018-01-04)
app/user_types.go (7301, 2018-01-04)
appengine.go (1586, 2018-01-04)
client/ (0, 2018-01-04)
client/account.go (6118, 2018-01-04)
client/bottle.go (9454, 2018-01-04)
client/client.go (1271, 2018-01-04)
client/health.go (1143, 2018-01-04)
client/js.go (1247, 2018-01-04)
client/media_types.go (18027, 2018-01-04)
client/public.go (1183, 2018-01-04)
client/swagger.go (1214, 2018-01-04)
client/user_types.go (7304, 2018-01-04)
controllers/ (0, 2018-01-04)
controllers/account.go (2812, 2018-01-04)
controllers/account_test.go (6091, 2018-01-04)
controllers/bottle.go (5227, 2018-01-04)
controllers/bottle_test.go (8517, 2018-01-04)
controllers/health.go (704, 2018-01-04)
controllers/helpers_test.go (1008, 2018-01-04)
controllers/js.go (305, 2018-01-04)
controllers/public.go (341, 2018-01-04)
... ...

# goa Cellar The goa winecellar service provides an example for the [goa](http://goa.design) web application framework. The service implements an API for managing wine bottles. The service is multitenant: bottles are created in the context of an account. At this time the database is emulated with a in-memory hash. An instance of this example is hosted at http://cellar.goa.design. ## Usage ### Calling the Hosted Service Using the excellent [httpie client](https://github.com/jkbrzt/httpie): Listing bottles in account 1: ```bash http http://cellar.goa.design/cellar/accounts/1/bottles HTTP/1.1 200 OK Content-Length: 707 Content-Type: application/vnd.goa.example.bottle+json; type=collection; charset=utf-8 Date: Sun, 06 Dec 2015 09:06:10 GMT Server: Google Frontend Vary: Origin [ { "href": "/cellar/accounts/1/bottles/100", "id": 100, "links": { "account": { "href": "/cellar/accounts/1", "id": 1, "name": "account 1" } }, "name": "Number 8", "rating": 4, "varietal": "Merlot", "vineyard": "Asti Winery", "vintage": 2012 }, # ... ``` Creating a new account: ```bash http POST http://cellar.goa.design/cellar/accounts name=sonoma created_by=me HTTP/1.1 201 Created Content-Length: 0 Content-Type: text/html; charset=utf-8 Date: Sun, 06 Dec 2015 09:08:55 GMT Location: /cellar/accounts/3 Server: Google Frontend Vary: Origin ``` Showing the newly created account: ```bash http http://cellar.goa.design/cellar/accounts/3 HTTP/1.1 200 OK Content-Length: 66 Content-Type: application/vnd.goa.example.account+json; charset=utf-8 Date: Sun, 06 Dec 2015 09:10:09 GMT Server: Google Frontend Vary: Origin { "created_at": "", "created_by": "me", "href": "", "id": 3, "name": "sonoma" } ``` ### Running Locally Assuming a working Go setup: ```bash go install github.com/goadesign/goa-cellar goa-cellar ``` Once running `goa-cellar` listens on port 8081. The service serves the generated JavaScript example at `/ui`, open [http://localhost:8081/ui](http://localhost:8081/ui) in a browser to display it. This example loads the generated JavaScript client from the service. It then calls the JavaScript client `ListBottle` function which makes a request to list the bottles to the service and displayes the results. ## Generated vs. Non Generated Code One thing to be aware of when looking at the example is that most of it is generated code. The `design` package contains the DSL that describes the winecellar API. The contents of the `app`, `client`, `js`, `schema` and `swagger` folders are all completely generated by the [goagen](http://goa.design/implement/goagen.html) tool from the `design` package. The only non-generated directories are: * the `controllers` package, which contains the API business logic * the `store` package, which contains the database operations. * the `design` package itself, which contains the DSL the describes the API and which is used to generate the code The generated documentation for the example API is available on [swagger.goa.design](http://swagger.goa.design/?url=goadesign%2Fgoa-cellar%2Fdesign). ## FAQ ### Why are the controllers in a "controllers" package instead of the default "main" package? `goagen` generates both `main.go` and the controller files in the main package by default. This example splits the two and keeps `main.go` in the main package but moves the controller implementations (`account.go` and `bottle.go`) to the `controllers` package. The files were moved and edited "manually". This is to illustrate an important aspect of code generation in goa: `goagen` generates two types of outputs: - The *scaffold* is code that is produced once. It consists of `main.go`, the controller files and the client `main.go`. These files are generated to help the project get started quickly however they should be edited, moved, renamed etc. as needed. - The *generated* code is produced each time entirely from scratch. This is the vast majority of the code that is outputed by `goagen` and the parts that change the most as the design evolves. This includes the `app` package and its `test` subpackage, the swagger files and the client files. While it is possible to control where both the scaffold and generated code is produced (with the `--output` flag) it is not possible to edit the generated code. Any change made to these files will be overridden next time `goagen` is invoked. This is to enforce a clean separation between generated code and user code. Generated code calls the user code via explicit Go interfaces so that it's clear what needs to be done when the generated code differs as a result of changes in the design. ### Where are the tests? The `controllers` package illustrates how to write component level tests. These tests setup input data, call the generated test helpers which package that data into HTTP requests and calls the actual controller functions. The test helpers retrieve the written responses, deserialize them, validate the generated data structures (against the validations written in the design) and make them available to the tests. This makes it simple to use table driven tests that setup various kinds of inputs and validate the resulting responses. See the file [account_test.go](https://github.com/goadesign/goa-cellar/blob/master/controllers/account_test.go).

近期下载者

相关文件


收藏者