#[macro_use]
#[allow(unused_imports)]
extern crate serde_derive;
pub use serde_derive::{Deserialize, Serialize};
pub use actix_http;
pub use actix_rt;
pub use actix_web;
pub use async_trait;
pub use awc;
pub use futures;
pub use serde_json;
pub use serde_urlencoded;
pub use url;
pub use openssl;
pub use url::Url;
use actix_http::StatusCode;
use actix_web::{Error as ActixError, HttpResponse};
pub trait HasStatusCode {
fn status_code(&self) -> StatusCode;
}
#[derive(Debug, thiserror::Error)]
pub enum ClientError {
#[error("Unknown status code: {:?}", _0)]
BadStatus(StatusCode),
#[error("Actix error: {}", _0)]
Actix(#[from] ActixError),
}
pub fn configure_spec(
cfg: &mut actix_web::web::ServiceConfig,
spec: &'static str,
ui: &'static str,
) {
use actix_web::http::header::ContentType;
async fn serve_spec(spec: &'static str) -> HttpResponse {
HttpResponse::Ok()
.insert_header(ContentType::json())
.body(spec.to_owned())
}
async fn serve_ui(ui: &'static str) -> HttpResponse {
HttpResponse::Ok()
.insert_header(ContentType::json())
.body(ui.to_owned())
}
cfg.route(
"/spec.json",
actix_web::web::get().to(
move || serve_spec(spec), ),
)
.route("/ui.html", actix_web::web::get().to(move || serve_ui(ui)));
}
pub struct Config {
pub host: Url,
pub ssl: Option<openssl::ssl::SslAcceptorBuilder>,
}
impl Config {
pub fn with_host(host: Url) -> Self {
Self { host, ssl: None }
}
}