Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves dev environment and switches to grpc-dispatcher-go library path #5

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ Try it out and let us know what you think! If you notice any bugs or have any fe

First, add the library to your Go project:
```console
go get github.com/kubetail-org/grpc-dispatcher
go get github.com/kubetail-org/grpc-dispatcher-go
```

Next write your dispatch code:
```go
import (
"context"

"github.com/kubetail-org/grpc-dispatcher"
"github.com/kubetail-org/grpc-dispatcher-go"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -99,7 +99,7 @@ func main() {

## Docs

See [Go docs](https://pkg.go.dev/github.com/kubetail-org/grpc-dispatcher) for library documentation.
See [Go docs](https://pkg.go.dev/github.com/kubetail-org/grpc-dispatcher-go) for library documentation.

## Example

Expand Down
8 changes: 4 additions & 4 deletions example/cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"syscall"
"time"

"github.com/kubetail-org/grpc-dispatcher/example/internal/app"
"github.com/kubetail-org/grpc-dispatcher-go/example/internal/app"
)

func main() {
Expand All @@ -35,7 +35,7 @@ func main() {
// create app
app, err := app.NewApp()
if err != nil {
log.Fatal(err)
log.Fatalf("Error: %v", err)
}

// create server
Expand All @@ -51,7 +51,7 @@ func main() {
go func() {
log.Println("Starting server on :4000")
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatal(err)
log.Fatalf("Error: %v", err)
}
}()

Expand All @@ -68,7 +68,7 @@ func main() {
done := make(chan struct{})
go func() {
if err := server.Shutdown(ctx); err != nil {
log.Println(err)
log.Printf("Error: %v", err)
}
close(done)
}()
Expand Down
2 changes: 1 addition & 1 deletion example/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

"google.golang.org/grpc"

"github.com/kubetail-org/grpc-dispatcher/example/internal/examplepb"
"github.com/kubetail-org/grpc-dispatcher-go/example/internal/examplepb"
)

type ExampleService struct {
Expand Down
6 changes: 3 additions & 3 deletions example/go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module github.com/kubetail-org/grpc-dispatcher/example
module github.com/kubetail-org/grpc-dispatcher-go/example

go 1.22.5

require (
github.com/gin-gonic/gin v1.10.0
github.com/kubetail-org/grpc-dispatcher v0.0.0
github.com/kubetail-org/grpc-dispatcher-go v0.0.0
google.golang.org/grpc v1.66.0
google.golang.org/protobuf v1.34.2
)

replace github.com/kubetail-org/grpc-dispatcher => ../
replace github.com/kubetail-org/grpc-dispatcher-go => ../

require (
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
Expand Down
8 changes: 4 additions & 4 deletions example/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"time"

"github.com/gin-gonic/gin"
grpcdispatcher "github.com/kubetail-org/grpc-dispatcher"
"github.com/kubetail-org/grpc-dispatcher/example/internal/examplepb"
grpcdispatcher "github.com/kubetail-org/grpc-dispatcher-go"
"github.com/kubetail-org/grpc-dispatcher-go/example/internal/examplepb"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
Expand Down Expand Up @@ -99,7 +99,7 @@ func NewApp() (*App, error) {
// execute grpc request
resp, err := client.Echo(ctx, &examplepb.EchoRequest{Message: "hello", DurationMs: 0})
if err != nil {
fmt.Println(err)
log.Printf("Error: %v", err)
return
}

Expand Down Expand Up @@ -135,7 +135,7 @@ func NewApp() (*App, error) {
// execute grpc request
resp, err := client.Echo(ctx, &examplepb.EchoRequest{Message: "hello", DurationMs: 0})
if err != nil {
fmt.Println(err)
log.Printf("Error: %v", err)
return
}

Expand Down
67 changes: 48 additions & 19 deletions example/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example App</title>
<style>
#output {
margin-top: 20px;
h2 {
padding: 0;
margin: 30px 0 5px;
}

.output {
margin-top: 10px;
height: 200px;
width: 600px;
border: 1px solid black;
Expand All @@ -15,17 +20,9 @@
}
</style>
<script>
let eventSource;

const stopEvents = () => {
if (eventSource && eventSource.readyState !== EventSource.CLOSED) {
eventSource.close();
}
}

const runExample = (endpoint) => {
eventSource = new EventSource(endpoint);
const output = document.getElementById('output');
const runFanoutExample = () => {
const eventSource = new EventSource('/fanout-events');
const output = document.getElementById('fanout-example-output');

output.innerHTML = '';

Expand All @@ -40,16 +37,48 @@
};

eventSource.onerror = function(error) {
console.error('EventSource failed:', error);
console.error('Fanout Example EventSource failed:', error);
};
};

let subscriptionES;

const startFanoutSubscribeExample = () => {
subscriptionES = new EventSource('/fanout-subscribe-events');
const output = document.getElementById('fanout-subscribe-output');

output.innerHTML = '';

subscriptionES.onmessage = function(event) {
const el = document.createElement('div');
el.textContent = event.data;
output.appendChild(el);

if (event.data === "finished") {
subscriptionES.close();
}
};

subscriptionES.onerror = function(error) {
console.error('Fanout Subscribe Example EventSource failed:', error);
};
}

const stopFanoutSubscribeExample = () => {
if (subscriptionES && subscriptionES.readyState !== EventSource.CLOSED) {
subscriptionES.close();
}
}
</script>
</script>
</head>
<body>
<h1>Example App</h1>
<button type="button" onclick="runExample('/fanout-events')">Start Fanout Example</button>
<button type="button" onclick="runExample('/fanout-subscribe-events')">Start Fanout Subscribe Example</button>
<button type="button" onclick="stopEvents()">Stop</button>
<div id="output"></div>
<h2>Fanout Example:</h2>
<button type="button" onclick="runFanoutExample()">Run</button>
<div id="fanout-example-output" class="output"></div>
<h2>Fanout Subscribe Example:</h2>
<button type="button" onclick="startFanoutSubscribeExample()">Start</button>
<button type="button" onclick="stopFanoutSubscribeExample()">Stop</button>
<div id="fanout-subscribe-output" class="output"></div>
</body>
</html>
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/kubetail-org/grpc-dispatcher
module github.com/kubetail-org/grpc-dispatcher-go

go 1.22.5

Expand Down
4 changes: 2 additions & 2 deletions hack/tilt/chaoskube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ spec:
- name: chaoskube
image: ghcr.io/linki/chaoskube:v0.31.0
args:
- --interval=2m
- --interval=30s
- --labels=app.kubernetes.io/name=example,app.kubernetes.io/component=server
- --namespaces=default
- --minimum-age=4m
- --minimum-age=0s
- --no-dry-run
securityContext:
runAsNonRoot: true
Expand Down
5 changes: 5 additions & 0 deletions hack/tilt/example-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ spec:
- name: http
protocol: TCP
containerPort: 4000
#env:
#- name: GRPC_GO_LOG_SEVERITY_LEVEL
# value: "INFO"
#- name: GRPC_GO_LOG_VERBOSITY_LEVEL
# value: "2"
resources: {}