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
// StringInt create a type alias for type int | |
type StringInt int | |
// UnmarshalJSON create a custom unmarshal for the StringInt | |
/// this helps us check the type of our value before unmarshalling it | |
func (st *StringInt) UnmarshalJSON(b []byte) error { | |
//convert the bytes into an interface | |
//this will help us check the type of our value | |
//if it is a string that can be converted into an int we convert it |
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
use jsonwebtoken::{ | |
decode, encode, Algorithm, DecodingKey, EncodingKey, Header, TokenData, Validation, | |
}; | |
use serde::{Deserialize, Serialize}; | |
#[derive(Serialize, Deserialize, Debug)] | |
pub struct Claims { | |
// aud: String, // Optional. Audience | |
pub exp: usize, // Required (validate_exp defaults to true in validation). Expiration time (as UTC timestamp) | |
pub iat: usize, // Optional. Issued at (as UTC timestamp) |
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
// compat module between xitca-http and axum. | |
mod tower_compat { | |
use core::{cell::RefCell, fmt, future::Future, marker::PhantomData}; | |
use std::net::SocketAddr; | |
use http_body::Body; | |
use xitca_http::{ | |
bytes::Bytes, | |
h1::RequestBody, |
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
type Datetime struct { | |
time.Time | |
} | |
func (t *Datetime) UnmarshalJSON(input []byte) error { | |
strInput := strings.Trim(string(input), `"`) | |
newTime, err := time.Parse("2006-01-02", strInput) | |
if err != nil { | |
return err | |
} |
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
fn main() { | |
let strs = ["hello world", "1", "hello", "world"]; | |
let mut remaining: &[&str] = &strs; | |
while let [current, tail @ ..] = remaining { | |
println!("{} - {:?}", current, tail); | |
remaining = tail; | |
} | |
println!("The real strs {:?}", strs); | |
} |
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
before_script: | |
- "command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )" | |
- eval $(ssh-agent -s) | |
- chmod 400 "$SSH_PRIVATE_KEY" | |
- ssh-add "$SSH_PRIVATE_KEY" | |
- mkdir -p ~/.ssh | |
- chmod 700 ~/.ssh |
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
{ | |
"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"], | |
"insecure-registries" : ["192.168.1.57:8004"], | |
"data-root": "/home/xfy/data/docker-var" | |
} |
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
use axum::{ | |
async_trait, | |
extract::{rejection::FormRejection, FromRequest, Request}, | |
Form, Json, | |
}; | |
use once_cell::sync::Lazy; | |
use regex::Regex; | |
use serde::de::DeserializeOwned; | |
use validator::Validate; |
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
use std::sync::OnceLock; | |
use jsonwebtoken::{DecodingKey, EncodingKey, Header}; | |
use serde::{Deserialize, Serialize}; | |
pub struct Keys { | |
pub encoding: EncodingKey, | |
pub decoding: DecodingKey, | |
} | |
impl Keys { |
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
use anyhow::{anyhow, Context}; | |
use tokio::task; | |
use argon2::password_hash::SaltString; | |
use argon2::{password_hash, Argon2, PasswordHash, PasswordHasher, PasswordVerifier}; | |
/// 生成 hash | |
/// | |
/// ## Arguments | |
/// |
NewerOlder