03 2025 档案

摘要:package main​import ( "crypto/hmac" "crypto/sha256" "encoding/base64" "encoding/json" "fmt" "time")​// jwt原始头部信息type JwtHeaderRaw struct { Alg string 阅读全文
posted @ 2025-03-31 17:41 CJTARRR 阅读(50) 评论(0) 推荐(0)
摘要:StdEncoding: 常规编码 base64.StdEncoding.EncodeToString([]byte("Hello world. 你好,世界!"))// SGVsbG8gd29ybGQuIOS9oOWlve+8jOS4lueVjO+8gQ== URLEncoding: URL saf 阅读全文
posted @ 2025-03-31 17:17 CJTARRR 阅读(165) 评论(0) 推荐(0)
摘要:// Distinct 函数用于对输入的切片进行去重,支持整型、浮点型和字符串类型func Distinct[T int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | floa 阅读全文
posted @ 2025-03-28 11:02 CJTARRR 阅读(70) 评论(0) 推荐(0)
摘要:import asynciofrom inspect import iscoroutinefunctionfrom typing import Any, Awaitable, List​​class CoroutinePool: def __init__(self, max_size: int): 阅读全文
posted @ 2025-03-13 15:28 CJTARRR 阅读(28) 评论(0) 推荐(0)
摘要:import asyncio class AsyncReadWriteLock: def __init__(self): self._readers = 0 self._writers_waiting = 0 self._writer_active = False self._lock = asyn 阅读全文
posted @ 2025-03-13 15:07 CJTARRR 阅读(67) 评论(0) 推荐(0)
摘要:背景 python利用多核就需要开启多进程,如果多进程之间需要共享数据又不希望引入第三方的服务,就需要使用共享内存。 multiprocessing.shared_memory python 3.8之后,python内置的multiprocessing库提供了一种新的共享内存方式,shared_me 阅读全文
posted @ 2025-03-13 09:45 CJTARRR 阅读(1316) 评论(0) 推荐(0)
摘要:安装 pip install "redis[hiredis]" 检查是否启用hiredis import redisimport redis.connectionfrom redis.connection import ConnectionPoolfrom redis.utils import HI 阅读全文
posted @ 2025-03-12 16:23 CJTARRR 阅读(101) 评论(0) 推荐(0)
摘要:import re options = "i" regex_pattern = re.escape(字符串) query = {"$regex": regex_pattern, "$options": options} 结果 = 集合.find(query) # 这里用re.escape套一下字符串 阅读全文
posted @ 2025-03-12 09:33 CJTARRR 阅读(69) 评论(0) 推荐(0)
摘要:1.在fastapi的中间件中,如果不做处理直接抛出HttpException,框架是不会捕获并处理成响应的,这时客户端看到的就是500 Internal Server Error。 2.为了能在中间件中直接抛出异常,方便写代码,需要自己添加一个中间件来对所有中间件的异常做处理。该中间件代码如下: 阅读全文
posted @ 2025-03-07 09:50 CJTARRR 阅读(197) 评论(0) 推荐(0)