go-admingo-admin
  • Guide
  • Development
    • Advanced
    • Commands
  • Advanced
  • Help
  • GitHub
  • Changelog
⌘ K
Standard Practice
Standard Module Development
Backend Basics
Backend Directory Structure
Backend Config File
Starting the Backend
Frontend Basics
Frontend Directory Structure
Frontend Config File
Starting the Frontend
Development Patterns
Actions Pattern
Hand-Written Pattern
First API Endpoint
Layered Development
API Layer
Service Layer
DTO Definitions
Model Definitions
Router Registration
Multi-Environment Config
Database Table Conventions
Data Permissions
Response Format
Code Generation
Pre-Generation Setup
Generating Business Code
One-Click Menu Generation
Binding APIs to the Menu
Configuring Role Permissions
Verifying the Feature
Generating Code with an LLM
Advanced Capabilities
Runtime Core API
Authentication & Authorization
Logging
Request Tracing
Cache
Queue
File Upload
Rate Limiting
Scheduled Jobs
Air Hot Reload
Swagger Docs
Code Generation Tool
Last updated:
Open-source MIT Licensed | Copyright © 2020-present
Powered by go-admin-team

TABLE OF CONTENTS

‌
‌
‌
‌

Model Definitions

A Model is a GORM struct describing a table's schema and field mapping — it's the vehicle for database interaction.

INFO

Every module needs this layer, whether it uses the Actions Pattern or the Hand-Written Pattern.

package and import

Grouped in three blocks: standard library, third-party, project-internal:

go
package models
import (
"go-admin/common/models"
)

The Table Struct

go
type SysPost struct {
PostId int `gorm:"primaryKey;autoIncrement" json:"postId"` // post ID
PostName string `gorm:"size:128;" json:"postName"` // post name
PostCode string `gorm:"size:128;" json:"postCode"` // post code
Sort int `gorm:"size:4;" json:"sort"` // sort order
Status int `gorm:"size:4;" json:"status"` // status
Remark string `gorm:"size:255;" json:"remark"` // remark
models.ControlBy
models.ModelTime
DataScope string `gorm:"-" json:"dataScope"`
Params string `gorm:"-" json:"params"`
}
func (SysPost) TableName() string {
return "sys_post"
}
func (e *SysPost) Generate() models.ActiveRecord {
o := *e
return &o
}
func (e *SysPost) GetId() interface{} {
return e.PostId
}

WARNING

Where to get help:

If anything in this guide is unclear, please open an issue.