Skip to content

Commit

Permalink
add helper function to get sdk version
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin67 committed Nov 1, 2024
1 parent 7e534a9 commit 5ce0b53
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions inngest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pub mod serve;
pub mod signature;
pub mod step_tool;
pub(crate) mod utils;
pub(crate) mod version;
17 changes: 7 additions & 10 deletions inngest/src/serve/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
basic_error,
handler::{Handler, IntrospectResult, RunQueryParams, SyncQueryParams, SyncResponse},
header::{self, Headers},
result::{Error, SdkResponse},
result::{Error, SdkResponse}, version,
};

use axum::{
Expand Down Expand Up @@ -57,13 +57,12 @@ where
impl IntoResponse for SdkResponse {
fn into_response(self) -> axum::response::Response {
let mut headers = HeaderMap::new();
let sdk = format!("rust:{}", env!("CARGO_PKG_VERSION"));
headers.insert(
header::CONTENT_TYPE,
HeaderValue::from_static("application/json"),
);
headers.insert(header::INNGEST_FRAMEWORK, HeaderValue::from_static("axum"));
headers.insert(header::INNGEST_SDK, HeaderValue::from_str(&sdk).unwrap());
headers.insert(header::INNGEST_FRAMEWORK, HeaderValue::from_static(&FRAMEWORK));
headers.insert(header::INNGEST_SDK, HeaderValue::from_str(&version::sdk()).unwrap());
headers.insert(header::INNGEST_REQ_VERSION, HeaderValue::from_static("1"));

match self.status {
Expand All @@ -79,13 +78,12 @@ impl IntoResponse for SdkResponse {
impl IntoResponse for SyncResponse {
fn into_response(self) -> axum::response::Response {
let mut headers = HeaderMap::new();
let sdk = format!("rust:{}", env!("CARGO_PKG_VERSION"));
headers.insert(
header::CONTENT_TYPE,
HeaderValue::from_static("application/json"),
);
headers.insert(header::INNGEST_FRAMEWORK, HeaderValue::from_static("axum"));
headers.insert(header::INNGEST_SDK, HeaderValue::from_str(&sdk).unwrap());
headers.insert(header::INNGEST_FRAMEWORK, HeaderValue::from_static(&FRAMEWORK));
headers.insert(header::INNGEST_SDK, HeaderValue::from_str(&version::sdk()).unwrap());
headers.insert(header::INNGEST_REQ_VERSION, HeaderValue::from_static("1"));

(StatusCode::OK, headers, Json(&self)).into_response()
Expand All @@ -95,13 +93,12 @@ impl IntoResponse for SyncResponse {
impl IntoResponse for IntrospectResult {
fn into_response(self) -> axum::response::Response {
let mut headers = HeaderMap::new();
let sdk = format!("rust:{}", env!("CARGO_PKG_VERSION"));
headers.insert(
header::CONTENT_TYPE,
HeaderValue::from_static("application/json"),
);
headers.insert(header::INNGEST_FRAMEWORK, HeaderValue::from_static("axum"));
headers.insert(header::INNGEST_SDK, HeaderValue::from_str(&sdk).unwrap());
headers.insert(header::INNGEST_FRAMEWORK, HeaderValue::from_static(&FRAMEWORK));
headers.insert(header::INNGEST_SDK, HeaderValue::from_str(&version::sdk()).unwrap());
headers.insert(header::INNGEST_REQ_VERSION, HeaderValue::from_static("1"));

(StatusCode::OK, headers, Json(&self)).into_response()
Expand Down
3 changes: 3 additions & 0 deletions inngest/src/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub(crate) fn sdk() -> String {
format!("rust:{}", env!("CARGO_PKG_VERSION"))
}

0 comments on commit 5ce0b53

Please sign in to comment.