企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] > [参考](https://uber-go.github.io/fx/get-started/registration.html) ## 概述 有时候,初始化函数是接口函数 ``` type Route interface { http.Handler // Pattern reports the path at which this is registered. Pattern() string } func (*EchoHandler) Pattern() string { return "/echo" } func NewServeMux(route Route) *http.ServeMux { mux := http.NewServeMux() mux.Handle(route.Pattern(), route) return mux } // main fx.Provide( NewHTTPServer, NewServeMux, fx.Annotate( NewEchoHandler, fx.As(new(Route)), ), zap.NewExample, ), ```