Skip to content

Commit

Permalink
Merge pull request #50 from Jzow/master
Browse files Browse the repository at this point in the history
v1.0.0 update and add doc
  • Loading branch information
Jzow authored Jun 25, 2022
2 parents 8fff8ba + 62b8191 commit 516266c
Show file tree
Hide file tree
Showing 20 changed files with 129 additions and 70 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ summer_boot::log
____) | |_| | | | | | | | | | | | __/ | | |_) | (_) | (_) | |_
|_____/ \__,_|_| |_| |_|_| |_| |_|\___|_| |____/ \___/ \___/ \__|

:: Summer Boot Version:: (0.1.0)
:: Summer Boot Version:: (1.0.0)

summer_boot::web2::server::server Server listening on http://127.0.0.1:8080
```
Expand All @@ -25,7 +25,7 @@ summer_boot::web2::server::server Server listening on http://127.0.0.1:8080

Cargo.toml:
```rust
summer-boot = "0.1.3"
summer-boot = "1.0.0"
```

Add resuorce configuration file to src directory
Expand All @@ -34,12 +34,11 @@ src/resources/application.yml
```yml
profiles:
active: test

```
src/resources/application-test.yml
```yml
server:
port: 7798
port: 8080
context_path: /
```
Expand Down
12 changes: 10 additions & 2 deletions summer-boot-autoconfigure/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
[package]
name = "summer-boot-autoconfigure"
version = "0.1.2"
version = "1.0.0"
rust-version = "1.60.0"
edition = "2021"
description = "summer boot autoconfigure"
authors = [
"James Zow <[email protected]>"
"James Zow <[email protected]>",
"Xinyu Gao",
"Summeros Team <[email protected]>"
]
license = "Apache-2.0"
readme = "README.md"
keywords = ["middleware", "autoconfigure", "summer"]
documentation = "https://github.com/summer-os/summer-boot/summer-boot-autoconfigure/#readme"
repository = "https://github.com/summer-os/summer-boot"
homepage = "https://summeros.io/"


[dependencies]
serde = { version = "1", features = ["derive"] }
Expand Down
2 changes: 2 additions & 0 deletions summer-boot-autoconfigure/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Summer Boot AutoConfigure

Implementation of automatic configuration for summer boot, At present, there is an implementation of reading YML files
14 changes: 9 additions & 5 deletions summer-boot-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
[package]
name = "summer-boot-macro"
version = "0.1.2"
version = "1.0.0"
rust-version = "1.60.0"
edition = "2021"
description = "summer boot macro"
license = "Apache-2.0"
authors = [
"James Zow <[email protected]>",
"Yangandmore <[email protected]>"
"Yangandmore <[email protected]>",
"Summeros Team <[email protected]>"
]

readme = "README.md"
documentation = "https://github.com/summer-os/summer-boot/blob/master/summer-boot-macro/README.md"
repository = "https://github.com/summer-os/summer-boot"
homepage = "https://summeros.io/"

[lib]
proc-macro = true
Expand All @@ -21,7 +25,7 @@ syn = { version = "1.0", features = ["full"] }
toml = "0.5"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
summer-boot-autoconfigure = { version = "0.1.2", path = "../summer-boot-autoconfigure" }
summer-boot-autoconfigure = { version = "1.0.0", path = "../summer-boot-autoconfigure" }

[dev-dependencies]
summer-boot = { version = "0.1.2", path = "../summer-boot" }
summer-boot = { version = "1.0.0", path = "../summer-boot" }
14 changes: 10 additions & 4 deletions summer-boot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
[package]
name = "summer-boot"
version = "0.1.3"
version = "1.0.0"
rust-version = "1.60.0"
edition = "2021"
description = "summer boot web2"
description = "summer boot"
authors = [
"James Zow <[email protected]>"
"James Zow <[email protected]>",
"Summeros Team <[email protected]>"
]
license = "Apache-2.0"
readme = "README.md"
keywords = ["tcp", "http", "web2", "web3", "summer"]
documentation = "https://github.com/summer-os/summer-boot#readme"
repository = "https://github.com/summer-os/summer-boot"
homepage = "https://summeros.io/"

[features]
default = ["macros"]
Expand Down Expand Up @@ -39,7 +45,7 @@ futures-util = "0.3.6"


# summer dependencies
summer-boot-macro = { version = "0.1.2", path = "../summer-boot-macro", optional = true }
summer-boot-macro = { version = "1.0.0", path = "../summer-boot-macro", optional = true }

#log
femme = { version = "2.1.1"}
Expand Down
76 changes: 76 additions & 0 deletions summer-boot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Summer Boot

<a href="https://app.bors.tech/repositories/45710"><img src="https://bors.tech/images/badge_small.svg" alt="Bors enabled"></a>
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fsummer-os%2Fsummer-boot.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fsummer-os%2Fsummer-boot?ref=badge_shield)

The next generation decentralized web framework allows users to manage and share their own data.
It will be a wide area and cross regional web framework.

```rust
summer_boot::log Logger started
summer_boot::log
_____ ____ _
/ ____| | _ \ | |
| (___ _ _ _ __ ___ _ __ ___ ___ _ __ | |_) | ___ ___ | |_
\___ \| | | | '_ ` _ \| '_ ` _ \ / _ \ '__| | _ < / _ \ / _ \| __|
____) | |_| | | | | | | | | | | | __/ | | |_) | (_) | (_) | |_
|_____/ \__,_|_| |_| |_|_| |_| |_|\___|_| |____/ \___/ \___/ \__|

:: Summer Boot Version:: (1.0.0)

summer_boot::web2::server::server Server listening on http://127.0.0.1:8080
```

## Quick Start

Cargo.toml:
```rust
summer-boot = "1.0.0"
```

Add resuorce configuration file to src directory

src/resources/application.yml
```yml
profiles:
active: test

```
src/resources/application-test.yml
```yml
server:
port: 8080
```
src/main.rs
```rust
use serde::Deserialize;
use summer_boot::{Request, Result};
use summer_boot::log;

#[derive(Debug, Deserialize)]
struct User {
name: String,
age: u16,
}

#[summer_boot::auto_scan]
#[summer_boot::main]
async fn main() {
summer_boot::run();
}

#[summer_boot::post("/test/api")]
async fn test_api(mut req: Request<()>) -> Result {
let User { name, age } = req.body_json().await?;
Ok(format!("Hello, {}! {} years old", name, age).into())
}
```

## License

Licensed under either of

- [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fsummer-os%2Fsummer-boot.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fsummer-os%2Fsummer-boot?ref=badge_large)
7 changes: 2 additions & 5 deletions summer-boot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ pub mod common;
pub mod log;
pub mod web2;

use async_std::io;
use serde_json::ser::State;
use web2::tcp::ToListener;
use web2::{aop, context, gateway, http1, tcp, utils};
use web2::{aop, context, gateway, http1, tcp, utils, server};

pub use http1::http;
pub use utils::middleware::{Middleware, Next};
Expand All @@ -14,7 +11,7 @@ pub use utils::response::Response;
pub use utils::response_builder::ResponseBuilder;
pub use utils::util;

pub use aop::endpoint::Endpoint;
pub use server::endpoint::Endpoint;
pub use gateway::route::Route;
pub use http_types::{self, Body, Error, Status, StatusCode};

Expand Down
4 changes: 2 additions & 2 deletions summer-boot/src/log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn start() {
____) | |_| | | | | | | | | | | | __/ | | |_) | (_) | (_) | |_
|_____/ \\__,_|_| |_| |_|_| |_| |_|\\___|_| |____/ \\___/ \\___/ \\__|
:: Summer Boot Version:: (0.1.0)
:: Summer Boot Version:: (1.0.0)
");
}

Expand All @@ -54,6 +54,6 @@ pub fn with_level(level: LevelFilter) {
____) | |_| | | | | | | | | | | | __/ | | |_) | (_) | (_) | |_
|_____/ \\__,_|_| |_| |_|_| |_| |_|\\___|_| |____/ \\___/ \\___/ \\__|
:: Summer Boot Version:: (0.1.0)
:: Summer Boot Version:: (1.0.0)
");
}
2 changes: 1 addition & 1 deletion summer-boot/src/web2/aop/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod endpoint;

4 changes: 2 additions & 2 deletions summer-boot/src/web2/gateway/route.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::aop;
use crate::server;
use crate::context;
use crate::gateway;
use crate::log;
Expand All @@ -9,7 +9,7 @@ use std::io;
use std::path::Path;
use std::sync::Arc;

use aop::endpoint::{Endpoint, MiddlewareEndpoint};
use server::endpoint::{Endpoint, MiddlewareEndpoint};
use context::serve_dir::ServeDir;
use context::serve_file::ServeFile;
use utils::middleware::Middleware;
Expand Down
4 changes: 2 additions & 2 deletions summer-boot/src/web2/gateway/router.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::aop;
use crate::server;
use crate::{Request, Response, StatusCode};

use routefinder::{Captures, Router as MethodRouter};
use std::collections::HashMap;

use aop::endpoint::DynEndpoint;
use server::endpoint::DynEndpoint;

/// `Server` 使用的路由
///
Expand Down
1 change: 1 addition & 0 deletions summer-boot/src/web2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod gateway;
pub mod server;
pub mod tcp;
pub mod utils;
pub mod ssl;

///
/// 后续考虑把http1和http2 封装成rust的future
Expand Down
38 changes: 1 addition & 37 deletions summer-boot/src/web2/server/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,40 +52,4 @@ where
}

PollFn(func)
}

/// Adapt a `Stream` of incoming connections into an `Accept`.
/// 将传入连接的 `Stream` 改为 `Accept`。
///
/// # Optional
///
/// 此功能需要在
/// `Cargo.toml` feature进行配置。
#[cfg(feature = "stream")]
pub fn from_stream<S, IO, E>(stream: S) -> impl Accept<Conn = IO, Error = E>
where
S: Stream<Item = Result<IO, E>>,
{
pin_project! {
struct FromStream<S> {
#[pin]
stream: S,
}
}

impl<S, IO, E> Accept for FromStream<S>
where
S: Stream<Item = Result<IO, E>>,
{
type Conn = IO;
type Error = E;
fn poll_accept(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
) -> Poll<Option<Result<Self::Conn, Self::Error>>> {
self.project().stream.poll_next(cx)
}
}

FromStream { stream }
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion summer-boot/src/web2/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod accept;
pub mod server;
pub mod ssl;
pub mod endpoint;
5 changes: 3 additions & 2 deletions summer-boot/src/web2/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use crate::gateway;
use crate::log;
use crate::tcp;
use crate::utils;
use crate::{Endpoint, Request, Route};
use crate::{Request, Route};
use super::endpoint::Endpoint;

use async_std::io;
use async_std::sync::Arc;
use serde_json::Value;

use gateway::router::{Router, Selection};
use tcp::{Listener, ToListener};
Expand Down Expand Up @@ -66,6 +66,7 @@ impl Server<()> {
/// 默认开启日志记录
/// 读取yml然后绑定监听
///
/// 目前把他移动到macro扫描里面去了
pub fn run() -> Self {
log::start();
let server = Self::with_state(());
Expand Down
1 change: 1 addition & 0 deletions summer-boot/src/web2/ssl/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod ssl;
File renamed without changes.
2 changes: 1 addition & 1 deletion summer-boot/src/web2/tcp/tcp_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn handle_tcp<State: Clone + Send + Sync + 'static>(app: Server<State>, stream:
});

if let Err(error) = fut.await {
log::error!("async-h1 error", { error: error.to_string() });
log::error!("http1 error", { error: error.to_string() });
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions summer-boot/src/web2/utils/middleware.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::aop;
use crate::web2::server;
use crate::{Request, Response};

use aop::endpoint::DynEndpoint;
use server::endpoint::DynEndpoint;
use async_trait::async_trait;
use std::future::Future;
use std::pin::Pin;
Expand Down

0 comments on commit 516266c

Please sign in to comment.