<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 工具包插件 插件是將外部代碼集成到Micro工具箱的一種方式。這與Micro插件完全分開。這里使用的插件,允許您在工具包中添加額外的標志,命令和HTTP處理程序。 ## 怎么運行的? 在`micro/plugin`下有一個全局插件管理器,它包含整個工具包中使用的插件。可以通過調用`plugin.Register`來注冊插件。每個組件(api,web,sidecar,cli,bot)都有一個單獨的插件管理器,用于注冊只作為該組件一部分的添加插件。它們可以通過稱為`api.Register`,`web.Register`等以相同的方式使用。 這是接口 ``` // Plugin is the interface for plugins to micro. It differs from go-micro in that it's for // the micro API, Web, Sidecar, CLI. It's a method of building middleware for the HTTP side. type Plugin interface { // Global Flags Flags() []cli.Flag // Sub-commands Commands() []cli.Command // Handle is the middleware handler for HTTP requests. We pass in // the existing handler so it can be wrapped to create a call chain. Handler() Handler // Init called when command line args are parsed. // The initialised cli.Context is passed in. Init(*cli.Context) error // Name of the plugin String() string } // Manager is the plugin manager which stores plugins and allows them to be retrieved. // This is used by all the components of micro. type Manager interface { Plugins() map[string]Plugin Register(name string, plugin Plugin) error } // Handler is the plugin middleware handler which wraps an existing http.Handler passed in. // Its the responsibility of the Handler to call the next http.Handler in the chain. type Handler func(http.Handler) http.Handler ``` ## 如何使用它 這里有一個簡單的插件示例,它添加一個標志,然后打印該值。 ### 插件 在頂級目錄中創建一個plugin.go文件。 ``` package main import ( "log" "github.com/micro/cli" "github.com/micro/micro/plugin" ) func init() { plugin.Register(plugin.NewPlugin( plugin.WithName("example"), plugin.WithFlag(cli.StringFlag{ Name: "example_flag", Usage: "This is an example plugin flag", EnvVar: "EXAMPLE_FLAG", Value: "avalue", }), plugin.WithInit(func(ctx *cli.Context) error { log.Println("Got value for example_flag", ctx.String("example_flag")) return nil }), )) } ``` ### 構建代碼 只需使用該插件構建micro。 ``` go build -o micro ./main.go ./plugin.go ``` ## 知識庫 該工具包的插件可以在中找到[github.com/micro/go-plugins/micro](https://github.com/micro/go-plugins/tree/master/micro)。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看