ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的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, ), ```