亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我正在使用 go openAPI 進行測試

我正在使用 go openAPI 進行測試

Go
慕婉清6462132 2022-12-13 16:13:35
我正在使用 OpenApi 進行測試,并以https://github.com/d-vignesh/Todo-App-with-OpenAPI為例,但如果我運行它,我會收到以下錯誤:.\main.go:9:77: undefined: GetTodosParams.\main.go:31:19: undefined: Handler如果我刪除 API-Definition 中的 GetTodosParams 并生成新文件,我可以減少處理程序錯誤 - 但我不明白處理程序未定義的問題:type TodoServer struct{}func (t TodoServer) GetTodos(w http.ResponseWriter, r *http.Request) {    // our logic to retrieve all todos from a persistent layer    w.WriteHeader(http.StatusOK)}func (t TodoServer) CreateTodo(w http.ResponseWriter, r *http.Request) {    // our logic to store the todo into a persistent layer}func (t TodoServer) DeleteTodo(w http.ResponseWriter, r *http.Request, todoId int32) {    // our logic to delete a todo from the persistent layer}func (t TodoServer) UpdateTodo(w http.ResponseWriter, r *http.Request, todoId int32) {    // our logic to update the todo.}func main() {    s := TodoServer{}    h := Handler(s)    http.ListenAndServe(":3000", h)}我可以將每個 handlefunc() 的句柄字符串鏈接到一個函數,但我想使用 TodoServer 因為主包中有 Serverinterface 的類似接口函數type ServerInterface interface {    // (GET /todos)    GetTodos(w http.ResponseWriter, r *http.Request)    // (POST /todos)    CreateTodo(w http.ResponseWriter, r *http.Request)    // (DELETE /todos/{todoId})    DeleteTodo(w http.ResponseWriter, r *http.Request, todoId int32)    // (PUT /todos/{todoId})    UpdateTodo(w http.ResponseWriter, r *http.Request, todoId int32)}相反,我可以使用 net/http 的標準 Servrhttp 啟動它,但這無助于理解為什么接口功能不起作用
查看完整描述

1 回答

?
小唯快跑啊

TA貢獻1863條經驗 獲得超2個贊

main.go我猜您正在嘗試以已棄用的非模塊方式運行該文件。試試下面的食譜。


克隆存儲庫:


git clone https://github.com/d-vignesh/Todo-App-with-OpenAPI

cd Todo-App-with-OpenAPI/

像這樣運行它:


go run github.com/d-vignesh/Openapi-todo-app

像這樣構建它:


go install github.com/d-vignesh/Openapi-todo-app


# Then run the executable:

Openapi-todo-app


查看完整回答
反對 回復 2022-12-13
  • 1 回答
  • 0 關注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號