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

add: params parse #1964

Merged
merged 1 commit into from Jul 5, 2022
Merged

add: params parse #1964

merged 1 commit into from Jul 5, 2022

Conversation

olongfen
Copy link
Contributor

@olongfen olongfen commented Jul 5, 2022

Hello, This PR is binds the param string to a struct

Parse path parameters and body parameters using a struct

	app.Put("/user/:id", func(ctx *Ctx) error {
		type User struct {
			// uri
			ID uint `uri:"id" validate:"required"`
			// body
			Username string `json:"username" validate:"required"`
			Age      int    `json:"age"`
		}
		var (
			d = new(User)
		)
		// params parser
		_ = ctx.ParamsParser(d)
		// body parser
		_ = ctx.BodyParser(d)
		// then validate
		validate.Struct(d)
		return nil
	})

@welcome
Copy link

welcome bot commented Jul 5, 2022

Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@ReneWerner87
Copy link
Member

ReneWerner87 commented Jul 5, 2022

  • please add a part in the documentation repository
    @olongfen

@ReneWerner87 ReneWerner87 merged commit dfa24a0 into gofiber:master Jul 5, 2022
@welcome
Copy link

welcome bot commented Jul 5, 2022

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@liaohongxing
Copy link
Contributor

liaohongxing commented Jul 6, 2022

uri tag should be renamed params , similar to Echo Gin in the go ecosystem

considering the existing params(), paramsint(), is it param or params that needs to be discussed

@olongfen
Copy link
Contributor Author

olongfen commented Jul 6, 2022

uri tag should be renamed params , similar to Echo Gin in the go ecosystem

considering the existing params(), paramsint(), is it param or params that needs to be discussed

gin use struct tag is uri tag , path param include many value,so i think use paramsParser is better

image

@liaohongxing
Copy link
Contributor

it is recommended to change to params, consistent with the existing API

func (c *Ctx) Params(key string, defaultValue ... string) string
func (c *Ctx) ParamsInt(key string) (int, error)
func (c *Ctx) ParamsParser(out interface{}) error // Tag is params

func (c *Ctx) Query(key string, defaultValue ... string) string
func (c *Ctx) QueryParser(out interface{}) error // Tag is query

@liaohongxing
Copy link
Contributor

@efectn what do you think

@ReneWerner87
Copy link
Member

@olongfen what do you think ? its a valid point

@olongfen
Copy link
Contributor Author

olongfen commented Jul 6, 2022

@olongfen what do you think ? its a valid point

I also think it's ok, keep it consistent with the current one

@ReneWerner87
Copy link
Member

ok, can you pls change the documentation and the code for the new tag name ?

@olongfen
Copy link
Contributor Author

olongfen commented Jul 6, 2022

ok

trim21 pushed a commit to trim21/fiber that referenced this pull request Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants