1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-27 17:22:57 +01:00

Update example (#12)

* Update example

* Check example's build on CI

* Update README
This commit is contained in:
Yuki Okushi 2020-01-25 02:39:32 +09:00 committed by GitHub
parent 777990d575
commit 71e2f682e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 25 deletions

View File

@ -35,7 +35,7 @@ script:
if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then
USE_SKEPTIC=1 cargo test USE_SKEPTIC=1 cargo test
else else
cargo test cargo test && cargo check --examples
fi fi
- | - |
if [[ "$TRAVIS_RUST_VERSION" == "nightly" && $CLIPPY ]]; then if [[ "$TRAVIS_RUST_VERSION" == "nightly" && $CLIPPY ]]; then

View File

@ -6,23 +6,25 @@ Protobuf support for actix-web framework.
## Example ## Example
```rust,ignore ```rust,ignore
use actix_web::{HttpResponse, Result}; use actix_protobuf::*;
use actix_protobuf::ProtoBuf; use actix_web::*;
#[derive(Clone, Debug, PartialEq, Message)] #[derive(Clone, PartialEq, Message)]
pub struct MyObj { pub struct MyObj {
#[prost(int32, tag="1")] #[prost(int32, tag = "1")]
pub number: i32, pub number: i32,
#[prost(string, tag="2")] #[prost(string, tag = "2")]
pub name: String, pub name: String,
} }
fn index(msg: ProtoBuf<MyObj>) -> Result<HttpResponse> { async fn index(msg: ProtoBuf<MyObj>) -> Result<HttpResponse> {
println!("model: {:?}", msg); println!("model: {:?}", msg);
HttpResponse::Ok().protobuf(msg.0) // <- send response HttpResponse::Ok().protobuf(msg.0) // <- send response
} }
``` ```
See [here](https://github.com/actix/actix-protobuf/tree/master/examples/prost-example) for the complete example.
## License ## License
This project is licensed under either of This project is licensed under either of

View File

@ -1,10 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# just start server and run client.py # just start server and run client.py
# wget https://github.com/google/protobuf/releases/download/v3.5.1/protobuf-python-3.5.1.zip # wget https://github.com/protocolbuffers/protobuf/releases/download/v3.11.2/protobuf-python-3.11.2.zip
# unzip protobuf-python-3.5.1.zip.1 # unzip protobuf-python-3.11.2.zip.1
# cd protobuf-3.5.1/python/ # cd protobuf-3.11.2/python/
# python3.6 setup.py install # python3 setup.py install
# pip3 install --upgrade pip # pip3 install --upgrade pip
# pip3 install aiohttp # pip3 install aiohttp

View File

@ -1,13 +1,11 @@
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT! # Generated by the protocol buffer compiler. DO NOT EDIT!
# source: test.proto # source: test.proto
import sys
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message from google.protobuf import message as _message
from google.protobuf import reflection as _reflection from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database from google.protobuf import symbol_database as _symbol_database
from google.protobuf import descriptor_pb2
# @@protoc_insertion_point(imports) # @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default() _sym_db = _symbol_database.Default()
@ -19,9 +17,9 @@ DESCRIPTOR = _descriptor.FileDescriptor(
name='test.proto', name='test.proto',
package='', package='',
syntax='proto3', syntax='proto3',
serialized_pb=_b('\n\ntest.proto\"%\n\x05MyObj\x12\x0e\n\x06number\x18\x01 \x01(\x05\x12\x0c\n\x04name\x18\x02 \x01(\tb\x06proto3') serialized_options=None,
serialized_pb=b'\n\ntest.proto\"%\n\x05MyObj\x12\x0e\n\x06number\x18\x01 \x01(\x05\x12\x0c\n\x04name\x18\x02 \x01(\tb\x06proto3'
) )
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
@ -39,21 +37,21 @@ _MYOBJ = _descriptor.Descriptor(
has_default_value=False, default_value=0, has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None, message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None, is_extension=False, extension_scope=None,
options=None), serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor( _descriptor.FieldDescriptor(
name='name', full_name='MyObj.name', index=1, name='name', full_name='MyObj.name', index=1,
number=2, type=9, cpp_type=9, label=1, number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'), has_default_value=False, default_value=b"".decode('utf-8'),
message_type=None, enum_type=None, containing_type=None, message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None, is_extension=False, extension_scope=None,
options=None), serialized_options=None, file=DESCRIPTOR),
], ],
extensions=[ extensions=[
], ],
nested_types=[], nested_types=[],
enum_types=[ enum_types=[
], ],
options=None, serialized_options=None,
is_extendable=False, is_extendable=False,
syntax='proto3', syntax='proto3',
extension_ranges=[], extension_ranges=[],
@ -64,12 +62,13 @@ _MYOBJ = _descriptor.Descriptor(
) )
DESCRIPTOR.message_types_by_name['MyObj'] = _MYOBJ DESCRIPTOR.message_types_by_name['MyObj'] = _MYOBJ
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
MyObj = _reflection.GeneratedProtocolMessageType('MyObj', (_message.Message,), dict( MyObj = _reflection.GeneratedProtocolMessageType('MyObj', (_message.Message,), {
DESCRIPTOR = _MYOBJ, 'DESCRIPTOR' : _MYOBJ,
__module__ = 'test_pb2' '__module__' : 'test_pb2'
# @@protoc_insertion_point(class_scope:MyObj) # @@protoc_insertion_point(class_scope:MyObj)
)) })
_sym_db.RegisterMessage(MyObj) _sym_db.RegisterMessage(MyObj)