上一页 1 ··· 64 65 66 67 68 69 70 71 72 ··· 186 下一页
摘要: 一,定义一个日志group config/autoload/logger.php 'daily' => [ 'handler' => [ 'class' => Monolog\Handler\RotatingFileHandler::class, 'constructor' => [ 'filena 阅读全文
posted @ 2025-02-09 19:17 刘宏缔的架构森林 阅读(111) 评论(0) 推荐(0)
摘要: 一,自定义异常 global/customError.go package global // 自定义错误类型 type CustomError struct { Code int Error error } 二,抛出异常 我们在gorm的自定义log中已经处理过数据库的异常,所以在查询遇到erro 阅读全文
posted @ 2025-02-09 19:17 刘宏缔的架构森林 阅读(162) 评论(0) 推荐(0)
摘要: 一,自定义异常类 Exception/BusinessException.php 我们用官方提供的这个现成的类: <?php declare(strict_types=1); /** * This file is part of Hyperf. * * @link https://www.hyper 阅读全文
posted @ 2025-02-09 19:17 刘宏缔的架构森林 阅读(109) 评论(0) 推荐(0)
摘要: 一,遇到记录不存在时,不记录异常到日志 在建立数据库连接时指定配置 var ( DBLink *gorm.DB ) func SetupDBLink() (error) { var err error //IgnoreRecordNotFoundError: false,默认是false,设置为tr 阅读全文
posted @ 2025-02-09 19:16 刘宏缔的架构森林 阅读(213) 评论(0) 推荐(0)
摘要: 一,什么是context? 1,context是什么? context是 goroutine(协程) 的上下文,包含 goroutine 的运行状态、环境、现场等信息。context 主要用来在 goroutine 之间传递上下文信息,包括:取消信号、超时时间、截止时间、k-v 等。 2,conte 阅读全文
posted @ 2025-02-09 19:16 刘宏缔的架构森林 阅读(261) 评论(0) 推荐(0)
摘要: 一,创建middleware $ php bin/hyperf.php gen:middleware AccesslogMiddleware App\Middleware\AccesslogMiddleware created successfully. 二,配置一个日志 config/autolo 阅读全文
posted @ 2025-02-09 19:16 刘宏缔的架构森林 阅读(180) 评论(0) 推荐(0)
摘要: 一,配置 config/autoload/exceptions.php <?php declare(strict_types=1); /** * This file is part of Hyperf. * * @link https://www.hyperf.io * @document http 阅读全文
posted @ 2025-02-09 19:15 刘宏缔的架构森林 阅读(197) 评论(1) 推荐(0)
摘要: 一,安装第三方库: $ go get -u gorm.io/gorm go: added github.com/jinzhu/inflection v1.0.0 go: added github.com/jinzhu/now v1.1.5 go: added gorm.io/gorm v1.25.1 阅读全文
posted @ 2025-02-02 12:38 刘宏缔的架构森林 阅读(108) 评论(0) 推荐(0)
摘要: 一,代码 1,global/validator.go package global import "github.com/go-playground/validator/v10" //存放GetMessages()方法 type Validator interface { GetMessages() 阅读全文
posted @ 2025-01-31 17:39 刘宏缔的架构森林 阅读(290) 评论(0) 推荐(0)
摘要: 一,安装第三方库: $ go get -u github.com/go-playground/validator/v10 go: downloading github.com/go-playground/validator/v10 v10.24.0 go: downloading github.co 阅读全文
posted @ 2025-01-31 15:02 刘宏缔的架构森林 阅读(63) 评论(0) 推荐(0)
上一页 1 ··· 64 65 66 67 68 69 70 71 72 ··· 186 下一页