Browse Source

Adding health encdpoint

* Reorgnaized to use router for the actix_web::App factory
*Inlined the version from the cargo metadata
* Changed the project name to rsddns
* Added a healthcheck function
* Added dependencies serde and serde_derive
* Added build configuration to the release profile to shrink binary
master
Drew Short 6 years ago
parent
commit
21c7b74ce2
  1. 6
      .gitlab-ci.yml
  2. 22
      Cargo.lock
  3. 10
      Cargo.toml
  4. 11
      src/main.rs
  5. 13
      src/router.rs
  6. 7
      src/server.rs
  7. 16
      src/server/mod.rs

6
.gitlab-ci.yml

@ -17,7 +17,7 @@ debug:
- cargo build
artifacts:
paths:
- target/debug/ddns
- target/debug/rsddns
tags:
- docker
@ -26,9 +26,9 @@ release:
stage: build
script:
- cargo build --release
- strip target/release/ddns
- strip target/release/rsddns
artifacts:
paths:
- target/release/ddns
- target/release/rsddns
tags:
- docker

22
Cargo.lock

@ -360,16 +360,6 @@ dependencies = [
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ddns"
version = "0.1.0"
dependencies = [
"actix-web 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cloudflare 0.1.0 (git+https://github.com/nocduro/cloudflare-rs)",
"yaml-rust 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.3"
@ -1113,6 +1103,18 @@ dependencies = [
"untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rsddns"
version = "0.1.0"
dependencies = [
"actix-web 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cloudflare 0.1.0 (git+https://github.com/nocduro/cloudflare-rs)",
"serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)",
"yaml-rust 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-demangle"
version = "0.1.9"

10
Cargo.toml

@ -1,10 +1,18 @@
[package]
name = "ddns"
name = "rsddns"
version = "0.1.0"
authors = ["Drew Short <warrick@sothr.com>"]
[profile.release]
panic = "abort"
lto = true
codegen-units = 1
incremental = false
[dependencies]
clap = "2.32.0"
yaml-rust = "0.4.0"
serde = "1.0.78"
serde_derive = "1.0.78"
actix-web = "0.7.7"
cloudflare = { git = "https://github.com/nocduro/cloudflare-rs", branch = "master" }

11
src/main.rs

@ -1,13 +1,20 @@
#[macro_use]
extern crate serde_derive;
extern crate actix_web;
extern crate clap;
extern crate serde;
use clap::{App, Arg};
mod router;
mod server;
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
fn main() {
let args = App::new("Dynamic DNS Server")
.version("0.1")
.version(VERSION)
.author("Drew Short <warrick@sothr.com>")
.about("Recieve DDNS requests and update cloudflare subdomains")
.arg(
@ -37,7 +44,7 @@ fn main() {
println!("Starting server on {} with config {}", port, config);
actix_web::server::new(|| actix_web::App::new().resource("/", |r| r.f(server::index)))
actix_web::server::new(|| router::create())
.bind(format!("localhost:{}", port))
.unwrap()
.run();

13
src/router.rs

@ -0,0 +1,13 @@
extern crate actix_web;
use actix_web::{http, App};
use server;
pub fn create() -> App {
actix_web::App::new()
.resource("/", |r| r.f(server::index))
.resource("/health", |r| {
r.method(http::Method::GET).with(server::healthcheck)
})
}

7
src/server.rs

@ -1,7 +0,0 @@
extern crate actix_web;
use actix_web::HttpRequest;
pub fn index(_req: &HttpRequest) -> &'static str {
"Hello, World!"
}

16
src/server/mod.rs

@ -0,0 +1,16 @@
use actix_web::{HttpRequest, Json, Result};
use VERSION;
#[derive(Serialize)]
pub struct Health {
version: &'static str,
}
pub fn index(_req: &HttpRequest) -> &'static str {
"Hello, World!"
}
pub fn healthcheck(_req: HttpRequest) -> Result<Json<Health>> {
Ok(Json(Health { version: VERSION }))
}
Loading…
Cancel
Save