Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for setting the parameter size accepted by the interface and custom timeout in API file #1713

Merged
merged 4 commits into from Mar 31, 2022

Conversation

jiang4869
Copy link
Contributor

@jiang4869 jiang4869 commented Mar 25, 2022

It can be used like this

func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
	server.AddRoutes(
		[]rest.Route{
			{
				Method:  http.MethodPost,
				Path:    "/upload",
				Handler: UploadHandler(serverCtx),
			},
		},
		rest.WithMaxBytes(52428800),
	)
}

custom timeout and maxbytes in api file can be used like this
The unit of timeout is time.Second

@server(
	timeout: 1ms
	group: user
)
service user {
	@handler getUser // etst
	get /users/id (request) returns (response)
}

general code

// Code generated by goctl. DO NOT EDIT.
package handler

import (
	"net/http"

	user "joj-backend/api/internal/handler/user"
	"joj-backend/api/internal/svc"

	"github.com/zeromicro/go-zero/rest"
)

func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
	server.AddRoutes(
		[]rest.Route{
			{
				Method:  http.MethodGet,
				Path:    "/users/id",
				Handler: user.GetUserHandler(serverCtx),
			},
		}, rest.WithTimeout(1000000),
	)
}

@jiang4869 jiang4869 changed the title Added support for setting the parameter size accepted by the interface Added support for setting the parameter size accepted by the interface and custom timeout and maxbytes in API file Mar 26, 2022
@chenquan
Copy link
Member

chenquan commented Mar 27, 2022

I think you just need to use MaxBytes in ResConf.
but rest.WithMaxBytes is greet.

@jiang4869
Copy link
Contributor Author

jiang4869 commented Mar 27, 2022

I think you just need to use MaxBytes in ResConf.

If maxbytes is set in the configuration file, all interfaces are the same. But sometimes you just want to set the upload file interface larger.

@fynxiu
Copy link
Contributor

fynxiu commented Mar 27, 2022

Now that you've chosen microservices, think in terms of microservices. Would it be a better idea to have the uploading module as a separate service?

@jiang4869
Copy link
Contributor Author

Now that you've chosen microservices, think in terms of microservices. Would it be a better idea to have the uploading module as a separate service?

Using API as the gateway of micro service

@kevwan kevwan requested a review from kesonan March 28, 2022 13:09
@kevwan
Copy link
Contributor

kevwan commented Mar 28, 2022

timeout: 2

I prefer to use timeout: 2s, in this case, we can support like 200ms.

Also, if service level, just set it in yaml files.

@jiang4869
Copy link
Contributor Author

timeout: 2

I prefer to use timeout: 2s, in this case, we can support like 200ms.

Also, if service level, just set it in yaml files.

added time units?

@kevwan
Copy link
Contributor

kevwan commented Mar 28, 2022

timeout: 2
I prefer to use timeout: 2s, in this case, we can support like 200ms.
Also, if service level, just set it in yaml files.

added time units?

yes, for 2, users don't know it's 2s.

@chenquan
Copy link
Member

chenquan commented Mar 28, 2022

My thoughts:

  1. Don't need to define timeout and maxBytes in @server
  2. Use ResConf can be in the service level.
  3. Keep WithMaxBytes (maxBytes Int64) for user customization.

@kevwan kevwan merged commit 321dc2d into zeromicro:master Mar 31, 2022
@jiang4869 jiang4869 changed the title Added support for setting the parameter size accepted by the interface and custom timeout and maxbytes in API file Added support for setting the parameter size accepted by the interface and custom timeout in API file Mar 31, 2022
fynxiu pushed a commit to fynxiu/go-zero that referenced this pull request Apr 1, 2022
…e and custom timeout and maxbytes in API file (zeromicro#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants