Skip to content

Commit

Permalink
Merge pull request #1 from gomatic/goa
Browse files Browse the repository at this point in the history
Goa
  • Loading branch information
nicerobot authored Nov 27, 2016
2 parents a66eb30 + 014e177 commit f311c31
Show file tree
Hide file tree
Showing 75 changed files with 615 additions and 1,563 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
opinionated
app/

# Created by https://www.gitignore.io/api/go

Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
[submodule "vendor/application/vendor/github.com/gorilla/context"]
path = vendor/application/vendor/github.com/gorilla/context
url = https://github.com/gorilla/context.git
[submodule "vendor/github.com/urfave/cli"]
path = vendor/github.com/urfave/cli
url = https://github.com/urfave/cli.git
[submodule "vendor/application/vendor/github.com/boltdb/bolt"]
path = vendor/application/vendor/github.com/boltdb/bolt
url = https://github.com/boltdb/bolt.git
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ notificaitons:
on_failure: always
install:
- go get -t ./...
- export PATH=$PATH:$HOME/gopath/bin
script:
- go test -v
115 changes: 0 additions & 115 deletions app.go

This file was deleted.

13 changes: 0 additions & 13 deletions app_test.go

This file was deleted.

36 changes: 36 additions & 0 deletions client/client.go
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
}
41 changes: 41 additions & 0 deletions client/media_types.go
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
}
36 changes: 36 additions & 0 deletions client/user.go
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
}
13 changes: 13 additions & 0 deletions client/user_types.go
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
2 changes: 1 addition & 1 deletion vendor/application/debugger.go → debugger.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package application
package main

import (
"fmt"
Expand Down
40 changes: 40 additions & 0 deletions design/api.go
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")
})
})
29 changes: 29 additions & 0 deletions main.go
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 added opinionated
Binary file not shown.
2 changes: 1 addition & 1 deletion vendor/application/settings.go → settings.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package application
package main

import (
"log"
Expand Down
4 changes: 3 additions & 1 deletion vendor/application/start.go → start.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package application
// +build ignore

package main

import (
"crypto/tls"
Expand Down
2 changes: 1 addition & 1 deletion vendor/application/start_test.go → start_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package application_test
package main_test

import "testing"

Expand Down
1 change: 1 addition & 0 deletions swagger/swagger.json
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"}}}}
Loading

0 comments on commit f311c31

Please sign in to comment.