http_private: add config, launch with cli helpers

This commit is contained in:
Joakim Frostegård 2022-04-02 14:35:40 +02:00
parent 6e97bff93f
commit 088daa72ff
8 changed files with 200 additions and 30 deletions

View file

@ -1 +1,2 @@
pub mod request;
pub mod socket;

View file

@ -0,0 +1,5 @@
use crate::config::Config;
pub fn run_request_worker(config: Config) -> anyhow::Result<()> {
Ok(())
}

View file

@ -1,16 +1,16 @@
mod db;
mod routes;
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpListener};
use std::net::{SocketAddr, TcpListener};
use anyhow::Context;
use axum::{routing::get, Extension, Router};
use sqlx::mysql::MySqlPoolOptions;
pub fn run_socket_worker() -> anyhow::Result<()> {
let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 3000));
use crate::config::Config;
let tcp_listener = create_tcp_listener(addr, false)?;
pub fn run_socket_worker(config: Config) -> anyhow::Result<()> {
let tcp_listener = create_tcp_listener(config.network.address)?;
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
@ -40,7 +40,7 @@ async fn run_app(tcp_listener: TcpListener) -> anyhow::Result<()> {
Ok(())
}
fn create_tcp_listener(addr: SocketAddr, only_ipv6: bool) -> anyhow::Result<TcpListener> {
fn create_tcp_listener(addr: SocketAddr) -> anyhow::Result<TcpListener> {
let domain = if addr.is_ipv4() {
socket2::Domain::IPV4
} else {
@ -49,10 +49,6 @@ fn create_tcp_listener(addr: SocketAddr, only_ipv6: bool) -> anyhow::Result<TcpL
let socket = socket2::Socket::new(domain, socket2::Type::STREAM, Some(socket2::Protocol::TCP))?;
if only_ipv6 {
socket.set_only_v6(true).with_context(|| "set only_ipv6")?;
}
socket
.set_reuse_port(true)
.with_context(|| "set_reuse_port")?;