-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
158 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
. | ||
!go.mod | ||
!go.sum | ||
!main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
### build stage ### | ||
FROM golang:1.22-alpine AS builder | ||
|
||
WORKDIR /helloworld | ||
|
||
COPY . . | ||
|
||
RUN go build -o server /helloworld/main.go | ||
|
||
### run stage ### | ||
FROM alpine:latest | ||
COPY --from=builder /helloworld/server ./server | ||
CMD ["./server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Run the example | ||
|
||
Firs, go to the root of the baker project and run the following command to start the baker | ||
|
||
``` | ||
docker-compose up | ||
``` | ||
|
||
Second, navigate to `examples/static` folder and run the following command | ||
|
||
``` | ||
docker-compose up --build --scale example-service=3 | ||
``` | ||
|
||
There should be some logs prints out in Baker terminal indicating that services are registering | ||
|
||
Finally, run the following curl command which demonstrate the dynamic reverse proxy of Baker | ||
|
||
``` | ||
curl -H "Host: example.com" http://localhost:80/api/v1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
services: | ||
example-static-service: | ||
build: . | ||
|
||
labels: | ||
- "baker.enable=true" | ||
- "baker.network=baker" | ||
- "baker.service.port=8000" | ||
- "baker.service.static.domain=example.com" | ||
- "baker.service.static.path=/*" | ||
|
||
networks: | ||
- baker | ||
|
||
networks: | ||
baker: | ||
name: baker | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module helloworld | ||
|
||
go 1.22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"math/rand" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
|
||
func init() { | ||
rand.Seed(time.Now().UnixNano()) | ||
} | ||
|
||
func generateRandomString(length int) string { | ||
b := make([]byte, length) | ||
for i := range b { | ||
b[i] = charset[rand.Intn(len(charset))] | ||
} | ||
return string(b) | ||
} | ||
func main() { | ||
id := generateRandomString(8) | ||
|
||
http.HandleFunc("/api/v1", func(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintf(w, "Received from %s: %s\n", id, r.URL.Path) | ||
}) | ||
|
||
fmt.Printf("Starting server at port 8000\n") | ||
|
||
if err := http.ListenAndServe(":8000", nil); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
Oops, something went wrong.