Admin Plugins
Pages
CI tests
Architecture
Development
Template Development
Quick Start
GoAdmin makes it easy to use in various web frameworks through various adapters. Currently supported web frameworks are:
You can choose the framework which your own project is using. If there is no framework you like, please feel free to give us an issue or pr!
Let's take the gin framework for example to demonstrate the build process.

main.go

Firstly, create a new main.go file in your project folder with the following contents:
1
package main
2
3
import (
4
_ "github.com/GoAdminGroup/go-admin/adapter/gin" // Import the adapter, it must be imported. If it is not imported, you need to define it yourself.
5
_ "github.com/GoAdminGroup/themes/adminlte" // Import the theme
6
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql" // Import the sql driver
7
8
"github.com/GoAdminGroup/go-admin/engine"
9
"github.com/GoAdminGroup/go-admin/modules/config"
10
"github.com/GoAdminGroup/go-admin/modules/language"
11
"github.com/gin-gonic/gin"
12
)
13
14
func main() {
15
r := gin.Default()
16
17
// Instantiate a GoAdmin engine object.
18
eng := engine.Default()
19
20
// GoAdmin global configuration, can also be imported as a json file.
21
cfg := config.Config{
22
Databases: []config.Database{
23
{
24
Host: "127.0.0.1",
25
Port: "3306",
26
User: "root",
27
Pwd: "root",
28
Name: "godmin",
29
MaxIdleCon: 50,
30
MaxOpenCon: 150,
31
Driver: "mysql",
32
},
33
},
34
UrlPrefix: "admin", // The url prefix of the website.
35
// Store must be set and guaranteed to have write access, otherwise new administrator users cannot be added.
36
Store: config.Store{
37
Path: "./uploads",
38
Prefix: "uploads",
39
},
40
Language: language.EN,
41
}
42
43
// Add configuration and plugins, use the Use method to mount to the web framework.
44
_ = eng.AddConfig(cfg).
45
Use(r)
46
47
_ = r.Run(":9033")
48
}
Copied!
Please pay attention to the above code and comments, the corresponding steps are added to the comments, it is simple to use. Summary of up to five steps:
  • Import the adapter, the theme and the sql driver
  • Set global configuration items
  • Mounted to the web framework
Then execute go run main.go to run the code and access: http://localhost:9033/admin/login default account: admin default password: admin

Add your own business table for management

See:

Global configuration item description

1
package config
2
3
import (
4
"html/template"
5
)
6
7
// Database is a type of database connection config.
8
// Because a little difference of different database driver.
9
// The Config has multiple options but may be not used.
10
// Such as the sqlite driver only use the FILE option which
11
// can be ignored when the driver is mysql.
12
//
13
// If the Dsn is configured, when driver is mysql/postgresql/
14
// mssql, the other configurations will be ignored, except for
15
// MaxIdleCon and MaxOpenCon.
16
type Database struct {
17
Host string
18
Port string
19
User string
20
Pwd string
21
Name string
22
MaxIdleCon int
23
MaxOpenCon int
24
Driver string
25
File string
26
Dsn string
27
}
28
29
// Database configuration
30
// which is a map where key is the name of the database connection and
31
// value is the corresponding data configuration.
32
// The key is the default database is the default database, but also
33
// the database used by the framework, and you can configure multiple
34
// databases to be used by your business tables to manage different databases.
35
type DatabaseList map[string]Database
36
37
// Store is the file store config. Path is the local store path.
38
// and prefix is the url prefix used to visit it.
39
type Store struct {
40
Path string
41
Prefix string
42
}
43
44
// Config type is the global config of goAdmin. It will be
45
// initialized in the engine.
46
type Config struct {
47
// An map supports multi database connection. The first
48
// element of Databases is the default connection. See the
49
// file connection.go.
50
Databases DatabaseList `json:"database"`
51
52
// The cookie domain used in the auth modules. see
53
// the session.go.
54
Domain string `json:"domain"`
55
56
// Used to set as the localize language which show in the
57
// interface.
58
Language string `json:"language"`
59
60
// The global url prefix.
61
UrlPrefix string `json:"prefix"`
62
63
// The theme name of template.
64
Theme string `json:"theme"`
65
66
// The path where files will be stored into.
67
Store Store `json:"store"`
68
69
// The title of web page.
70
Title string `json:"title"`
71
72
// Logo is the top text in the sidebar.
73
Logo template.HTML `json:"logo"`
74
75
// Mini-logo is the top text in the sidebar when folding.
76
MiniLogo template.HTML `json:"mini_logo"`
77
78
// The url redirect to after login
79
IndexUrl string `json:"index"`
80
81
// Debug mode
82
Debug bool `json:"debug"`
83
84
// Env is the environment, which maybe local, test, prod.
85
Env string
86
87
// Info log path
88
InfoLogPath string `json:"info_log"`
89
90
// Error log path
91
ErrorLogPath string `json:"error_log"`
92
93
// Access log path
94
AccessLogPath string `json:"access_log"`
95
96
// Sql operator record log switch
97
SqlLog bool `json:"sql_log"`
98
99
AccessLogOff bool
100
InfoLogOff bool
101
ErrorLogOff bool
102
103
// Color scheme
104
ColorScheme string `json:"color_scheme"`
105
106
// Session life time, unit is second.
107
SessionLifeTime int `json:"session_life_time"`
108
109
// Cdn link of assets
110
AssetUrl string `json:"asset_url"`
111
112
// File upload engine, default "local"
113
FileUploadEngine FileUploadEngine `json:"file_upload_engine"`
114
115
// Custom html in the tag head.
116
CustomHeadHtml template.HTML `json:"custom_head_html"`
117
118
// Custom html after body.
119
CustomFootHtml template.HTML `json:"custom_foot_html"`
120
121
// Login page title
122
LoginTitle string `json:"login_title"`
123
124
// Login page logo
125
LoginLogo template.HTML `json:"login_logo"`
126
127
// Auth user table
128
AuthUserTable string `json:"auth_user_table",yaml:"auth_user_table",ini:"auth_user_table"`
129
130
// Extra config info
131
Extra ExtraInfo `json:"extra",yaml:"extra",ini:"extra"`
132
133
// Page animation
134
Animation PageAnimation `json:"animation",yaml:"animation",ini:"animation"`
135
136
// Limit login with different IPs
137
NoLimitLoginIP bool `json:"no_limit_login_ip",yaml:"no_limit_login_ip",ini:"no_limit_login_ip"`
138
139
// When site off is true, website will be closed
140
SiteOff bool `json:"site_off",yaml:"site_off",ini:"site_off"`
141
142
// Hide config center entrance flag
143
HideConfigCenterEntrance bool `json:"hide_config_center_entrance",yaml:"hide_config_center_entrance",ini:"hide_config_center_entrance"`
144
145
// Hide app info entrance flag
146
HideAppInfoEntrance bool `json:"hide_app_info_entrance",yaml:"hide_app_info_entrance",ini:"hide_app_info_entrance"`
147
148
// Update Process Function
149
UpdateProcessFn UpdateConfigProcessFn `json:"-",yaml:"-",ini:"-"`
150
151
// Is open admin plugin json api
152
OpenAdminApi bool `json:"open_admin_api",yaml:"open_admin_api",ini:"open_admin_api"`
153
154
HideVisitorUserCenterEntrance bool `json:"hide_visitor_user_center_entrance",yaml:"hide_visitor_user_center_entrance",ini:"hide_visitor_user_center_entrance"`
155
156
// Custom 404 Page
157
Custom404HTML template.HTML `json:"custom_404_html,omitempty",yaml:"custom_404_html",ini:"custom_404_html"`
158
159
// Custom 403 Page
160
Custom403HTML template.HTML `json:"custom_403_html,omitempty",yaml:"custom_403_html",ini:"custom_403_html"`
161
162
// Custom 500 Page
163
Custom500HTML template.HTML `json:"custom_500_html,omitempty",yaml:"custom_500_html",ini:"custom_500_html"`
164
}
Copied!
Logger configuration:
1
type Logger struct {
2
Encoder EncoderCfg `json:"encoder",yaml:"encoder",ini:"encoder"`
3
Rotate RotateCfg `json:"rotate",yaml:"rotate",ini:"rotate"`
4
Level int8 `json:"level",yaml:"level",ini:"level"`
5
}
6
7
// Logger encode configuration
8
type EncoderCfg struct {
9
// TimeKey, default is ts
10
TimeKey string `json:"time_key",yaml:"time_key",ini:"time_key"`
11
// LevelKey, default is level
12
LevelKey string `json:"level_key",yaml:"level_key",ini:"level_key"`
13
// LevelKey, default is logger
14
NameKey string `json:"name_key",yaml:"name_key",ini:"name_key"`
15
// CallerKey caller
16
CallerKey string `json:"caller_key",yaml:"caller_key",ini:"caller_key"`
17
// MessageKey, default is msg
18
MessageKey string `json:"message_key",yaml:"message_key",ini:"message_key"`
19
// StacktraceKey, default is stacktrace
20
StacktraceKey string `json:"stacktrace_key",yaml:"stacktrace_key",ini:"stacktrace_key"`
21
// Level Encoder, default is CapticalColor
22
Level string `json:"level",yaml:"level",ini:"level"`
23
// Time Encoder, default is ISO8601
24
Time string `json:"time",yaml:"time",ini:"time"`
25
// Duration Encoder, default is seconds
26
Duration string `json:"duration",yaml:"duration",ini:"duration"`
27
// Caller Encoder, default is short
28
Caller string `json:"caller",yaml:"caller",ini:"caller"`
29
// Encoding Format, default is console
30
Encoding string `json:"encoding",yaml:"encoding",ini:"encoding"`
31
}
32
33
// Logger rotate configuration
34
type RotateCfg struct {
35
// Max file size, unit is m, default is 10m
36
MaxSize int `json:"max_size",yaml:"max_size",ini:"max_size"`
37
// Max file backups, default is 5
38
MaxBackups int `json:"max_backups",yaml:"max_backups",ini:"max_backups"`
39
// Max store age, unit is day, default is 30 day
40
MaxAge int `json:"max_age",yaml:"max_age",ini:"max_age"`
41
// Is compress or not, defaul is false
42
Compress bool `json:"compress",yaml:"compress",ini:"compress"`
43
}
Copied!
English is not my main language. If any typo or wrong translation you found, you can help to translate in github here. I will very appreciate it.
Last modified 1yr ago