feat: direct call download api by cgo

This commit is contained in:
liwei committed 2024-11-26 23:32:54 +08:00
1 parent 85fe92a378
commit 467ada5500
22 files changed
+1040 -709

No files matched your search

+22 -14
View File
@@ -1,29 +1,37 @@
package main
/*
#include <stdlib.h>
*/
import "C"
import (
"encoding/json"
"github.com/GopeedLab/gopeed/pkg/rest"
"github.com/GopeedLab/gopeed/pkg/rest/model"
"github.com/GopeedLab/gopeed/bind"
"github.com/GopeedLab/gopeed/pkg/api"
"github.com/GopeedLab/gopeed/pkg/api/model"
"unsafe"
)
func main() {}
//export Start
func Start(cfg *C.char) (int, *C.char) {
//export Create
func Create(cfg *C.char) *C.char {
var config model.StartConfig
if err := json.Unmarshal([]byte(C.GoString(cfg)), &config); err != nil {
return 0, C.CString(err.Error())
return C.CString(bind.BuildResult(err))
}
config.ProductionMode = true
realPort, err := rest.Start(&config)
if err != nil {
return 0, C.CString(err.Error())
}
return realPort, nil
defer C.free(unsafe.Pointer(cfg))
return C.CString(bind.Create(&config))
}
//export Stop
func Stop() {
rest.Stop()
//export Invoke
func Invoke(index int, req *C.char) *C.char {
var request api.Request
if err := json.Unmarshal([]byte(C.GoString(req)), &request); err != nil {
return C.CString(bind.BuildResult(err))
}
defer C.free(unsafe.Pointer(req))
return C.CString(bind.Invoke(index, &request))
}