feat: direct call download api by cgo dart

This commit is contained in:
liwei committed 2024-12-02 00:39:28 +08:00
1 parent 467ada5500
commit 91dfd78b77
71 files changed
+6936 -1883

No files matched your search

+11 -4
View File
@@ -22,7 +22,7 @@ import (
const instanceKey string = "apiInstance"
func ListenHttp(httpCfg *base.DownloaderHttpConfig, ai *Instance) error {
func ListenHttp(httpCfg *base.DownloaderHttpConfig, ai *Instance) (*model.HttpListenResult, func(), error) {
var r = mux.NewRouter()
r.Methods(http.MethodGet).Path("/api/v1/info").HandlerFunc(Info)
r.Methods(http.MethodPost).Path("/api/v1/resolve").HandlerFunc(Resolve)
@@ -106,12 +106,19 @@ func ListenHttp(httpCfg *base.DownloaderHttpConfig, ai *Instance) error {
listener, err := net.Listen("tcp", net.JoinHostPort(httpCfg.Host, fmt.Sprintf("%d", httpCfg.Port)))
if err != nil {
return err
return nil, nil, err
}
ai.srv = srv
ai.listener = listener
return nil
return &model.HttpListenResult{
Host: httpCfg.Host,
Port: listener.Addr().(*net.TCPAddr).Port,
}, func() {
if err := srv.Serve(listener); err != nil && !errors.Is(err, http.ErrServerClosed) {
ai.downloader.Logger.Error().Err(err).Msg("http server listen error")
}
}, nil
}
func getInstance(r *http.Request) *Instance {