单机使用手册
1 服务管理
1.1 配置管理
1.1.1 配置全览
# coding:utf8
"""
Butterfly config
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SERVER_LISTEN_ADDR = ("0.0.0.0", 8585)
SERVER_THREAD_NUM = 16
SERVER_NAME = "Butterfly_app"
# Reqid prefix, two characters
SERVER_ID = "BF"
SERVER_IDC = "default"
# static
STATIC_PATH = "static"
STATIC_PREFIX = "static"
# DB
"""
# wuxing/ruqi use default database
"""
DATABASES = {
"default": "mysql+retrypool://root:password@127.0.0.1:3306/test?max_connections=300&stale_timeout=300",
}
# Redis
"""
# eg1:"redis://[[username]:[password]]@localhost:6379/0"
# eg2:"redis://@localhost:6379/0?socket_timeout=2&socket_connect_timeout=1&retry_on_timeout=true"
"""
CACHES = {
"default": "redis://@localhost:6379/0",
# for cache: connect_timeout 100ms, read_timeout 200ms
# "wuxing": "redis://@localhost:6379/0?socket_timeout=0.2&socket_connect_timeout=0.1&retry_on_timeout=false",
# for mq: connect_timeout 500ms, read_timeout 2000ms
# "baichuan": "redis://@localhost:6379/0?socket_timeout=2&socket_connect_timeout=0.5&retry_on_timeout=false",
}
# Local data or cache
LOCALDATA_DIR = os.path.join(BASE_DIR, "data")
# Auth
SECRET_KEY = None # If it is None, a key will be randomly generated each time butterfly is started
JWT_TOKEN_TTL = 28800 # default 8 hours
HEADER_USERNAME = "HTTP_X_USERNAME"
# Scheduler
scheduler_store = "memory" # ("mysql"/"memory")
# Adaptor
"""
# {"stat":"ERR", "data":{}} --> {"stat":"ERR", "success":False, "message":"ERR", "data":{}}
STAT_ADAPTOR={"status_name":"success", "status_map":{"OK":True,"default":False}, "message_name":"message"}
"""
STAT_ADAPTOR = None1.1.2 SERVER
1.1.4 STATIC
1.1.5 DB
1.1.6 Redis
1.1.7 LOCALDATA
1.1.8 AUTH
1.1.9 Scheduler
1.1.10 Adaptor
1.2 启动管理
如何修改启动项标识
1.3 日志管理
1.3.1 启动日志
1.3.2 butterfly 框架日志
1.3.3 自定义日志输出
2 接口开发
2.1 编写函数(根据返回值,区分为两种方式)
2.1.1 推荐方式
2.1.2 自定义 HTTP 码返回方式
2.2 路由注册
2.3 访问接口函数
get 请求
post 请求
python post 方式提交 json 字符串
2.4 handler 访问本目录文件
3 手动测试 handler
Last updated