生成 api檔案

laosan123發表於2021-10-21

進入需要生成api的路徑

luwei@luweideMacBook-Pro-2 api % pwd
/Users/myself/Golang/common_project/src/shorturl/api
luwei@luweideMacBook-Pro-2 api % 
  • 開始生成
    luwei@luweideMacBook-Pro-2 api % goctl api -o shorturl.api
    Done.
    luwei@luweideMacBook-Pro-2 api % pwd
    /Users/myself/Golang/common_project/src/shorturl/api
    luwei@luweideMacBook-Pro-2 api % ls
    shorturl.api
    luwei@luweideMacBook-Pro-2 api % 

預設內容


syntax = "v1"

info(
   title: // TODO: add title
  desc: // TODO: add description
  author: "donglei"
  email: "2781897595@qq.com"
)

type request {
   // TODO: add members here and delete this comment
}

type response {
   // TODO: add members here and delete this comment
}

service shorturl-api {
   @handler GetUser // TODO: set handler name and delete this comment
  get /users/id/:userId(request) returns(response)

   @handler CreateUser // TODO: set handler name and delete this comment
  post /users/create(request)
}

報錯 field para1 is not set

這樣會報錯
提示 field para1 is not set

type Request1 {
    //    Para1 string `json:"para1,optional"`
    Para1 string `json:"para1"`
}

這樣不會
type Request1 {
      Para1 string `json:"para1,optional"`
  //Para1 string `json:"para1"`
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章