-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from gomatic/goa
Goa
- Loading branch information
Showing
75 changed files
with
615 additions
and
1,563 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
opinionated | ||
app/ | ||
|
||
# Created by https://www.gitignore.io/api/go | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/goadesign/goa" | ||
goaclient "github.com/goadesign/goa/client" | ||
) | ||
|
||
// Client is the opinionated service client. | ||
type Client struct { | ||
*goaclient.Client | ||
Encoder *goa.HTTPEncoder | ||
Decoder *goa.HTTPDecoder | ||
} | ||
|
||
// New instantiates the client. | ||
func New(c goaclient.Doer) *Client { | ||
client := &Client{ | ||
Client: goaclient.New(c), | ||
Encoder: goa.NewHTTPEncoder(), | ||
Decoder: goa.NewHTTPDecoder(), | ||
} | ||
|
||
// Setup encoders and decoders | ||
client.Encoder.Register(goa.NewJSONEncoder, "application/json") | ||
client.Encoder.Register(goa.NewGobEncoder, "application/gob", "application/x-gob") | ||
client.Encoder.Register(goa.NewXMLEncoder, "application/xml") | ||
client.Decoder.Register(goa.NewJSONDecoder, "application/json") | ||
client.Decoder.Register(goa.NewGobDecoder, "application/gob", "application/x-gob") | ||
client.Decoder.Register(goa.NewXMLDecoder, "application/xml") | ||
|
||
// Setup default encoder and decoder | ||
client.Encoder.Register(goa.NewJSONEncoder, "*/*") | ||
client.Decoder.Register(goa.NewJSONDecoder, "*/*") | ||
|
||
return client | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//************************************************************************// | ||
// API "opinionated": Application Media Types | ||
// | ||
// Generated with goagen v1.0.0, command line: | ||
// $ goagen | ||
// --design=github.com/gomatic/opinionated/design | ||
// --out=$(GOPATH)/src/github.com/gomatic/opinionated | ||
// --version=v1.0.0 | ||
// | ||
// The content of this file is auto-generated, DO NOT MODIFY | ||
//************************************************************************// | ||
|
||
package client | ||
|
||
import ( | ||
"github.com/goadesign/goa" | ||
"net/http" | ||
) | ||
|
||
// Credentials (default view) | ||
// | ||
// Identifier: application/json; view=default | ||
type JSON struct { | ||
// Username | ||
ID string `form:"id" json:"id" xml:"id"` | ||
} | ||
|
||
// Validate validates the JSON media type instance. | ||
func (mt *JSON) Validate() (err error) { | ||
if mt.ID == "" { | ||
err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "id")) | ||
} | ||
return | ||
} | ||
|
||
// DecodeJSON decodes the JSON instance encoded in resp body. | ||
func (c *Client) DecodeJSON(resp *http.Response) (*JSON, error) { | ||
var decoded JSON | ||
err := c.Decoder.Decode(&decoded, resp.Body, resp.Header.Get("Content-Type")) | ||
return &decoded, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/net/context" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
// LoginUserPath computes a request path to the login action of user. | ||
func LoginUserPath(username string) string { | ||
return fmt.Sprintf("/u/%v", username) | ||
} | ||
|
||
// Login | ||
func (c *Client) LoginUser(ctx context.Context, path string) (*http.Response, error) { | ||
req, err := c.NewLoginUserRequest(ctx, path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return c.Client.Do(ctx, req) | ||
} | ||
|
||
// NewLoginUserRequest create the request corresponding to the login action endpoint of the user resource. | ||
func (c *Client) NewLoginUserRequest(ctx context.Context, path string) (*http.Request, error) { | ||
scheme := c.Scheme | ||
if scheme == "" { | ||
scheme = "http" | ||
} | ||
u := url.URL{Host: c.Host, Scheme: scheme, Path: path} | ||
req, err := http.NewRequest("GET", u.String(), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return req, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//************************************************************************// | ||
// API "opinionated": Application User Types | ||
// | ||
// Generated with goagen v1.0.0, command line: | ||
// $ goagen | ||
// --design=github.com/gomatic/opinionated/design | ||
// --out=$(GOPATH)/src/github.com/gomatic/opinionated | ||
// --version=v1.0.0 | ||
// | ||
// The content of this file is auto-generated, DO NOT MODIFY | ||
//************************************************************************// | ||
|
||
package client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package application | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package design | ||
|
||
import ( | ||
. "github.com/goadesign/goa/design" | ||
. "github.com/goadesign/goa/design/apidsl" | ||
) | ||
|
||
var _ = API("opinionated", func() { | ||
Title("An opinionated application starter") | ||
Description("A basic starter service") | ||
Scheme("http") | ||
Host("localhost:3080") | ||
}) | ||
|
||
var _ = Resource("user", func() { | ||
BasePath("/u") | ||
DefaultMedia(UserJSON) | ||
|
||
Action("login", func() { | ||
Description("Login") | ||
Routing(GET("/:username")) | ||
Params(func() { | ||
Param("username", String, "Username") | ||
}) | ||
Response(OK) | ||
Response(NotFound) | ||
}) | ||
}) | ||
|
||
var UserJSON = MediaType("application/json", func() { | ||
Description("Credentials") | ||
Attributes(func() { | ||
Attribute("id", String, "Username") | ||
Attribute("token", String, "Token") | ||
Required("id", "token") | ||
}) | ||
View("default", func() { | ||
Attribute("id") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//go:generate goagen bootstrap -d github.com/gomatic/opinionated/design | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/goadesign/goa" | ||
"github.com/goadesign/goa/middleware" | ||
"github.com/gomatic/opinionated/app" | ||
) | ||
|
||
func main() { | ||
// Create service | ||
service := goa.New("opinionated") | ||
|
||
// Mount middleware | ||
service.Use(middleware.RequestID()) | ||
service.Use(middleware.LogRequest(true)) | ||
service.Use(middleware.ErrorHandler(service, true)) | ||
service.Use(middleware.Recover()) | ||
|
||
// Mount "user" controller | ||
c := NewUserController(service) | ||
app.MountUserController(service, c) | ||
|
||
// Start service | ||
if err := service.ListenAndServe(":3080"); err != nil { | ||
service.LogError("startup", "err", err) | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package application | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
package application | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package application_test | ||
package main_test | ||
|
||
import "testing" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"swagger":"2.0","info":{"title":"An opinionated application starter","description":"A basic starter service","version":""},"host":"localhost:3080","schemes":["http"],"consumes":["application/json","application/xml","application/gob","application/x-gob"],"produces":["application/json","application/xml","application/gob","application/x-gob"],"paths":{"/u/{username}":{"get":{"tags":["user"],"summary":"login user","description":"Login","operationId":"user#login","parameters":[{"name":"username","in":"path","description":"Username","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Json"}},"404":{"description":"Not Found"}},"schemes":["http"]}}},"definitions":{"Json":{"title":"Mediatype identifier: application/json","type":"object","properties":{"id":{"type":"string","description":"Username","example":"Nihil assumenda dolorum quasi ratione nisi aut."}},"description":"Credentials (default view)","example":{"id":"Nihil assumenda dolorum quasi ratione nisi aut."},"required":["id"]}},"responses":{"NotFound":{"description":"Not Found"},"OK":{"description":"OK","schema":{"$ref":"#/definitions/Json"}}}} |
Oops, something went wrong.