Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pacedotdev/oto
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.3.0
Choose a base ref
...
head repository: pacedotdev/oto
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.4.0
Choose a head ref

Commits on Feb 23, 2020

  1. removed unused image

    matryer committed Feb 23, 2020
    Copy the full SHA
    4880b39 View commit details

Commits on Mar 3, 2020

  1. add example

    kandros committed Mar 3, 2020
    Copy the full SHA
    252b2f9 View commit details
  2. copy pasteable commands

    kandros committed Mar 3, 2020
    Copy the full SHA
    f366acb View commit details

Commits on May 16, 2020

  1. Merge pull request #3 from kandros/add-example

    add example
    matryer authored May 16, 2020
    Copy the full SHA
    7aadc6e View commit details
  2. Update readme.md

    matryer authored May 16, 2020
    Copy the full SHA
    1680de2 View commit details
  3. Copy the full SHA
    c372100 View commit details
  4. Update greeter_service.go

    matryer authored May 16, 2020
    Copy the full SHA
    f2500b9 View commit details
  5. simpler example

    matryer committed May 16, 2020
    Copy the full SHA
    ad2d1ad View commit details

Commits on May 26, 2020

  1. Merge pull request #2 from kandros/readme

    copy pasteable commands
    matryer authored May 26, 2020
    Copy the full SHA
    a283cc8 View commit details
  2. small tweaks

    matryer committed May 26, 2020
    Copy the full SHA
    450b9e8 View commit details
  3. fmt

    matryer committed May 26, 2020
    Copy the full SHA
    8290934 View commit details
  4. fmt

    matryer committed May 26, 2020
    Copy the full SHA
    2b50a95 View commit details
  5. trying a width

    matryer committed May 26, 2020
    Copy the full SHA
    434fd76 View commit details
  6. didn't work

    matryer committed May 26, 2020
    Copy the full SHA
    670710b View commit details

Commits on Jun 1, 2020

  1. Fixing a typo in the Encode Content-Type header.

    The code had a type where the Content-Type header was being set to `chatset=...` instead of `charset=...`. I don't think this really justifies any new tests but that's up to you 😄
    joncalhoun authored Jun 1, 2020
    Copy the full SHA
    f8c5070 View commit details

Commits on Jun 2, 2020

  1. Merge pull request #5 from joncalhoun/patch-1

    Fixing a typo in the Encode Content-Type header.
    dahernan authored Jun 2, 2020
    Copy the full SHA
    7e24b40 View commit details

Commits on Jun 21, 2020

  1. Update README.md

    matryer authored Jun 21, 2020
    Copy the full SHA
    1545c6f View commit details

Commits on Jun 29, 2020

  1. fix missing slash typo

    DylanGraham committed Jun 29, 2020
    Copy the full SHA
    cfabe6a View commit details
  2. Merge pull request #7 from DylanGraham/master

    fix missing slash typo
    matryer authored Jun 29, 2020
    Copy the full SHA
    7572d77 View commit details

Commits on Jun 30, 2020

  1. ignored oto binary

    matryer committed Jun 30, 2020
    Copy the full SHA
    48fba28 View commit details
  2. added json helper function

    matryer committed Jun 30, 2020
    Copy the full SHA
    cbabc70 View commit details
  3. linefeed

    matryer committed Jun 30, 2020
    Copy the full SHA
    650a128 View commit details

Commits on Jul 13, 2020

  1. Copy the full SHA
    7be99fb View commit details
  2. Copy the full SHA
    f55f430 View commit details

Commits on Jul 15, 2020

  1. Copy the full SHA
    0971275 View commit details
Showing with 500 additions and 89 deletions.
  1. +3 −0 .gitignore
  2. +56 −36 README.md
  3. +29 −0 example/client.gen.js
  4. +29 −0 example/client.js.plush
  5. +16 −0 example/def/greeter_service.go
  6. +14 −0 example/generate.sh
  7. +5 −0 example/go.mod
  8. +5 −0 example/go.sum
  9. +20 −0 example/index.html
  10. +32 −0 example/main.go
  11. +21 −0 example/readme.md
  12. +55 −0 example/server.gen.go
  13. +62 −0 example/server.go.plush
  14. +18 −6 go.mod
  15. +69 −0 go.sum
  16. +0 −1 main.go
  17. +1 −1 otohttp/server.go
  18. BIN pace-logo.png
  19. +38 −30 parser.go
  20. +12 −12 parser_test.go
  21. +14 −2 render.go
  22. +1 −1 render_test.go
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -10,3 +10,6 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# binary
oto
92 changes: 56 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,10 +2,10 @@

Go driven rpc code generation tool for right now.

* 100% Go
* Describe services with Go interfaces
* Generate server and client code
* Modify the templates to solve your particular needs
- 100% Go
- Describe services with Go interfaces
- Generate server and client code
- Modify the templates to solve your particular needs

## Tutorial

@@ -18,72 +18,92 @@ go install github.com/pacedotdev/oto
Create a project folder, and write your service definition as a Go interface:

```go
// definitions/definitons.go
package definitions

type GreeterService interface {
Greet(GreetRequest) GreetResponse
Greet(GreetRequest) GreetResponse
}

type GreetRequest struct {
Name string
Name string
}

type GreetResponse struct {
Greeting string
Greeting string
}
```

Download templates from otohttp

```bash
mkdir templates \
&& wget https://raw.githubusercontent.com/pacedotdev/oto/master/otohttp/templates/server.go.plush -q -O ./templates/server.go.plush \
&& wget https://raw.githubusercontent.com/pacedotdev/oto/master/otohttp/templates/client.js.plush -q -O ./templates/client.js.plush
```

Use the `oto` tool to generate a client and server:

```bash
oto -template ./otohttp/templates/server.go.plush \
-out ./api/oto.gen.go \
-ignore Ignorer \
./api/definitions
gofmt -w ./api/oto.gen.go ./api/oto.gen.go
mkdir generated &&
oto -template ./templates/server.go.plush \
-out ./generated/oto.gen.go \
-ignore Ignorer \
-pkg generated \
./definitions/definitions.go &&
gofmt -w ./generated/oto.gen.go ./generated/oto.gen.go &&
oto -template ./templates/client.js.plush \
-out ./generated/oto.gen.js \
-ignore Ignorer \
./definitions/definitions.go
```

* Run `oto -help` for more information about these flags
- Run `oto -help` for more information about these flags

Implement the service in Go:

```go
package api
// greeter_service.go
package main

type greeterService struct{}
type GreeterService struct{}

func (greeterService) Greet(ctx context.Context, r GreetRequest) (*GreetResponse, error) {
resp := &GreetResponse{
Greeting: "Hello " + r.Name,
}
return resp, nil
func (GreeterService) Greet(ctx context.Context, r GreetRequest) (*GreetResponse, error) {
resp := &GreetResponse{
Greeting: "Hello " + r.Name,
}
return resp, nil
}
```

Use the generated Go code to write a `main.go` that exposes the server:

```go
// main.go
package main

func main() {
g := greeterService{}
server := otohttp.NewServer()
RegisterGreeterService(server, g)
http.Handle("/oto/", server)
log.Fatal(http.ListenAndServe(":8080", nil))
g := GreeterService{}
server := otohttp.NewServer()
generated.RegisterGreeterService(server, g)
http.Handle("/oto/", server)
log.Fatal(http.ListenAndServe(":8080", nil))
}
```

Use the generated client to access the service in JavaScript:

```javascript
import { GreeterService } from 'oto.gen.js'
import { GreeterService } from "oto.gen.js";

const greeterService = new GreeterService()
const greeterService = new GreeterService();

greeterService.greet({
name: "Mat",
})
.then((response) => alert(response.greeting))
.catch((e) => alert(e))
greeterService
.greet({
name: "Mat"
})
.then(response => alert(response.greeting))
.catch(e => alert(e));
```

### Specifying additional template data
@@ -92,10 +112,10 @@ You can provide strings to your templates via the `-params` flag:

```bash
oto \
-template ./otohttp/templates/server.go.plush \
-out ./api/oto.gen.go
-params "key1:value1,key2:value2"
./api/definitions
-template ./templates/server.go.plush \
-out ./generated/oto.gen.go \
-params "key1:value1,key2:value2" \
./definitions/definitions.go
```

Within your templates, you may access these strings with `<%= params["key1"] %>`.
29 changes: 29 additions & 0 deletions example/client.gen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Code generated by oto; DO NOT EDIT.

'use strict';


class GreeterService {

async greet(greetRequest) {
const headers = {
'Accept': 'application/json',
'Accept-Encoding': 'gzip',
'Content-Type': 'application/json',
}
greetRequest = greetRequest || {}
const response = await fetch('/oto/GreeterService.Greet', {
method: 'POST',
headers: headers,
body: JSON.stringify(greetRequest)
})
return response.json().then((json) => {
if (json.error) {
throw new Error(json.error)
}
return json
})
}

}

29 changes: 29 additions & 0 deletions example/client.js.plush
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Code generated by oto; DO NOT EDIT.

'use strict';

<%= for (service) in def.Services { %>
class <%= service.Name %> {
<%= for (method) in service.Methods { %>
async <%= camelize_down(method.Name) %>(<%= camelize_down(method.InputObject.TypeName) %>) {
const headers = {
'Accept': 'application/json',
'Accept-Encoding': 'gzip',
'Content-Type': 'application/json',
}
<%= camelize_down(method.InputObject.TypeName) %> = <%= camelize_down(method.InputObject.TypeName) %> || {}
const response = await fetch('/oto/<%= service.Name %>.<%= method.Name %>', {
method: 'POST',
headers: headers,
body: JSON.stringify(<%= camelize_down(method.InputObject.TypeName) %>)
})
return response.json().then((json) => {
if (json.error) {
throw new Error(json.error)
}
return json
})
}
<% } %>
}
<% } %>
16 changes: 16 additions & 0 deletions example/def/greeter_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package def

// GreeterService is a polite API for greeting people.
type GreeterService interface {
Greet(GreetRequest) GreetResponse
}

type GreetRequest struct {
// Name is the person to greet.
Name string
}

type GreetResponse struct {
// Greeting is a nice message welcoming somebody.
Greeting string
}
14 changes: 14 additions & 0 deletions example/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

oto -template server.go.plush \
-out server.gen.go \
-pkg main \
./def
gofmt -w server.gen.go server.gen.go
echo "generated server.gen.go"

oto -template client.js.plush \
-out client.gen.js \
-pkg main \
./def
echo "generated client.gen.js"
5 changes: 5 additions & 0 deletions example/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/pacedotdev/oto/example2

go 1.14

require github.com/pacedotdev/oto/otohttp v0.3.0
5 changes: 5 additions & 0 deletions example/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
github.com/pacedotdev/oto v0.3.0 h1:ZtwT3ImKVan6mzXo8q1Tdyu7RzpB2DAhDzYjHQA+HeE=
github.com/pacedotdev/oto/otohttp v0.3.0 h1:ZbykCnQ4JYaei8COdd42gQAvlhtZxnQqpptPx7Ncl+Y=
github.com/pacedotdev/oto/otohttp v0.3.0/go.mod h1:e03n82JQJNrKE3qQdPCwPkgFi3Ss7Us6ij2Jc0RHa0w=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
20 changes: 20 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<head>
<meta charset='UTF-8' />
<title>otohttp Example</title>
</head>
<body>
<script src='client.gen.js'></script>
<script>

const greeterService = new GreeterService()
greeterService.greet({
Name: "world",
})
.then(response => {
document.write(response.greeting)
})
.catch(e => alert(e))

</script>
</body>
32 changes: 32 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"context"
"fmt"
"log"
"net/http"

"github.com/pacedotdev/oto/otohttp"
)

//go:generate ./generate.sh

// greeterService implements the generated GreeterService interface.
type greeterService struct{}

func (greeterService) Greet(ctx context.Context, r GreetRequest) (*GreetResponse, error) {
resp := &GreetResponse{
Greeting: fmt.Sprintf("Hello, %s.", r.Name),
}
return resp, nil
}

func main() {
var greeterService greeterService
server := otohttp.NewServer()
RegisterGreeterService(server, greeterService)
http.Handle("/oto/", server)
http.Handle("/", http.FileServer(http.Dir(".")))
fmt.Println("listening at http://localhost:8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
21 changes: 21 additions & 0 deletions example/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# otohttp Example

* The `def` folder holds the Oto definition made up of Go interface types.
* The `generate.sh` file (run with `go generate`) uses the `oto` tool to generate the server and client code from `server.go.plush` and `client.js.plush` templates.
* In `main.go` we implement the `greeterService` following the interface generated by the `oto` tool
* `index.html` is a simple page that uses the generated client to access the service

## Run the example

```bash
go run *.go
```

Open http://localhost:8080

## Exercise

1. Add a new service interface to the `def` package.
1. Run `go generate` to regenerate the server and client code
1. See the generated files `server.gen.go` and `client.gen.js`
1. Call your new service in `index.html`
55 changes: 55 additions & 0 deletions example/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions example/server.go.plush
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Code generated by oto; DO NOT EDIT.

package <%= def.PackageName %>

import (
"context"
"log"
"net/http"

"github.com/pacedotdev/oto/otohttp"
<%= for (importPath, name) in def.Imports { %>
<%= name %> "<%= importPath %>"
<% } %>
)

<%= for (service) in def.Services { %>
type <%= service.Name %> interface {
<%= for (method) in service.Methods { %>
<%= method.Name %>(context.Context, <%= method.InputObject.TypeName %>) (*<%= method.OutputObject.TypeName %>, error)<% } %>
}
<% } %>

<%= for (service) in def.Services { %>
type <%= camelize_down(service.Name) %>Server struct {
server *otohttp.Server
<%= camelize_down(service.Name) %> <%= service.Name %>
}

func Register<%= service.Name %>(server *otohttp.Server, <%= camelize_down(service.Name) %> <%= service.Name %>) {
handler := &<%= camelize_down(service.Name) %>Server{
server: server,
<%= camelize_down(service.Name) %>: <%= camelize_down(service.Name) %>,
}
<%= for (method) in service.Methods { %>server.Register("<%= service.Name %>", "<%= method.Name %>", handler.handle<%= method.Name %>)
<% } %>}
<%= for (method) in service.Methods { %>
func (s *<%= camelize_down(service.Name) %>Server) handle<%= method.Name %>(w http.ResponseWriter, r *http.Request) {
var request <%= method.InputObject.TypeName %>
if err := otohttp.Decode(r, &request); err != nil {
s.server.OnErr(w, r, err)
return
}
response, err := s.<%= camelize_down(service.Name) %>.<%= method.Name %>(r.Context(), request)
if err != nil {
log.Println("TODO: oto service error:", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := otohttp.Encode(w, r, http.StatusOK, response); err != nil {
s.server.OnErr(w, r, err)
return
}
}
<% } %>
<% } %>

<%= for (object) in def.Objects { %>
type <%= object.Name %> struct {
<%= for (field) in object.Fields { %><%= field.Name %> <%= if (field.Type.Multiple == true) { %>[]<% } %><%= field.Type.TypeName %> `json:"<%= camelize_down(field.Name) %><%= if (field.OmitEmpty) { %>,omitempty<% } %>"`
<% } %>
}
<% } %>
24 changes: 18 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -4,14 +4,26 @@ go 1.13

require (
github.com/dustin/go-humanize v1.0.0
github.com/gobuffalo/envy v1.7.1 // indirect
github.com/gobuffalo/helpers v0.4.0 // indirect
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gobuffalo/flect v0.2.1 // indirect
github.com/gobuffalo/helpers v0.6.1 // indirect
github.com/gobuffalo/plush v3.8.3+incompatible
github.com/gobuffalo/tags v2.1.7+incompatible // indirect
github.com/gobuffalo/uuid v2.0.5+incompatible // indirect
github.com/gobuffalo/validate v2.0.4+incompatible // indirect
github.com/gobuffalo/validate/v3 v3.3.0 // indirect
github.com/gofrs/uuid v3.3.0+incompatible // indirect
github.com/golang/protobuf v1.3.1 // indirect
github.com/markbates/inflect v1.0.4
github.com/matryer/is v1.2.0
github.com/pkg/errors v0.8.1
github.com/rogpeppe/go-internal v1.5.0 // indirect
golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914 // indirect
golang.org/x/tools v0.0.0-20191120001058-ad01d5993d97
github.com/microcosm-cc/bluemonday v1.0.3 // indirect
github.com/onsi/ginkgo v1.10.1 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/pkg/errors v0.9.1
github.com/rogpeppe/go-internal v1.6.0 // indirect
github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516 // indirect
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/tools v0.0.0-20200714190737-9048b464a08d
)

69 changes: 69 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,95 +1,164 @@
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/chris-ramon/douceur v0.2.0 h1:IDMEdxlEUUBYBKE4z/mJnFyVXox+MjuEVDJNN27glkU=
github.com/chris-ramon/douceur v0.2.0/go.mod h1:wDW5xjJdeoMm1mRt4sD4c/LbF/mWdEpRXQKjTR8nIBE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gobuffalo/envy v1.6.5 h1:X3is06x7v0nW2xiy2yFbbIjwHz57CD6z6MkvqULTCm8=
github.com/gobuffalo/envy v1.6.5/go.mod h1:N+GkhhZ/93bGZc6ZKhJLP6+m+tCNPKwgSpH9kaifseQ=
github.com/gobuffalo/envy v1.7.0 h1:GlXgaiBkmrYMHco6t4j7SacKO4XUjvh5pwXh0f4uxXU=
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
github.com/gobuffalo/envy v1.7.1 h1:OQl5ys5MBea7OGCdvPbBJWRgnhC/fGona6QKfvFeau8=
github.com/gobuffalo/envy v1.7.1/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w=
github.com/gobuffalo/envy v1.9.0 h1:eZR0DuEgVLfeIb1zIKt3bT4YovIMf9O9LXQeCZLXpqE=
github.com/gobuffalo/envy v1.9.0/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w=
github.com/gobuffalo/flect v0.1.6 h1:D7KWNRFiCknJKA495/e1BO7oxqf8tbieaLv/ehoZ/+g=
github.com/gobuffalo/flect v0.1.6/go.mod h1:W3K3X9ksuZfir8f/LrfVtWmCDQFfayuylOJ7sz/Fj80=
github.com/gobuffalo/flect v0.2.0/go.mod h1:W3K3X9ksuZfir8f/LrfVtWmCDQFfayuylOJ7sz/Fj80=
github.com/gobuffalo/flect v0.2.1 h1:GPoRjEN0QObosV4XwuoWvSd5uSiL0N3e91/xqyY4crQ=
github.com/gobuffalo/flect v0.2.1/go.mod h1:vmkQwuZYhN5Pc4ljYQZzP+1sq+NEkK+lh20jmEmX3jc=
github.com/gobuffalo/github_flavored_markdown v1.1.0 h1:8Zzj4fTRl/OP2R7sGerzSf6g2nEJnaBEJe7UAOiEvbQ=
github.com/gobuffalo/github_flavored_markdown v1.1.0/go.mod h1:TSpTKWcRTI0+v7W3x8dkSKMLJSUpuVitlptCkpeY8ic=
github.com/gobuffalo/helpers v0.4.0 h1:DR/iYihrVCXv1cYeIGSK3EZz2CljO+DqDLQPWZAod9c=
github.com/gobuffalo/helpers v0.4.0/go.mod h1:2q/ZnVxCehM4/y1bNz3+wXsvWvWUY+iTUr7mPC6QqGQ=
github.com/gobuffalo/helpers v0.6.1 h1:LLcL4BsiyDQYtMRUUpyFdBFvFXQ6hNYOpwrcYeilVWM=
github.com/gobuffalo/helpers v0.6.1/go.mod h1:wInbDi0vTJKZBviURTLRMFLE4+nF2uRuuL2fnlYo7w4=
github.com/gobuffalo/plush v3.8.3+incompatible h1:kzvUTnFPhwyfPEsx7U7LI05/IIslZVGnAlMA1heWub8=
github.com/gobuffalo/plush v3.8.3+incompatible/go.mod h1:rQ4zdtUUyZNqULlc6bqd5scsPfLKfT0+TGMChgduDvI=
github.com/gobuffalo/tags v2.1.0+incompatible h1:qQjj3n2RtHxfooqXQ4/A9SsEfZ7/7guv8cp/GdAPa+Y=
github.com/gobuffalo/tags v2.1.0+incompatible/go.mod h1:9XmhOkyaB7UzvuY4UoZO4s67q8/xRMVJEaakauVQYeY=
github.com/gobuffalo/tags v2.1.7+incompatible h1:GUxxh34f9SI4U0Pj3ZqvopO9SlzuqSf+g4ZGSPSszt4=
github.com/gobuffalo/tags v2.1.7+incompatible/go.mod h1:9XmhOkyaB7UzvuY4UoZO4s67q8/xRMVJEaakauVQYeY=
github.com/gobuffalo/tags/v3 v3.1.0 h1:mzdCYooN2VsLRr8KIAdEZ1lh1Py7JSMsiEGCGata2AQ=
github.com/gobuffalo/tags/v3 v3.1.0/go.mod h1:ZQeN6TCTiwAFnS0dNcbDtSgZDwNKSpqajvVtt6mlYpA=
github.com/gobuffalo/uuid v2.0.5+incompatible h1:c5uWRuEnYggYCrT9AJm0U2v1QTG7OVDAvxhj8tIV5Gc=
github.com/gobuffalo/uuid v2.0.5+incompatible/go.mod h1:ErhIzkRhm0FtRuiE/PeORqcw4cVi1RtSpnwYrxuvkfE=
github.com/gobuffalo/validate v2.0.3+incompatible h1:6f4JCEz11Zi6iIlexMv7Jz10RBPvgI795AOaubtCwTE=
github.com/gobuffalo/validate v2.0.3+incompatible/go.mod h1:N+EtDe0J8252BgfzQUChBgfd6L93m9weay53EWFVsMM=
github.com/gobuffalo/validate v2.0.4+incompatible h1:ZTxozrIw8qQ5nfhShmc4izjYPTsPhfdXTdhXOd5OS9o=
github.com/gobuffalo/validate v2.0.4+incompatible/go.mod h1:N+EtDe0J8252BgfzQUChBgfd6L93m9weay53EWFVsMM=
github.com/gobuffalo/validate/v3 v3.0.0 h1:dF7Bg8NMF9Zv8bZvUMXYJXxZdj+eSZ8z/lGM7/jVFUE=
github.com/gobuffalo/validate/v3 v3.0.0/go.mod h1:HFpjq+AIiA2RHoQnQVTFKF/ZpUPXwyw82LgyDPxQ9r0=
github.com/gobuffalo/validate/v3 v3.3.0 h1:j++FFx9gtjTmIQeI9xlaIDZ0nV4x8YQZz4RJAlZNUxg=
github.com/gobuffalo/validate/v3 v3.3.0/go.mod h1:HFpjq+AIiA2RHoQnQVTFKF/ZpUPXwyw82LgyDPxQ9r0=
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84=
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/markbates/inflect v1.0.4 h1:5fh1gzTFhfae06u3hzHYO9xe3l3v3nW5Pwt3naLTP5g=
github.com/markbates/inflect v1.0.4/go.mod h1:1fR9+pO2KHEO9ZRtto13gDwwZaAKstQzferVeWqbgNs=
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s=
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
github.com/microcosm-cc/bluemonday v1.0.3 h1:EjVH7OqbU219kdm8acbveoclh2zZFqPJTJw6VUlTLAQ=
github.com/microcosm-cc/bluemonday v1.0.3/go.mod h1:8iwZnFn2CDDNZ0r6UXhF4xawGvzaqzCRa1n3/lO3W2w=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo=
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.5.0 h1:Usqs0/lDK/NqTkvrmKSwA/3XkZAs7ZAW/eLeQ2MVBTw=
github.com/rogpeppe/go-internal v1.5.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.6.0 h1:IZRgg4sfrDH7nsAD1Y/Nwj+GzIfEwpJSLjCaNC3SbsI=
github.com/rogpeppe/go-internal v1.6.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516 h1:ofR1ZdrNSkiWcMsRrubK9tb2/SlZVWttAfqUjJi6QYc=
github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d h1:yKm7XZV6j9Ev6lojP2XaIshpT4ymkqhMeSghO5Ps00E=
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE=
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e h1:qpG93cPwA5f7s/ZPBJnGOYQNK/vKsaDaseuKT5Asee8=
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914 h1:MlY3mEfbnWGmUi4rtHOtNnnnN4UJRGSyLPx+DXA5Sq4=
golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190515120540-06a5c4944438 h1:khxRGsvPk4n2y8I/mLLjp7e5dMTJmH75wvqS6nMwUtY=
golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191120001058-ad01d5993d97 h1:u8hSFDulpuhoY0GHMbG6Rp23PzphtTnZrQX3dOvEae0=
golang.org/x/tools v0.0.0-20191120001058-ad01d5993d97/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200714190737-9048b464a08d h1:hYhnolbefSSt3WZp66sgmgnEOFv5PD6a5PIcnKJ8jdU=
golang.org/x/tools v0.0.0-20200714190737-9048b464a08d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -92,7 +92,6 @@ flags:`)
fmt.Printf("\tTotal Methods: %d", methodsCount)
fmt.Printf("\tTotal Objects: %d\n", len(def.Objects))
fmt.Printf("\tOutput size: %s\n", humanize.Bytes(uint64(len(out))))

}
return nil
}
2 changes: 1 addition & 1 deletion otohttp/server.go
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ func Encode(w http.ResponseWriter, r *http.Request, status int, v interface{}) e
out = gzw
defer gzw.Close()
}
w.Header().Set("Content-Type", "application/json; chatset=utf-8")
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(status)
if _, err := out.Write(b); err != nil {
return err
Binary file removed pace-logo.png
Binary file not shown.
68 changes: 38 additions & 30 deletions parser.go
Original file line number Diff line number Diff line change
@@ -12,16 +12,17 @@ import (

var errNotFound = errors.New("not found")

type definition struct {
// Definition describes an Oto definition.
type Definition struct {
PackageName string `json:"packageName,omitempty"`
Services []service `json:"services,omitempty"`
Objects []object `json:"objects,omitempty"`
Services []Service `json:"services,omitempty"`
Objects []Object `json:"objects,omitempty"`
Imports map[string]string `json:"imports,omitempty"`
}

// Object looks up an object by name. Returns errNotFound error
// if it cannot find it.
func (d *definition) Object(name string) (*object, error) {
func (d *Definition) Object(name string) (*Object, error) {
for i := range d.Objects {
obj := &d.Objects[i]
if obj.Name == name {
@@ -31,39 +32,46 @@ func (d *definition) Object(name string) (*object, error) {
return nil, errNotFound
}

type service struct {
// Service describes a service, akin to an interface in Go.
type Service struct {
Name string `json:"name,omitempty"`
Methods []method `json:"methods,omitempty"`
Methods []Method `json:"methods,omitempty"`
}

type method struct {
// Method describes a method that a Service can perform.
type Method struct {
Name string `json:"name,omitempty"`
InputObject fieldType `json:"inputObject,omitempty"`
OutputObject fieldType `json:"outputObject,omitempty"`
InputObject FieldType `json:"inputObject,omitempty"`
OutputObject FieldType `json:"outputObject,omitempty"`
}

type object struct {
// Object describes a data structure that is part of this definition.
type Object struct {
TypeID string `json:"typeID"`
Name string `json:"name"`
Imported bool `json:"imported,omitempty"`
Fields []field `json:"fields,omitempty"`
Fields []Field `json:"fields,omitempty"`
}

type field struct {
// Field describes the field inside an Object.
type Field struct {
Name string `json:"name,omitempty"`
Type fieldType `json:"type,omitempty"`
Type FieldType `json:"type,omitempty"`
OmitEmpty bool `json:"omitEmpty,omitempty"`
}

type fieldType struct {
// FieldType holds information about the type of data that this
// Field stores.
type FieldType struct {
TypeID string `json:"typeID"`
TypeName string `json:"typeName"`
Multiple bool `json:"multiple"`
Package string `json:"package"`
IsObject bool `json:"isObject"`
}

func (f fieldType) JSType() (string, error) {
// JSType gets the JavaScript type for this FieldType.
func (f FieldType) JSType() (string, error) {
if f.IsObject {
return "object", nil
}
@@ -90,7 +98,7 @@ type parser struct {
ExcludeInterfaces []string

patterns []string
def definition
def Definition

// outputObjects marks output object names.
outputObjects map[string]struct{}
@@ -107,7 +115,7 @@ func newParser(patterns ...string) *parser {
}
}

func (p *parser) parse() (definition, error) {
func (p *parser) parse() (Definition, error) {
cfg := &packages.Config{
Mode: packages.NeedTypes | packages.NeedDeps | packages.NeedName,
Tests: false,
@@ -144,7 +152,7 @@ func (p *parser) parse() (definition, error) {
}
}
// remove any excluded objects
nonExcludedObjects := make([]object, 0, len(p.def.Objects))
nonExcludedObjects := make([]Object, 0, len(p.def.Objects))
for _, object := range p.def.Objects {
excluded := false
for _, excludedTypeID := range excludedObjectsTypeIDs {
@@ -168,8 +176,8 @@ func (p *parser) parse() (definition, error) {
return p.def, nil
}

func (p *parser) parseService(pkg *packages.Package, obj types.Object, interfaceType *types.Interface) (service, error) {
var s service
func (p *parser) parseService(pkg *packages.Package, obj types.Object, interfaceType *types.Interface) (Service, error) {
var s Service
s.Name = obj.Name()
if p.Verbose {
fmt.Printf("%s ", s.Name)
@@ -186,8 +194,8 @@ func (p *parser) parseService(pkg *packages.Package, obj types.Object, interface
return s, nil
}

func (p *parser) parseMethod(pkg *packages.Package, serviceName string, methodType *types.Func) (method, error) {
var m method
func (p *parser) parseMethod(pkg *packages.Package, serviceName string, methodType *types.Func) (Method, error) {
var m Method
m.Name = methodType.Name()
sig := methodType.Type().(*types.Signature)
inputParams := sig.Params()
@@ -211,9 +219,9 @@ func (p *parser) parseMethod(pkg *packages.Package, serviceName string, methodTy
return m, nil
}

// parseObject parses a struct type and adds it to the definition.
// parseObject parses a struct type and adds it to the Definition.
func (p *parser) parseObject(pkg *packages.Package, o types.Object, v *types.Struct) error {
var obj object
var obj Object
obj.Name = o.Name()
if _, found := p.objects[obj.Name]; found {
// if this has already been parsed, skip it
@@ -240,8 +248,8 @@ func (p *parser) parseObject(pkg *packages.Package, o types.Object, v *types.Str
return nil
}

func (p *parser) parseField(pkg *packages.Package, v *types.Var) (field, error) {
var f field
func (p *parser) parseField(pkg *packages.Package, v *types.Var) (Field, error) {
var f Field
f.Name = v.Name()
if !v.Exported() {
return f, p.wrapErr(errors.New(f.Name+" must be exported"), pkg, v.Pos())
@@ -254,8 +262,8 @@ func (p *parser) parseField(pkg *packages.Package, v *types.Var) (field, error)
return f, nil
}

func (p *parser) parseFieldType(pkg *packages.Package, obj types.Object) (fieldType, error) {
var ftype fieldType
func (p *parser) parseFieldType(pkg *packages.Package, obj types.Object) (FieldType, error) {
var ftype FieldType
pkgPath := pkg.PkgPath
resolver := func(other *types.Package) string {
if other.Name() != pkg.Name {
@@ -291,10 +299,10 @@ func (p *parser) parseFieldType(pkg *packages.Package, obj types.Object) (fieldT
// addOutputFields adds built-in fields to the response objects
// mentioned in p.outputObjects.
func (p *parser) addOutputFields() error {
errorField := field{
errorField := Field{
OmitEmpty: true,
Name: "Error",
Type: fieldType{
Type: FieldType{
TypeName: "string",
},
}
24 changes: 12 additions & 12 deletions parser_test.go
Original file line number Diff line number Diff line change
@@ -123,18 +123,18 @@ func TestParse(t *testing.T) {

func TestFieldJSType(t *testing.T) {
is := is.New(t)
for in, expected := range map[fieldType]string{
fieldType{TypeName: "string"}: "string",
fieldType{TypeName: "int"}: "number",
fieldType{TypeName: "uint"}: "number",
fieldType{TypeName: "uint32"}: "number",
fieldType{TypeName: "int32"}: "number",
fieldType{TypeName: "int64"}: "number",
fieldType{TypeName: "float64"}: "number",
fieldType{TypeName: "bool"}: "boolean",
fieldType{TypeName: "interface{}"}: "any",
fieldType{TypeName: "map[string]interface{}"}: "object",
fieldType{TypeName: "SomeObject", IsObject: true}: "object",
for in, expected := range map[FieldType]string{
{TypeName: "string"}: "string",
{TypeName: "int"}: "number",
{TypeName: "uint"}: "number",
{TypeName: "uint32"}: "number",
{TypeName: "int32"}: "number",
{TypeName: "int64"}: "number",
{TypeName: "float64"}: "number",
{TypeName: "bool"}: "boolean",
{TypeName: "interface{}"}: "any",
{TypeName: "map[string]interface{}"}: "object",
{TypeName: "SomeObject", IsObject: true}: "object",
} {
actual, err := in.JSType()
is.NoErr(err)
16 changes: 14 additions & 2 deletions render.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
package main

import (
"encoding/json"
"html/template"

"github.com/gobuffalo/plush"
"github.com/markbates/inflect"
)

var defaultRuleset = inflect.NewDefaultRuleset()

// render renders the template using the definition.
func render(template string, def definition, params map[string]interface{}) (string, error) {
// render renders the template using the Definition.
func render(template string, def Definition, params map[string]interface{}) (string, error) {
ctx := plush.NewContext()
ctx.Set("camelize_down", camelizeDown)
ctx.Set("def", def)
ctx.Set("params", params)
ctx.Set("json", toJSONHelper)
s, err := plush.Render(string(template), ctx)
if err != nil {
return "", err
}
return s, nil
}

func toJSONHelper(v interface{}) (template.HTML, error) {
b, err := json.Marshal(v)
if err != nil {
return "", err
}
return template.HTML(b), nil
}

// camelizeDown converts a name or other string into a camel case
// version with the first letter lowercase. "ModelID" becomes "modelID".
func camelizeDown(s string) string {
2 changes: 1 addition & 1 deletion render_test.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (

func TestRender(t *testing.T) {
is := is.New(t)
def := definition{
def := Definition{
PackageName: "services",
}
params := map[string]interface{}{