Skip to content

Commit

Permalink
Fix stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
m110 committed Aug 23, 2024
1 parent 5fa815e commit d993f9b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 38 deletions.
18 changes: 2 additions & 16 deletions _examples/basic/1-your-first-app/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,17 @@ services:
server:
image: golang:1.23
restart: unless-stopped
depends_on:
- kafka
volumes:
- .:/app
- $GOPATH/pkg/mod:/go/pkg/mod
working_dir: /app
command: go run main.go

zookeeper:
image: confluentinc/cp-zookeeper:7.3.1
logging:
driver: none
restart: unless-stopped
environment:
ZOOKEEPER_CLIENT_PORT: 2181

kafka:
image: confluentinc/cp-kafka:7.3.1
logging:
driver: none
image: bitnami/kafka:3.5.0
restart: unless-stopped
depends_on:
- zookeeper
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
ALLOW_PLAINTEXT_LISTENER: yes
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
4 changes: 2 additions & 2 deletions _examples/basic/1-your-first-app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"context"
"encoding/json"
"log"
"fmt"
"time"

"github.com/ThreeDotsLabs/watermill"
Expand Down Expand Up @@ -67,7 +67,7 @@ func main() {
return nil, err
}

log.Printf("received event %+v", consumedPayload)
fmt.Printf("received event %+v\n", consumedPayload)

newPayload, err := json.Marshal(processedEvent{
ProcessedID: consumedPayload.ID,
Expand Down
48 changes: 28 additions & 20 deletions dev/validate-examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand All @@ -24,7 +23,7 @@ type Config struct {
}

func (c *Config) LoadFrom(path string) error {
file, err := ioutil.ReadFile(path)
file, err := os.ReadFile(path)
if err != nil {
return err
}
Expand Down Expand Up @@ -109,35 +108,44 @@ func validate(path string) error {
}
}()

success := make(chan error)
success := make(chan bool)
lines := make(chan string)

go func() {
io.MultiReader()

output := bufio.NewReader(io.MultiReader(stdout, stderr))
for {
line, _, err := output.ReadLine()
if err != nil {
if err == io.EOF {
break
}
}
go readLines(stdout, lines)
go readLines(stderr, lines)

fmt.Printf("[%s] > %s\n", color.CyanString(dirName), string(line))
go func() {
for line := range lines {
fmt.Printf("[%s] > %s\n", color.CyanString(dirName), line)

ok, _ := regexp.Match(config.ExpectedOutput, line)
ok, _ := regexp.MatchString(config.ExpectedOutput, line)
if ok {
success <- nil
success <- true
return
}
}
success <- fmt.Errorf("could not find expected output: %s", config.ExpectedOutput)
}()

select {
case err := <-success:
return err
case <-success:
return nil
case <-time.After(time.Duration(config.Timeout) * time.Second):
return fmt.Errorf("validation command timed out")
}
}

func readLines(reader io.Reader, output chan<- string) {
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
if scanner.Err() != nil {
if scanner.Err() == io.EOF {
return
}

continue
}

line := scanner.Text()
output <- line
}
}

0 comments on commit d993f9b

Please # to comment.