This step should be familiar to everyone, so we'll keep the explanation brief.
API
app/gateway/api/user/v1/user.go
package v1
import "github.com/gogf/gf/v2/frame/g"
type LoginReq struct {
g.Meta `path:"users/login" method:"post" sm:"Login" tags:"User"`
Username string `json:"username" v:"required|length:3,12"`
Password string `json:"password" v:"required|length:6,16"`
}
type LoginRes struct {
Token string `json:"token" dc:"Add Authorization: token in header for authenticated endpoints"`
}
app/gateway/api/words/v1/words.go
package v1
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
type CreateReq struct {
g.Meta `path:"words" method:"post" sm:"Create" tags:"Word"`
Word string `json:"word" v:"required|length:1,100" dc:"Word"`
Definition string `json:"definition" v:"required|length:1,300" dc:"Word definition"`
}
type CreateRes struct {
}
type DetailReq struct {
g.Meta `path:"words/{id}" method:"get" sm:"Details" tags:"Word"`
Id uint `json:"id" v:"required"`
}
type DetailRes struct {
Id uint `json:"id"`
Word string `json:"word"`
Definition string `json:"definition"`
ExampleSentence string `json:"exampleSentence"`
ChineseTranslation string `json:"chineseTranslation"`
Pronunciation string `json:"pronunciation"`
CreatedAt *gtime.Time `json:"createdAt"`
UpdatedAt *gtime.Time `json:"updatedAt"`
}
Controller
Execute the following command to generate controllers:
$ gf gen ctrl
generated: D:\project\proxima\app\gateway\api\user\user.go
generated: D:\project\proxima\app\gateway\internal\controller\user\user.go
generated: D:\project\proxima\app\gateway\internal\controller\user\user_new.go
generated: D:\project\proxima\app\gateway\internal\controller\user\user_v1_login.go
generated: D:\project\proxima\app\gateway\api\words\words.go
generated: D:\project\proxima\app\gateway\internal\controller\words\words.go
generated: D:\project\proxima\app\gateway\internal\controller\words\words_new.go
generated: D:\project\proxima\app\gateway\internal\controller\words\words_v1_create.go
generated: D:\project\proxima\app\gateway\internal\controller\words\words_v1_detail.go
done!