mirror of
https://github.com/ZeusWPI/ZNS.git
synced 2024-11-22 05:41:11 +01:00
format
This commit is contained in:
parent
335670c3c2
commit
5cd801a6d0
4 changed files with 10 additions and 7 deletions
10
src/api.rs
10
src/api.rs
|
@ -36,7 +36,7 @@ async fn create_record(req: Request<hyper::body::Incoming>) -> Result<Response<B
|
||||||
Ok(record) => {
|
Ok(record) => {
|
||||||
let rdata = record
|
let rdata = record
|
||||||
._type
|
._type
|
||||||
.to_bytes(&record.data)
|
.to_data(&record.data)
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
match insert_into_database(RR {
|
match insert_into_database(RR {
|
||||||
name: record.name,
|
name: record.name,
|
||||||
|
@ -67,9 +67,13 @@ async fn create_record(req: Request<hyper::body::Incoming>) -> Result<Response<B
|
||||||
|
|
||||||
async fn get_record(req: Request<hyper::body::Incoming>) -> Result<Response<BoxBody>> {
|
async fn get_record(req: Request<hyper::body::Incoming>) -> Result<Response<BoxBody>> {
|
||||||
if let Some(q) = req.uri().query() {
|
if let Some(q) = req.uri().query() {
|
||||||
let params = form_urlencoded::parse(q.as_bytes()).into_owned().collect::<HashMap<String,String>>();
|
let params = form_urlencoded::parse(q.as_bytes())
|
||||||
|
.into_owned()
|
||||||
|
.collect::<HashMap<String, String>>();
|
||||||
if let Some(domain) = params.get("domain_name") {
|
if let Some(domain) = params.get("domain_name") {
|
||||||
return Ok(Response::builder().status(StatusCode::OK).body(full(domain.to_owned()))?)
|
return Ok(Response::builder()
|
||||||
|
.status(StatusCode::OK)
|
||||||
|
.body(full(domain.to_owned()))?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ use diesel::sqlite::SqliteConnection;
|
||||||
use dotenvy::dotenv;
|
use dotenvy::dotenv;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
|
|
||||||
pub fn establish_connection() -> SqliteConnection {
|
pub fn establish_connection() -> SqliteConnection {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
pub mod models;
|
|
||||||
pub mod lib;
|
pub mod lib;
|
||||||
|
pub mod models;
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub trait FromBytes {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Type {
|
impl Type {
|
||||||
pub fn to_bytes(&self, text: &String) -> Result<Vec<u8>> {
|
pub fn to_data(&self, text: &String) -> Result<Vec<u8>> {
|
||||||
match self {
|
match self {
|
||||||
Type::A => {
|
Type::A => {
|
||||||
let arr: Vec<u8> = text
|
let arr: Vec<u8> = text
|
||||||
|
@ -57,7 +57,7 @@ impl Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn from_bytes(&self, bytes: &[u8]) -> Result<String> {
|
pub fn from_data(&self, bytes: &[u8]) -> Result<String> {
|
||||||
match self {
|
match self {
|
||||||
Type::A => {
|
Type::A => {
|
||||||
if bytes.len() == 4 {
|
if bytes.len() == 4 {
|
||||||
|
|
Loading…
Reference in a new issue