fix: update toad, fix env
This commit is contained in:
parent
757c35e20f
commit
81f811f8d3
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -906,9 +906,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "toad"
|
||||
version = "1.0.0-beta.4"
|
||||
version = "1.0.0-beta.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7680b4a4868e2527ee0cb58b3850179f9ad9a44532b13fb9e4487a176091b71a"
|
||||
checksum = "b305d4763b0236558486735374e796a028567a8d6f6a4c94c07096b73573ba0a"
|
||||
dependencies = [
|
||||
"embedded-time",
|
||||
"log",
|
||||
|
@ -5,8 +5,8 @@ edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
toad = "1.0.0-beta.3"
|
||||
toad-msg = "1.0.0-beta.1"
|
||||
toad = "1.0.0-beta.6"
|
||||
toad-msg = "1.0.0-beta.2"
|
||||
simple_logger = "4.2"
|
||||
nb = "1.1.0"
|
||||
serde = {version = "1", features = ["derive"]}
|
||||
|
16
src/env.rs
16
src/env.rs
@ -33,13 +33,12 @@ pub enum Error {
|
||||
impl Env {
|
||||
pub fn try_read() -> Result<Self, Error> {
|
||||
fn get(k: &'static str) -> Result<Option<String>, Error> {
|
||||
std::env::var("POSTGRES_USER").map(Some)
|
||||
.recover(|e| match e {
|
||||
| std::env::VarError::NotPresent => Ok(None),
|
||||
| std::env::VarError::NotUnicode(os) => {
|
||||
Err(Error::VarNotUnicode(k.into(), os))
|
||||
},
|
||||
})
|
||||
std::env::var(k).map(Some).recover(|e| match e {
|
||||
| std::env::VarError::NotPresent => Ok(None),
|
||||
| std::env::VarError::NotUnicode(os) => {
|
||||
Err(Error::VarNotUnicode(k.into(), os))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
fn get_required(k: &'static str) -> Result<String, Error> {
|
||||
@ -53,7 +52,8 @@ impl Env {
|
||||
|
||||
let api_addr = get("API_ADDR")?.unwrap_or("127.0.0.1:4444".into());
|
||||
|
||||
let api = Api { addr: api_addr.trim().parse()
|
||||
let api = Api { addr: api_addr.trim()
|
||||
.parse()
|
||||
.map_err(|e| Error::VarNotSocketAddr("API_ADDR".into(), e))? };
|
||||
|
||||
Ok(Env { postgres, api })
|
||||
|
37
src/main.rs
37
src/main.rs
@ -77,15 +77,30 @@ newtype!(
|
||||
pub struct Email(String);
|
||||
);
|
||||
|
||||
type Dtls = toad::std::dtls::N;
|
||||
type ToadT = toad::std::PlatformTypes<Dtls>;
|
||||
type Toad = toad::std::Platform<Dtls, toad::step::runtime::std::Runtime<Dtls>>;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, serde::Serialize, serde::Deserialize)]
|
||||
struct Foo {
|
||||
id: String,
|
||||
mod __toad_aliases {
|
||||
use naan::hkt;
|
||||
use toad::std::dtls;
|
||||
use toad::step::parse::Parse;
|
||||
use toad::step::provision_tokens::ProvisionTokens;
|
||||
use toad::step::runtime::{BufferResponses, HandleAcks, Observe, ProvisionIds, Retry};
|
||||
pub type ToadT = toad::std::PlatformTypes<dtls::N>;
|
||||
pub type Runtime =
|
||||
Observe<ToadT,
|
||||
hkt::Vec,
|
||||
BufferResponses<ToadT,
|
||||
hkt::BTreeMap,
|
||||
HandleAcks<hkt::BTreeMap,
|
||||
Retry<ToadT,
|
||||
hkt::Vec,
|
||||
ProvisionTokens<ProvisionIds<ToadT,
|
||||
hkt::BTreeMap,
|
||||
hkt::Vec,
|
||||
Parse<()>>>>>>>;
|
||||
pub type Toad = toad::std::Platform<dtls::N, Runtime>;
|
||||
}
|
||||
|
||||
use __toad_aliases::*;
|
||||
|
||||
fn handle_request(req: Addrd<Req<ToadT>>) -> Result<Addrd<Message>, String> {
|
||||
let path = req.data()
|
||||
.path()
|
||||
@ -97,10 +112,14 @@ fn handle_request(req: Addrd<Req<ToadT>>) -> Result<Addrd<Message>, String> {
|
||||
if path_segments.peek() == Some(&"users") {
|
||||
let mut path_segments = path_segments.clone();
|
||||
let _id = path_segments.nth(2);
|
||||
let msg = Message::builder(Type::Ack, toad::resp::code::NOT_FOUND).build();
|
||||
let msg =
|
||||
Message::builder(Type::Ack, toad::resp::code::NOT_FOUND).token(req.data().msg().token)
|
||||
.build();
|
||||
Ok(Addrd(msg, req.addr()))
|
||||
} else {
|
||||
let msg = Message::builder(Type::Ack, toad::resp::code::NOT_FOUND).build();
|
||||
let msg =
|
||||
Message::builder(Type::Ack, toad::resp::code::NOT_FOUND).token(req.data().msg().token)
|
||||
.build();
|
||||
Ok(Addrd(msg, req.addr()))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user