-
Notifications
You must be signed in to change notification settings - Fork 31
Refactor project structure, separate concerns, and enhance usage documentation #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e2dfc32
chore: restructure project layout and move tests to /tests
x0rw 756b809
Add examples register_service and deregister_service
x0rw d027678
Separate errors
x0rw 5b536bc
Update README.md
x0rw b927d46
Move lock and helper functions out of lib.rs for clarity
x0rw 6f8e474
Update README.md
x0rw 8c3b41e
Addressing reviews, ensuring non-breaking changes
x0rw f55c44c
Move tokio-test to dev-dependencies
x0rw 9ca1171
Re-export errors with proper visibility
x0rw 84b1c08
chores: directly exporting errors from consul_rs in test
x0rw 508cd66
migrate: replace quick_error with thiserror
x0rw 1fedbdd
Update Cargo.toml
x0rw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,23 @@ | ||
use rs_consul::{types::*, Config, Consul}; | ||
|
||
#[tokio::main] // Enables async main | ||
async fn main() { | ||
let consul_config = Config { | ||
address: "http://localhost:8500".to_string(), | ||
token: None, // Token is None in developpement mode | ||
..Default::default() | ||
}; | ||
let consul = Consul::new(consul_config); | ||
|
||
let node_id = "root-node"; | ||
let service_name = "new-service-1"; | ||
|
||
let payload = DeregisterEntityPayload { | ||
Node: Some(node_id.to_string()), | ||
Datacenter: None, | ||
CheckID: None, | ||
ServiceID: Some(service_name.to_string()), | ||
Namespace: None, | ||
}; | ||
consul.deregister_entity(&payload).await.unwrap(); | ||
} |
This file contains hidden or 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,34 @@ | ||
use rs_consul::{types::*, Config, Consul}; | ||
|
||
#[tokio::main] // Enables async main | ||
async fn main() { | ||
let consul_config = Config { | ||
address: "http://localhost:8500".to_string(), | ||
token: None, // Token is None in developpement mode | ||
..Default::default() | ||
}; | ||
let consul = Consul::new(consul_config); | ||
|
||
let node_id = "root-node"; | ||
let service_name = "new-service-1"; | ||
let payload = RegisterEntityPayload { | ||
ID: None, | ||
Node: node_id.to_string(), | ||
Address: "127.0.0.1".to_string(), | ||
Datacenter: None, | ||
TaggedAddresses: Default::default(), | ||
NodeMeta: Default::default(), | ||
Service: Some(RegisterEntityService { | ||
ID: None, | ||
Service: service_name.to_string(), | ||
Tags: vec![], | ||
TaggedAddresses: Default::default(), | ||
Meta: Default::default(), | ||
Port: Some(42424), | ||
Namespace: None, | ||
}), | ||
Check: None, | ||
SkipNodeUpdate: None, | ||
}; | ||
consul.register_entity(&payload).await.unwrap(); | ||
} |
This file contains hidden or 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,71 @@ | ||
use thiserror::Error; | ||
|
||
pub(crate) type Result<T> = std::result::Result<T, ConsulError>; | ||
|
||
/// The error type returned from all calls into this crate. | ||
#[derive(Debug, Error)] | ||
pub enum ConsulError { | ||
/// The request was invalid and could not be serialized to valid json. | ||
#[error("Invalid request: {0}")] | ||
InvalidRequest(#[source] serde_json::Error), | ||
|
||
/// The request was invalid and could not be converted into a proper http request. | ||
#[error("Request error: {0}")] | ||
RequestError(#[source] http::Error), | ||
|
||
/// The consul server response could not be converted into a proper http response. | ||
#[error("Response error: {0}")] | ||
ResponseError(#[source] hyper_util::client::legacy::Error), | ||
|
||
/// The consul server response was invalid. | ||
#[error("Invalid response: {0}")] | ||
InvalidResponse(#[source] hyper::Error), | ||
|
||
/// The consul server response could not be deserialized from json. | ||
#[error("Response deserialization failed: {0}")] | ||
ResponseDeserializationFailed(#[source] serde_json::Error), | ||
|
||
/// The consul server response could not be deserialized from bytes. | ||
#[error("Response string deserialization failed: {0}")] | ||
ResponseStringDeserializationFailed(#[source] std::str::Utf8Error), | ||
|
||
/// The consul server response was something other than 200. | ||
#[error("Unexpected response code: {0}, body: {1:?}")] | ||
UnexpectedResponseCode(hyper::http::StatusCode, Option<String>), | ||
|
||
/// The consul server refused a lock acquisition. | ||
#[error("Lock acquisition failure: {0}")] | ||
LockAcquisitionFailure(u64), | ||
|
||
/// Consul returned invalid UTF8. | ||
#[error("Invalid UTF8: {0}")] | ||
InvalidUtf8(#[from] std::str::Utf8Error), | ||
|
||
/// Consul returned invalid base64. | ||
#[error("Invalid base64: {0}")] | ||
InvalidBase64(#[from] base64::DecodeError), | ||
|
||
/// IO error from sync api. | ||
#[error("Sync IO error: {0}")] | ||
SyncIoError(#[from] std::io::Error), | ||
|
||
/// Response parse error from sync api. | ||
#[error("Sync invalid response error: {0}")] | ||
SyncInvalidResponseError(#[from] std::str::ParseBoolError), | ||
|
||
/// Unexpected response code from sync api. | ||
#[error("Sync unexpected response code: {0}, body: {1}")] | ||
SyncUnexpectedResponseCode(u16, String), | ||
|
||
/// Consul request exceeded specified timeout. | ||
#[error("Consul request exceeded timeout of {0:?}")] | ||
TimeoutExceeded(std::time::Duration), | ||
|
||
/// Unable to resolve the service's instances in Consul. | ||
#[error("Unable to resolve service '{0}' to a concrete list of addresses and ports for its instances via consul.")] | ||
ServiceInstanceResolutionFailed(String), | ||
|
||
/// An error from ureq occurred. | ||
#[error("UReq error: {0}")] | ||
UReqError(#[from] ureq::Error), | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.