Skip to content

Commit 4798b71

Browse files
add polyglot mono repo example. (#59)
* add polyglot mono repo example. * add note on CLI compatibility. --------- Co-authored-by: Ryan Cartwright <[email protected]>
1 parent e261087 commit 4798b71

File tree

13 files changed

+285
-0
lines changed

13 files changed

+285
-0
lines changed

v1/multi-language/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<p align="center"><a href="https://nitric.io" target="_blank"><img src="https://raw.githubusercontent.com/nitrictech/nitric/main/docs/assets/nitric-logo.svg" height="120"></a></p>
2+
3+
## Nitric Multi-Language Example
4+
5+
An example of a polyglot nitric mono repo written in Typescript and Golang, that demonstrates interservice communication via Topics.
6+
7+
![Architecture Diagram](architecture.png)
8+
9+
## Running this project
10+
11+
To run this project you'll need the [Nitric CLI](https://nitric.io/docs/installation) installed, then you can use the CLI commands to run, build or deploy the project.
12+
13+
You'll also want to make sure the project's required dependencies have been installed for the golang and typescript projects.
14+
15+
```bash
16+
# install node dependencies
17+
cd ts
18+
npm install
19+
```
20+
21+
```bash
22+
# install go dependencies
23+
cd go
24+
go mod tidy
25+
```
26+
27+
```bash
28+
# run locally (from project root)
29+
nitric start
30+
```
31+
32+
## Learn more about Nitric
33+
34+
Nitric provides detailed and intuitive [documentation](https://nitric.io/docs) and [guides](https://nitric.io/docs/getting-started) to help you get started quickly.
35+
36+
If you'd rather chat with the maintainers or community, come and join our [Discord](https://nitric.io/chat) server, [GitHub Discussions](https://github.com/nitrictech/nitric/discussions) or find us on [Twitter](https://twitter.com/nitric_io).
37+
38+
39+
40+

v1/multi-language/architecture.png

80.2 KB
Loading

v1/multi-language/go/.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# 'nitric run' log directory
15+
.nitric/
16+
17+
git.store

v1/multi-language/go/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<p align="center"><a href="https://nitric.io" target="_blank"><img src="https://raw.githubusercontent.com/nitrictech/nitric/main/docs/assets/nitric-logo.svg" height="120"></a></p>
2+
3+
## About Nitric
4+
5+
> ⚠️ Note: This repo contains features that require a minimum nitric CLI version of [1.52.0](https://github.com/nitrictech/cli/releases/tag/v1.52.0)
6+
7+
This is a [Nitric](https://nitric.io) Golang project, but Nitric is a framework for rapid development of cloud-native and serverless applications in many languages.
8+
9+
Using Nitric you define your apps in terms of the resources they need, then write the code for serverless function based APIs, event subscribers and scheduled jobs.
10+
11+
Apps built with Nitric can be deployed to AWS, Azure or Google Cloud all from the same code base so you can focus on your products, not your cloud provider.
12+
13+
Nitric makes it easy to:
14+
15+
- Create smart [serverless functions and APIs](https://nitric.io/docs/apis)
16+
- Build reliable distributed apps that use [events](https://nitric.io/docs/messaging/topics) and/or [queues](https://nitric.io/docs/messaging/queues)
17+
- Securely store, retrieve and rotate [secrets](https://nitric.io/docs/secrets)
18+
- Read and write files from [buckets](https://nitric.io/docs/storage)
19+
20+
## Learning Nitric
21+
22+
Nitric provides detailed and intuitive [documentation](https://nitric.io/docs) and [guides](https://nitric.io/docs/getting-started) to help you get started quickly.
23+
24+
If you'd rather chat with the maintainers or community, come and join our [Discord](https://nitric.io/chat) server, [GitHub Discussions](https://github.com/nitrictech/nitric/discussions) or find us on [Twitter](https://twitter.com/nitric_io).
25+
26+
## Running this project
27+
28+
To run this project you'll need the [Nitric CLI](https://nitric.io/docs/installation) installed, then you can use the CLI commands to run, build or deploy the project.
29+
30+
```bash
31+
# install dependencies
32+
go mod tidy
33+
34+
# run locally
35+
nitric start
36+
```

v1/multi-language/go/go.mod

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module github.com/nitrictech/templates/go-starter
2+
3+
go 1.21
4+
5+
toolchain go1.21.4
6+
7+
require github.com/nitrictech/go-sdk v1.0.7
8+
9+
require (
10+
github.com/missionMeteora/toolkit v0.0.0-20170713173850-88364e3ef8cc // indirect
11+
github.com/nitrictech/nitric/core v0.0.0-20240614052744-71e6e05bc47e // indirect
12+
github.com/nitrictech/protoutils v0.0.0-20220321044654-02667a814cdf // indirect
13+
golang.org/x/net v0.26.0 // indirect
14+
golang.org/x/sys v0.21.0 // indirect
15+
golang.org/x/text v0.16.0 // indirect
16+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240624140628-dc46fd24d27d // indirect
17+
google.golang.org/grpc v1.64.0 // indirect
18+
google.golang.org/protobuf v1.34.2 // indirect
19+
)

v1/multi-language/go/go.sum

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
4+
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
5+
github.com/golang/mock v1.7.0-rc.1 h1:YojYx61/OLFsiv6Rw1Z96LpldJIy31o+UHmwAUMJ6/U=
6+
github.com/golang/mock v1.7.0-rc.1/go.mod h1:s42URUywIqd+OcERslBJvOjepvNymP31m3q8d/GkuRs=
7+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
8+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
9+
github.com/missionMeteora/toolkit v0.0.0-20170713173850-88364e3ef8cc h1:/oFlKiuu6L1sIvZ7A363qMhNM+DUQL5WsVe1xIRQnFU=
10+
github.com/missionMeteora/toolkit v0.0.0-20170713173850-88364e3ef8cc/go.mod h1:AtX+JBtXbQ+taj82QFzCSgN5EzM4Bi0YRyS+TVbjENs=
11+
github.com/nitrictech/go-sdk v1.0.7 h1:SQsy522EhKCIc6NIHUMqDA4fDzD3gW0MHqABg1F840c=
12+
github.com/nitrictech/go-sdk v1.0.7/go.mod h1:QmLPatYHvbQ+8ajVDxHplgQIyWWP9SzMXDL+PI/gL2E=
13+
github.com/nitrictech/nitric/core v0.0.0-20240614052744-71e6e05bc47e h1:WV7BHlv3V25mKQuyPJ97W4aWCJL8h7MGSa4imTFqZcA=
14+
github.com/nitrictech/nitric/core v0.0.0-20240614052744-71e6e05bc47e/go.mod h1:atiPRiYDBs4Wx3flZ45KnQenUD6eAdpL0lOLZT91yyM=
15+
github.com/nitrictech/protoutils v0.0.0-20220321044654-02667a814cdf h1:8MB8W8ylM8sCM2COGfiO39/tB6BTdiawLszaUGCNL5w=
16+
github.com/nitrictech/protoutils v0.0.0-20220321044654-02667a814cdf/go.mod h1:b2lzk2a4o1bvSrSCE6yvTldHuXCJymuDVhdMJGOSslw=
17+
github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
18+
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
19+
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
20+
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
21+
github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA=
22+
github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
23+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
24+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
25+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
26+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
27+
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
28+
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
29+
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
30+
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
31+
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
32+
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
33+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240624140628-dc46fd24d27d h1:k3zyW3BYYR30e8v3x0bTDdE9vpYFjZHK+HcyqkrppWk=
34+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240624140628-dc46fd24d27d/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
35+
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
36+
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
37+
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
38+
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
39+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
40+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
41+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
42+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
FROM golang:alpine as build
3+
4+
ARG HANDLER
5+
6+
WORKDIR /app/
7+
8+
COPY go.mod *.sum ./
9+
10+
RUN go mod download
11+
12+
COPY . .
13+
14+
# Build the Go App from the provided HANDLER (this will be based on matches in your nitric.yaml fle)
15+
RUN go build -o /bin/main ./${HANDLER}/...
16+
17+
FROM alpine
18+
19+
COPY --from=build /bin/main /bin/main
20+
21+
RUN chmod +x-rw /bin/main
22+
RUN apk update && \
23+
apk add --no-cache tzdata ca-certificates && \
24+
update-ca-certificates
25+
26+
ENTRYPOINT ["/bin/main"]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/nitrictech/go-sdk/handler"
8+
"github.com/nitrictech/go-sdk/nitric"
9+
)
10+
11+
func main() {
12+
helloTypescriptTopic, err := nitric.NewTopic("hello-typescript").Allow(nitric.TopicPublish)
13+
if err != nil {
14+
fmt.Println(err)
15+
return
16+
}
17+
18+
helloGolangTopic := nitric.NewTopic("hello-golang")
19+
20+
api, err := nitric.NewApi("main")
21+
if err != nil {
22+
fmt.Println(err)
23+
return
24+
}
25+
26+
helloGolangTopic.Subscribe(func(ctx *handler.MessageContext, next handler.MessageHandler) (*handler.MessageContext, error) {
27+
fmt.Println("Received message from Typescript")
28+
return next(ctx)
29+
})
30+
31+
api.Get("/hello-typescript", func(ctx *handler.HttpContext, next handler.HttpHandler) (*handler.HttpContext, error) {
32+
ctx.Response.Body = []byte("Saying hello to typescript from Golang")
33+
34+
helloTypescriptTopic.Publish(context.TODO(), map[string]interface{}{
35+
"message": "Hello from Golang",
36+
})
37+
38+
return next(ctx)
39+
})
40+
41+
if err := nitric.Run(); err != nil {
42+
fmt.Println(err)
43+
}
44+
45+
fmt.Println("Service has started")
46+
}

v1/multi-language/nitric.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: multi-language
2+
services:
3+
- basedir: ./ts
4+
match: services/*.ts
5+
start: npm run dev:services $SERVICE_PATH
6+
- basedir: ./go
7+
match: services/*
8+
runtime: go
9+
start: go run ./$SERVICE_PATH/...
10+
runtimes:
11+
go:
12+
dockerfile: ./go/golang.dockerfile
13+
args: {}

v1/multi-language/ts/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
.nitric/
3+
.npmrc
4+
git.store

0 commit comments

Comments
 (0)