🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[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, ), ```