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

[BUG] schema: invalid path "username" #2456

Open
baiyuxiong opened this issue May 7, 2024 · 1 comment
Open

[BUG] schema: invalid path "username" #2456

baiyuxiong opened this issue May 7, 2024 · 1 comment
Assignees

Comments

@baiyuxiong
Copy link

Describe the bug
Browser shows:
schema: invalid path "username"schema: invalid path "username"

To Reproduce
Steps to reproduce the behavior:
codes as follow:

//main.go
user := mvc.New(app.Party("/my"))
	user.Register(
		userService,
		sessManager.Start,
	)
	user.Handle(new(controller.MyController))

//my_controller.go
type MyController struct {
	Ctx     iris.Context
	Service service.UserService
	Session *sessions.Session
}

func (c *MyController) GetLogin() mvc.Result {
	return mvc.View{
		Name: "my/login.html",
	}
}

type loginForm struct {
	Username string `form:"username"`
}

func (c *MyController) PostLogin(form loginForm) mvc.Result {
	fmt.Println(form.Username)
	return mvc.Response{
		Path: "/my/login",
	}
}

//my/login.html
<form action="/my/login" method="POST" enctype="multipart/form-data">
    <div class="container">
        <label><b>Username</b></label>
        <input type="text" placeholder="Enter Username" name="username" required>

        <button type="submit">Login</button>
    </div>
</form>

After click the login button, the page shows :
schema: invalid path "username"schema: invalid path "username"

Desktop (please complete the following information):

  • OS: debian

iris.Version

  • v12.2.11
@baiyuxiong
Copy link
Author

I have found the reason why. It is due to my implementation of the NewUserService function.

userService in main.go is created by :
userService := service.NewUserService()

This NewUserService is wrong:

func NewUserService() *UserService {
	return &UserService{}
}

and if * was removed, it will work fine:

func NewUserService() UserService {
	return UserService{}
}

Superficially,the error msg "schema: invalid path" has nothing to do NewUserService. It makes me so confused.

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

No branches or pull requests

2 participants