【英文】Go语言通过sqlx模块操作数据库报错

Introduction

When operating the database using the sqlx module in Go language, an error occurs: missing destination name xxx in xxx.

Reason

  • Unable to map struct properties to database fields.

Solution

  • Add a tag to each property of the struct with the corresponding database field name.
1
2
3
4
type User struct {
Username string `db:"Username"`
Password string `db:"Password"`
}

Done

References

CSDN——HNU_GeorgeYang