mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-07 04:23:49 +08:00
fix golint.
This commit is contained in:
parent
e56e3b5036
commit
19b2a86c7c
@ -125,6 +125,7 @@ type WebsocketReverse struct {
|
|||||||
MiddleWares `yaml:"middlewares"`
|
MiddleWares `yaml:"middlewares"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LambdaServer 云函数配置
|
||||||
type LambdaServer struct {
|
type LambdaServer struct {
|
||||||
Disabled bool `yaml:"disabled"`
|
Disabled bool `yaml:"disabled"`
|
||||||
Type string `yaml:"type"`
|
Type string `yaml:"type"`
|
||||||
@ -246,6 +247,7 @@ func generateConfig() {
|
|||||||
> 2: 正向 Websocket 通信
|
> 2: 正向 Websocket 通信
|
||||||
> 3: 反向 Websocket 通信
|
> 3: 反向 Websocket 通信
|
||||||
> 4: pprof 性能分析服务器
|
> 4: pprof 性能分析服务器
|
||||||
|
> 5: 云函数服务
|
||||||
请输入你需要的编号,可输入多个,同一编号也可输入多个(如: 233)
|
请输入你需要的编号,可输入多个,同一编号也可输入多个(如: 233)
|
||||||
您的选择是:`)
|
您的选择是:`)
|
||||||
input := bufio.NewReader(os.Stdin)
|
input := bufio.NewReader(os.Stdin)
|
||||||
@ -263,6 +265,8 @@ func generateConfig() {
|
|||||||
sb.WriteString(wsReverseDefault)
|
sb.WriteString(wsReverseDefault)
|
||||||
case '4':
|
case '4':
|
||||||
sb.WriteString(pprofDefault)
|
sb.WriteString(pprofDefault)
|
||||||
|
case '5':
|
||||||
|
sb.WriteString(lambdaDefault)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = os.WriteFile("config.yml", []byte(sb.String()), 0o644)
|
_ = os.WriteFile("config.yml", []byte(sb.String()), 0o644)
|
||||||
|
1
main.go
1
main.go
@ -382,7 +382,6 @@ func main() {
|
|||||||
} else {
|
} else {
|
||||||
coolq.SetMessageFormat(conf.Message.PostFormat)
|
coolq.SetMessageFormat(conf.Message.PostFormat)
|
||||||
}
|
}
|
||||||
log.Info("正在加载事件过滤器.")
|
|
||||||
coolq.IgnoreInvalidCQCode = conf.Message.IgnoreInvalidCQCode
|
coolq.IgnoreInvalidCQCode = conf.Message.IgnoreInvalidCQCode
|
||||||
coolq.SplitURL = conf.Message.FixURL
|
coolq.SplitURL = conf.Message.FixURL
|
||||||
coolq.ForceFragmented = conf.Message.ForceFragment
|
coolq.ForceFragmented = conf.Message.ForceFragment
|
||||||
|
@ -19,12 +19,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type lambdaClient struct {
|
type lambdaClient struct {
|
||||||
nextUrl string
|
nextURL string
|
||||||
responseURL string
|
responseURL string
|
||||||
lambdaType string
|
lambdaType string
|
||||||
|
|
||||||
client http.Client
|
client http.Client
|
||||||
http *httpServer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type lambdaResponse struct {
|
type lambdaResponse struct {
|
||||||
@ -55,7 +54,7 @@ func (l *lambdaResponseWriter) Write(data []byte) (int, error) {
|
|||||||
for k, v := range l.header {
|
for k, v := range l.header {
|
||||||
header[k] = v[0]
|
header[k] = v[0]
|
||||||
}
|
}
|
||||||
json.NewEncoder(buffer).Encode(&lambdaResponse{
|
_ = json.NewEncoder(buffer).Encode(&lambdaResponse{
|
||||||
IsBase64Encoded: false,
|
IsBase64Encoded: false,
|
||||||
StatusCode: l.statusCode,
|
StatusCode: l.statusCode,
|
||||||
Headers: header,
|
Headers: header,
|
||||||
@ -77,9 +76,10 @@ func (l *lambdaResponseWriter) WriteHeader(statusCode int) {
|
|||||||
|
|
||||||
var cli *lambdaClient
|
var cli *lambdaClient
|
||||||
|
|
||||||
func init() {
|
// RunLambdaClient type: [scf,aws]
|
||||||
|
func RunLambdaClient(bot *coolq.CQBot, conf *config.LambdaServer) {
|
||||||
cli = &lambdaClient{
|
cli = &lambdaClient{
|
||||||
lambdaType: "scf",
|
lambdaType: conf.Type,
|
||||||
client: http.Client{Timeout: 0},
|
client: http.Client{Timeout: 0},
|
||||||
}
|
}
|
||||||
switch cli.lambdaType { // todo: aws
|
switch cli.lambdaType { // todo: aws
|
||||||
@ -88,7 +88,7 @@ func init() {
|
|||||||
os.Getenv("SCF_RUNTIME_API"),
|
os.Getenv("SCF_RUNTIME_API"),
|
||||||
os.Getenv("SCF_RUNTIME_API_PORT"),
|
os.Getenv("SCF_RUNTIME_API_PORT"),
|
||||||
)
|
)
|
||||||
cli.nextUrl = base + "invocation/next"
|
cli.nextURL = base + "invocation/next"
|
||||||
cli.responseURL = base + "invocation/response"
|
cli.responseURL = base + "invocation/response"
|
||||||
post, err := http.Post(base+"init/ready", "", nil)
|
post, err := http.Post(base+"init/ready", "", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -99,13 +99,12 @@ func init() {
|
|||||||
case "aws": // aws lambda
|
case "aws": // aws lambda
|
||||||
const apiVersion = "2018-06-01"
|
const apiVersion = "2018-06-01"
|
||||||
base := fmt.Sprintf("http://%s/%s/runtime/", os.Getenv("AWS_LAMBDA_RUNTIME_API"), apiVersion)
|
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"
|
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)
|
api := newAPICaller(bot)
|
||||||
if conf.RateLimit.Enabled {
|
if conf.RateLimit.Enabled {
|
||||||
api.use(rateLimit(conf.RateLimit.Frequency, conf.RateLimit.Bucket))
|
api.use(rateLimit(conf.RateLimit.Frequency, conf.RateLimit.Bucket))
|
||||||
@ -135,7 +134,7 @@ func RunLambdaClient(bot *coolq.CQBot, conf *config.LambdaServer) {
|
|||||||
|
|
||||||
type lambdaInvoke struct {
|
type lambdaInvoke struct {
|
||||||
Headers map[string]string
|
Headers map[string]string
|
||||||
HttpMethod string `json:"httpMethod"`
|
HTTPMethod string `json:"httpMethod"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
QueryString map[string]string
|
QueryString map[string]string
|
||||||
@ -145,7 +144,7 @@ type lambdaInvoke struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *lambdaClient) next() *http.Request {
|
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 {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -161,7 +160,7 @@ func (c *lambdaClient) next() *http.Request {
|
|||||||
var invoke = new(lambdaInvoke)
|
var invoke = new(lambdaInvoke)
|
||||||
_ = json.NewDecoder(resp.Body).Decode(invoke)
|
_ = json.NewDecoder(resp.Body).Decode(invoke)
|
||||||
|
|
||||||
req.Method = invoke.HttpMethod
|
req.Method = invoke.HTTPMethod
|
||||||
req.Body = io.NopCloser(strings.NewReader(invoke.Body))
|
req.Body = io.NopCloser(strings.NewReader(invoke.Body))
|
||||||
req.Header = make(map[string][]string)
|
req.Header = make(map[string][]string)
|
||||||
for k, v := range invoke.Headers {
|
for k, v := range invoke.Headers {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user