Skip to content

Commit c88831d

Browse files
authored
Merge pull request #737 from marle3003/develop
Develop
2 parents 1a8fc54 + 9e9bdfc commit c88831d

File tree

121 files changed

+5923
-1109
lines changed

Some content is hidden

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

121 files changed

+5923
-1109
lines changed

api/handler_events_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ func TestHandler_Events(t *testing.T) {
123123
},
124124
"url": "http://localhost/foo",
125125
},
126-
"response": map[string]interface{}{"body": "", "size": float64(0), "statusCode": float64(0)}},
126+
"response": map[string]interface{}{"body": "", "size": float64(0), "statusCode": float64(0)},
127+
"clientIP": "192.0.2.1",
128+
},
127129
m[0]["data"])
128130
}))
129131
},
@@ -174,7 +176,9 @@ func TestHandler_Events(t *testing.T) {
174176
},
175177
"url": "http://localhost/foo",
176178
},
177-
"response": map[string]interface{}{"body": "", "size": float64(0), "statusCode": float64(0)}},
179+
"response": map[string]interface{}{"body": "", "size": float64(0), "statusCode": float64(0)},
180+
"clientIP": "192.0.2.1",
181+
},
178182
m[0]["data"])
179183
}))
180184
},

api/handler_schema_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func TestHandler_Schema_Example(t *testing.T) {
247247
},
248248
},
249249
{
250-
name: "string or number",
250+
name: "string or integer",
251251
app: &runtime.App{
252252
Monitor: monitor.New(),
253253
},
@@ -256,7 +256,7 @@ func TestHandler_Schema_Example(t *testing.T) {
256256
http.MethodGet,
257257
"http://foo.api/api/schema/example",
258258
nil,
259-
`{"name": "", "schema": {"type": ["string","number"]}}`,
259+
`{"name": "", "schema": {"type": ["string","integer"]}}`,
260260
h,
261261
try.HasStatusCode(200),
262262
try.HasHeader("Content-Type", "application/json"),
@@ -266,10 +266,10 @@ func TestHandler_Schema_Example(t *testing.T) {
266266
require.NoError(t, err)
267267
b, err := base64.StdEncoding.DecodeString(data[0]["value"])
268268
require.NoError(t, err)
269-
require.Equal(t, "609859.0117483337", string(b))
269+
require.Equal(t, "-168643", string(b))
270270

271271
}),
272-
try.HasBody(`[{"contentType":"application/json","value":"NjA5ODU5LjAxMTc0ODMzMzc="}]`))
272+
try.HasBody(`[{"contentType":"application/json","value":"LTE2ODY0Mw=="}]`))
273273
},
274274
},
275275
{

config/static/static_config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
log "github.com/sirupsen/logrus"
87
"mokapi/config/tls"
98
"net/url"
109
"strconv"
1110
"strings"
11+
12+
log "github.com/sirupsen/logrus"
1213
)
1314

1415
type Config struct {

engine/common/host.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ type HttpClient interface {
104104

105105
type HttpClientOptions struct {
106106
MaxRedirects int
107+
Timeout time.Duration
107108
}
108109

109110
type Action struct {

engine/enginetest/host.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Host struct {
2222
DebugFunc func(args ...interface{})
2323
IsLevelEnabledFunc func(level string) bool
2424
HttpClientTest *HttpClient
25+
HttpClientFunc func(opts common.HttpClientOptions) common.HttpClient
2526
KafkaClientTest *KafkaClient
2627
EveryFunc func(every string, do func(), opt common.JobOptions)
2728
CronFunc func(every string, do func(), opt common.JobOptions)
@@ -128,7 +129,10 @@ func (h *Host) Unlock() {
128129
h.m.Unlock()
129130
}
130131

131-
func (h *Host) HttpClient(_ common.HttpClientOptions) common.HttpClient {
132+
func (h *Host) HttpClient(opts common.HttpClientOptions) common.HttpClient {
133+
if h.HttpClientFunc != nil {
134+
return h.HttpClientFunc(opts)
135+
}
132136
return h.HttpClientTest
133137
}
134138

engine/host.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func (sh *scriptHost) KafkaClient() common.KafkaClient {
310310

311311
func (sh *scriptHost) HttpClient(opts common.HttpClientOptions) common.HttpClient {
312312
return &http.Client{
313-
Timeout: time.Second * 30,
313+
Timeout: opts.Timeout,
314314
CheckRedirect: func(req *http.Request, via []*http.Request) error {
315315
if l := len(via); l > opts.MaxRedirects {
316316
log.Warnf("Stopped after %d redirects, original URL was %s", opts.MaxRedirects, via[0].URL)

examples/mokapi/kafka.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ export let events = [
345345
binary: base64.encode([0xa, 0x43, 0x61, 0x72, 0x6f, 0x6c, 0x3a].map(x => String.fromCharCode(x)).join(''))
346346
},
347347
partition: 0,
348-
messageId: 'shopOrder'
348+
messageId: 'avro'
349349
}
350350
}
351351
]

examples/mokapi/services_http.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,14 @@ export let events = [
588588
url: "http://127.0.0.1:18080/pet",
589589
parameters: [
590590
{
591-
name: 'Acceot-Encoding',
591+
name: 'Accept-Encoding',
592592
type: 'header',
593593
raw: 'gzip, deflate'
594+
},
595+
{
596+
name: 'LongHeader',
597+
type: 'header',
598+
raw: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
594599
}
595600
],
596601
contentType: "application/xml",
@@ -625,7 +630,7 @@ export let events = [
625630
url: "http://127.0.0.1:18080/pet",
626631
parameters: [
627632
{
628-
name: 'Acceot-Encoding',
633+
name: 'Accept-Encoding',
629634
type: 'header',
630635
raw: 'gzip, deflate'
631636
}
@@ -642,7 +647,8 @@ export let events = [
642647
})
643648
]
644649
}
645-
]
650+
],
651+
clientIP: '127.0.0.1'
646652
},
647653
},
648654
{
@@ -691,7 +697,8 @@ export let events = [
691697
message: 'An example script error message'
692698
}
693699
}
694-
]
700+
],
701+
clientIP: '127.0.0.1'
695702
}
696703
},
697704
{
@@ -735,7 +742,8 @@ export let events = [
735742
event: "http"
736743
}
737744
}
738-
]
745+
],
746+
clientIP: '127.0.0.1'
739747
}
740748
},
741749
{
@@ -773,7 +781,8 @@ export let events = [
773781
event: "http"
774782
}
775783
}
776-
]
784+
],
785+
clientIP: '127.0.0.1'
777786
}
778787
},
779788
{
@@ -819,6 +828,7 @@ export let events = [
819828
size: 512
820829
},
821830
duration: 133,
831+
clientIP: '192.0.1.127'
822832
}
823833
}
824834
]

go.mod

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ go 1.25.1
44

55
require (
66
github.com/Masterminds/sprig v2.22.0+incompatible
7-
github.com/blevesearch/bleve/v2 v2.5.3
7+
github.com/blevesearch/bleve/v2 v2.5.4
88
github.com/blevesearch/bleve_index_api v1.2.10
99
github.com/bradleyfalzon/ghinstallation/v2 v2.17.0
1010
github.com/brianvoe/gofakeit/v6 v6.28.0
1111
github.com/dop251/goja v0.0.0-20250309171923-bcd7cc6bf64c
12-
github.com/evanw/esbuild v0.25.11
12+
github.com/evanw/esbuild v0.25.12
1313
github.com/fsnotify/fsnotify v1.9.0
1414
github.com/go-co-op/gocron v1.37.0
1515
github.com/go-git/go-git/v5 v5.16.3
@@ -39,7 +39,7 @@ require (
3939
github.com/blevesearch/go-porterstemmer v1.0.3 // indirect
4040
github.com/blevesearch/gtreap v0.1.1 // indirect
4141
github.com/blevesearch/mmap-go v1.0.4 // indirect
42-
github.com/blevesearch/scorch_segment_api/v2 v2.3.10 // indirect
42+
github.com/blevesearch/scorch_segment_api/v2 v2.3.12 // indirect
4343
github.com/blevesearch/segment v0.9.1 // indirect
4444
github.com/blevesearch/snowballstem v0.9.0 // indirect
4545
github.com/blevesearch/upsidedown_store_api v1.0.2 // indirect
@@ -49,7 +49,7 @@ require (
4949
github.com/blevesearch/zapx/v13 v13.4.2 // indirect
5050
github.com/blevesearch/zapx/v14 v14.4.2 // indirect
5151
github.com/blevesearch/zapx/v15 v15.4.2 // indirect
52-
github.com/blevesearch/zapx/v16 v16.2.4 // indirect
52+
github.com/blevesearch/zapx/v16 v16.2.6 // indirect
5353
github.com/cloudflare/circl v1.6.1 // indirect
5454
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
5555
github.com/davecgh/go-spew v1.1.1 // indirect
@@ -60,7 +60,6 @@ require (
6060
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
6161
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
6262
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
63-
github.com/golang/protobuf v1.5.4 // indirect
6463
github.com/golang/snappy v0.0.4 // indirect
6564
github.com/google/go-github/v75 v75.0.0 // indirect
6665
github.com/google/go-querystring v1.1.0 // indirect
@@ -83,6 +82,6 @@ require (
8382
go.uber.org/atomic v1.9.0 // indirect
8483
golang.org/x/crypto v0.43.0 // indirect
8584
golang.org/x/sys v0.37.0 // indirect
86-
google.golang.org/protobuf v1.33.0 // indirect
85+
google.golang.org/protobuf v1.36.6 // indirect
8786
gopkg.in/warnings.v0 v0.1.2 // indirect
8887
)

go.sum

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY
2222
github.com/bits-and-blooms/bitset v1.12.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
2323
github.com/bits-and-blooms/bitset v1.22.0 h1:Tquv9S8+SGaS3EhyA+up3FXzmkhxPGjQQCkcs2uw7w4=
2424
github.com/bits-and-blooms/bitset v1.22.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
25-
github.com/blevesearch/bleve/v2 v2.5.3 h1:9l1xtKaETv64SZc1jc4Sy0N804laSa/LeMbYddq1YEM=
26-
github.com/blevesearch/bleve/v2 v2.5.3/go.mod h1:Z/e8aWjiq8HeX+nW8qROSxiE0830yQA071dwR3yoMzw=
25+
github.com/blevesearch/bleve/v2 v2.5.4 h1:1iur8e+PHsxtncV2xIVuqlQme/V8guEDO2uV6Wll3lQ=
26+
github.com/blevesearch/bleve/v2 v2.5.4/go.mod h1:yB4PnV4N2q5rTEpB2ndG8N2ISexBQEFIYgwx4ztfvoo=
2727
github.com/blevesearch/bleve_index_api v1.2.10 h1:FMFmZCmTX6PdoLLvwUnKF2RsmILFFwO3h0WPevXY9fE=
2828
github.com/blevesearch/bleve_index_api v1.2.10/go.mod h1:rKQDl4u51uwafZxFrPD1R7xFOwKnzZW7s/LSeK4lgo0=
2929
github.com/blevesearch/geo v0.2.4 h1:ECIGQhw+QALCZaDcogRTNSJYQXRtC8/m8IKiA706cqk=
@@ -36,8 +36,8 @@ github.com/blevesearch/gtreap v0.1.1 h1:2JWigFrzDMR+42WGIN/V2p0cUvn4UP3C4Q5nmaZG
3636
github.com/blevesearch/gtreap v0.1.1/go.mod h1:QaQyDRAT51sotthUWAH4Sj08awFSSWzgYICSZ3w0tYk=
3737
github.com/blevesearch/mmap-go v1.0.4 h1:OVhDhT5B/M1HNPpYPBKIEJaD0F3Si+CrEKULGCDPWmc=
3838
github.com/blevesearch/mmap-go v1.0.4/go.mod h1:EWmEAOmdAS9z/pi/+Toxu99DnsbhG1TIxUoRmJw/pSs=
39-
github.com/blevesearch/scorch_segment_api/v2 v2.3.10 h1:Yqk0XD1mE0fDZAJXTjawJ8If/85JxnLd8v5vG/jWE/s=
40-
github.com/blevesearch/scorch_segment_api/v2 v2.3.10/go.mod h1:Z3e6ChN3qyN35yaQpl00MfI5s8AxUJbpTR/DL8QOQ+8=
39+
github.com/blevesearch/scorch_segment_api/v2 v2.3.12 h1:GGZc2qwbyRBwtckPPkHkLyXw64mmsLJxdturBI1cM+c=
40+
github.com/blevesearch/scorch_segment_api/v2 v2.3.12/go.mod h1:JBRGAneqgLSI2+jCNjtwMqp2B7EBF3/VUzgDPIU33MM=
4141
github.com/blevesearch/segment v0.9.1 h1:+dThDy+Lvgj5JMxhmOVlgFfkUtZV2kw49xax4+jTfSU=
4242
github.com/blevesearch/segment v0.9.1/go.mod h1:zN21iLm7+GnBHWTao9I+Au/7MBiL8pPFtJBJTsk6kQw=
4343
github.com/blevesearch/snowballstem v0.9.0 h1:lMQ189YspGP6sXvZQ4WZ+MLawfV8wOmPoD/iWeNXm8s=
@@ -56,8 +56,8 @@ github.com/blevesearch/zapx/v14 v14.4.2 h1:2SGHakVKd+TrtEqpfeq8X+So5PShQ5nW6GNxT
5656
github.com/blevesearch/zapx/v14 v14.4.2/go.mod h1:rz0XNb/OZSMjNorufDGSpFpjoFKhXmppH9Hi7a877D8=
5757
github.com/blevesearch/zapx/v15 v15.4.2 h1:sWxpDE0QQOTjyxYbAVjt3+0ieu8NCE0fDRaFxEsp31k=
5858
github.com/blevesearch/zapx/v15 v15.4.2/go.mod h1:1pssev/59FsuWcgSnTa0OeEpOzmhtmr/0/11H0Z8+Nw=
59-
github.com/blevesearch/zapx/v16 v16.2.4 h1:tGgfvleXTAkwsD5mEzgM3zCS/7pgocTCnO1oyAUjlww=
60-
github.com/blevesearch/zapx/v16 v16.2.4/go.mod h1:Rti/REtuuMmzwsI8/C/qIzRaEoSK/wiFYw5e5ctUKKs=
59+
github.com/blevesearch/zapx/v16 v16.2.6 h1:OHuUl2GhM+FpBq9RwNsJ4k/QodqbMMHoQEgn/IHYpu8=
60+
github.com/blevesearch/zapx/v16 v16.2.6/go.mod h1:cuAPB+YoIyRngNhno1S1GPr9SfMk+x/SgAHBLXSIq3k=
6161
github.com/bradleyfalzon/ghinstallation/v2 v2.17.0 h1:SmbUK/GxpAspRjSQbB6ARvH+ArzlNzTtHydNyXUQ6zg=
6262
github.com/bradleyfalzon/ghinstallation/v2 v2.17.0/go.mod h1:vuD/xvJT9Y+ZVZRv4HQ42cMyPFIYqpc7AbB4Gvt/DlY=
6363
github.com/brianvoe/gofakeit/v6 v6.28.0 h1:Xib46XXuQfmlLS2EXRuJpqcw8St6qSZz75OUo0tgAW4=
@@ -81,8 +81,8 @@ github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o
8181
github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE=
8282
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
8383
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
84-
github.com/evanw/esbuild v0.25.11 h1:NGtezc+xk+Mti4fgWaoD3dncZNCzcTA+r0BxMV3Koyw=
85-
github.com/evanw/esbuild v0.25.11/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48=
84+
github.com/evanw/esbuild v0.25.12 h1:7kIg7aG2++vhheW5YCzut1q1AjehYVQU752NcMuGVsw=
85+
github.com/evanw/esbuild v0.25.12/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48=
8686
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
8787
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
8888
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
@@ -103,8 +103,6 @@ github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXe
103103
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
104104
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
105105
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
106-
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
107-
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
108106
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
109107
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
110108
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
@@ -219,8 +217,8 @@ golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
219217
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
220218
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
221219
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
222-
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
223-
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
220+
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
221+
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
224222
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
225223
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
226224
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 commit comments

Comments
 (0)