From f681f0bb170e9f5e794f5739b4e4671fd1999569 Mon Sep 17 00:00:00 2001 From: yanweidong Date: Tue, 23 Sep 2025 12:41:31 +0800 Subject: [PATCH] =?UTF-8?q?```=20refactor(service):=20=E4=BC=98=E5=8C=96Us?= =?UTF-8?q?e=E5=87=BD=E6=95=B0=E5=8F=82=E6=95=B0=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除Use函数中initFunc参数的指针包装,直接使用func() error类型。 简化函数内部调用逻辑,提升代码可读性和健壮性。 ``` --- service/service.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/service/service.go b/service/service.go index 19b1aa6..6b58cdd 100644 --- a/service/service.go +++ b/service/service.go @@ -108,14 +108,11 @@ func (s *Service) Gateway(grpcAddr string, httpAddr string) { http.ListenAndServe(httpAddr, s.Opts.GatewayMux) } -func (s *Service) Use(initFunc *func() error) { - // Execute the Init function if it's not nil - if initFunc != nil { - err := (*initFunc)() - if err != nil { - print.Error(err.Error()) - panic(err) - } +func (s *Service) Use(initFunc func() error) { + err := (initFunc)() + if err != nil { + print.Error(err.Error()) + panic(err) } }