分类目录归档:backend

[ git登陆保持 ]


git登陆保持

git credential-cache exit # 清除缓存
git config --global --unset credential.helper  # 删除
git config --global credential.helper store # 保持到文件

配置用户名邮箱

git config --global user.name "新的用户名"
git config --global user.email "新的邮箱"

git 输入密码后保存密码的文件

rm ~/.git-credentials

< Read more >

[ python同步变异步 ]


python中把不修改原来同步的代码,变成异步.

import asyncio
import time
from functools import wraps
from concurrent.futures import ThreadPoolExecutor
from typing import List, Callable, Any

# 创建数据库连接池
pool_executor = ThreadPoolExecutor(max_workers=10)

def to_async(func):
    @wraps(func)
    async def wrapper(*args, *

< Read more >

[ django下载文件浏览器显示进度条 ]


django使用流响应文件, 浏览器会有下载进度条, 可以点击进行暂停, 继续

后端

    @action(detail=False, methods=['get'], schema=AutoDocSchema())
    def get_big_files(self, request):
        def file_iterator(file_path, start_byte=0, chunk_size=256):
            with open(file_path, 'rb') as f:
                f.seek(

< Read more >

[ gin验证请求参数 ]


golang验证结构体

相当于验证用户上传的json参数

定义结构

package dto

type TestJsonReq struct {
    Name     string `json:"name" binding:"min=3,max=20,required"`
    Password string `json:"password" binding:"required"`
    Age      int    `json:"age" binding:"required

< Read more >

[ gin使用jwt ]


主要使用jwt/v5框架

package collections

import (
    "fmt"
    "time"

    "github.com/golang-jwt/jwt/v5"
)

var hmacSampleSecret = []byte("my_eyjwt_secret")

type TokenMap struct {
    Type     string
    Nbf      int64
    Username string
    UserId   int
    Exp 

< Read more >

[ golang创建环境 ]


golang创建环境-点击跳转官方文档

在当前文件夹下创建依赖跟踪mod

go mod init example/hello

chf@chf:~/go_obj/test$ cat go.mod

module test_mod

go 1.23.2

自动根据当前文件夹下使用到的模块,下载并且添加到mod里面

go mod tidy

配置mod使用关系

GO111MODULE开启或关闭模块支持 GO111MODULE=off 关闭模块支持,go 会从 GOPATH 和 vendor 文件夹寻找包。 GO111MODULE=on 开启模块支持,go 会忽略 GOPATH 和 vendo

< Read more >

[ golang安装 ]


golang下载安装-点击跳转官方文档

下载地址

Linux中安装

安装位置自行选择当前是/usr/local/

tar -C /usr/local -xzf go1.23.2.linux-amd64.tar.gz

您可以通过将以下行添加到 $HOME/.profile 或 /etc/profile(用于系统范围的安装):

export PATH=$PATH:/usr/local/go/bin

通过打开命令提示符并键入 Go 来验证是否已安装 Go 以下命令:

 go version

< Read more >

[ celery指定时间执行 ]


django中的celery任务指定时间执行

我这里是发送邮件, 定时晚上6点执行

from datetime import datetime, timedelta
from django.conf import settings
from django.utils import timezone
from backend.cews.tasks import send_email_when_check_eform
import pytz

def schedule_email(recipient_email, subject, message):
    """

< Read more >