mirror of
https://github.com/langgenius/dify-plugin-daemon.git
synced 2026-07-22 01:35:24 -04:00
ca3d00229e
* use slog instead of log package and format to new log schema * update the environment name to LOG_OUTPUT_FORMAT * add the env to .env.example * fix log reference error * change the order of milldlewares * delete unused code * fix the concurrently session potential race condition * fix the log format in tests * update the duplicate code * refactor: convert log functions to slog structured format - Change log.Error/Info/Warn/Debug/Panic to accept msg + key-value pairs - Remove printf-style formatting from log functions - Update log calls in internal/cluster, internal/db, internal/core/session_manager - Remove unused 'initialized' variable from log package - Remaining files will be updated in follow-up commits 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: update all log call sites to use slog structured format Convert all log.Error, log.Info, log.Warn, log.Debug, and log.Panic calls from printf-style formatting to slog key-value pairs. Before: log.Error("failed to do something: %s", err.Error()) After: log.Error("failed to do something", "error", err) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: update cmd/ log calls to use slog structured format 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: implement GnetLogger for structured logging in gnet * refactor: remove deprecated log visibility functions and related calls * feat: enhance session management with trace and identity context propagation * feat: implement serverless transaction handler and writer for plugin runtime * refactor: rename context field to traceCtx in RealBackwardsInvocation --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Yeuoly <admin@srmxy.cn>
120 lines
4.0 KiB
Go
120 lines
4.0 KiB
Go
package http_requests
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
)
|
|
|
|
type HttpOptions struct {
|
|
Type string
|
|
Value interface{}
|
|
}
|
|
|
|
const (
|
|
HttpOptionTypeWriteTimeout = "write_timeout"
|
|
HttpOptionTypeReadTimeout = "read_timeout"
|
|
HttpOptionTypeHeader = "header"
|
|
HttpOptionTypeParams = "params"
|
|
HttpOptionTypePayload = "payload"
|
|
HttpOptionTypePayloadText = "payloadText"
|
|
HttpOptionTypePayloadJson = "payloadJson"
|
|
HttpOptionTypePayloadMultipart = "payloadMultipart"
|
|
HttpOptionTypeRaiseErrorWhenStreamDataNotMatch = "raiseErrorWhenStreamDataNotMatch"
|
|
HttpOptionTypeDirectReferer = "directReferer"
|
|
HttpOptionTypeRetCode = "retCode"
|
|
HttpOptionTypeUsingLengthPrefixed = "usingLengthPrefixed"
|
|
HttpOptionTypeContext = "context"
|
|
)
|
|
|
|
// milliseconds
|
|
func HttpWriteTimeout(timeout int64) HttpOptions {
|
|
return HttpOptions{HttpOptionTypeWriteTimeout, timeout}
|
|
}
|
|
|
|
// milliseconds
|
|
func HttpReadTimeout(timeout int64) HttpOptions {
|
|
return HttpOptions{HttpOptionTypeReadTimeout, timeout}
|
|
}
|
|
|
|
func HttpHeader(header map[string]string) HttpOptions {
|
|
return HttpOptions{HttpOptionTypeHeader, header}
|
|
}
|
|
|
|
// which is used for params with in url
|
|
func HttpParams(params map[string]string) HttpOptions {
|
|
return HttpOptions{HttpOptionTypeParams, params}
|
|
}
|
|
|
|
// which is used for POST method only
|
|
func HttpPayload(payload map[string]string) HttpOptions {
|
|
return HttpOptions{HttpOptionTypePayload, payload}
|
|
}
|
|
|
|
// which is used for POST method only
|
|
func HttpPayloadText(payload string) HttpOptions {
|
|
return HttpOptions{HttpOptionTypePayloadText, payload}
|
|
}
|
|
|
|
// which is used for POST method only
|
|
func HttpPayloadReader(reader io.ReadCloser) HttpOptions {
|
|
return HttpOptions{"payloadReader", reader}
|
|
}
|
|
|
|
// which is used for POST method only
|
|
func HttpPayloadJson(payload interface{}) HttpOptions {
|
|
return HttpOptions{HttpOptionTypePayloadJson, payload}
|
|
}
|
|
|
|
type HttpPayloadMultipartFile struct {
|
|
Filename string
|
|
Reader io.Reader
|
|
}
|
|
|
|
// which is used for POST method only
|
|
// payload follows the form data format, and files is a map from filename to file
|
|
func HttpPayloadMultipart(payload map[string]string, files map[string]HttpPayloadMultipartFile) HttpOptions {
|
|
return HttpOptions{HttpOptionTypePayloadMultipart, map[string]interface{}{
|
|
"payload": payload,
|
|
"files": files,
|
|
}}
|
|
}
|
|
|
|
func HttpRaiseErrorWhenStreamDataNotMatch(raise bool) HttpOptions {
|
|
return HttpOptions{HttpOptionTypeRaiseErrorWhenStreamDataNotMatch, raise}
|
|
}
|
|
|
|
func HttpWithDirectReferer() HttpOptions {
|
|
return HttpOptions{HttpOptionTypeDirectReferer, true}
|
|
}
|
|
|
|
func HttpWithRetCode(retCode *int) HttpOptions {
|
|
return HttpOptions{HttpOptionTypeRetCode, retCode}
|
|
}
|
|
|
|
// For standard SSE protocol, response are split by \n\n
|
|
// Which leads a bad performance when decoding, we need a larger chunk to store temporary data
|
|
// This option is used to enable length-prefixed mode, which is faster but less memory-friendly
|
|
// We uses following format:
|
|
//
|
|
// | Field | Size | Description |
|
|
// |---------------|----------|---------------------------------|
|
|
// | Magic Number | 1 byte | Magic number identifier |
|
|
// | Reserved | 1 byte | Reserved field |
|
|
// | Header Length | 2 bytes | Header length (usually 0xa) |
|
|
// | Data Length | 4 bytes | Length of the data |
|
|
// | Reserved | 6 bytes | Reserved fields |
|
|
// | Data | Variable | Actual data content |
|
|
//
|
|
// | Reserved Fields | Header | Data |
|
|
// |-----------------|----------|----------|
|
|
// | 4 bytes total | Variable | Variable |
|
|
//
|
|
// with the above format, we can achieve a better performance, avoid unexpected memory growth
|
|
func HttpUsingLengthPrefixed(using bool) HttpOptions {
|
|
return HttpOptions{HttpOptionTypeUsingLengthPrefixed, using}
|
|
}
|
|
|
|
func HttpContext(ctx context.Context) HttpOptions {
|
|
return HttpOptions{HttpOptionTypeContext, ctx}
|
|
}
|