我在一些文件传输过程中使用“wso2/ftp”包,并且在我的主 .bal 文件中有一个 ftp:Client 端点,如下所示。
endpoint ftp:Client server1 {
protocol: ftp:FTP,
host:<ip_address>,
port:21,
secureSocket: {
basicAuth: {
username: <user_name>,
password: <password>
}
}
};
将此端点传递给另一个 .bal 文件中的公共(public)函数的方法有哪些。
尝试这样做,
function functionName(ftp:Client server1){
functionFromOtherBalFile(server1);
}
但出现错误
invalid action invocation, expected an endpoint
来自包含“functionFromOtherBalFile”实现的第二个 .bal 文件。
“functionFromOtherBalFile”的实现:
public function functionFromOtherBalFile(ftp:Client server1){
var readFile=server1->get("/file.txt");
match readFile{
error err=>{
io:println("An error occured");
return err;
}
io:ByteChannel =>{
io:println("Success");
return readFile;
}
}
}
有人可以帮我解决这个问题吗
最佳答案
此处介绍了如何将端点作为参数传递给函数。
import ballerina/http;
import ballerina/io;
function main (string... args) {
endpoint http:Client cheapAir {
url: "http://localhost:9090/CheapAir"
};
invoke(cheapAir);
}
function invoke(http:Client client) {
endpoint http:Client myEP = client;
json reqPayload = {firstName:"Sameera", lastName:"Jayasoma"};
http:Response response = check myEP -> post("/bookFlight", reqPayload);
json resPayload = check response.getJsonPayload();
io:println(resPayload);
}
关于ftp - 如何将端点作为参数传递给 Ballerina 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51351030/