Skip to content

Commit

Permalink
Add gRPC API and shell command (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
adambabik authored Jan 9, 2023
1 parent b208a2b commit b362060
Show file tree
Hide file tree
Showing 38 changed files with 3,575 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ go.work
gha-creds-*.json

# Binary build with make
rdme
runme
/rdme
/runme

# Logs
*.log
Expand Down
38 changes: 19 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
exclude: ^internal/standupper/.snapshots/
- repo: https://github.com/TekWizely/pre-commit-golang
rev: v1.0.0-beta.5
hooks:
- id: go-fumpt
- id: go-build-mod
- id: go-mod-tidy
- id: go-test-mod
args: ["-timeout=5s"]
- id: go-revive-repo-mod
- id: go-staticcheck-mod
- id: go-sec-repo-mod
args: ["-exclude=G204,G304", "-exclude-generated"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/TekWizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: go-fumpt
exclude: ^internal/gen/.*$
- id: go-build-mod
- id: go-mod-tidy
- id: go-test-mod
args: ["-timeout=5s"]
- id: go-revive-repo-mod
- id: go-staticcheck-mod
- id: go-sec-repo-mod
args: ["-exclude=G204,G304,G404", "-exclude-generated"]
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"go.testTimeout": "10s",
"protoc": {
"options": [
// It's not a typical location, you likely need to symlink it
// from a location where you installed protoc.
"--proto_path=/usr/local/include/protoc"
]
},
// Uncomment if you want to work on files in ./web.
// "go.buildTags": "js,wasm"
}
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,18 @@ install/dev:
go install honnef.co/go/tools/cmd/staticcheck@v0.3.3
go install mvdan.cc/gofumpt@v0.3.1

.PHONY: install/goreleaser
install/goreleaser:
go install github.com/goreleaser/goreleaser@v1.10.2

.PHONY: generate
generate:
buf generate

.PHONY: gen/clean
generate/clean:
rm -rf internal/gen/proto

.PHONY: release
release: install/goreleaser
@goreleaser check
Expand Down
12 changes: 12 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: v1
plugins:
- plugin: go
out: internal/gen/proto/go
opt: paths=source_relative
- plugin: go-grpc
out: internal/gen/proto/go
opt: paths=source_relative
- name: es
path: ./node_modules/.bin/protoc-gen-es
opt: target=ts
out: internal/gen/proto/ts
3 changes: 3 additions & 0 deletions buf.work.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v1
directories:
- internal/api
2 changes: 2 additions & 0 deletions examples/daemon/Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
brew "bufbuild/buf/buf"
brew "grpcurl"
42 changes: 42 additions & 0 deletions examples/daemon/grpc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Daemon/kernel functionality

Install system dependencies

```sh
$ brew bundle --no-lock
```

Let's build the project first and include working directory into PATH

```sh
$ cd ../..
$ make
$ export CWD=$(cd ../.. && pwd | tr -d '\n')
$ export PATH="$CWD:$PATH"
```

## Exercise GRPC interface

Bring up the server. It's GRPC based.

```sh { background=true }
$ runme daemon --address ./runme.sock
```

Issue a simple call to the deserialize API, first set markdown input data

```sh
export mddata="# Ohai this is my cool headline"
```

Then issue RPC call and display the result

```sh { closeTerminalOnSuccess=false }
$ data="$(echo $mddata | openssl base64 | tr -d '\n')"
$ cd ../.. && grpcurl \
-protoset <(buf build -o -) \
-d "{\"source\": \"$data\"}" \
-plaintext \
-unix examples/daemon/runme.sock \
runme.v1.RunmeService/Deserialize
```
40 changes: 25 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,62 @@ go 1.19

require (
github.com/Masterminds/semver/v3 v3.1.1
github.com/cli/cli/v2 v2.14.2
github.com/cli/cli/v2 v2.21.1
github.com/creack/pty v1.1.18
github.com/google/go-github/v45 v45.2.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/hashicorp/go-multierror v1.1.1
github.com/rogpeppe/go-internal v1.9.0
github.com/rs/xid v1.4.0
github.com/rwtodd/Go.Sed v0.0.0-20210816025313-55464686f9ef
github.com/yuin/goldmark v1.4.12
golang.org/x/exp v0.0.0-20221208044002-44028be4359e
golang.org/x/oauth2 v0.0.0-20220630143837-2104d58473e0
golang.org/x/term v0.2.0
google.golang.org/protobuf v1.28.0
)

require (
github.com/briandowns/spinner v1.18.1 // indirect
github.com/cli/safeexec v1.0.0 // indirect
github.com/cli/go-gh v1.0.0 // indirect
github.com/cli/safeexec v1.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 // indirect
github.com/muesli/termenv v0.12.0 // indirect
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rivo/uniseg v0.4.2 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/net v0.0.0-20220923203811-8be639271d50 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/go-playground/validator/v10 v10.11.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.5.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.7.5
github.com/stretchr/testify v1.8.0
go.uber.org/zap v1.24.0
golang.org/x/sync v0.1.0
google.golang.org/grpc v1.51.0
)
Loading

0 comments on commit b362060

Please sign in to comment.