我使用Go作为我的后端服务器和Javascript作为我的前端,我以前成功地使用http在Go中的IPC中本地托管一些简单的数据,然后在我的表中从Javascript中的本地主机URL获取和检索.但现在我遇到了麻烦,试图设置一种服务和检索数据的方式使用飞行.
所以,我的问题主要是如何在Go后端本地设置Apache箭头飞行服务器(我的箭头记录是发送的数据),然后在Javascript前端检索这些数据?
代码从我的main. go文件设置数据:
import (
"fmt"
"github.com/apache/arrow/go/v16/arrow"
"github.com/apache/arrow/go/v16/arrow/array"
"github.com/apache/arrow/go/v16/arrow/flight"
"github.com/apache/arrow/go/v16/arrow/memory"
"log"
"net/http"
)
var metadata = arrow.NewMetadata(
[]string{"type", "round", "date"},
[]string{"int", "1dp", "2024/03/30"},
)
var schema = arrow.NewSchema([]arrow.Field{
{Name: "X", Type: arrow.PrimitiveTypes.Int32},
{Name: "X + 5", Type: arrow.PrimitiveTypes.Int32},
}, &metadata)
func GetPutData() arrow.Record {
pool := memory.NewGoAllocator()
recordBuilder := array.NewRecordBuilder(pool, schema)
recordBuilder.Field(0).(*array.Int32Builder).AppendValues([]int32{1, 2, 3, 4, 5}, nil)
recordBuilder.Field(1).(*array.Int32Builder).AppendValues([]int32{6, 7, 8, 9, 10}, nil)
record := recordBuilder.NewRecord()
return record
}
我想我的主要方法是这样的:
func main() {
// Create a Flight server locally with data from GetPutData
rec := GetPutData()
// Start flight server
fmt.Println("Flight serving on port...")
}
然后在前端,我想象它会是这样的代码:
import * as Arrow from 'apache-arrow';
import * as Flight from 'apache-arrow/flight';
async function runExample(url) {
const table = // Fetch data from flight server
console.table(table.toArray());
console.log(table.schema)
console.log(table.data)
}
runExample(url);
我试过使用之前的例子,但它们似乎过时了?但我也试着查看文档here,但我发现旧方法已经改变了什么是令人难以置信的混乱,等等,而且我目前不担心添加任何身份验证.