diff --git a/.gitignore b/.gitignore index db1ec67..ebe39a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -opinionated +app/ # Created by https://www.gitignore.io/api/go diff --git a/.gitmodules b/.gitmodules index e7250af..8026e47 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/README.md b/README.md index 09267f0..e69de29 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app.go b/app.go deleted file mode 100644 index 9d347de..0000000 --- a/app.go +++ /dev/null @@ -1,115 +0,0 @@ -package main - -import ( - _ "expvar" - "os" - "strings" - - "application" - - "github.com/urfave/cli" -) - -// -const MAJOR = "0.1" - -// DO NOT UPDATE. This is populated by the build. See the Makefile. -var VERSION = "0" - -// -func main() { - app := cli.NewApp() - app.Name = "opinionated" - app.Usage = "Opinionated." - app.Version = MAJOR + "." + VERSION - app.EnableBashCompletion = true - - application.Settings.Version = app.Version - application.Settings.Server = app.Name - application.Settings.Powered = app.Name + "/" + app.Version - - app.Flags = []cli.Flag{ - cli.BoolFlag{ - Name: "debug, debugger, debugging, d", - Usage: "Enable debugging server.", - Destination: &application.Settings.Debugger, - }, - } - - app.Before = func(ctx *cli.Context) error { - if application.Settings.Debugger { - application.Debugger() - } - application.Settings.Mode = strings.ToLower(application.Settings.Mode) - if application.Settings.Addr == "" && application.Settings.Mode == "development" { - application.Settings.Addr = "localhost" - } - return nil - } - - app.Commands = []cli.Command{ - cli.Command{ - Name: "configuration", - Aliases: []string{"configure", "config"}, - Usage: "Configure.", - Action: func(ctx *cli.Context) error { - return application.Configure() - }, - }, - cli.Command{ - Name: "manager", - Aliases: []string{"manage", "administer", "admin"}, - Usage: "Administer.", - Action: func(ctx *cli.Context) error { - return application.Manage() - }, - }, - cli.Command{ - Name: "start", - Aliases: []string{"server", "serve", "run"}, - Usage: "Run.", - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "address, a", - Usage: "Bind to address.", - Value: "", - Destination: &application.Settings.Addr, - }, - cli.IntFlag{ - Name: "port, p", - Usage: "Server port.", - Value: 3443, - Destination: &application.Settings.Port, - }, - cli.BoolFlag{ - Name: "insecure, k", - Usage: "Disable TLS server.", - Destination: &application.Settings.Insecure, - }, - cli.BoolFlag{ - Name: "verbose, v", - Usage: "Enable verbose server.", - Destination: &application.Settings.Verbose, - }, - cli.StringFlag{ - Name: "mode", - Usage: "Provide a run-mode.", - EnvVar: "DEPLOYMENT", - Destination: &application.Settings.Mode, - }, - }, - Before: func(ctx *cli.Context) error { - application.Settings.Mode = strings.ToLower(application.Settings.Mode) - if application.Settings.Addr == "" && application.Settings.Mode == "development" { - application.Settings.Addr = "localhost" - } - return nil - }, - Action: func(ctx *cli.Context) error { - return application.Start() - }, - }, - } - - app.Run(os.Args) -} diff --git a/app_test.go b/app_test.go deleted file mode 100644 index 3d378c8..0000000 --- a/app_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package main_test - -import "testing" - -// -func TestMain(m *testing.M) { - m.Run() -} - -// -func TestCLI(t *testing.T) { - -} diff --git a/client/client.go b/client/client.go new file mode 100644 index 0000000..33eeaa9 --- /dev/null +++ b/client/client.go @@ -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 +} diff --git a/client/media_types.go b/client/media_types.go new file mode 100644 index 0000000..a1a4751 --- /dev/null +++ b/client/media_types.go @@ -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 +} diff --git a/client/user.go b/client/user.go new file mode 100644 index 0000000..31b7a45 --- /dev/null +++ b/client/user.go @@ -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 +} diff --git a/client/user_types.go b/client/user_types.go new file mode 100644 index 0000000..7b928b1 --- /dev/null +++ b/client/user_types.go @@ -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 diff --git a/vendor/application/debugger.go b/debugger.go similarity index 95% rename from vendor/application/debugger.go rename to debugger.go index a55a119..0419d20 100644 --- a/vendor/application/debugger.go +++ b/debugger.go @@ -1,4 +1,4 @@ -package application +package main import ( "fmt" diff --git a/design/api.go b/design/api.go new file mode 100644 index 0000000..c9b3230 --- /dev/null +++ b/design/api.go @@ -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") + }) +}) diff --git a/main.go b/main.go new file mode 100644 index 0000000..f08fe11 --- /dev/null +++ b/main.go @@ -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) + } +} diff --git a/opinionated b/opinionated new file mode 100755 index 0000000..39bebdd Binary files /dev/null and b/opinionated differ diff --git a/vendor/application/settings.go b/settings.go similarity index 98% rename from vendor/application/settings.go rename to settings.go index ed3952c..b37adbd 100644 --- a/vendor/application/settings.go +++ b/settings.go @@ -1,4 +1,4 @@ -package application +package main import ( "log" diff --git a/vendor/application/start.go b/start.go similarity index 98% rename from vendor/application/start.go rename to start.go index e17c9ae..51153f2 100644 --- a/vendor/application/start.go +++ b/start.go @@ -1,4 +1,6 @@ -package application +// +build ignore + +package main import ( "crypto/tls" diff --git a/vendor/application/start_test.go b/start_test.go similarity index 69% rename from vendor/application/start_test.go rename to start_test.go index f9cbd94..6d3fcc7 100644 --- a/vendor/application/start_test.go +++ b/start_test.go @@ -1,4 +1,4 @@ -package application_test +package main_test import "testing" diff --git a/swagger/swagger.json b/swagger/swagger.json new file mode 100644 index 0000000..6c0181c --- /dev/null +++ b/swagger/swagger.json @@ -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"}}}} \ No newline at end of file diff --git a/swagger/swagger.yaml b/swagger/swagger.yaml new file mode 100644 index 0000000..09c60c0 --- /dev/null +++ b/swagger/swagger.yaml @@ -0,0 +1,62 @@ +consumes: +- application/json +- application/xml +- application/gob +- application/x-gob +definitions: + Json: + description: Credentials (default view) + example: + id: Nihil assumenda dolorum quasi ratione nisi aut. + properties: + id: + description: Username + example: Nihil assumenda dolorum quasi ratione nisi aut. + type: string + required: + - id + title: 'Mediatype identifier: application/json' + type: object +host: localhost:3080 +info: + description: A basic starter service + title: An opinionated application starter + version: "" +paths: + /u/{username}: + get: + description: Login + operationId: user#login + parameters: + - description: Username + in: path + name: username + required: true + type: string + responses: + "200": + description: OK + schema: + $ref: '#/definitions/Json' + "404": + description: Not Found + schemes: + - http + summary: login user + tags: + - user +produces: +- application/json +- application/xml +- application/gob +- application/x-gob +responses: + NotFound: + description: Not Found + OK: + description: OK + schema: + $ref: '#/definitions/Json' +schemes: +- http +swagger: "2.0" diff --git a/tool/cellar-cli/main.go b/tool/cellar-cli/main.go new file mode 100644 index 0000000..9f8bdc5 --- /dev/null +++ b/tool/cellar-cli/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "fmt" + goaclient "github.com/goadesign/goa/client" + "github.com/gomatic/opinionated/client" + "github.com/gomatic/opinionated/tool/cli" + "github.com/spf13/cobra" + "net/http" + "os" + "time" +) + +func main() { + // Create command line parser + app := &cobra.Command{ + Use: "cellar-cli", + Short: `CLI client for the cellar service`, + } + + // Create client struct + httpClient := newHTTPClient() + c := client.New(goaclient.HTTPClientDoer(httpClient)) + + // Register global flags + app.PersistentFlags().StringVarP(&c.Scheme, "scheme", "s", "", "Set the requests scheme") + app.PersistentFlags().StringVarP(&c.Host, "host", "H", "localhost:8080", "API hostname") + app.PersistentFlags().DurationVarP(&httpClient.Timeout, "timeout", "t", time.Duration(20)*time.Second, "Set the request timeout") + app.PersistentFlags().BoolVar(&c.Dump, "dump", false, "Dump HTTP request and response.") + + // Initialize API client + c.UserAgent = "cellar-cli/0" + + // Register API commands + cli.RegisterCommands(app, c) + + // Execute! + if err := app.Execute(); err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + os.Exit(-1) + } +} + +// newHTTPClient returns the HTTP client used by the API client to make requests to the service. +func newHTTPClient() *http.Client { + // TBD: Change as needed (e.g. to use a different transport to control redirection policy or + // disable cert validation or...) + return http.DefaultClient +} diff --git a/tool/cli/commands.go b/tool/cli/commands.go new file mode 100644 index 0000000..aa4b129 --- /dev/null +++ b/tool/cli/commands.go @@ -0,0 +1,224 @@ +package cli + +import ( + "encoding/json" + "fmt" + "github.com/goadesign/goa" + goaclient "github.com/goadesign/goa/client" + uuid "github.com/goadesign/goa/uuid" + "github.com/gomatic/opinionated/client" + "github.com/spf13/cobra" + "golang.org/x/net/context" + "log" + "os" + "strconv" + "strings" + "time" +) + +type ( + // LoginUserCommand is the command line data structure for the login action of user + LoginUserCommand struct { + // Username + Username string + PrettyPrint bool + } +) + +// RegisterCommands registers the resource action CLI commands. +func RegisterCommands(app *cobra.Command, c *client.Client) { + var command, sub *cobra.Command + command = &cobra.Command{ + Use: "login", + Short: `Login`, + } + tmp1 := new(LoginUserCommand) + sub = &cobra.Command{ + Use: `user ["/u/USERNAME"]`, + Short: ``, + RunE: func(cmd *cobra.Command, args []string) error { return tmp1.Run(c, args) }, + } + tmp1.RegisterFlags(sub, c) + sub.PersistentFlags().BoolVar(&tmp1.PrettyPrint, "pp", false, "Pretty print response body") + command.AddCommand(sub) + app.AddCommand(command) +} + +func intFlagVal(name string, parsed int) *int { + if hasFlag(name) { + return &parsed + } + return nil +} + +func float64FlagVal(name string, parsed float64) *float64 { + if hasFlag(name) { + return &parsed + } + return nil +} + +func boolFlagVal(name string, parsed bool) *bool { + if hasFlag(name) { + return &parsed + } + return nil +} + +func stringFlagVal(name string, parsed string) *string { + if hasFlag(name) { + return &parsed + } + return nil +} + +func hasFlag(name string) bool { + for _, arg := range os.Args[1:] { + if strings.HasPrefix(arg, "--"+name) { + return true + } + } + return false +} + +func jsonVal(val string) (*interface{}, error) { + var t interface{} + err := json.Unmarshal([]byte(val), &t) + if err != nil { + return nil, err + } + return &t, nil +} + +func jsonArray(ins []string) ([]interface{}, error) { + if ins == nil { + return nil, nil + } + var vals []interface{} + for _, id := range ins { + val, err := jsonVal(id) + if err != nil { + return nil, err + } + vals = append(vals, val) + } + return vals, nil +} + +func timeVal(val string) (*time.Time, error) { + t, err := time.Parse(time.RFC3339, val) + if err != nil { + return nil, err + } + return &t, nil +} + +func timeArray(ins []string) ([]time.Time, error) { + if ins == nil { + return nil, nil + } + var vals []time.Time + for _, id := range ins { + val, err := timeVal(id) + if err != nil { + return nil, err + } + vals = append(vals, *val) + } + return vals, nil +} + +func uuidVal(val string) (*uuid.UUID, error) { + t, err := uuid.FromString(val) + if err != nil { + return nil, err + } + return &t, nil +} + +func uuidArray(ins []string) ([]uuid.UUID, error) { + if ins == nil { + return nil, nil + } + var vals []uuid.UUID + for _, id := range ins { + val, err := uuidVal(id) + if err != nil { + return nil, err + } + vals = append(vals, *val) + } + return vals, nil +} + +func float64Val(val string) (*float64, error) { + t, err := strconv.ParseFloat(val, 64) + if err != nil { + return nil, err + } + return &t, nil +} + +func float64Array(ins []string) ([]float64, error) { + if ins == nil { + return nil, nil + } + var vals []float64 + for _, id := range ins { + val, err := float64Val(id) + if err != nil { + return nil, err + } + vals = append(vals, *val) + } + return vals, nil +} + +func boolVal(val string) (*bool, error) { + t, err := strconv.ParseBool(val) + if err != nil { + return nil, err + } + return &t, nil +} + +func boolArray(ins []string) ([]bool, error) { + if ins == nil { + return nil, nil + } + var vals []bool + for _, id := range ins { + val, err := boolVal(id) + if err != nil { + return nil, err + } + vals = append(vals, *val) + } + return vals, nil +} + +// Run makes the HTTP request corresponding to the LoginUserCommand command. +func (cmd *LoginUserCommand) Run(c *client.Client, args []string) error { + var path string + if len(args) > 0 { + path = args[0] + } else { + path = fmt.Sprintf("/u/%v", cmd.Username) + } + logger := goa.NewLogger(log.New(os.Stderr, "", log.LstdFlags)) + ctx := goa.WithLogger(context.Background(), logger) + resp, err := c.LoginUser(ctx, path) + if err != nil { + goa.LogError(ctx, "failed", "err", err) + return err + } + + goaclient.HandleResponse(c.Client, resp, cmd.PrettyPrint) + return nil +} + +// RegisterFlags registers the command flags with the command line. +func (cmd *LoginUserCommand) RegisterFlags(cc *cobra.Command, c *client.Client) { + var username string + cc.Flags().StringVar(&cmd.Username, "username", username, `Username`) +} diff --git a/tool/opinionated-cli/main.go b/tool/opinionated-cli/main.go new file mode 100644 index 0000000..6dd3a1e --- /dev/null +++ b/tool/opinionated-cli/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "fmt" + goaclient "github.com/goadesign/goa/client" + "github.com/gomatic/opinionated/client" + "github.com/gomatic/opinionated/tool/cli" + "github.com/spf13/cobra" + "net/http" + "os" + "time" +) + +func main() { + // Create command line parser + app := &cobra.Command{ + Use: "opinionated-cli", + Short: `CLI client for the opinionated service`, + } + + // Create client struct + httpClient := newHTTPClient() + c := client.New(goaclient.HTTPClientDoer(httpClient)) + + // Register global flags + app.PersistentFlags().StringVarP(&c.Scheme, "scheme", "s", "", "Set the requests scheme") + app.PersistentFlags().StringVarP(&c.Host, "host", "H", "localhost:3080", "API hostname") + app.PersistentFlags().DurationVarP(&httpClient.Timeout, "timeout", "t", time.Duration(20)*time.Second, "Set the request timeout") + app.PersistentFlags().BoolVar(&c.Dump, "dump", false, "Dump HTTP request and response.") + + // Initialize API client + c.UserAgent = "opinionated-cli/0" + + // Register API commands + cli.RegisterCommands(app, c) + + // Execute! + if err := app.Execute(); err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + os.Exit(-1) + } +} + +// newHTTPClient returns the HTTP client used by the API client to make requests to the service. +func newHTTPClient() *http.Client { + // TBD: Change as needed (e.g. to use a different transport to control redirection policy or + // disable cert validation or...) + return http.DefaultClient +} diff --git a/user.go b/user.go new file mode 100644 index 0000000..f9c97a0 --- /dev/null +++ b/user.go @@ -0,0 +1,27 @@ +package main + +import ( + "github.com/goadesign/goa" + "github.com/gomatic/opinionated/app" +) + +// UserController implements the user resource. +type UserController struct { + *goa.Controller +} + +// NewUserController creates a user controller. +func NewUserController(service *goa.Service) *UserController { + return &UserController{Controller: service.NewController("UserController")} +} + +// Login runs the login action. +func (c *UserController) Login(ctx *app.LoginUserContext) error { + // UserController_Login: start_implement + + // Put your logic here + + // UserController_Login: end_implement + res := &app.JSON{} + return ctx.OK(res) +} diff --git a/vendor/application/README.md b/vendor/application/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/application/application_test.go b/vendor/application/application_test.go deleted file mode 100644 index fad37e0..0000000 --- a/vendor/application/application_test.go +++ /dev/null @@ -1,8 +0,0 @@ -package application_test - -import "testing" - -// -func TestMain(m *testing.M) { - m.Run() -} diff --git a/vendor/application/configure.go b/vendor/application/configure.go deleted file mode 100644 index a506f90..0000000 --- a/vendor/application/configure.go +++ /dev/null @@ -1,6 +0,0 @@ -package application - -// -func Configure() error { - return nil -} diff --git a/vendor/application/configure_test.go b/vendor/application/configure_test.go deleted file mode 100644 index a31d91b..0000000 --- a/vendor/application/configure_test.go +++ /dev/null @@ -1,8 +0,0 @@ -package application_test - -import "testing" - -// -func TestConfigure(t *testing.T) { - -} diff --git a/vendor/application/manage.go b/vendor/application/manage.go deleted file mode 100644 index 0f35d4a..0000000 --- a/vendor/application/manage.go +++ /dev/null @@ -1,6 +0,0 @@ -package application - -// -func Manage() error { - return nil -} diff --git a/vendor/application/manage_test.go b/vendor/application/manage_test.go deleted file mode 100644 index 43aad27..0000000 --- a/vendor/application/manage_test.go +++ /dev/null @@ -1,8 +0,0 @@ -package application_test - -import "testing" - -// -func TestManage(t *testing.T) { - -} diff --git a/vendor/application/route_login.go b/vendor/application/route_login.go deleted file mode 100644 index 257e408..0000000 --- a/vendor/application/route_login.go +++ /dev/null @@ -1,30 +0,0 @@ -package application - -import ( - "middleware/logging" - "service/login" - - "github.com/gorilla/mux" - - httptransport "github.com/go-kit/kit/transport/http" - - "golang.org/x/net/context" -) - -// -func routeLoginService(ctx context.Context, r *mux.Router) { - - logged := logging.New("login", Settings.Program.Name).Middleware() - - loginService := login.New() - - // POST / - - r.Methods("POST").Path("/").Handler(httptransport.NewServer( - ctx, - logged(loginService.Endpoint()), - loginService.Decoder, - servered(jsoned(loginService.Encoder)), - )).Name("POST") - -} diff --git a/vendor/application/route_query.go b/vendor/application/route_query.go deleted file mode 100644 index 9ef51b7..0000000 --- a/vendor/application/route_query.go +++ /dev/null @@ -1,36 +0,0 @@ -package application - -import ( - "middleware/logging" - "service/query" - "transport/http/caching" - - "github.com/gorilla/mux" - - httptransport "github.com/go-kit/kit/transport/http" - - "golang.org/x/net/context" -) - -// -func routeQueryService(ctx context.Context, r *mux.Router) { - - logger := logging.New("query", Settings.Program.Name) - logged := logger.Middleware() - - queryService, err := query.New() - if err != nil { - logger.Log("error", err.Error()) - return - } - - // POST /:id - - r.Methods("POST", "GET").Path("/{id}").Handler(caching.New(-1, httptransport.NewServer( - ctx, - logged(queryService.Endpoint()), - queryService.Decoder, - servered(jsoned(queryService.Encoder)), - ))).Name("GET/POST Id") - -} diff --git a/vendor/application/route_starwars.go b/vendor/application/route_starwars.go deleted file mode 100644 index 85f483b..0000000 --- a/vendor/application/route_starwars.go +++ /dev/null @@ -1,45 +0,0 @@ -package application - -import ( - "middleware/logging" - "service/starwars" - "transport/http/caching" - - "github.com/gorilla/mux" - - httptransport "github.com/go-kit/kit/transport/http" - - "golang.org/x/net/context" -) - -// -func routeStarWarsService(ctx context.Context, r *mux.Router) { - - logger := logging.New("starwars", Settings.Program.Name) - logged := logger.Middleware() - - starWarsService, err := starwars.New() - if err != nil { - logger.Log("error", err.Error()) - return - } - - // POST /:query - - r.Methods("POST").Path("/").Handler(caching.New(-1, httptransport.NewServer( - ctx, - logged(starWarsService.Endpoint()), - starWarsService.Decoder, - servered(jsoned(starWarsService.Encoder)), - ))).Name("POST") - - // GET /:query - - r.Methods("GET").Path("/{query}").Handler(caching.New(-1, httptransport.NewServer( - ctx, - logged(starWarsService.Endpoint()), - starWarsService.Decoder, - servered(jsoned(starWarsService.Encoder)), - ))).Name("GET Query") - -} diff --git a/vendor/application/route_tests.go b/vendor/application/route_tests.go deleted file mode 100644 index 680b09a..0000000 --- a/vendor/application/route_tests.go +++ /dev/null @@ -1,67 +0,0 @@ -package application - -import ( - "middleware/logging" - "service/testing" - "transport/http/caching" - - "github.com/gorilla/mux" - - httptransport "github.com/go-kit/kit/transport/http" - - "golang.org/x/net/context" -) - -// -func routeTestService(ctx context.Context, r *mux.Router) { - - logged := logging.New("test", Settings.Program.Name).Middleware() - - testService := testing.New() - - // POST / - - r.Methods("POST").Path("/").Handler(httptransport.NewServer( - ctx, - logged(testService.Post()), - testService.DecodePost, - servered(jsoned(testService.EncodePost)), - )).Name("POST") - - // GET /:id - - r.Methods("POST", "GET").Path("/{id}").Handler(caching.New(-1, httptransport.NewServer( - ctx, - logged(testService.Get()), - testService.DecodeGet, - servered(jsoned(testService.EncodeGet)), - ))).Name("GET/POST Id") - - // PUT /:id - - r.Methods("PUT").Path("/{id}").Handler(caching.New(-1, httptransport.NewServer( - ctx, - logged(testService.Put()), - testService.DecodePut, - servered(jsoned(testService.EncodePut)), - ))).Name("PUT Id") - - // PATCH /:id - - r.Methods("PATCH").Path("/{id}").Handler(httptransport.NewServer( - ctx, - logged(testService.Patch()), - testService.DecodePatch, - servered(jsoned(testService.EncodePatch)), - )).Name("PATCH Id") - - // DELETE /:id - - r.Methods("DELETE").Path("/{id}").Handler(caching.New(-1, httptransport.NewServer( - ctx, - logged(testService.Delete()), - testService.DecodeDelete, - servered(jsoned(testService.EncodeDelete)), - ))).Name("DELETE Id") - -} diff --git a/vendor/application/routes.go b/vendor/application/routes.go deleted file mode 100644 index 9ee02a6..0000000 --- a/vendor/application/routes.go +++ /dev/null @@ -1,44 +0,0 @@ -package application - -import ( - "net/http" - "transport/http/headered" - - "github.com/gorilla/mux" - - "golang.org/x/net/context" -) - -// -func routeServices() *mux.Router { - r := mux.NewRouter() - ctx := context.Background() - - // Login - - routeLoginService(ctx, r.PathPrefix("/login").Subrouter().StrictSlash(true)) - - // Query - - routeQueryService(ctx, r.PathPrefix("/query").Subrouter().StrictSlash(true)) - - // StarWars - - routeStarWarsService(ctx, r.PathPrefix("/starwars").Subrouter().StrictSlash(true)) - - // Testing - - routeTestService(ctx, r.PathPrefix("/test").Subrouter().StrictSlash(true)) - - return r -} - -var ( - servered = headered.New(func(hs http.Header) { - hs.Set("Server", Settings.Server) - hs.Set("X-Powered-By", Settings.Powered) - }) - jsoned = headered.New(func(hs http.Header) { - hs.Set("Content-Type", "application/json") - }) -) diff --git a/vendor/application/vendor/controllers/README.md b/vendor/application/vendor/controllers/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/application/vendor/controllers/api.go b/vendor/application/vendor/controllers/api.go deleted file mode 100644 index 2d32936..0000000 --- a/vendor/application/vendor/controllers/api.go +++ /dev/null @@ -1 +0,0 @@ -package controllers diff --git a/vendor/application/vendor/controllers/contact.go b/vendor/application/vendor/controllers/contact.go deleted file mode 100644 index 2d32936..0000000 --- a/vendor/application/vendor/controllers/contact.go +++ /dev/null @@ -1 +0,0 @@ -package controllers diff --git a/vendor/application/vendor/controllers/home.go b/vendor/application/vendor/controllers/home.go deleted file mode 100644 index 2d32936..0000000 --- a/vendor/application/vendor/controllers/home.go +++ /dev/null @@ -1 +0,0 @@ -package controllers diff --git a/vendor/application/vendor/controllers/user.go b/vendor/application/vendor/controllers/user.go deleted file mode 100644 index 2d32936..0000000 --- a/vendor/application/vendor/controllers/user.go +++ /dev/null @@ -1 +0,0 @@ -package controllers diff --git a/vendor/application/vendor/github.com/boltdb/bolt b/vendor/application/vendor/github.com/boltdb/bolt deleted file mode 160000 index 4b1ebc1..0000000 --- a/vendor/application/vendor/github.com/boltdb/bolt +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4b1ebc1869ad66568b313d0dc410e2be72670dda diff --git a/vendor/application/vendor/github.com/eknkc/amber b/vendor/application/vendor/github.com/eknkc/amber deleted file mode 160000 index a69a021..0000000 --- a/vendor/application/vendor/github.com/eknkc/amber +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a69a021e158c3b06700cc881c05d0923f627b578 diff --git a/vendor/application/vendor/github.com/go-kit/kit b/vendor/application/vendor/github.com/go-kit/kit deleted file mode 160000 index 1984f57..0000000 --- a/vendor/application/vendor/github.com/go-kit/kit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1984f573fe650f119b280dffeea9187a4e64491d diff --git a/vendor/application/vendor/github.com/gorilla/context b/vendor/application/vendor/github.com/gorilla/context deleted file mode 160000 index 08b5f42..0000000 --- a/vendor/application/vendor/github.com/gorilla/context +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 08b5f424b9271eedf6f9f0ce86cb9396ed337a42 diff --git a/vendor/application/vendor/github.com/graphql-go/graphql b/vendor/application/vendor/github.com/graphql-go/graphql deleted file mode 160000 index 8c31740..0000000 --- a/vendor/application/vendor/github.com/graphql-go/graphql +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8c317402d1b72dff3dd9008bad7e41d0ae96e3c6 diff --git a/vendor/application/vendor/github.com/markbates/goth b/vendor/application/vendor/github.com/markbates/goth deleted file mode 160000 index 75b41c4..0000000 --- a/vendor/application/vendor/github.com/markbates/goth +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 75b41c4517c2bbca43e4518b2cd504f637ab8718 diff --git a/vendor/application/vendor/middleware/logging/README.md b/vendor/application/vendor/middleware/logging/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/application/vendor/middleware/logging/logging.go b/vendor/application/vendor/middleware/logging/logging.go deleted file mode 100644 index bda023b..0000000 --- a/vendor/application/vendor/middleware/logging/logging.go +++ /dev/null @@ -1,46 +0,0 @@ -package logging - -import ( - "os" - - "github.com/go-kit/kit/endpoint" - "github.com/go-kit/kit/log" - - "golang.org/x/net/context" -) - -// -type logger struct { - *log.Context -} - -// -func New(options ...string) *logger { - l := log.NewLogfmtLogger(os.Stderr) - c := log.NewContext(l).With("time", log.DefaultTimestampUTC) - for i := len(options) - 1; i >= 0; i-- { - switch i { - case 0: - c = c.With("service", options[i]) - case 1: - c = c.With("app", options[i]) - } - } - return &logger{c} -} - -// -func (l *logger) Middleware() endpoint.Middleware { - if l == nil { - l = New("") - } - - return func(next endpoint.Endpoint) endpoint.Endpoint { - logger := log.Logger(l.Context) - return func(ctx context.Context, request interface{}) (interface{}, error) { - logger.Log("msg", "calling endpoint", next) - defer logger.Log("msg", "called endpoint") - return next(ctx, request) - } - } -} diff --git a/vendor/application/vendor/middleware/logging/logging_test.go b/vendor/application/vendor/middleware/logging/logging_test.go deleted file mode 100644 index 6cf2272..0000000 --- a/vendor/application/vendor/middleware/logging/logging_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package logging - -import "testing" - -// -func TestMain(m *testing.M) { - m.Run() -} - -// -func TestLogging(t *testing.T) { - -} diff --git a/vendor/application/vendor/models/README.md b/vendor/application/vendor/models/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/application/vendor/models/user.go b/vendor/application/vendor/models/user.go deleted file mode 100644 index 2640e7f..0000000 --- a/vendor/application/vendor/models/user.go +++ /dev/null @@ -1 +0,0 @@ -package models diff --git a/vendor/application/vendor/service/login/README.md b/vendor/application/vendor/service/login/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/application/vendor/service/login/login.go b/vendor/application/vendor/service/login/login.go deleted file mode 100644 index 02d6881..0000000 --- a/vendor/application/vendor/service/login/login.go +++ /dev/null @@ -1,86 +0,0 @@ -package login - -import ( - "encoding/json" - "errors" - "net/http" - "strings" - - "github.com/go-kit/kit/endpoint" - - "golang.org/x/net/context" -) - -// Errors - -// ErrNoCredentials. -var ErrNoCredentials = errors.New("empty credentials") - -// Model - -// Login operations. -type Service interface { - Login(string) (string, error) -} - -// Private Login model. -type loginService struct{} - -// Login requests. -type loginRequest struct { - S string `json:"s"` -} - -// Login response. -type loginResponse struct { - V string `json:"v"` - Err string `json:"err,omitempty"` // errors don't define JSON marshaling -} - -// -func (loginService) Login(s string) (string, error) { - if s == "" { - return "", ErrNoCredentials - } - return strings.ToUpper(s), nil -} - -// Initialization - -// -type loginEndpoint endpoint.Endpoint - -// -func New() loginEndpoint { - svc := loginService{} - - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(loginRequest) - v, err := svc.Login(req.S) - if err != nil { - return loginResponse{v, err.Error()}, nil - } - return loginResponse{v, ""}, nil - } -} - -// Convenience to get a go-kit type back of login's private endpoint type. -func (e loginEndpoint) Endpoint() endpoint.Endpoint { - return endpoint.Endpoint(e) -} - -// Request/response encoding and decoding. - -// -func (e loginEndpoint) Decoder(_ context.Context, r *http.Request) (interface{}, error) { - var request loginRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -// -func (e loginEndpoint) Encoder(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} diff --git a/vendor/application/vendor/service/login/login_test.go b/vendor/application/vendor/service/login/login_test.go deleted file mode 100644 index bfe3f04..0000000 --- a/vendor/application/vendor/service/login/login_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package login - -import "testing" - -// -func TestMain(m *testing.M) { - m.Run() -} - -// -func TestLogin(t *testing.T) { - -} diff --git a/vendor/application/vendor/service/query/README.md b/vendor/application/vendor/service/query/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/application/vendor/service/query/query.go b/vendor/application/vendor/service/query/query.go deleted file mode 100644 index 2873405..0000000 --- a/vendor/application/vendor/service/query/query.go +++ /dev/null @@ -1,101 +0,0 @@ -package query - -import ( - "encoding/json" - "errors" - "fmt" - "net/http" - - "github.com/go-kit/kit/endpoint" - "github.com/graphql-go/graphql" - "golang.org/x/net/context" -) - -// Errors - -// ErrNoQuery. -var ErrNoQuery = errors.New("empty query") - -// Model - -// Query operations. -type Service interface { - Query(string) (*graphql.Result, error) -} - -// Private Query model. -type queryService struct{} - -// Query requests. -type queryRequest struct { - S string `json:"query"` -} - -var ( - schema graphql.Schema -) - -// -func (queryService) Query(query string) (*graphql.Result, error) { - params := graphql.Params{Schema: schema, RequestString: query} - r := graphql.Do(params) - if len(r.Errors) > 0 { - return nil, fmt.Errorf("failed to execute graphql operation, errors: %+v", r.Errors) - } - return r, nil -} - -// Initialization - -// -type queryEndpoint endpoint.Endpoint - -// -func New() (endpoint queryEndpoint, err error) { - svc := queryService{} - - // Schema - fields := graphql.Fields{ - "hello": &graphql.Field{ - Type: graphql.String, - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - return "world", nil - }, - }, - } - rootQuery := graphql.ObjectConfig{Name: "Query", Fields: fields} - schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)} - - schema, err = graphql.NewSchema(schemaConfig) - if err != nil { - return nil, err - } - - endpoint = func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(queryRequest) - return svc.Query(req.S) - } - - return endpoint, nil -} - -// Convenience to get a go-kit type back of query's private endpoint type. -func (e queryEndpoint) Endpoint() endpoint.Endpoint { - return endpoint.Endpoint(e) -} - -// Request/response encoding and decoding. - -// -func (e queryEndpoint) Decoder(_ context.Context, r *http.Request) (interface{}, error) { - var request queryRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -// -func (e queryEndpoint) Encoder(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} diff --git a/vendor/application/vendor/service/query/query_test.go b/vendor/application/vendor/service/query/query_test.go deleted file mode 100644 index 4e23aed..0000000 --- a/vendor/application/vendor/service/query/query_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package query - -import "testing" - -// -func TestMain(m *testing.M) { - m.Run() -} - -// -func TestQuery(t *testing.T) { - -} diff --git a/vendor/application/vendor/service/starwars/README.md b/vendor/application/vendor/service/starwars/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/application/vendor/service/starwars/service.go b/vendor/application/vendor/service/starwars/service.go deleted file mode 100644 index f9987f2..0000000 --- a/vendor/application/vendor/service/starwars/service.go +++ /dev/null @@ -1,85 +0,0 @@ -package starwars - -import ( - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "net/http" - - "github.com/go-kit/kit/endpoint" - "github.com/gorilla/mux" - "github.com/graphql-go/graphql" - "golang.org/x/net/context" -) - -// Errors - -// ErrNoQuery. -var ErrNoQuery = errors.New("empty starwars") - -// Model - -// Query operations. -type Service interface { - Query(string) (*graphql.Result, error) -} - -// Private Query model. -type starwarsService struct{} - -// -func (starwarsService) Query(query string) (*graphql.Result, error) { - params := graphql.Params{Schema: StarWarsSchema, RequestString: query} - r := graphql.Do(params) - if len(r.Errors) > 0 { - return nil, fmt.Errorf("failed to execute graphql operation, errors: %+v", r.Errors) - } - return r, nil -} - -// Initialization - -// -type starwarsEndpoint endpoint.Endpoint - -// -func New() (endpoint starwarsEndpoint, err error) { - svc := starwarsService{} - - endpoint = func(ctx context.Context, request interface{}) (interface{}, error) { - return svc.Query(request.(string)) - } - - return endpoint, nil -} - -// Convenience to get a go-kit type back of starwars's private endpoint type. -func (e starwarsEndpoint) Endpoint() endpoint.Endpoint { - return endpoint.Endpoint(e) -} - -// Request/response encoding and decoding. - -// -func (e starwarsEndpoint) Decoder(ctx context.Context, r *http.Request) (interface{}, error) { - vars := mux.Vars(r) - if q, exists := vars["query"]; exists && q != "" { - return q, nil - } - query := r.URL.Query() - if q := query.Get("query"); q != "" { - return string(q), nil - } - if q, err := ioutil.ReadAll(r.Body); err != nil { - return nil, err - } else if len(q) != 0 { - return string(q), nil - } - return nil, fmt.Errorf("Requires a query") -} - -// -func (e starwarsEndpoint) Encoder(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} diff --git a/vendor/application/vendor/service/starwars/starwars.go b/vendor/application/vendor/service/starwars/starwars.go deleted file mode 100644 index 7938bf3..0000000 --- a/vendor/application/vendor/service/starwars/starwars.go +++ /dev/null @@ -1,464 +0,0 @@ -package starwars - -import ( - "encoding/json" - "reflect" - "strconv" - "testing" - - "github.com/graphql-go/graphql" - "github.com/graphql-go/graphql/language/ast" - "github.com/graphql-go/graphql/language/parser" - "github.com/kr/pretty" -) - -var ( - Luke StarWarsChar - Vader StarWarsChar - Han StarWarsChar - Leia StarWarsChar - Tarkin StarWarsChar - Threepio StarWarsChar - Artoo StarWarsChar - HumanData map[int]StarWarsChar - DroidData map[int]StarWarsChar - StarWarsSchema graphql.Schema - - humanType *graphql.Object - droidType *graphql.Object -) - -type StarWarsChar struct { - ID string - Name string - Friends []StarWarsChar - AppearsIn []int - HomePlanet string - PrimaryFunction string -} - -func init() { - Luke = StarWarsChar{ - ID: "1000", - Name: "Luke Skywalker", - AppearsIn: []int{4, 5, 6}, - HomePlanet: "Tatooine", - } - Vader = StarWarsChar{ - ID: "1001", - Name: "Darth Vader", - AppearsIn: []int{4, 5, 6}, - HomePlanet: "Tatooine", - } - Han = StarWarsChar{ - ID: "1002", - Name: "Han Solo", - AppearsIn: []int{4, 5, 6}, - } - Leia = StarWarsChar{ - ID: "1003", - Name: "Leia Organa", - AppearsIn: []int{4, 5, 6}, - HomePlanet: "Alderaa", - } - Tarkin = StarWarsChar{ - ID: "1004", - Name: "Wilhuff Tarkin", - AppearsIn: []int{4}, - } - Threepio = StarWarsChar{ - ID: "2000", - Name: "C-3PO", - AppearsIn: []int{4, 5, 6}, - PrimaryFunction: "Protocol", - } - Artoo = StarWarsChar{ - ID: "2001", - Name: "R2-D2", - AppearsIn: []int{4, 5, 6}, - PrimaryFunction: "Astromech", - } - Luke.Friends = append(Luke.Friends, []StarWarsChar{Han, Leia, Threepio, Artoo}...) - Vader.Friends = append(Luke.Friends, []StarWarsChar{Tarkin}...) - Han.Friends = append(Han.Friends, []StarWarsChar{Luke, Leia, Artoo}...) - Leia.Friends = append(Leia.Friends, []StarWarsChar{Luke, Han, Threepio, Artoo}...) - Tarkin.Friends = append(Tarkin.Friends, []StarWarsChar{Vader}...) - Threepio.Friends = append(Threepio.Friends, []StarWarsChar{Luke, Han, Leia, Artoo}...) - Artoo.Friends = append(Artoo.Friends, []StarWarsChar{Luke, Han, Leia}...) - HumanData = map[int]StarWarsChar{ - 1000: Luke, - 1001: Vader, - 1002: Han, - 1003: Leia, - 1004: Tarkin, - } - DroidData = map[int]StarWarsChar{ - 2000: Threepio, - 2001: Artoo, - } - - episodeEnum := graphql.NewEnum(graphql.EnumConfig{ - Name: "Episode", - Description: "One of the films in the Star Wars Trilogy", - Values: graphql.EnumValueConfigMap{ - "NEWHOPE": &graphql.EnumValueConfig{ - Value: 4, - Description: "Released in 1977.", - }, - "EMPIRE": &graphql.EnumValueConfig{ - Value: 5, - Description: "Released in 1980.", - }, - "JEDI": &graphql.EnumValueConfig{ - Value: 6, - Description: "Released in 1983.", - }, - }, - }) - - characterInterface := graphql.NewInterface(graphql.InterfaceConfig{ - Name: "Character", - Description: "A character in the Star Wars Trilogy", - Fields: graphql.Fields{ - "id": &graphql.Field{ - Type: graphql.NewNonNull(graphql.String), - Description: "The id of the character.", - }, - "name": &graphql.Field{ - Type: graphql.String, - Description: "The name of the character.", - }, - "appearsIn": &graphql.Field{ - Type: graphql.NewList(episodeEnum), - Description: "Which movies they appear in.", - }, - }, - ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object { - if character, ok := p.Value.(StarWarsChar); ok { - id, _ := strconv.Atoi(character.ID) - human := GetHuman(id) - if human.ID != "" { - return humanType - } - } - return droidType - }, - }) - characterInterface.AddFieldConfig("friends", &graphql.Field{ - Type: graphql.NewList(characterInterface), - Description: "The friends of the character, or an empty list if they have none.", - }) - - humanType = graphql.NewObject(graphql.ObjectConfig{ - Name: "Human", - Description: "A humanoid creature in the Star Wars universe.", - Fields: graphql.Fields{ - "id": &graphql.Field{ - Type: graphql.NewNonNull(graphql.String), - Description: "The id of the human.", - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - if human, ok := p.Source.(StarWarsChar); ok { - return human.ID, nil - } - return nil, nil - }, - }, - "name": &graphql.Field{ - Type: graphql.String, - Description: "The name of the human.", - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - if human, ok := p.Source.(StarWarsChar); ok { - return human.Name, nil - } - return nil, nil - }, - }, - "friends": &graphql.Field{ - Type: graphql.NewList(characterInterface), - Description: "The friends of the human, or an empty list if they have none.", - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - if human, ok := p.Source.(StarWarsChar); ok { - return human.Friends, nil - } - return []interface{}{}, nil - }, - }, - "appearsIn": &graphql.Field{ - Type: graphql.NewList(episodeEnum), - Description: "Which movies they appear in.", - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - if human, ok := p.Source.(StarWarsChar); ok { - return human.AppearsIn, nil - } - return nil, nil - }, - }, - "homePlanet": &graphql.Field{ - Type: graphql.String, - Description: "The home planet of the human, or null if unknown.", - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - if human, ok := p.Source.(StarWarsChar); ok { - return human.HomePlanet, nil - } - return nil, nil - }, - }, - }, - Interfaces: []*graphql.Interface{ - characterInterface, - }, - }) - droidType = graphql.NewObject(graphql.ObjectConfig{ - Name: "Droid", - Description: "A mechanical creature in the Star Wars universe.", - Fields: graphql.Fields{ - "id": &graphql.Field{ - Type: graphql.NewNonNull(graphql.String), - Description: "The id of the droid.", - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - if droid, ok := p.Source.(StarWarsChar); ok { - return droid.ID, nil - } - return nil, nil - }, - }, - "name": &graphql.Field{ - Type: graphql.String, - Description: "The name of the droid.", - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - if droid, ok := p.Source.(StarWarsChar); ok { - return droid.Name, nil - } - return nil, nil - }, - }, - "friends": &graphql.Field{ - Type: graphql.NewList(characterInterface), - Description: "The friends of the droid, or an empty list if they have none.", - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - if droid, ok := p.Source.(StarWarsChar); ok { - friends := []map[string]interface{}{} - for _, friend := range droid.Friends { - friends = append(friends, map[string]interface{}{ - "name": friend.Name, - "id": friend.ID, - }) - } - return droid.Friends, nil - } - return []interface{}{}, nil - }, - }, - "appearsIn": &graphql.Field{ - Type: graphql.NewList(episodeEnum), - Description: "Which movies they appear in.", - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - if droid, ok := p.Source.(StarWarsChar); ok { - return droid.AppearsIn, nil - } - return nil, nil - }, - }, - "primaryFunction": &graphql.Field{ - Type: graphql.String, - Description: "The primary function of the droid.", - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - if droid, ok := p.Source.(StarWarsChar); ok { - return droid.PrimaryFunction, nil - } - return nil, nil - }, - }, - }, - Interfaces: []*graphql.Interface{ - characterInterface, - }, - }) - - queryType := graphql.NewObject(graphql.ObjectConfig{ - Name: "Query", - Fields: graphql.Fields{ - "hero": &graphql.Field{ - Type: characterInterface, - Args: graphql.FieldConfigArgument{ - "episode": &graphql.ArgumentConfig{ - Description: "If omitted, returns the hero of the whole saga. If " + - "provided, returns the hero of that particular episode.", - Type: episodeEnum, - }, - }, - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - return GetHero(p.Args["episode"]), nil - }, - }, - "human": &graphql.Field{ - Type: humanType, - Args: graphql.FieldConfigArgument{ - "id": &graphql.ArgumentConfig{ - Description: "id of the human", - Type: graphql.NewNonNull(graphql.String), - }, - }, - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - return GetHuman(p.Args["id"].(int)), nil - }, - }, - "droid": &graphql.Field{ - Type: droidType, - Args: graphql.FieldConfigArgument{ - "id": &graphql.ArgumentConfig{ - Description: "id of the droid", - Type: graphql.NewNonNull(graphql.String), - }, - }, - Resolve: func(p graphql.ResolveParams) (interface{}, error) { - return GetDroid(p.Args["id"].(int)), nil - }, - }, - }, - }) - StarWarsSchema, _ = graphql.NewSchema(graphql.SchemaConfig{ - Query: queryType, - }) -} - -func GetHuman(id int) StarWarsChar { - if human, ok := HumanData[id]; ok { - return human - } - return StarWarsChar{} -} -func GetDroid(id int) StarWarsChar { - if droid, ok := DroidData[id]; ok { - return droid - } - return StarWarsChar{} -} -func GetHero(episode interface{}) interface{} { - if episode == 5 { - return Luke - } - return Artoo -} - -// Test helper functions - -func TestParse(t *testing.T, query string) *ast.Document { - astDoc, err := parser.Parse(parser.ParseParams{ - Source: query, - Options: parser.ParseOptions{ - // include source, for error reporting - NoSource: false, - }, - }) - if err != nil { - t.Fatalf("Parse failed: %v", err) - } - return astDoc -} -func TestExecute(t *testing.T, ep graphql.ExecuteParams) *graphql.Result { - return graphql.Execute(ep) -} - -func Diff(a, b interface{}) []string { - return pretty.Diff(a, b) -} - -func ASTToJSON(t *testing.T, a ast.Node) interface{} { - b, err := json.Marshal(a) - if err != nil { - t.Fatalf("Failed to marshal Node %v", err) - } - var f interface{} - err = json.Unmarshal(b, &f) - if err != nil { - t.Fatalf("Failed to unmarshal Node %v", err) - } - return f -} - -func ContainSubsetSlice(super []interface{}, sub []interface{}) bool { - if len(sub) == 0 { - return true - } -subLoop: - for _, subVal := range sub { - found := false - innerLoop: - for _, superVal := range super { - if subVal, ok := subVal.(map[string]interface{}); ok { - if superVal, ok := superVal.(map[string]interface{}); ok { - if ContainSubset(superVal, subVal) { - found = true - break innerLoop - } else { - continue - } - } else { - return false - } - - } - if subVal, ok := subVal.([]interface{}); ok { - if superVal, ok := superVal.([]interface{}); ok { - if ContainSubsetSlice(superVal, subVal) { - found = true - break innerLoop - } else { - continue - } - } else { - return false - } - } - if reflect.DeepEqual(superVal, subVal) { - found = true - break innerLoop - } - } - if !found { - return false - } - continue subLoop - } - return true -} - -func ContainSubset(super map[string]interface{}, sub map[string]interface{}) bool { - if len(sub) == 0 { - return true - } - for subKey, subVal := range sub { - if superVal, ok := super[subKey]; ok { - switch superVal := superVal.(type) { - case []interface{}: - if subVal, ok := subVal.([]interface{}); ok { - if !ContainSubsetSlice(superVal, subVal) { - return false - } - } else { - return false - } - case map[string]interface{}: - if subVal, ok := subVal.(map[string]interface{}); ok { - if !ContainSubset(superVal, subVal) { - return false - } - } else { - return false - } - default: - if !reflect.DeepEqual(superVal, subVal) { - return false - } - } - } else { - return false - } - } - return true -} - -func EqualErrorMessage(expected, result *graphql.Result, i int) bool { - return expected.Errors[i].Message == result.Errors[i].Message -} diff --git a/vendor/application/vendor/service/starwars/starwars_test.go b/vendor/application/vendor/service/starwars/starwars_test.go deleted file mode 100644 index 96486b4..0000000 --- a/vendor/application/vendor/service/starwars/starwars_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package starwars - -import "testing" - -// -func TestMain(m *testing.M) { - m.Run() -} - -// -func TestStarWars(t *testing.T) { - -} diff --git a/vendor/application/vendor/service/testing/README.md b/vendor/application/vendor/service/testing/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/application/vendor/service/testing/testing.go b/vendor/application/vendor/service/testing/testing.go deleted file mode 100644 index 3010edb..0000000 --- a/vendor/application/vendor/service/testing/testing.go +++ /dev/null @@ -1,159 +0,0 @@ -package testing - -import ( - "encoding/json" - "errors" - "net/http" - "strings" - - "github.com/go-kit/kit/endpoint" - - "golang.org/x/net/context" -) - -// Errors - -// ErrEmpty. -var ErrEmpty = errors.New("empty") - -// Model - -// Operations. -type Service interface { - Test(string) (string, error) -} - -// -type testService struct{} - -// Test requests. -type testRequest struct { - S string `json:"s"` -} - -// Test response. -type testResponse struct { - V string `json:"v"` - Err string `json:"err,omitempty"` // errors don't define JSON marshaling -} - -// -func (testService) Test(s string) (string, error) { - if s == "" { - return "", ErrEmpty - } - return strings.ToUpper(s), nil -} - -// Initialization - -// -type testEndpoint endpoint.Endpoint - -// -func New() testEndpoint { - svc := testService{} - - return func(ctx context.Context, request interface{}) (interface{}, error) { - req := request.(testRequest) - v, err := svc.Test(req.S) - if err != nil { - return testResponse{v, err.Error()}, nil - } - return testResponse{v, ""}, nil - } -} - -// -func (e testEndpoint) Post() endpoint.Endpoint { - return endpoint.Endpoint(e) -} - -// -func (e testEndpoint) Get() endpoint.Endpoint { - return endpoint.Endpoint(e) -} - -// -func (e testEndpoint) Put() endpoint.Endpoint { - return endpoint.Endpoint(e) -} - -// -func (e testEndpoint) Patch() endpoint.Endpoint { - return endpoint.Endpoint(e) -} - -// -func (e testEndpoint) Delete() endpoint.Endpoint { - return endpoint.Endpoint(e) -} - -// Request/response encoding and decoding. - -// POST -func (e testEndpoint) DecodePost(_ context.Context, r *http.Request) (interface{}, error) { - var request testRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -// -func (e testEndpoint) EncodePost(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} - -// GET -func (e testEndpoint) DecodeGet(_ context.Context, r *http.Request) (interface{}, error) { - var request testRequest - return request, nil -} - -// -func (e testEndpoint) EncodeGet(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} - -// PUT -func (e testEndpoint) DecodePut(_ context.Context, r *http.Request) (interface{}, error) { - var request testRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -// -func (e testEndpoint) EncodePut(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} - -// PATCH -func (e testEndpoint) DecodePatch(_ context.Context, r *http.Request) (interface{}, error) { - var request testRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -// -func (e testEndpoint) EncodePatch(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} - -// DELETE -func (e testEndpoint) DecodeDelete(_ context.Context, r *http.Request) (interface{}, error) { - var request testRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - return nil, err - } - return request, nil -} - -// -func (e testEndpoint) EncodeDelete(_ context.Context, w http.ResponseWriter, response interface{}) error { - return json.NewEncoder(w).Encode(response) -} diff --git a/vendor/application/vendor/service/testing/testing_test.go b/vendor/application/vendor/service/testing/testing_test.go deleted file mode 100644 index 926fb4c..0000000 --- a/vendor/application/vendor/service/testing/testing_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package testing - -import "testing" - -// -func TestMain(m *testing.M) { - m.Run() -} - -// -func TestTesting(t *testing.T) { - -} diff --git a/vendor/application/vendor/service/view/README.md b/vendor/application/vendor/service/view/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/application/vendor/service/view/vs_test.go b/vendor/application/vendor/service/view/vs_test.go deleted file mode 100644 index ef1189a..0000000 --- a/vendor/application/vendor/service/view/vs_test.go +++ /dev/null @@ -1 +0,0 @@ -package view diff --git a/vendor/application/vendor/transport/http/README.md b/vendor/application/vendor/transport/http/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/application/vendor/transport/http/caching/README.md b/vendor/application/vendor/transport/http/caching/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/application/vendor/transport/http/caching/caching.go b/vendor/application/vendor/transport/http/caching/caching.go deleted file mode 100644 index 5f16b63..0000000 --- a/vendor/application/vendor/transport/http/caching/caching.go +++ /dev/null @@ -1,73 +0,0 @@ -package caching - -import ( - "crypto/md5" - "fmt" - stderr "log" - "math/rand" - "net/http" - "time" -) - -type cached struct { - next http.Handler - maxAge int - options []string -} - -// -func (c cached) ServeHTTP(w http.ResponseWriter, req *http.Request) { - now := time.Now() - utc := now.UTC() - tomorrow := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).AddDate(0, 0, 1) - age := c.maxAge - if age <= 0 { - age = int(tomorrow.Sub(now).Seconds()) - } - - nows := fmt.Sprintf("%8x", utc.UnixNano()) - rnds := fmt.Sprintf("%8x", rand.Int63()) - url5 := md5.Sum([]byte(req.URL.String())) - pth5 := md5.Sum([]byte(req.URL.Path)) - qry5 := md5.Sum([]byte(fmt.Sprintf("%+v", req.URL.Query()))) - rnd5 := md5.Sum([]byte(fmt.Sprintf("%v.%v", nows, rnds))) - - // ETags are currently just generated daily based on the time and the URL. - etag := fmt.Sprintf(`W/"%x"`, md5.Sum([]byte(fmt.Sprintf("%v.%v", tomorrow, url5)))) - - ifNoneMatch := req.Header.Get("If-None-Match") - if etag != "" && etag == ifNoneMatch { - stderr.Printf("Not Modified") - http.Error(w, "Not Modified", http.StatusNotModified) - return - } - - hs := w.Header() - - hs.Set("Etag", etag) - - requestId := fmt.Sprintf("%x%x%x%x", pth5[:4], qry5[:4], url5[:4], rnd5[:4]) - - hs.Set("Last-Modified", utc.Format(time.RFC850)) - hs.Set("X-Request-Id", requestId) - - if len(c.options) > 0 && c.options[0] == "development" { - stderr.Printf("WARNING: Development mode enabled! Caching disabled.") - hs.Set("Cache-Control", "no-cache, no-store, must-revalidate") - hs.Set("Pragma", "no-cache") - hs.Set("Expires", "0") - } else { - hs.Set("Cache-Control", fmt.Sprintf("public, max-age=%v", age)) - } - - c.next.ServeHTTP(w, req) -} - -// -func New(maxAge int, server http.Handler, options ...string) http.Handler { - return cached{ - next: server, - maxAge: maxAge, - options: options, - } -} diff --git a/vendor/application/vendor/transport/http/caching/caching_test.go b/vendor/application/vendor/transport/http/caching/caching_test.go deleted file mode 100644 index 86e9d1a..0000000 --- a/vendor/application/vendor/transport/http/caching/caching_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package caching - -import "testing" - -// -func TestMain(m *testing.M) { - m.Run() -} - -// -func TestCaching(t *testing.T) { - -} diff --git a/vendor/application/vendor/transport/http/headered/README.md b/vendor/application/vendor/transport/http/headered/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/application/vendor/transport/http/headered/headered.go b/vendor/application/vendor/transport/http/headered/headered.go deleted file mode 100644 index 956c7dd..0000000 --- a/vendor/application/vendor/transport/http/headered/headered.go +++ /dev/null @@ -1,23 +0,0 @@ -package headered - -import ( - "net/http" - - chain "transport/http" - - httptransport "github.com/go-kit/kit/transport/http" - "golang.org/x/net/context" -) - -// -type Headered func(http.Header) - -// -func New(hf Headered) chain.ChainResponseEncoders { - return func(next httptransport.EncodeResponseFunc) httptransport.EncodeResponseFunc { - return func(ctx context.Context, resp http.ResponseWriter, i interface{}) error { - hf(resp.Header()) - return next(ctx, resp, i) - } - } -} diff --git a/vendor/application/vendor/transport/http/headered/headered_test.go b/vendor/application/vendor/transport/http/headered/headered_test.go deleted file mode 100644 index 9226f06..0000000 --- a/vendor/application/vendor/transport/http/headered/headered_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package headered - -import "testing" - -// -func TestMain(m *testing.M) { - m.Run() -} - -// -func TestHeadered(t *testing.T) { - -} diff --git a/vendor/application/vendor/transport/http/http.go b/vendor/application/vendor/transport/http/http.go deleted file mode 100644 index 062ff68..0000000 --- a/vendor/application/vendor/transport/http/http.go +++ /dev/null @@ -1,15 +0,0 @@ -package http - -import ( - httptransport "github.com/go-kit/kit/transport/http" - "github.com/gorilla/mux" -) - -// -type ChainResponseEncoders func(next httptransport.EncodeResponseFunc) httptransport.EncodeResponseFunc - -// -type ChainRequestDecoders func(next httptransport.DecodeRequestFunc) httptransport.DecodeRequestFunc - -// -type ChainRouter func(next *mux.Router) *mux.Router diff --git a/vendor/application/vendor/transport/http/http_test.go b/vendor/application/vendor/transport/http/http_test.go deleted file mode 100644 index ed94922..0000000 --- a/vendor/application/vendor/transport/http/http_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package http - -import "testing" - -// -func TestMain(m *testing.M) { - m.Run() -} - -// -func TestHTTP(t *testing.T) { - -} diff --git a/vendor/github.com/urfave/cli b/vendor/github.com/urfave/cli deleted file mode 160000 index 492afb9..0000000 --- a/vendor/github.com/urfave/cli +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 492afb91497e22b398e972924eda64bfd706b102 diff --git a/vendor/application/vendor/service/view/vs.go b/vendor/service/view/view.go similarity index 100% rename from vendor/application/vendor/service/view/vs.go rename to vendor/service/view/view.go