-
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.
- Loading branch information
Showing
75 changed files
with
614 additions
and
1,605 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
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 | ||
- [ ] github | ||
- [ ] persistence | ||
|
||
### Client | ||
|
||
- [ ] landing page | ||
- [ ] tests | ||
- [ ] auth | ||
- [ ] github | ||
- [ ] demos | ||
- [ ] websocket chat | ||
- [ ] todo list | ||
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.
Oops, something went wrong.