Serie: Go
go
40 líneas
· Actualizado 2026-04-18
dto.go
Go/Baasid/internal/dto/dto.go
// Package dto defines JSON request/response shapes decoupled from GORM models.
//
// Keeping transport types separate from persistence models lets you rename
// database columns without breaking the public API contract from the spec.
package dto
// LoginRequest is the JSON body for POST /auth/login.
type LoginRequest struct {
Account string `json:"account" example:"admin"`
Password string `json:"password" example:"password123"`
}
// LoginResponse is returned in the JSON body on successful login (HTTP 200).
// The JWT itself is returned in the Authorization response header per spec.
type LoginResponse struct {
Account string `json:"account" example:"admin"`
Name string `json:"name" example:"系統管理員"`
}
// GoodsCreateRequest is the JSON body for POST /goods/add.
type GoodsCreateRequest struct {
GoodsName string `json:"goods_name" example:"Sample Product"`
}
// GoodsUpdateRequest is the JSON body for PUT /goods/{id}.
type GoodsUpdateRequest struct {
GoodsName string `json:"goods_name" example:"Updated name"`
}
// GoodsResponse is the canonical JSON representation of a product in API responses.
type GoodsResponse struct {
ID string `json:"_id" example:"550e8400-e29b-41d4-a716-446655440000"`
GoodsName string `json:"goods_name" example:"Sample Product"`
}
// ErrorMessage is a simple JSON envelope for non-2xx errors where we still
// want a machine-readable body (Echo's default string body is fine too).
type ErrorMessage struct {
Message string `json:"message"`
}
Artículos relacionados
Go
go
Actualizado 2026-04-18
main.go
main.go — go source code from the Go learning materials (Go/Baasid/cmd/hashpw/main.go).
Leer artículo →
Go
go
Actualizado 2026-04-18
main.go
main.go — go source code from the Go learning materials (Go/Baasid/cmd/server/main.go).
Leer artículo →
Go
go
Actualizado 2026-04-18
docs.go
docs.go — go source code from the Go learning materials (Go/Baasid/docs/docs.go).
Leer artículo →
Go
go
Actualizado 2026-04-18
jwt.go
jwt.go — go source code from the Go learning materials (Go/Baasid/internal/auth/jwt.go).
Leer artículo →
Go
go
Actualizado 2026-04-18
password.go
password.go — go source code from the Go learning materials (Go/Baasid/internal/auth/password.go).
Leer artículo →
Go
go
Actualizado 2026-04-18
password_test.go
password_test.go — go source code from the Go learning materials (Go/Baasid/internal/auth/password_test.go).
Leer artículo →