84 lines
2.9 KiB
Dart
84 lines
2.9 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:EasyDartModule/EasyDartModule.dart';
|
|
import 'package:EasyDartModule/base/database/DataBase.dart';
|
|
import 'package:EasyDartModule/base/discovery/Discovery.dart';
|
|
import 'package:EasyDartModule/base/logger/Logger.dart';
|
|
import 'package:EasyDartModule/base/storage/Storage.dart';
|
|
import 'package:EasyDartModule/base/webserver/WebServer.dart';
|
|
|
|
void main() async {
|
|
//初始化服务发现
|
|
EasyDartModule.init(
|
|
discoveryConfig: DiscoveryConfig(
|
|
host: "http://10.20.1.2:8848",
|
|
namespaceId: "d3b43bfe-f584-4b8f-a390-353abc69c856"));
|
|
String ip = "10.20.0.80";
|
|
int port = 9100;
|
|
String sn = "test-server";
|
|
//注册实例
|
|
await EasyDartModule.discovery.registerInstance(sn, ip, port);
|
|
|
|
//查询日志服务配置信息
|
|
String logger = await EasyDartModule.discovery.getConfig("logger");
|
|
var loggerConfig = jsonDecode(logger);
|
|
//查询数据库配置信息
|
|
String mongodb = await EasyDartModule.discovery.getConfig("mongodb");
|
|
var mongodbConfig = jsonDecode(mongodb);
|
|
//查询存储配置
|
|
String storage = await EasyDartModule.discovery.getConfig("storage");
|
|
var storageConfig = jsonDecode(storage);
|
|
|
|
EasyDartModule.init(
|
|
loggerConfig: LoggerConfig(host: loggerConfig["host"], serviceName: sn),
|
|
dataBaseConfig: DataBaseConfig(
|
|
host: mongodbConfig["host"],
|
|
userName: mongodbConfig["userName"],
|
|
password: mongodbConfig["password"],
|
|
dataBase: mongodbConfig["dataBase"]),
|
|
storageConfig: StorageConfig(
|
|
host: storageConfig["host"],
|
|
port: storageConfig["port"],
|
|
accessKey: storageConfig["accessKey"],
|
|
secretKey: storageConfig["secretKey"]));
|
|
|
|
EasyDartModule.webServer.addHandler(TestController());
|
|
EasyDartModule.webServer.start(port);
|
|
|
|
//测试db
|
|
Future.delayed(Duration(seconds: 5), () {
|
|
var db = EasyDartModule.dataBase;
|
|
var r = db.query("uc_sys_user");
|
|
print(r);
|
|
});
|
|
|
|
//测试minio
|
|
String bucketName = "test-bu";
|
|
String objectName = "/aa/bb/objectName.gif";
|
|
// EasyDartModule.storage.createBucket(bucketName).then((v) {
|
|
// EasyDartModule.storage
|
|
// .uploadObject(
|
|
// bucketName,
|
|
// objectName,
|
|
// File("F:\\qq\\11603720\\Image\\Group2\\\$C\\WL\\\$CWLJBX}@Z7E487L2J4MH`G.gif")
|
|
// .readAsBytesSync())
|
|
// .then((path) {
|
|
// print("上传文件: $path");
|
|
// EasyDartModule.storage.getObject(bucketName, objectName).then((data) {
|
|
// print("下载文件");
|
|
// File("a.gif").writeAsBytesSync(data);
|
|
// print("下载完毕");
|
|
// });
|
|
// });
|
|
// // EasyDartModule.storage.deleteObject(bucketName, "objectName");
|
|
// });
|
|
}
|
|
|
|
@RequestMapping(path: "/test")
|
|
class TestController {
|
|
@RequestMapping(path: "/tt", method: HttpMethod.GET)
|
|
Response test(Request request) {
|
|
return Response(200, body: "ok");
|
|
}
|
|
}
|