html或者说是模板的控制
以下是是系统的设置
server:
address: ":8000"
serverRoot: "resource/public" #这里要加上,为以后的静态文件的引入准备
openapiPath: "/api.json"
swaggerPath: "/swagger"
cookieMaxAge: "365d"
cookiePath: "/"
cookieDomain: ""
sessionMaxAge: "24h"
sessionIdName: "gfsessionid"
sessionCookieOutput: true
sessionPath: "/tmp/gsessions"
logPath: ""
logStdout: true
errorStack: true
errorLogEnabled: true
errorLogPattern: "error-{Ymd}.log"
accessLogEnabled: false
accessLogPattern: "access-{Ymd}.log"
pprofEnabled: false
pprofPattern: ""
clientMaxBodySize: 810241024
formParsingMemory: 1048576
nameToUriType: 0
routeOverWrite: false
dumpRouterMap: true
graceful: false
gracefulTimeout: 2
logger:
path: ""
file: "{Y-m-d}.log"
prefix: ""
level: "all"
timeFormat: "2006-01-02T15:04:05"
ctxKeys: []
header: true
stdout: true
database:
default:
type: "mysql"
debug: "true"
dryRun: "false"
charset: "utf8mb4"
maxIdle: "0"
maxOpen: "10"
maxLifetime: "30s"
host: "127.0.0.1"
port: "3306"
user: "root"
pass: "123456"
name: "web"
timezone: "Local"
redis:
default:
address: 127.0.0.1:6379
db: 0
pass: 123456
maxActive: 50
修改controller,调用相关的模板
// Package admin 提供后台管理相关的控制器
package admin
import (
"context"
"web/api/admin"
"github.com/gogf/gf/v2/frame/g"
)
// 实现登录控制器
type Controller struct{}
// New 创建一个新的登录控制器实例
func New() admin.ILogin {
return &Controller{}
}
// Login 处理管理员登录请求
// ctx: 上下文
// req: 登录请求参数
// 返回登录响应和可能的错误
func (c *Controller) Login(ctx context.Context, req *admin.LoginReq) (res *admin.LoginRes, err error) {
// 获取请求对象
// 调用模版
g.RequestFromCtx(ctx).Response.WriteTpl("admin/index.html")
return
}
func (c *Controller) Logout(ctx context.Context, req *admin.LogoutReq) (res *admin.LogoutRes, err error) {
g.RequestFromCtx(ctx).Response.Writeln("Logout success!")
return
}
修改静态文件的图片,js css一类的调用路径:
如下图:
运行效果如下: