Skip to content

Commit

Permalink
publish ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Az107 committed Jun 12, 2024
1 parent d8a0301 commit 27fcadc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 53 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "Cafetera"
name = "cafetera"
version = "0.1.0"
edition = "2021"

Expand Down
31 changes: 1 addition & 30 deletions src/config_parser.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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();
Expand Down
8 changes: 2 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
6 changes: 1 addition & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, path::Path};
use std::collections::HashMap;

pub struct SimpleRNG {
state: u64,
Expand All @@ -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
Expand Down

0 comments on commit 27fcadc

Please sign in to comment.