-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
201 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "land-apiserver" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
authors = { workspace = true } | ||
|
||
[dependencies] | ||
anyhow = { workspace = true } | ||
axum = { workspace = true } | ||
clap = { workspace = true } | ||
land-common = { workspace = true } | ||
land-dao = { workspace = true } | ||
tokio = { workspace = true } | ||
tracing = { workspace = true } | ||
land-core-service = { workspace = true } | ||
serde = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use land_common::tracing::TraceArgs; | ||
use land_common::version; | ||
|
||
mod server; | ||
mod v1; | ||
|
||
#[derive(Parser, Debug)] | ||
#[clap(author, version)] | ||
#[clap(disable_version_flag = true)] // handled manually | ||
#[clap( | ||
name = env!("CARGO_PKG_NAME"), | ||
about = concat!(env!("CARGO_PKG_NAME")," ",env!("CARGO_PKG_VERSION")), | ||
)] | ||
struct Args { | ||
/// Print version info and exit. | ||
#[clap(short = 'V', long)] | ||
version: bool, | ||
#[clap(flatten)] | ||
output: TraceArgs, | ||
/// Address to listen on. | ||
#[clap(long, default_value("0.0.0.0:9814"))] | ||
address: String, | ||
#[clap(flatten)] | ||
dbargs: land_dao::db::DBArgs, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let args = Args::parse(); | ||
if args.version { | ||
version::print(env!("CARGO_PKG_NAME"), args.output.verbose); | ||
return Ok(()); | ||
} | ||
|
||
// Initialize tracing | ||
land_common::tracing::init(args.output.verbose); | ||
|
||
// Connect to database | ||
args.dbargs.connect().await?; | ||
|
||
// Start the server | ||
server::start(args.address.parse()?).await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use anyhow::Result; | ||
use axum::routing::get; | ||
use axum::Router; | ||
use std::net::SocketAddr; | ||
use tracing::info; | ||
|
||
use crate::v1; | ||
|
||
pub async fn start(addr: SocketAddr) -> Result<()> { | ||
// routes | ||
let app = Router::new() | ||
.route("/", get(index)) | ||
.nest("/v1", v1::router()?); | ||
|
||
info!("Starting server on {}", addr); | ||
|
||
// with connect info | ||
let app = app.into_make_service_with_connect_info::<SocketAddr>(); | ||
|
||
// run server | ||
let listener = tokio::net::TcpListener::bind(addr).await?; | ||
axum::serve(listener, app).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn index() -> &'static str { | ||
"Hello, World!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use anyhow::Result; | ||
use axum::routing::post; | ||
use axum::Router; | ||
|
||
pub mod tokens; | ||
|
||
pub fn router() -> Result<Router> { | ||
Ok(Router::new().route("/token", post(tokens::create))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use axum::response::IntoResponse; | ||
use axum::Json; | ||
use land_core_service::httputil::ServerJsonError; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct CreateTokenUserParam { | ||
pub first_name: String, | ||
pub last_name: String, | ||
pub email: String, | ||
pub image_url: String, | ||
pub has_image: bool, | ||
pub identifier: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct CreateTokenSessionParam { | ||
pub id: String, | ||
pub value: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct CreateTokenParam { | ||
pub user: CreateTokenUserParam, | ||
pub session: CreateTokenSessionParam, | ||
} | ||
|
||
pub async fn create(Json(j): Json<CreateTokenParam>) -> Result<impl IntoResponse, ServerJsonError> { | ||
println!("{:?}", j); | ||
Ok(Json("abc")) | ||
} |