diff --git a/Cargo.lock b/Cargo.lock index 0821c2e..6976195 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,17 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "Cafetera" -version = "0.1.0" -dependencies = [ - "hteapot", - "serde", - "serde_json", - "serde_with", - "toml", -] - [[package]] name = "android-tzdata" version = "0.1.1" @@ -46,6 +35,17 @@ version = "3.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" +[[package]] +name = "cafetera" +version = "0.1.0" +dependencies = [ + "hteapot", + "serde", + "serde_json", + "serde_with", + "toml", +] + [[package]] name = "cc" version = "1.0.90" diff --git a/Cargo.toml b/Cargo.toml index e6e9ff8..c8763b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "Cafetera" +name = "cafetera" version = "0.1.0" edition = "2021" diff --git a/src/config_parser.rs b/src/config_parser.rs index aa5a2bd..b93a71c 100644 --- a/src/config_parser.rs +++ b/src/config_parser.rs @@ -1,8 +1,7 @@ use std::{collections::HashMap, fs}; use serde::{Deserialize, Serialize}; -use serde_json::Value; -use hteapot::{HttpMethod, HttpStatus}; + use toml; use crate::utils::compare_path; @@ -39,34 +38,6 @@ pub struct Config { impl Config { - pub fn new() -> Self { - let mut endpoints = HashMap::new(); - let e1 = Endpoint { - path: "/test".to_string(), - status: 200, - body: "Hello world".to_string() - }; - let e2 = Endpoint { - path: "/".to_string(), - status: 201, - body: "abc".to_string() - }; - let e3 = Endpoint { - path: "/error".to_string(), - status: 404, - body: "error".to_string() - }; - - endpoints.insert(HttpMethod::GET.to_str().to_string(), vec![e1,e2,e3]); - Config { - endpoints: endpoints - } - } - - - pub fn to_str(&self) -> String { - toml::to_string(self).unwrap().to_string() - } pub fn import(path: &str) -> Self { let config_toml = fs::read_to_string(path).unwrap(); diff --git a/src/main.rs b/src/main.rs index e3fe835..4a85f61 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,12 @@ mod config_parser; mod utils; -use std::env; + use utils::SimpleRNG; use utils::clean_arg; -use hteapot::{HttpMethod, HttpStatus, Hteapot}; +use hteapot::{HttpStatus, Hteapot}; use config_parser::{Config, EndpointSearch}; - -const DEFAULT_PORT: &str = "7878"; - - // section MAIN fn main() { diff --git a/src/utils.rs b/src/utils.rs index 9b6e98f..8bcc577 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, path::Path}; +use std::collections::HashMap; pub struct SimpleRNG { state: u64, @@ -13,10 +13,6 @@ impl SimpleRNG { SimpleRNG { state: seed } } - pub fn new_with_seed(seed: u64) -> Self { - SimpleRNG { state: seed } - } - pub fn next(&mut self) -> u64 { self.state = self.state.wrapping_mul(6364136223846793061).wrapping_add(1); self.state >> 16