1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 20:13:50 +08:00

fix golint.

This commit is contained in:
wdvxdr 2021-07-25 13:04:15 +08:00
parent e56e3b5036
commit 19b2a86c7c
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
3 changed files with 16 additions and 14 deletions

View File

@ -125,6 +125,7 @@ type WebsocketReverse struct {
MiddleWares `yaml:"middlewares"`
}
// LambdaServer 云函数配置
type LambdaServer struct {
Disabled bool `yaml:"disabled"`
Type string `yaml:"type"`
@ -246,6 +247,7 @@ func generateConfig() {
> 2: 正向 Websocket 通信
> 3: 反向 Websocket 通信
> 4: pprof 性能分析服务器
> 5: 云函数服务
请输入你需要的编号可输入多个同一编号也可输入多个(: 233)
您的选择是:`)
input := bufio.NewReader(os.Stdin)
@ -263,6 +265,8 @@ func generateConfig() {
sb.WriteString(wsReverseDefault)
case '4':
sb.WriteString(pprofDefault)
case '5':
sb.WriteString(lambdaDefault)
}
}
_ = os.WriteFile("config.yml", []byte(sb.String()), 0o644)

View File

@ -382,7 +382,6 @@ func main() {
} else {
coolq.SetMessageFormat(conf.Message.PostFormat)
}
log.Info("正在加载事件过滤器.")
coolq.IgnoreInvalidCQCode = conf.Message.IgnoreInvalidCQCode
coolq.SplitURL = conf.Message.FixURL
coolq.ForceFragmented = conf.Message.ForceFragment

View File

@ -19,12 +19,11 @@ import (
)
type lambdaClient struct {
nextUrl string
nextURL string
responseURL string
lambdaType string
client http.Client
http *httpServer
}
type lambdaResponse struct {
@ -55,7 +54,7 @@ func (l *lambdaResponseWriter) Write(data []byte) (int, error) {
for k, v := range l.header {
header[k] = v[0]
}
json.NewEncoder(buffer).Encode(&lambdaResponse{
_ = json.NewEncoder(buffer).Encode(&lambdaResponse{
IsBase64Encoded: false,
StatusCode: l.statusCode,
Headers: header,
@ -77,9 +76,10 @@ func (l *lambdaResponseWriter) WriteHeader(statusCode int) {
var cli *lambdaClient
func init() {
// RunLambdaClient type: [scf,aws]
func RunLambdaClient(bot *coolq.CQBot, conf *config.LambdaServer) {
cli = &lambdaClient{
lambdaType: "scf",
lambdaType: conf.Type,
client: http.Client{Timeout: 0},
}
switch cli.lambdaType { // todo: aws
@ -88,7 +88,7 @@ func init() {
os.Getenv("SCF_RUNTIME_API"),
os.Getenv("SCF_RUNTIME_API_PORT"),
)
cli.nextUrl = base + "invocation/next"
cli.nextURL = base + "invocation/next"
cli.responseURL = base + "invocation/response"
post, err := http.Post(base+"init/ready", "", nil)
if err != nil {
@ -99,13 +99,12 @@ func init() {
case "aws": // aws lambda
const apiVersion = "2018-06-01"
base := fmt.Sprintf("http://%s/%s/runtime/", os.Getenv("AWS_LAMBDA_RUNTIME_API"), apiVersion)
cli.nextUrl = base + "invocation/next"
cli.nextURL = base + "invocation/next"
cli.responseURL = base + "invocation/response"
default:
log.Fatal("unknown lambda type:", conf.Type)
}
}
// RunLambdaClient type: [scf,aws]
func RunLambdaClient(bot *coolq.CQBot, conf *config.LambdaServer) {
api := newAPICaller(bot)
if conf.RateLimit.Enabled {
api.use(rateLimit(conf.RateLimit.Frequency, conf.RateLimit.Bucket))
@ -135,7 +134,7 @@ func RunLambdaClient(bot *coolq.CQBot, conf *config.LambdaServer) {
type lambdaInvoke struct {
Headers map[string]string
HttpMethod string `json:"httpMethod"`
HTTPMethod string `json:"httpMethod"`
Body string `json:"body"`
Path string `json:"path"`
QueryString map[string]string
@ -145,7 +144,7 @@ type lambdaInvoke struct {
}
func (c *lambdaClient) next() *http.Request {
r, err := http.NewRequest(http.MethodGet, c.nextUrl, nil)
r, err := http.NewRequest(http.MethodGet, c.nextURL, nil)
if err != nil {
return nil
}
@ -161,7 +160,7 @@ func (c *lambdaClient) next() *http.Request {
var invoke = new(lambdaInvoke)
_ = json.NewDecoder(resp.Body).Decode(invoke)
req.Method = invoke.HttpMethod
req.Method = invoke.HTTPMethod
req.Body = io.NopCloser(strings.NewReader(invoke.Body))
req.Header = make(map[string][]string)
for k, v := range invoke.Headers {