Commit Graph

264 Commits

Author SHA1 Message Date
Kevin Wan
a987512c7b
feat: more meaningful error messages, close body on httpc requests (#2238)
* feat: more meaningful error messages, close body on httpc requests

* fix: test failure
2022-08-07 16:09:54 +08:00
Kevin Wan
5cd9229986
fix: only setup logx once (#2188)
* fix: only setup logx once

* fix: test failure

* chore: not reset logging level in reset

* chore: refactoring
2022-07-28 22:08:48 +08:00
chen quan
003adae51f
fix(httpc): fix typo errors (#2189) 2022-07-27 09:11:15 +08:00
Kevin Wan
b206dd28a3
feat: support form values in gateway (#2158) 2022-07-16 23:40:53 +08:00
Kevin Wan
3bad043413
chore: refactor (#2130) 2022-07-11 23:50:50 +08:00
虫子樱桃
d71b3c841f
feat:Add Routes method for server (#2125)
Co-authored-by: czyt <czyt@w.cn>
2022-07-11 23:23:38 +08:00
家福
f3b8fef34f
fix: type matching supports string to int (#2038)
* fix: type matching supports string to int

* feat: type matching supports string to int

Co-authored-by: 程家福 <chengjiafu@uniontech.com>
2022-07-01 23:21:31 +08:00
Zhang.Y
7da77302f4
fix: \u003cnil\u003e log output when http server shutdown. (#2055) 2022-06-29 21:35:01 +08:00
Kevin Wan
47c49de94e
feat: rest.WithChain to replace builtin middlewares (#2033)
* feat: rest.WithChain to replace builtin middlewares

* chore: add comments

* chore: refine code
2022-06-19 17:41:33 +08:00
Kevin Wan
018ca82048
chore: refactor to simplify disabling builtin middlewares (#2031)
* chore: refactor to simplify disabling builtin middlewares

* chore: rename methods
2022-06-18 20:16:34 +08:00
magickeha
6976ba7e13
add user middleware chain function (#1913)
* add user middleware chain function

* fix staticcheck SA4006

* chang code Implementation style

Co-authored-by: kemq1 <kemq1@spdb.com.cn>
2022-06-18 18:45:47 +08:00
chen quan
6518eb10b3
feat: add trace in httpc (#2011) 2022-06-17 15:01:14 +08:00
Kevin Wan
ed1c937998
feat: convert grpc errors to http status codes (#1997)
* feat: convert grpc errors to http status codes

* chore: circuit break include unimplemented grpc error

* chore: add reference link in comments
2022-06-11 23:07:26 +08:00
Kevin Wan
af05219b70
test: make tests stable (#1968)
* test: make tests stable

* test: fix fails
2022-06-04 23:46:29 +08:00
Kevin Wan
f366e1d936
chore: make print pretty (#1967) 2022-06-04 19:53:22 +08:00
Kevin Wan
b6b96d9dad
feat: print routes (#1964)
* feat: print rest routes

* feat: print rest routes
2022-06-04 13:26:14 +08:00
Kevin Wan
6b1e15cab1
chore: update k8s.io/client-go for security reason, go is upgrade to 1.16 (#1912)
* chore: fix jwt dependency security issue

* chore: update clickhouse driver

* chore: fix a security issue

* chore: update dependencies
2022-05-21 14:34:01 +08:00
Kevin Wan
6d2b9fd904
chore: improve codecov (#1878) 2022-05-08 13:17:48 +08:00
Kevin Wan
69c2bad410
feat: logx with color (#1872)
* feat: logx with color

* chore: update logs

* fix test error

* chore: change colors of http codes

* chore: add comments

* chore: use faith/color instead of ascii code color

* chore: update colors

* chore: update colors

* chore: fix duplicated slowcall text

* chore: remove slowcall colors
2022-05-07 23:22:39 +08:00
Kevin Wan
d0a59b13a6
chore: fix deprecated usages (#1871)
* add conf documents

* chore: use {} instead of () for environment variables

* chore: fix deprecated usages

* chore: fix unstable tests

* chore: show stack on github actions
2022-05-06 15:13:46 +08:00
Kevin Wan
ac321fc146
feat: add fields with logx methods, support using third party logging libs. (#1847)
* backup

* simplify

* chore: remove unused pool

* chore: fix lint errors

* chore: use strings.Builder instead of bytes.Buffer

* test: add more tests

* chore: fix reviewdog

* test: fix data race

* feat: make logger customizable

* chore: fix reviewdog

* test: fix fails

* chore: fix set writer twice

* chore: use context instead of golang.org context

* chore: specify uint32 for level types
2022-05-03 17:34:26 +08:00
Kevin Wan
f21970c117
test: add more tests (#1856) 2022-05-02 21:24:20 +08:00
Kevin Wan
3bbc90ec24
refactor: move json related header vars to internal (#1840)
* refactor: move json related header vars to internal

* refactor: use header.ContentType
2022-04-28 15:12:04 +08:00
Kevin Wan
cef83efd4e
fix #1838 (#1839) 2022-04-28 11:25:26 +08:00
Kevin Wan
f7a60cdc24
fix: remove deprecated dependencies (#1837)
* fix: remove deprecated dependencies

* backup

* fix test error
2022-04-27 21:34:54 +08:00
Kevin Wan
5c9fae7e62
feat: support sub domain for cors (#1827) 2022-04-25 21:56:59 +08:00
Vee Zhang
94ddb3380e
fix: rest: WriteJson get 200 when Marshal failed. (#1803)
Only the first WriteHeader call takes effect.
2022-04-21 21:55:01 +08:00
Kevin Wan
2cdff97934
feat: use mongodb official driver instead of mgo (#1782)
* wip: backup

* wip: backup

* wip: backup

* backup

* backup

* backup

* add more tests

* fix wrong dependency

* fix lint errors

* remove test due to data race

* add tests

* fix test error

* add mon.Model

* add mon.Model unmarshal

* add monc

* add more tests for monc

* add more tests for monc

* add docs for mon and monc packages

* fix doc errors

* chhore: add comment

* chore: fix test bug

* chore: refine tests

* chore: remove primitive.NewObjectID in test code

* chore: rename test files for typo
2022-04-19 14:03:04 +08:00
Kevin Wan
92b450eb11
fix: ignore timeout on websocket (#1802) 2022-04-18 20:14:46 +08:00
Kevin Wan
cb4fcf2c6c
fix marshal ptr in httpc (#1789)
* fix marshal ptr in httpc

* add more tests

* add more tests

* add more tests

* fix issue on options and optional both provided
2022-04-15 19:07:34 +08:00
Kevin Wan
50de01fb49
feat: add httpc.Do & httpc.Service.Do (#1775)
* backup

* backup

* backup

* feat: add httpc.Do & httpc.Service.Do

* fix: not using strings.Cut, it's from Go 1.18

* chore: remove redudant code

* feat: httpc.Do finished

* chore: fix reviewdog

* chore: break loop if found

* add more tests
2022-04-11 11:00:28 +08:00
Kevin Wan
ab01442d46
add more tests (#1763)
* feat: add goctl docker build scripts

* chore: add more tests
2022-04-06 16:09:06 +08:00
Kevin Wan
78ea0769fd
feat: simplify httpc (#1748)
* feat: simplify httpc

* chore: fix lint errors

* chore: fix log url issue

* chore: fix log url issue

* refactor: handle resp & err in ResponseHandler

* chore: remove unnecessary var names in return clause
2022-04-03 14:32:27 +08:00
Kevin Wan
2b9fc26c38
refactor: guard timeout on API files (#1726) 2022-03-31 21:39:02 +08:00
Xiaoju Jiang
321dc2d410
Added support for setting the parameter size accepted by the interface and custom timeout and maxbytes in API file (#1713)
* Added support for setting the parameter size accepted by the interface

* support custom timeout and maxbytes in API file

* support timeout used unit

* remove goctl maxBytes
2022-03-31 20:20:00 +08:00
Kevin Wan
ec271db7a0
chore: refactor code (#1699) 2022-03-23 18:24:44 +08:00
Kevin Wan
c1d9e6a00b
feat: add httpc.Parse (#1698) 2022-03-23 17:58:21 +08:00
Kevin Wan
f9e6013a6c
refactor: httpc package for easy to use (#1645) 2022-03-15 14:18:46 +08:00
Kevin Wan
b5d1d8b0d1
refactor: httpc package for easy to use (#1643) 2022-03-14 20:15:14 +08:00
Kevin Wan
2a5717d7fb
feat: add httpc/Service for convinience (#1641) 2022-03-14 15:36:06 +08:00
Kevin Wan
85cf662c6f
feat: add httpc/Get httpc/Post (#1640) 2022-03-13 14:49:14 +08:00
Kevin Wan
3279a7ef0f
feat: add rest/httpc to make http requests governacible (#1638)
* feat: change x-trace-id to traceparent to follow opentelemetry

* feat: add rest/httpc to make http requests governacible

* chore: remove blank lines
2022-03-13 14:11:14 +08:00
Kevin Wan
3b7ca86e4f
chore: add unit tests (#1615)
* test: add more tests

* test: add more tests
2022-03-04 17:54:09 +08:00
Kevin Wan
842656aa90
feat: log 404 requests with traceid (#1554) 2022-02-19 20:50:33 +08:00
Kevin Wan
fdc7f64d6f
chore: update unauthorized callback calling order (#1469)
* chore: update unauthorized callback calling order

* chore: add comments
2022-01-20 21:09:45 +08:00
Kevin Wan
bf2feee5b7
feat: implement console plain output for debug logs (#1456)
* feat: implement console plain output for debug logs

* chore: rename console encoding to plain

* chore: refactor names
2022-01-17 12:43:15 +08:00
Kevin Wan
272a3f347d
chore: remove jwt deprecated (#1452) 2022-01-16 10:34:44 +08:00
Kevin Wan
468c237189
chore: upgrade dependencies (#1444)
* chore: upgrade dependencies

* ci: upgrade go to 1.15
2022-01-14 11:01:02 +08:00
Kevin Wan
ba6a7c9dc8
chore: refactor rest/timeouthandler (#1415) 2022-01-05 11:17:10 +08:00
Kevin Wan
a91c3907a8
feat: rename module from tal-tech to zeromicro (#1413) 2022-01-04 15:51:32 +08:00
Kevin Wan
62266d8f91
fix #1070 (#1389)
* fix #1070

* test: add more tests
2021-12-29 21:34:28 +08:00
Kevin Wan
cd289465fd
chore: coding style and comments (#1361)
* chore: coding style and comments

* chore: optimize `ParseJsonBody` (#1353)

* chore: optimize `ParseJsonBody`

* chore: optimize `ParseJsonBody`

* fix: fix a test

* chore: optimize `ParseJsonBody`

* fix a test

* chore: add comment

* chore: refactor

Co-authored-by: chenquan <chenquan.dev@foxmail.com>
2021-12-22 21:43:37 +08:00
chenquan
263e426ae1
chore: optimize ParseJsonBody (#1353)
* chore: optimize `ParseJsonBody`

* chore: optimize `ParseJsonBody`

* fix: fix a test

* chore: optimize `ParseJsonBody`

* fix a test

* chore: add comment
2021-12-22 20:24:55 +08:00
charliecen
d5e493383a
chose: cancel the assignment and judge later (#1359)
Co-authored-by: charliecen <chq@abierr.com>
2021-12-22 20:05:35 +08:00
Kevin Wan
6f1d27354a
chore: put error message in error.log for verbose mode (#1355) 2021-12-21 11:36:01 +08:00
Kevin Wan
26101732d2
test: add more tests (#1352) 2021-12-20 22:42:36 +08:00
Kevin Wan
71d40e0c08
Revert "排除客户端中断导致的503错误 (#1343)" (#1351)
This reverts commit 2cdf5e7395.
2021-12-20 20:34:43 +08:00
Kevin Wan
4ba2ff7cdd
feat: treat client closed requests as code 499 (#1350)
* feat: treat client closed requests as code 499

* chore: add comments
2021-12-20 19:43:38 +08:00
vic
2cdf5e7395
排除客户端中断导致的503错误 (#1343) 2021-12-20 19:43:13 +08:00
Kevin Wan
3dda557410
chore: only allow cors middleware to change headers (#1276) 2021-11-26 14:14:06 +08:00
Kevin Wan
c800f6f723
chore: avoid superfluous WriteHeader call errors (#1275) 2021-11-26 11:09:57 +08:00
Kevin Wan
0395ba1816
feat: add rest.WithCustomCors to let caller customize the response (#1274) 2021-11-25 23:03:37 +08:00
Kevin Wan
a6c8113419
chore: refactor, better goctl message (#1228) 2021-11-11 22:58:33 +08:00
Kevin Wan
9d0b51fa26
fixes #1222 (#1223) 2021-11-10 21:25:51 +08:00
Kevin Wan
28409791fa
feat: support CORS, better implementation (#1217)
* feat: support CORS, better implementation

* chore: refine code
2021-11-09 20:35:57 +08:00
Kevin Wan
c28e01fed3
feat: support CORS by using rest.WithCors(...) (#1212)
* feat: support CORS by using rest.WithCors(...)

* chore: add comments

* refactor: lowercase unexported methods

* ci: fix lint errors
2021-11-07 22:42:40 +08:00
Kevin Wan
3ede597a15
feat: support customizing timeout for specific route (#1203)
* feat: support customizing timeout for specific route

* test: add more tests
2021-11-03 22:20:32 +08:00
Kevin Wan
91b10bd3b9
feat: add rest.WithPrefix to support route prefix (#1194) 2021-11-01 20:15:10 +08:00
Kevin Wan
7e3fe77e7b
chore: update goctl version to 1.2.3, prepare for release (#1193)
* feat: slow threshold customizable in rest

* chore: update goctl version to 1.2.3, prepare for release
2021-11-01 18:26:08 +08:00
Kevin Wan
ba43214dae
feat: slow threshold customizable in zrpc (#1191)
* feat: slow threshold customizable in rest

* feat: slow threshold customizable in rest

* feat: slow threshold customizable in rest

* feat: slow threshold customizable in zrpc
2021-11-01 15:04:38 +08:00
Kevin Wan
ebc90720ea
feat: slow threshold customizable in rest (#1189)
* feat: slow threshold customizable in rest

* feat: slow threshold customizable in rest
2021-11-01 14:48:26 +08:00
Kevin Wan
769d06c8ab
refactor: simplify tls config in rest (#1181) 2021-10-31 14:10:47 +08:00
Howie
cd1f8da13f
[update] add plugin config (#1180)
Signed-off-by: lihaowei <haoweili35@gmail.com>
2021-10-31 12:56:25 +08:00
Kevin Wan
496a2f341e
test: add more tests (#1163)
* chore: reverse the order of stopping services

* chore: reverse the order of stopping services

* test: add more tests
2021-10-25 21:10:08 +08:00
Kevin Wan
5636bf4955
test: add more tests (#1150) 2021-10-20 17:50:01 +08:00
chenquan
022c100dc9
Add request method in http log (#1120)
* Add request method in http log

* Update log format
2021-10-12 21:50:30 +08:00
Kevin Wan
10e7922597
feat: opentelemetry integration, removed self designed tracing (#1111)
* feat: opentelemetry integration, removed self designed tracing

* feat: support zipkin on opentelemetry integration

* feat: support zipkin on opentelemetry integration, enable it in conf

* style: format code

* fix: support logx without exporter configured

* fix: check return values

* refactor: simplify code

* refactor: simplify opentelemetry integration

* ci: fix staticcheck errors
2021-10-03 20:53:50 +08:00
Kevin Wan
ed15ca04f4
fix: opentelemetry traceid not correct (#1108) 2021-10-01 22:44:37 +08:00
Kevin Wan
65905b914d
ci: add reviewdog (#1096) 2021-09-29 13:09:20 +08:00
Kevin Wan
1eb1450c43
downgrade golang-jwt to support go 1.14 (#1073) 2021-09-21 13:42:45 +08:00
Kevin Wan
30e49f2939
fix jwt security issue by using golang-jwt package (#1066) 2021-09-19 22:33:35 +08:00
Kevin Wan
6476da4a18
rest log with context (#998) 2021-09-05 22:58:42 +08:00
Allen Liu
3b683fd498
feat: change logger to traceLogger for getting traceId when recovering (#374) 2021-09-05 22:40:10 +08:00
Kevin Wan
58874779e7
move opentelemetry into trace package, and refactoring (#996)
* move opentelemetry into trace package, and refactoring

* rename rewritten package names
2021-09-05 22:18:35 +08:00
Kevin Wan
9bdadf2381
fix golint issues (#992) 2021-09-04 12:16:30 +08:00
Kevin Wan
407a6cbf9c
format coding style (#983) 2021-09-01 19:52:56 +08:00
Vee Zhang
76fc1ef460
httpx.Error response without body (#982)
* httpx.Error support response without body

* fix doc
2021-09-01 19:33:33 +08:00
Kevin Wan
7618139dad
refactor (#977) 2021-08-31 12:04:09 +08:00
zhoushuguang
280e837c9e
rest otel support (#943) 2021-08-24 10:04:12 +08:00
Kevin Wan
f669e1226c
fix #556 (#938) 2021-08-22 23:36:35 +08:00
Kevin Wan
9672298fa8
make sure setting code happen before callback in rest (#936) 2021-08-22 09:27:20 +08:00
Kevin Wan
9c1ee50497
refactor (#920) 2021-08-17 10:24:12 +08:00
chenquan
7c842f22d0
Add traceId to the response headers (#919)
* Add traceId to the request headers

* Add test cases

* Update refactor code
2021-08-17 10:12:08 +08:00
Kevin Wan
fc04ad7854
export pathvar for user-defined routers (#911)
* refactor

* export pathvar for user-defined routers
2021-08-14 22:57:28 +08:00
Kevin Wan
54d57c7d4b
refactor rest code (#895) 2021-08-10 17:59:33 +08:00
voidint
28a7c9d38f
fix http header binding failure bug #885 (#887) 2021-08-10 17:38:03 +08:00
fangjianwei
b812e74d6f
Fixed http listener error. (#843) 2021-07-24 12:57:56 +08:00
Chen Quan
22a1315136
[WIP]Add parse headers info (#805)
* Add parse headers info

* Update parse headers info
2021-07-07 23:20:09 +08:00
Bo-Yi Wu
73906f996d
chore(format): change by gofumpt tool (#697)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-05-18 14:43:09 +08:00
noel
faf4d7e3bb
modify the order of PrometheusHandler (#670)
* modify the order of PrometheusHandler

* modify the order of PrometheusHandler
2021-05-08 17:11:16 +08:00
Kevin Wan
06eeef2cf3
disable prometheus if not configured (#663) 2021-04-30 15:09:49 +08:00
Bo-Yi Wu
afd9ff889e
chore: update code format. (#628) 2021-04-15 19:49:17 +08:00
另维64
7e087de6e6
doc: fix spell mistake (#627) 2021-04-14 17:58:27 +08:00
Kevin Wan
3c6951577d
make hijack more stable (#565) 2021-03-15 20:11:09 +08:00
Kevin Wan
fcd15c9b17
refactor, and add comments to describe graceful shutdown (#564) 2021-03-14 08:51:10 +08:00
Kevin Wan
1a1a6f5239
add http hijack methods (#555) 2021-03-09 21:30:45 +08:00
Kevin Wan
655ae8034c
fix golint issues in rest (#529) 2021-03-01 19:15:35 +08:00
Kevin Wan
ad32f9de23
fix golint issues in core/threading (#524) 2021-02-26 16:27:04 +08:00
hao
2087ac1e89
修正http转发头字段值错误 (#521) 2021-02-26 16:17:30 +08:00
Kevin Wan
395a1db22f
add more tests for rest (#462) 2021-02-10 23:08:48 +08:00
Kevin Wan
03b5fd4a10
fix golint issues (#458) 2021-02-09 14:03:19 +08:00
Kevin Wan
5e969cbef0
fix golint issues, else blocks (#457) 2021-02-09 13:50:21 +08:00
Kevin Wan
42883d0899
fix golint issues, redis methods (#455) 2021-02-09 10:58:11 +08:00
Kevin Wan
54414db91d
fix golint issues, exported doc (#451) 2021-02-08 21:31:56 +08:00
FengZhang
a8b550e7ef
Modify the http content-length max range : 30MB --> 32MB (#424)
Because we are programmer :)
2021-01-30 18:49:33 +08:00
FengZhang
cbfbebed00
modify the maximum content-length to 30MB (#413) 2021-01-29 22:14:48 +08:00
Kevin Wan
e97e1f10db
simplify code with http.Flusher type conversion (#325)
* simplify code with http.Flusher type conversion

* simplify code with http.Flusher type conversion, better version
2020-12-29 10:25:55 +08:00
jichangyun
0bd2a0656c
The ResponseWriters defined in rest.handler add Flush interface. (#318) 2020-12-28 21:30:24 +08:00
Kevin Wan
bf21203297
add more tests (#320) 2020-12-27 12:26:31 +08:00
Kevin Wan
ae98375194
add more tests (#319) 2020-12-26 20:30:02 +08:00
Kevin Wan
82d1ccf376
fixes #286 (#315) 2020-12-25 19:47:27 +08:00
Kevin Wan
99596a4149
fix issue #266 (#275)
* optimize dockerfile

* fix issue #266
2020-12-11 16:12:33 +08:00
bittoy
88ec89bdbd
optimization (#241) 2020-12-02 15:00:07 +08:00
kevin
9592639cb4 add error handle tests 2020-11-17 18:04:48 +08:00
kevin
abcb28e506 support error customization 2020-11-17 17:11:06 +08:00
bittoy
3819f67cf4
add redis geospatial (#209)
* add redis geospatial

* fix go test error
2020-11-16 19:45:43 +08:00
kevin
3806e66cf1 simplify http server starter 2020-11-08 13:17:14 +08:00
kevin
bd430baf52 graceful shutdown refined 2020-11-08 13:08:00 +08:00
kevin
c9ec22d5f4 add https listen and serve 2020-11-05 11:56:40 +08:00
kevin
4c9315e984 add more tests 2020-10-31 22:10:11 +08:00
kevin
668a7011c4 add more tests 2020-10-31 20:11:12 +08:00
kevin
5e87b33b23 support https in rest 2020-10-29 17:44:51 +08:00
kevin
9c8f31cf83 can only specify one origin in cors 2020-10-21 16:47:49 +08:00
kevin
fe0d0687f5 support cors in rest server 2020-10-21 14:10:36 +08:00
kevin
737cd4751a rename NewPatRouter to NewRouter 2020-10-20 14:23:21 +08:00
kingxt
aa3c391919
api add middleware support (#140)
* rebase upstream

* rebase

* trim no need line

* trim no need line

* trim no need line

* update doc

* remove update

* remove no need

* remove no need

* goctl add jwt support

* goctl add jwt support

* goctl add jwt support

* goctl support import

* goctl support import

* support return ()

* revert

* refactor and rename folder to group

* remove no need

* add anonymous annotation

* optimized

* rename

* rename

* update test

* api add middleware support: usage:

@server(
    middleware: M1, M2
)

* api add middleware support: usage:

@server(
    middleware: M1, M2
)

* simple logic

* should reverse middlewares

* optimized

* optimized

* rename

Co-authored-by: kingxt <dream4kingxt@163.com>
2020-10-19 18:34:10 +08:00
kevin
94645481b1 fix golint issues 2020-10-16 10:50:43 +08:00
kevin
20d53add46 update readme 2020-10-11 19:42:40 +08:00
kevin
adc275872d add more tests 2020-10-10 11:53:49 +08:00
kevin
b8fcdd5460 add more tests 2020-10-01 17:50:53 +08:00
kevin
9277ad77f7 fix typo of prometheus 2020-09-27 17:15:15 +08:00
kevin
a958400595 rename prommetric to prometheous, add unit tests 2020-09-27 16:14:16 +08:00
kevin
be9c48da7f add tracing logs in server side and client side 2020-09-22 17:34:39 +08:00
kevin
5e99f2b85d add trace/span in http logs 2020-09-20 22:02:45 +08:00
kevin
86d3de4c89 use package level defined contextKey as context key 2020-09-20 12:46:35 +08:00
kevin
0b1ee79d3a rename rpcx to zrpc 2020-09-18 11:41:52 +08:00
kevin
2b1466e41e add more tests 2020-08-21 23:09:35 +08:00
kevin
9e14820698 fix golint warnings 2020-08-19 16:00:55 +08:00
kevin
054d9b5540 rename rest files 2020-08-18 20:20:44 +08:00
kevin
d6c7da521e remove bodyless check 2020-08-12 14:44:09 +08:00