type User struct { ID int db:"id"` FamilyName string db:"family_name" validate:"require,max=50"` GivenName string db:"given_name" validate:"require,max=50"` Created time.Time db:"created"` Modified time.Time db:"modified"` } func (u *User) GetFullName() string { return u.FamilyName + " " + u.GivenName } User model を構造体として定義
( // লུ ) type UserViewService interface { Run(input UserViewInput) (UserViewOutput, *Error) } type UserViewInput struct { ID int } type UserViewOutput struct { User model.User } type Error struct { Code string Message string Status int Detail map[string]string }
(UserViewOutput, *Error) } type UserViewInput struct { ID int } type UserViewOutput struct { User model.User } type Error struct { Code string Message string Status int Detail map[string]string } service package の実装 ひとつのServiceごとにInterface型を定義
( // ུ ) type UserViewController struct { Service service.UserViewService } type UserViewRequest struct { ID int `json:"id"` } type UserViewResponse struct { ID int `json:"id"` FullName string `json:"full_name"` }
library which provides a set of extensions on go’s standard database/sql library. • See also: https://github.com/jmoiron/sqlx • Merits • Marshal rows into structs