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

checker: fix veb route method param with non ctx name (fix #23105) #23107

Merged
merged 2 commits into from
Dec 9, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Dec 9, 2024

This PR fix veb route method param with non ctx name (fix #23105).

  • Fix veb route method param with non ctx name.
  • Add test.
import veb

pub struct User {
pub mut:
	name string
	id   int
}

// Our context struct must embed `veb.Context`!
pub struct Context {
	veb.Context
pub mut:
	// In the context struct we store data that could be different
	// for each request. Like a User struct or a session id
	user       User
	session_id string
}

pub struct App {
pub:
	// In the app struct we store data that should be accessible by all endpoints.
	// For example, a database or configuration values.
	secret_key string
}

// This is how endpoints are defined in veb. This is the index route
pub fn (app &App) index(mut context Context) veb.Result {
	return context.text('Hello V! The secret key is "${app.secret_key}"')
}

fn main() {
	mut app := &App{
		secret_key: 'secret'
	}
	// Pass the App and context type and start the web server on port 8080
	veb.run[App, Context](mut app, 8080)
}

PS D:\Test\v\tt1> v run .
[veb] Running app on http://localhost:8080/

Huly®: V_0.6-21544

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman
Copy link
Member

@medvednikov ... that veb.Context implicit handling in the compiler, is a very big hack, and I suspect that it will continue to trip users :-| .

A big reason for veb instead of vweb, was to minimize the amount of special cases for its support in the compiler, in favor of using general features, supported for all user code :-( ...

@spytheman spytheman merged commit 6f75872 into vlang:master Dec 9, 2024
72 checks passed
@yuyi98 yuyi98 deleted the fix_veb_route branch December 10, 2024 01:00
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.

C error in veb example
2 participants