configs

package
v0.1.0-beta.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 2 Imported by: 0

README

自定义配置

您可以在您的程序运行的根目录创建此文件,程序会自动读取。 完整参数详见本目录的config.yaml 文件。

限流配置

您可以对您的搜题接口针对IP进行限流,防止恶意请求。默认是关闭的状态。

limit:
  enable: false # 是否开启
  duration: 3  # 时间窗口为3秒
  requests: 1  # 允许用户在3秒内通过1个请求

自定义外部题库配置

当然您也可以接入外部的第三方题库,通过简单的配置,如下给出两个demo。 其中需要注意的是:

  • url字段是您的题库的接口地址。
  • method字段是您的题库的请求方法。
  • headers字段是您的题库的请求头,您可以通过keyvalue来设置。必须设置正确Content-Type,否则可能无法正常请求。
  • body字段是您的题库的请求体,您可以通过${question}来获取用户的问题。支持的占位符有 ${question}${type}
  • answer字段是您的题库返回的答案的路径,您可以通过jsonpath语法来获取。

以下为您提供两个开箱即用的demo,您可以直接复制到您的config.yaml中,然后修改enabletrue即可测试。但是您需要注意,以下两个题库均已经集成到tikuAdapter中,所以您无需再次配置它,当您测试完毕,将enable改为false即可。

api:
  - name: '样例接口 json 请求'
    enable: false
    url: http://lyck6.cn/scriptService/api/autoFreeAnswer
    method: POST
    headers:
      - key: Content-Type
        value: application/json
    body: '{"question":"${question}"}'
    answer: 'result.answers.0.0'

  - name: '样例接口 表单请求'
    enable: false
    url: https://cx.icodef.com/wyn-nb?v=4
    method: POST
    headers:
      - key: Content-Type
        value: application/x-www-form-urlencoded
    body: 'question=${question}'
    answer: 'data'

自动录入题库功能

使用脚本答题或者请求API接口,将会自动记录您的问题和答案,可以通过 recordEmptyAnswer 来控制是否记录空答案。

recordEmptyAnswer: true # 设置为 true 将会记录空答案否则只会记录已有答案

持久化到数据库

您可以将您的题库数据持久化到数据库,目前支持的数据库有mysqlsqlite,您可以通过mysql来设置。如果不配置,默认使用sqlite

mysql: username:password@tcp(localhost:3306)/databasename

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Limit             LimitConfig          `yaml:"limit"`
	API               []search.API         `yaml:"api"`
	Elasticsearch     elasticsearch.Config `yaml:"elasticsearch"`
	RecordEmptyAnswer bool                 `yaml:"recordEmptyAnswer"`
	Mysql             string               `yaml:"mysql"`
}

Config 所有的配置文件

type LimitConfig

type LimitConfig struct {
	Enable   bool   `yaml:"enable"`
	Duration uint   `yaml:"duration"`
	Requests uint64 `yaml:"requests"`
}

LimitConfig 限流配置

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL