Last active: a year ago
Rust tracing logger with write to file
use std::env;
use tracing_subscriber::{fmt, prelude::*, registry, EnvFilter};
pub fn init_logger() {
let formatting_layer = fmt::layer()
// .pretty()
.with_thread_ids(false)
.with_target(false)
.with_writer(std::io::stdout);
let env_layer = EnvFilter::try_from_env("RHEA_LOG").unwrap_or_else(|_| {
format!("{}=info,tower_http=info,axum=info", env!("CARGO_PKG_NAME")).into()
});
registry().with(env_layer).with(formatting_layer).init();
}
Last active: a year ago
Rust tracing logger with write to file
use crate::config::Config;
use anyhow::Result;
use tracing_appender::{non_blocking::WorkerGuard, rolling};
use tracing_error::ErrorLayer;
use tracing_subscriber::{
filter, fmt, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, Registry,
};
pub fn logger_init(config: &Config) -> Result<WorkerGuard> {
let log_path = config.log_path.as_ref().expect("Can not read log path");
let formatting_layer = fmt::layer()
// .pretty()
.with_thread_ids(true)
.with_target(false)
.with_writer(std::io::stdout);
let file_appender = rolling::daily(log_path, "rus-list.log");
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
let file_layer = fmt::layer()
Last active: a year ago
Rust tracing logger with write to file
use tracing::level_filters::LevelFilter;
use tracing_subscriber::{fmt, layer::SubscriberExt, registry, util::SubscriberInitExt, EnvFilter};
pub fn init_logger() {
let formatting_layer = fmt::layer()
.with_thread_ids(true)
.with_target(true)
.with_writer(std::io::stdout);
let env_layer = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.with_env_var("SPIO_LOG")
.from_env_lossy();
registry().with(env_layer).with(formatting_layer).init();
}
Last active: 2 years ago
tokio http simple server
use anyhow::Result;
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::net::TcpListener;
#[tokio::main]
async fn main() -> Result<()> {
let listener = TcpListener::bind("localhost:4000").await?;
loop {
let (mut socket, _) = listener.accept().await?;
tokio::spawn(async move {
let (reader, mut write) = socket.split();
let mut buf = BufReader::new(reader);
let mut req = String::new();
loop {
let count = buf.read_line(&mut req).await.unwrap();
dbg!(count);
if count < 3 {
Last active: 2 years ago
Zego redux slice
import { Message } from '@/projects/court/hooks/zego/useMessage';
import { FileListData, FileListDatum } from '@/utils/api/chat';
import { createSelector, createSlice, PayloadAction } from '@reduxjs/toolkit';
import { nanoid } from 'nanoid';
import { ZegoStreamList } from 'zego-express-engine-webrtc/sdk/code/zh/ZegoExpressEntity.web';
import { ZegoUser } from 'zego-express-engine-webrtc/sdk/src/common/zego.entity';
import { ZegoBroadcastMessageInfo } from 'zego-express-engine-webrtm/sdk/code/zh/ZegoExpressEntity';
import { RootState } from '..';
export type RoomState = {
// 即构 APP ID
appID: number;
// 当前房间 ID
roomId: string;
// 即构当前用户 ID 与参展商手机号相同
userId: string;
// 用户名
userName: string;
// 用户角色
userType: '' | 'judege' | 'normal';
Last active: 2 years ago
unicodeAndAscii
/**
* 将 Unicode 编码为 ASCII
*/
export const toBinary = (target: string): string => {
const codeUnits = new Uint16Array(target.length);
for (let i = 0; i < codeUnits.length; i++) {
codeUnits[i] = target.charCodeAt(i);
}
const charCodes = new Uint8Array(codeUnits.buffer);
let result = '';
for (let i = 0; i < charCodes.byteLength; i++) {
result += String.fromCharCode(charCodes[i]);
}
return result;
};
/**
* 将 toBinary 编码过的 ASCII 解码为 Unicode
*/
export const fromBinary = (target: string): string => {
Last active: 2 years ago
import { Message } from '@/projects/court/hooks/zego/useMessage';
import { ZegoBroadcastMessageInfo } from 'zego-express-engine-webrtm/sdk/code/zh/ZegoExpressEntity';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { ZegoStreamList } from 'zego-express-engine-webrtc/sdk/code/zh/ZegoExpressEntity.web';
import { ZegoUser } from 'zego-express-engine-webrtc/sdk/src/common/zego.entity';
import { nanoid } from 'nanoid';
import { RoomState } from '@/projects/court/hooks/zego/useZego';
import { RootState } from '..';
export const initRoomState = {
appID: 0,
roomId: '',
// 用户 id 为当前登陆展台的手机号,必须先登陆
userId: '',
userName: '',
token: '',
id: '',
};
export type RoomUserMsg = {
Last active: 2 years ago
import LabelItem from '@/components/LabelItem';
import { globalSelectDone } from '@/projects/editor/data';
import { SearchData, SearchDataContent } from '@/show/interface';
import { SceneInfo, SpotBase } from '@/show/lib';
import { useAppDispatch, useAppSelector } from '@/store';
import { addSearchData, delSearchData } from '@/store/core/slice';
import { resetWithTarget, setShowSceneLibrary } from '@/store/ui/slice';
import { searchTypeList, serializeList } from '@/utils/api/search-list';
import { DeleteOutlined, DownOutlined } from '@ant-design/icons';
import { useBoolean, useRequest } from 'ahooks';
import { Button, Cascader, Dropdown, Empty, Menu, Popover } from 'antd';
import { useMemo, useState } from 'react';
import { MarkItem } from '../SandTable/Style';
import { Content } from './index.styles';
// 名称 map
export const typeMap = {
scene: '场景',
spot: '热点',
};
Last active: 2 years ago
/**
* 虚拟法院
*
* 分类搜索
*/
addSearchData(
state,
action: PayloadAction<{
list: number[];
data: SearchDataContent;
}>
) {
const searchData = state.proj.data.searchData;
const { list, data } = action.payload;
const len = list.length;
const defaultItem = {
id: 0,
pid: 0,
};
Last active: 2 years ago
import { useImmer } from 'use-immer';
import { ZegoDeviceInfo } from 'zego-express-engine-webrtc/sdk/code/zh/ZegoExpressEntity.web';
import { useCallback, useRef } from 'react';
import { ZegoExpressEngine } from 'zego-express-engine-webrtc';
/**
* 枚举并检测设备权限
* @param zg
* @returns
*/
const useDevices = (zg: ZegoExpressEngine | null) => {
// 设备列表 状态
const [device, setDevice] = useImmer<{
audioDeviceList: ZegoDeviceInfo[];
videoDeviceList: ZegoDeviceInfo[];
microphoneDevicesVal: string;
cameraDevicesVal: string;
}>({
audioDeviceList: [],
videoDeviceList: [],
Last active: 2 years ago
const setDepth = <T extends 'hide' | 'opacity'>(
type: T,
value: T extends 'opacity' ? string : boolean
) => {}
Last active: 2 years ago
use anyhow::Result;
use tokio::io;
use tokio::net::TcpListener;
#[tokio::main]
async fn main() -> Result<()> {
let listener = TcpListener::bind("localhost:6142").await?;
loop {
let (socket, _) = listener.accept().await?;
let (mut read, mut write) = io::split(socket);
tokio::spawn(async move {
io::copy(&mut read, &mut write).await?;
Ok::<_, io::Error>(())
});
}
}
Last active: 2 years ago
use anyhow::Result;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpListener;
#[tokio::main]
async fn main() -> Result<()> {
let listener = TcpListener::bind("localhost:6142").await?;
loop {
let (mut socket, _) = listener.accept().await?;
tokio::spawn(async move {
let mut buffer = vec![0; 10];
loop {
dbg!(&buffer);
match socket.read(&mut buffer).await {
Ok(0) => (),
Ok(_bytes) => (),
Err(_err) => (),
}