使用 echo 构建应用程序并基本上创建了一些路由。GET 的工作正常,但后一个是给我错误: Do not really understand where the error lies here。{....."method":"GET","uri":"/addPerson", message=Method Not Allowed",".....bytes_in":0,"bytes_out":33}main.go 片段 func initEchoServer() { e := echo.New() e.Use(middleware.Logger()) e.Use(middleware.Recover()) // get all persons e.GET("/persons", Info) // get specific id e.GET("/persons/:id", getPerson) e.POST("/addPerson", addPerson) e.Logger.Fatal(e.Start(viper.GetString("port")))}func addPerson(c echo.Context) error { ctx := context.Background() db, err := sql.Open("postgres", "host=postgres port=5432 user=postgres dbname=postgres password=postgres sslmode=disable") if err != nil { log.Fatal(err) } queries := postgres.New(db) insertedPerson, err := queries.CreatePersons(ctx, postgres.CreatePersonsParams{ Firstname: "Mike", Lastname: "Jordan", }) if err != nil { log.Errorf("Failed to insert a person %v", err) return err } fmt.Println(insertedPerson) return c.JSONPretty(http.StatusOK, insertedPerson, " ")}queries.sql.go 片段type CreatePersonsParams struct { Firstname string Lastname string}func (q *Queries) CreatePersons(ctx context.Context, arg CreatePersonsParams) (Person, error) { row := q.db.QueryRowContext(ctx, createPersons, arg.Firstname, arg.Lastname) var i Person err := row.Scan(&i.ID, &i.Firstname, &i.Lastname) return i, err}
- 2 回答
- 0 关注
- 120 浏览
添加回答
举报
0/150
提交
取消