Skip to content

Commit 6e33fd8

Browse files
committed
refactor: better use full crate import than lib.rs import
1 parent bd84f32 commit 6e33fd8

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/main.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,22 @@ use std::str::FromStr;
44

55
use core::fmt::Debug;
66

7+
use chatgpt_proxy_server::*;
78
use hyper::server::conn::AddrStream;
89
use hyper::service::{make_service_fn, service_fn};
910
use hyper::{Body, Client, Request, Response, Server, Uri};
1011
use hyper_tls::HttpsConnector;
1112
use lazy_static::lazy_static;
1213

13-
// import lib.rs
14-
mod lib;
15-
16-
// create config struct
17-
1814
use dotenv;
1915
use tokio::sync::Mutex;
2016

21-
#[derive(Debug)]
17+
// create config struct
2218
struct Config {
2319
chatgpt_url: String,
2420
ratelimit: u32,
2521
}
2622

27-
2823
lazy_static! {
2924
static ref CONFIG: Config = {
3025
dotenv::dotenv().ok();
@@ -51,14 +46,17 @@ impl Debug for CONFIG {
5146
}
5247

5348
lazy_static! {
54-
static ref RATE_LIMITER: Mutex<lib::RateLimiter> = Mutex::new(lib::RateLimiter::new(
55-
CONFIG.ratelimit
56-
));
49+
static ref RATE_LIMITER: Mutex<RateLimiter> = Mutex::new(RateLimiter::new(CONFIG.ratelimit));
5750
}
5851

5952
async fn proxy(req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
60-
let client_ip = &req.extensions().get::<SocketAddr>().unwrap().ip().to_string();
61-
// Read Client IP read form header or client
53+
let client_ip = &req
54+
.extensions()
55+
.get::<SocketAddr>()
56+
.unwrap()
57+
.ip()
58+
.to_string();
59+
// Read Client IP read form header or client
6260
let real_ip = req
6361
.headers()
6462
.get("X-Forwarded-For")
@@ -129,9 +127,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
129127
}))
130128
}
131129
});
132-
let server = Server::bind(&addr).serve(
133-
service
134-
);
130+
let server = Server::bind(&addr).serve(service);
135131
// print config
136132
println!("Config: {:?}", CONFIG);
137133
println!("Listening on http://{}", addr);

0 commit comments

Comments
 (0)