import 'package:EasyDartModule/EasyDartModule.dart'; abstract class WebServer { static late WebServer _webServer; static WebServer getInstance() { return _webServer; } static void setInstance(WebServer server) { _webServer = server; } void start(int port, {Response? Function(Request, Map)? interceptor, Future Function(String?)? tokenCheck}); void stop(); void addHandler(handler); } enum HttpMethod { GET, POST, PUT, DELETE, ALL, WS, ; static HttpMethod valueOf(String type) { var tmp = HttpMethod.values.where((t) => t.name == type).toList(); if (tmp.isEmpty) { return HttpMethod.ALL; } return tmp[0]; } } enum HttpResponseType { HTML("text/html; charset=utf-8"), TEXT("text/plain; charset=utf-8"), XML("text/xml; charset=utf-8"), JSON("application/json; charset=utf-8"), BINARY("application/octet-stream"), ; final String type; const HttpResponseType(this.type); static HttpResponseType valueOf(String type) { var tmp = HttpResponseType.values.where((t) => t.type == type).toList(); if (tmp.isEmpty) { return HttpResponseType.JSON; } return tmp[0]; } } class RequestMapping { final HttpMethod method; final String path; final HttpResponseType responseType; final bool auth; const RequestMapping( {this.method = HttpMethod.ALL, required this.path, this.auth = true, this.responseType = HttpResponseType.JSON}); } class TokenResult { bool status; String? errMsg; Map? payload; TokenResult({required this.status, this.errMsg, this.payload}); }