Skip to content

Commit 2940e62

Browse files
committed
refactor(*): refactor configuration
1 parent b7ed715 commit 2940e62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+533
-517
lines changed

.github/workflows/release-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
run: |
1818
docker compose up -d
1919
sleep 10
20-
STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:8080)
20+
STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:9601)
2121
if [ "$STATUS_CODE" -ne 200 ]; then
2222
echo "API failed with status code $STATUS_CODE"
2323
exit 1

.github/workflows/test.yml

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Test
22

3+
permissions:
4+
contents: read
5+
36
on:
47
pull_request:
58
paths-ignore:
@@ -13,59 +16,78 @@ on:
1316
- '**/*.gif'
1417

1518
jobs:
16-
unit-tests:
19+
tests-unit:
1720
runs-on: ubuntu-latest
18-
1921
steps:
2022
- uses: actions/checkout@v4
21-
2223
- uses: actions/setup-go@v5
2324
with:
2425
go-version-file: go.mod
25-
26-
- name: run tests
27-
run: make test-coverage
28-
29-
- name: upload coverage reselt to Codecov
26+
- name: runs tests
27+
run: |
28+
make test-unit FLAGS=-coverprofile=coverage.txt
29+
cat coverage.txt
30+
- name: uploads coverage reselt
3031
uses: codecov/codecov-action@v4
3132
with:
3233
token: ${{ secrets.CODECOV_TOKEN }}
3334
fail_ci_if_error: true
3435
flags: unit
3536

36-
services:
37-
httpbin:
38-
image: kennethreitz/httpbin
39-
ports:
40-
- 9999:80
41-
42-
integration-tests:
37+
tests-integration-main:
4338
runs-on: ubuntu-latest
44-
4539
steps:
4640
- uses: actions/checkout@v4
47-
4841
- uses: actions/setup-go@v5
4942
with:
5043
go-version-file: go.mod
51-
52-
- name: start dependencies
44+
- name: starts dependencies
5345
run: |
5446
mkdir -p test/output/otel
5547
sudo chmod 777 -R test/output/otel
5648
make test-deps
5749
sleep 3
5850
docker compose -f test/docker-compose.yml logs
59-
60-
- name: install
51+
- name: installs webhookx
6152
run: make install
62-
53+
- name: installs ginkgo
54+
run: go install github.com/onsi/ginkgo/v2/ginkgo
6355
- name: run tests
64-
run: make test-integration-coverage
65-
66-
- name: upload coverage reselt to Codecov
56+
run: |
57+
make test-main FLAGS="-coverpkg=github.com/webhookx-io/webhookx/... --cover --coverprofile=coverage.txt"
58+
cat coverage.txt
59+
- name: upload coverage reselt
6760
uses: codecov/codecov-action@v4
6861
with:
6962
token: ${{ secrets.CODECOV_TOKEN }}
7063
fail_ci_if_error: true
7164
flags: integration
65+
66+
tests-integration-o11:
67+
runs-on: ubuntu-latest
68+
steps:
69+
- uses: actions/checkout@v4
70+
- uses: actions/setup-go@v5
71+
with:
72+
go-version-file: go.mod
73+
- name: starts dependencies
74+
run: |
75+
mkdir -p test/output/otel
76+
sudo chmod 777 -R test/output/otel
77+
make test-deps
78+
sleep 3
79+
docker compose -f test/docker-compose.yml logs
80+
- name: installs webhookx
81+
run: make install
82+
- name: install ginkgo
83+
run: go install github.com/onsi/ginkgo/v2/ginkgo
84+
- name: run tests
85+
run: |
86+
make test-o11 FLAGS="-coverpkg=github.com/webhookx-io/webhookx/... --cover --coverprofile=coverage.txt"
87+
cat coverage.txt
88+
- name: upload coverage reselt
89+
uses: codecov/codecov-action@v4
90+
with:
91+
token: ${{ secrets.CODECOV_TOKEN }}
92+
fail_ci_if_error: true
93+
flags: integration-o11

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ FROM alpine:3.15
1313

1414
COPY --from=build-env /go/src/webhookx-io/webhookx/webhookx /usr/local/bin
1515

16-
EXPOSE 8080
16+
EXPOSE 9600
17+
EXPOSE 9601
18+
EXPOSE 9602
19+
1720

1821
CMD ["webhookx", "start"]

Makefile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@ test-deps:
2424
mkdir -p test/output/otel
2525
docker compose -f test/docker-compose.yml up -d
2626

27-
test: clean
28-
go test $$(go list ./... | grep -v /test/ | grep -v /examples/ )
27+
test-unit: clean
28+
go test $$(go list ./... | grep -v /test/ | grep -v /examples/ ) $(FLAGS)
2929

30-
test-coverage: clean
31-
go test $$(go list ./... | grep -v /test/ | grep -v /examples/ ) -coverprofile=coverage.txt
30+
test-o11: clean
31+
ginkgo -r $(FLAGS) ./test/metrics ./test/tracing
3232

33-
test-integration: clean
34-
go test -p 1 -v ./test/...
35-
36-
test-integration-coverage: clean
37-
go test -p 1 -v ./test/... --coverpkg ./... -coverprofile=coverage.txt
33+
test-main: clean
34+
ginkgo -r --skip-package=metrics,tracing $(FLAGS) ./test
3835

3936
goreleaser:
4037
goreleaser release --snapshot --clean

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ WebhookX is an open-source webhooks gateway for message receiving, processing, a
2323

2424
## Features
2525

26-
- **Admin API:** Expose a RESTful API on port `:8080` for managing WebhookX entities.
26+
- **Admin API:** Expose a RESTful API on port `:9601` for managing WebhookX entities.
2727
- **Retries:** Automatically retry unsuccessful deliveries with configurable delays.
2828
- **Fan out:** Route events to multiple endpoints based on the event type.
2929
- **Rate Limiting:** Protect the gateway ingestion and delivery endpoints from overload.
@@ -67,7 +67,7 @@ curl -O https://raw.githubusercontent.com/webhookx-io/webhookx/main/docker-compo
6767
Once it's running, you will see HTTP 200 response
6868

6969
```
70-
curl http://localhost:8080
70+
curl http://localhost:9601
7171
```
7272

7373
```http
@@ -102,10 +102,10 @@ Once it is set up, you're ready to send events to WebhookX.
102102

103103
### 3. Send events to WebhookX
104104

105-
> The Ingestion is exposed on port `:8081`
105+
> The Ingestion is exposed on port `:9600`
106106
107107
```
108-
curl -X POST http://localhost:8081 \
108+
curl -X POST http://localhost:9600 \
109109
--header 'Content-Type: application/json' \
110110
--data '{
111111
"event_type": "charge.succeeded",
@@ -125,12 +125,12 @@ We sent a `charge.succeeded` event including `data` to WebhookX, and it will be
125125
>
126126
> Attempt object represents the delivery result of an event, and contains inspection information.
127127
128-
> The Admin is exposed on port `:8080`
128+
> The Admin is exposed on port `:9601`
129129
130130
Let's make a request to retrieve the attempt list
131131

132132
```
133-
curl http://localhost:8080/workspaces/default/attempts
133+
curl http://localhost:9601/workspaces/default/attempts
134134
```
135135

136136
<details>
@@ -174,7 +174,7 @@ curl http://localhost:8080/workspaces/default/attempts
174174
To inspect the data such as `request.headers`, `request.body`, `response.headers`, and `response.body`, try
175175

176176
```
177-
http://localhost:8080/workspaces/default/attempts/338lax8Xe774EhimzBukip37Zne
177+
http://localhost:9601/workspaces/default/attempts/338lax8Xe774EhimzBukip37Zne
178178
```
179179

180180
<details>
@@ -243,8 +243,8 @@ Usage:
243243
Available Commands:
244244
admin Admin commands
245245
completion Generate the autocompletion script for the specified shell
246+
db Database commands
246247
help Help about any command
247-
migrations
248248
start Start server
249249
version Print the version
250250

app/app.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,11 @@ func (app *Application) initialize() error {
218218
Dispatcher: dispatcher,
219219
EventBus: app.bus,
220220
}
221-
if cfg.AccessLog.Enabled() {
221+
if cfg.AccessLog.Enabled {
222222
accessLogger, err := accesslog.NewAccessLogger("admin", accesslog.Options{
223-
File: cfg.AccessLog.File,
224-
Format: string(cfg.AccessLog.Format),
223+
File: cfg.AccessLog.File,
224+
Format: string(cfg.AccessLog.Format),
225+
Colored: cfg.AccessLog.Colored,
225226
})
226227
if err != nil {
227228
return err
@@ -247,10 +248,11 @@ func (app *Application) initialize() error {
247248
Srv: app.srv,
248249
RateLimiter: ratelimiter.NewRedisLimiter(client),
249250
}
250-
if cfg.AccessLog.Enabled() {
251+
if cfg.AccessLog.Enabled {
251252
accessLogger, err := accesslog.NewAccessLogger("proxy", accesslog.Options{
252-
File: cfg.AccessLog.File,
253-
Format: string(cfg.AccessLog.Format),
253+
File: cfg.AccessLog.File,
254+
Format: string(cfg.AccessLog.Format),
255+
Colored: cfg.AccessLog.Colored,
254256
})
255257
if err != nil {
256258
return err
@@ -268,10 +270,11 @@ func (app *Application) initialize() error {
268270

269271
if cfg.Status.IsEnabled() {
270272
var accessLogger accesslog.AccessLogger
271-
if cfg.AccessLog.Enabled() {
273+
if cfg.AccessLog.Enabled {
272274
accessLogger, err = accesslog.NewAccessLogger("status", accesslog.Options{
273-
File: cfg.AccessLog.File,
274-
Format: string(cfg.AccessLog.Format),
275+
File: cfg.AccessLog.File,
276+
Format: string(cfg.AccessLog.Format),
277+
Colored: cfg.AccessLog.Colored,
275278
})
276279
if err != nil {
277280
return err

cmd/admin_dump.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func newAdminDumpCmd() *cobra.Command {
7070
}
7171

7272
dump.Flags().StringVarP(&workspace, "workspace", "", "default", "Set a specific workspace.")
73-
dump.Flags().StringVarP(&addr, "addr", "", defaultAdminURL, "HTTP address of WebhookX's Admin API.")
73+
dump.Flags().StringVarP(&addr, "addr", "", AdminURL, "HTTP address of WebhookX's Admin API.")
7474
dump.Flags().IntVarP(&timeout, "timeout", "", 10, "Set the request timeout for the client to connect with WebhookX (in seconds).")
7575

7676
return dump

cmd/admin_sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func newAdminSyncCmd() *cobra.Command {
8080
}
8181

8282
sync.Flags().StringVarP(&workspace, "workspace", "", "default", "Set a specific workspace.")
83-
sync.Flags().StringVarP(&addr, "addr", "", defaultAdminURL, "HTTP address of WebhookX's Admin API.")
83+
sync.Flags().StringVarP(&addr, "addr", "", AdminURL, "HTTP address of WebhookX's Admin API.")
8484
sync.Flags().IntVarP(&timeout, "timeout", "", 10, "Set the request timeout for the client to connect with WebhookX (in seconds).")
8585

8686
return sync

cmd/db.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ func newDatabaseResetCmd() *cobra.Command {
4848
func newDatabaseCmd() *cobra.Command {
4949

5050
database := &cobra.Command{
51-
Use: "db",
52-
Aliases: []string{"migrations"},
53-
Short: "Database commands",
54-
Long: ``,
51+
Use: "db",
52+
Short: "Database commands",
53+
Long: ``,
5554
}
5655

5756
database.PersistentFlags().StringVarP(&configurationFile, "config", "", "", "The configuration filename")

cmd/root.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"os"
77
)
88

9-
const (
10-
defaultAdminURL = "http://localhost:8080"
9+
var (
10+
AdminURL = "http://localhost:9601"
1111
)
1212

1313
var (
@@ -18,11 +18,15 @@ var (
1818

1919
func initConfig() {
2020
var err error
21+
22+
var options config.Options
2123
if configurationFile != "" {
22-
cfg, err = config.InitWithFile(configurationFile)
23-
} else {
24-
cfg, err = config.Init()
24+
buf, err := os.ReadFile(configurationFile)
25+
cobra.CheckErr(err)
26+
options.YAML = buf
2527
}
28+
29+
cfg, err = config.New(&options)
2630
cobra.CheckErr(err)
2731

2832
err = cfg.Validate()

0 commit comments

Comments
 (0)