Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from arcticfox1919/dart3
Dart3
- Loading branch information
Showing
23 changed files
with
2,097 additions
and
1,398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
## 0.0.1 | ||
|
||
- Initial version, created by Stagehand | ||
## 0.1.0 | ||
- Upgrade to dart 3.x support | ||
- Added a websocket handler that can be used to provide websocket services | ||
- Added a static file serving handler to serve files | ||
- Fixed the error reporting for dart 3 isolate concurrency support | ||
|
||
## 0.0.2 | ||
|
||
- Fix dart version 3 error reporting | ||
|
||
## 0.0.1 | ||
|
||
- Initial version, created by Stagehand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,136 @@ | ||
|
||
# arowana | ||
|
||
|
||
![](https://gitee.com/arcticfox1919/ImageHosting/raw/master/img/2021-10-17-002.png) | ||
|
||
|
||
A lightweight HTTP server framework for Dart.It is based on the [shelf](https://github.com/dart-lang/shelf) library for handling HTTP requests and implements a high-performance routing with reference to Golang's Gin framework. | ||
|
||
It can be used in Flutter and run to mobile platforms. | ||
|
||
## Usage | ||
|
||
A simple usage example: | ||
|
||
```dart | ||
import 'dart:isolate'; | ||
import 'package:arowana/arowana.dart'; | ||
class MyAChannel extends DefaultChannel{ | ||
@override | ||
Future prepare() { | ||
print('current isolate [${Isolate.current.debugName}]'); | ||
return super.prepare(); | ||
} | ||
@override | ||
void entryPoint() { | ||
get('/hello', (r){ | ||
return Response.ok('hello,arowana!'); | ||
}); | ||
} | ||
} | ||
void main() { | ||
var app = Application(MyAChannel()); | ||
app.start(numberOfInstances: 2,consoleLogging: true); | ||
} | ||
``` | ||
Another example, containing grouped routes: | ||
```dart | ||
class MyAChannel extends AppChannel { | ||
Router app = Router(); | ||
Middleware verification() => (innerHandler) { | ||
return (request) async { | ||
if (request.query['name'] == 'abc' && | ||
request.query['pass'] == '123') { | ||
return await innerHandler(request); | ||
} else { | ||
return ResponseX.unauthorized('Authentication failed !!!'); | ||
} | ||
}; | ||
}; | ||
@override | ||
void entryPoint() { | ||
var r1 = app.group('/v1'); | ||
// var middleware = Pipeline().addMiddleware(verification()).middleware; | ||
r1.use(verification()); | ||
r1.get('/hello', (Request request) { | ||
return Response.ok('hello-world'); | ||
}); | ||
r1.get('/greet/:name', (Request request, String name) { | ||
return Response.ok('Hi,$name'); | ||
}); | ||
var r2 = app.group('/v2'); | ||
r2.get('/hello', (Request request) { | ||
return Response.ok('hello,arowana'); | ||
}); | ||
r2.get('/user/:name', (Request request, String user) { | ||
return Response.ok('hello, $user'); | ||
}); | ||
} | ||
@override | ||
FutureOr<Response> call(Request request) { | ||
print('current isolate [${Isolate.current.debugName}]'); | ||
return app.call(request); | ||
} | ||
} | ||
void main() { | ||
var app = Application(MyAChannel()); | ||
app.options = ApplicationOptions()..address = '127.0.0.1'; | ||
app.start(numberOfInstances: 2,consoleLogging: true); | ||
} | ||
``` | ||
|
||
## Example | ||
It has a complete example of authentication, visit [here](https://github.com/arcticfox1919/auth-server). | ||
|
||
## Features and bugs | ||
|
||
Please file feature requests and bugs at the [issue tracker][tracker]. | ||
|
||
[tracker]: http://example.com/issues/replaceme | ||
|
||
# arowana | ||
|
||
|
||
![](https://gitee.com/arcticfox1919/ImageHosting/raw/master/img/2021-10-17-002.png) | ||
|
||
|
||
A lightweight HTTP server framework for Dart.It is based on the [shelf](https://github.com/dart-lang/shelf) library for handling HTTP requests and implements a high-performance routing with reference to Golang's Gin framework. | ||
|
||
It can be used in Flutter and run to mobile platforms. | ||
|
||
## Usage | ||
|
||
A simple usage example: | ||
|
||
```dart | ||
import 'dart:isolate'; | ||
import 'package:arowana/arowana.dart'; | ||
class MyAChannel extends DefaultChannel{ | ||
@override | ||
Future prepare() { | ||
print('current isolate [${Isolate.current.debugName}]'); | ||
return super.prepare(); | ||
} | ||
@override | ||
void entryPoint() { | ||
get('/hello', (r){ | ||
return Response.ok('hello,arowana!'); | ||
}); | ||
} | ||
} | ||
void main() { | ||
var app = Application(() => MyAChannel('')); | ||
app.start(numberOfInstances: 2,consoleLogging: true); | ||
} | ||
``` | ||
Another example, containing grouped routes: | ||
```dart | ||
class MyAChannel extends AppChannel { | ||
Router app = Router(); | ||
Middleware verification() => (innerHandler) { | ||
return (request) async { | ||
if (request.query['name'] == 'abc' && | ||
request.query['pass'] == '123') { | ||
return await innerHandler(request); | ||
} else { | ||
return ResponseX.unauthorized('Authentication failed !!!'); | ||
} | ||
}; | ||
}; | ||
@override | ||
void entryPoint() { | ||
var r1 = app.group('/v1'); | ||
// var middleware = Pipeline().addMiddleware(verification()).middleware; | ||
r1.use(verification()); | ||
r1.get('/hello', (Request request) { | ||
return Response.ok('hello-world'); | ||
}); | ||
r1.get('/greet/:name', (Request request, String name) { | ||
return Response.ok('Hi,$name'); | ||
}); | ||
var r2 = app.group('/v2'); | ||
r2.get('/hello', (Request request) { | ||
return Response.ok('hello,arowana'); | ||
}); | ||
r2.get('/user/:name', (Request request, String user) { | ||
return Response.ok('hello, $user'); | ||
}); | ||
} | ||
@override | ||
FutureOr<Response> call(Request request) { | ||
print('current isolate [${Isolate.current.debugName}]'); | ||
return app.call(request); | ||
} | ||
} | ||
void main() { | ||
var app = Application(() => MyAChannel('')); | ||
app.options = ApplicationOptions()..address = '127.0.0.1'; | ||
app.start(numberOfInstances: 2,consoleLogging: true); | ||
} | ||
``` | ||
|
||
> Upgrade to 0.1.0: | ||
> You can create websocket serving and static file serving | ||
```dart | ||
final class MyWebSocket extends WebSocketController{ | ||
MyWebSocket() : super(null,null,null); | ||
@override | ||
void onConnection(WebSocketChannel webSocket, String? protocol) { | ||
webSocket.stream.listen((message) { | ||
webSocket.sink.add('echo $message'); | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
register: | ||
```dart | ||
@override | ||
void entryPoint() { | ||
get('/hello', (r) async { | ||
return Response.ok('hello,arowana! form:${Isolate.current.debugName}'); | ||
}); | ||
get('/ws', MyWebSocket()); | ||
// visit http://127.0.0.1:8888/example/example.dart | ||
get('/example/*path', createStaticHandler('.')); | ||
} | ||
``` | ||
|
||
|
||
|
||
|
||
## Example | ||
It has a complete example of authentication, visit [here](https://github.com/arcticfox1919/auth-server). | ||
|
||
## Features and bugs | ||
|
||
Please file feature requests and bugs at the [issue tracker][tracker]. | ||
|
||
[tracker]: http://example.com/issues/replaceme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,58 @@ | ||
import 'dart:async'; | ||
import 'dart:isolate'; | ||
|
||
import 'package:arowana/arowana.dart'; | ||
|
||
class MyAChannel extends AppChannel { | ||
Router app = Router(); | ||
|
||
Middleware verification() => (innerHandler) { | ||
return (request) async { | ||
if (request.query['name'] == 'abc' && | ||
request.query['pass'] == '123') { | ||
return await innerHandler(request); | ||
} else { | ||
return ResponseX.unauthorized('Authentication failed !!!'); | ||
} | ||
}; | ||
}; | ||
|
||
@override | ||
void entryPoint() { | ||
var r1 = app.group('/v1'); | ||
|
||
// var middleware = Pipeline().addMiddleware(verification()).middleware; | ||
r1.use(verification()); | ||
r1.get('/hello', (Request request) { | ||
return Response.ok('hello-world'); | ||
}); | ||
|
||
r1.get('/greet/:name', (Request request, String name) { | ||
return Response.ok('Hi,$name'); | ||
}); | ||
|
||
var r2 = app.group('/v2'); | ||
r2.get('/hello', (Request request) { | ||
return Response.ok('hello,arowana'); | ||
}); | ||
r2.get('/user/:name', (Request request, String user) { | ||
return Response.ok('hello, $user'); | ||
}); | ||
} | ||
|
||
@override | ||
FutureOr<Response> call(Request request) { | ||
print('current isolate [${Isolate.current.debugName}]'); | ||
return app.call(request); | ||
} | ||
} | ||
|
||
void main() { | ||
var app = Application(MyAChannel()); | ||
app.options = ApplicationOptions()..address = '127.0.0.1'; | ||
app.start(numberOfInstances: 2,consoleLogging: true); | ||
} | ||
import 'dart:async'; | ||
import 'dart:isolate'; | ||
|
||
import 'package:arowana/arowana.dart'; | ||
|
||
base class MyAChannel extends AppChannel { | ||
MyAChannel(String a); | ||
|
||
Router app = Router(); | ||
|
||
Middleware verification() => (innerHandler) { | ||
return (request) async { | ||
if (request.query['name'] == 'abc' && | ||
request.query['pass'] == '123') { | ||
return await innerHandler(request); | ||
} else { | ||
return Response.unauthorized('Authentication failed !!!'); | ||
} | ||
}; | ||
}; | ||
|
||
@override | ||
void entryPoint() { | ||
var r1 = app.group('/v1'); | ||
|
||
// var middleware = Pipeline().addMiddleware(verification()).middleware; | ||
r1.use(verification()); | ||
r1.get('/hello', (Request request) { | ||
return Response.ok('hello-world'); | ||
}); | ||
|
||
r1.get('/greet/:name', (Request request, String name) { | ||
return Response.ok('Hi,$name'); | ||
}); | ||
|
||
var r2 = app.group('/v2'); | ||
r2.get('/hello', (Request request) { | ||
return Response.ok('hello,arowana'); | ||
}); | ||
r2.get('/user/:name', (Request request, String user) { | ||
return Response.ok('hello, $user'); | ||
}); | ||
} | ||
|
||
@override | ||
FutureOr<Response> call(Request request) { | ||
print('current isolate [${Isolate.current.debugName}]'); | ||
return app.call(request); | ||
} | ||
} | ||
|
||
void main() { | ||
var app = Application(() => MyAChannel('')); | ||
app.options = ApplicationOptions() | ||
..port = 49218 | ||
..address = '127.0.0.1'; | ||
app.start(numberOfInstances: 2, consoleLogging: true); | ||
} |
Oops, something went wrong.