Skip to content

Commit

Permalink
/goa
Browse files Browse the repository at this point in the history
  • Loading branch information
nicerobot committed Nov 27, 2016
1 parent a66eb30 commit 616ec87
Show file tree
Hide file tree
Showing 75 changed files with 614 additions and 1,605 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
42 changes: 0 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +0,0 @@
# It's ... opinionated ... Go

[![Build Status](https://travis-ci.org/gomatic/opinionated.svg?branch=master)](https://travis-ci.org/gomatic/opinionated)

A starter Go/Web application framework in the style of [hackathon-starter](https://github.com/sahat/hackathon-starter). Started in response to [this reddit](https://www.reddit.com/r/golang/comments/4twe9q/hackathonstarter_alternative_in_golang/).

See the [wiki](https://github.com/gomatic/opinionated/wiki) for design ideas and goals.

## TODO

### Server

- [x] basic server on go-kit
- [x] static files
- [x] middlewares
- [x] logging
- [x] caching
- [x] headers
- [ ] tests
- [ ] auth
- [ ] facebook
- [ ] google
- [ ] twitter
- [ ] github
- [ ] linkedin
- [ ] instagram
- [ ] persistence

### Client

- [ ] landing page
- [ ] tests
- [ ] auth
- [ ] facebook
- [ ] google
- [ ] twitter
- [ ] github
- [ ] linkedin
- [ ] instagram
- [ ] demos
- [ ] websocket chat
- [ ] todo list
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.
Loading

0 comments on commit 616ec87

Please sign in to comment.