摘要:
一,代码 1,定义常量的类 Constants/BusinessConstants.php <?php declare(strict_types=1); /** * This file is part of Hyperf. * * @link https://www.hyperf.io * @doc 阅读全文
posted @ 2025-02-09 19:18
刘宏缔的架构森林
阅读(58)
评论(0)
推荐(0)
摘要:
一,安装hyperf/config库 $ composer require hyperf/config config()函数要用到 二,查看.env中的默认设置: 如果.env文件不存在,可以复制.env.example APP_NAME=skeleton APP_ENV=dev DB_DRIVER 阅读全文
posted @ 2025-02-09 19:17
刘宏缔的架构森林
阅读(248)
评论(0)
推荐(0)
摘要:
一,修改composer.json "autoload": { "psr-4": { "App\\": "app/" }, "files": [ "app/Functions.php" ] }, 在files数组中增加我们的函数文件 二,源代码 app/Functions.php <?php use 阅读全文
posted @ 2025-02-09 19:17
刘宏缔的架构森林
阅读(102)
评论(0)
推荐(0)
摘要:
一,定义一个日志group config/autoload/logger.php 'daily' => [ 'handler' => [ 'class' => Monolog\Handler\RotatingFileHandler::class, 'constructor' => [ 'filena 阅读全文
posted @ 2025-02-09 19:17
刘宏缔的架构森林
阅读(90)
评论(0)
推荐(0)
摘要:
一,自定义异常 global/customError.go package global // 自定义错误类型 type CustomError struct { Code int Error error } 二,抛出异常 我们在gorm的自定义log中已经处理过数据库的异常,所以在查询遇到erro 阅读全文
posted @ 2025-02-09 19:17
刘宏缔的架构森林
阅读(141)
评论(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
刘宏缔的架构森林
阅读(96)
评论(0)
推荐(0)
摘要:
一,遇到记录不存在时,不记录异常到日志 在建立数据库连接时指定配置 var ( DBLink *gorm.DB ) func SetupDBLink() (error) { var err error //IgnoreRecordNotFoundError: false,默认是false,设置为tr 阅读全文
posted @ 2025-02-09 19:16
刘宏缔的架构森林
阅读(135)
评论(0)
推荐(0)
摘要:
一,什么是context? 1,context是什么? context是 goroutine(协程) 的上下文,包含 goroutine 的运行状态、环境、现场等信息。context 主要用来在 goroutine 之间传递上下文信息,包括:取消信号、超时时间、截止时间、k-v 等。 2,conte 阅读全文
posted @ 2025-02-09 19:16
刘宏缔的架构森林
阅读(236)
评论(0)
推荐(0)
摘要:
一,创建middleware $ php bin/hyperf.php gen:middleware AccesslogMiddleware App\Middleware\AccesslogMiddleware created successfully. 二,配置一个日志 config/autolo 阅读全文
posted @ 2025-02-09 19:16
刘宏缔的架构森林
阅读(146)
评论(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
刘宏缔的架构森林
阅读(159)
评论(1)
推荐(0)
浙公网安备 33010602011771号