style: gofmt the tree

gofmt -l reported 13 files with misaligned struct tags / stale formatting.
This commit contains ONLY formatting: no behaviour change, no logic touched.
Files that also carry real changes in this series are formatted by their own
commits.
This commit is contained in:
JianFeeeee
2026-08-30 08:04:22 +08:00
parent 624fd74b45
commit 2ed1f0ecde
7 changed files with 65 additions and 64 deletions

View File

@ -88,4 +88,4 @@ func main() {
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM) signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
<-stop <-stop
log.Printf("[llmsproxy] shutting down") log.Printf("[llmsproxy] shutting down")
} }

View File

@ -326,4 +326,3 @@ func statusOf(resp *http.Response) int {
} }
return resp.StatusCode return resp.StatusCode
} }

View File

@ -24,9 +24,9 @@ type Config struct {
TLSKeyFile string `yaml:"tls_key_file,omitempty"` // PEM private key TLSKeyFile string `yaml:"tls_key_file,omitempty"` // PEM private key
PublicBaseURL string `yaml:"public_base_url,omitempty"` // external base for generated config snippets; default inferred from request PublicBaseURL string `yaml:"public_base_url,omitempty"` // external base for generated config snippets; default inferred from request
Sources []Source `yaml:"sources"` Sources []Source `yaml:"sources"`
Auto []ModelScope `yaml:"auto,omitempty"` // AUTO 调度链规则WebUI 优先级页编辑chat Auto []ModelScope `yaml:"auto,omitempty"` // AUTO 调度链规则WebUI 优先级页编辑chat
AutoImage []ModelScope `yaml:"auto_image,omitempty"` // AUTO 生图调度链规则WebUI 优先级页·生图) AutoImage []ModelScope `yaml:"auto_image,omitempty"` // AUTO 生图调度链规则WebUI 优先级页·生图)
Keys []GWKey `yaml:"keys,omitempty"` // 网关密钥WebUI 密钥页管理) Keys []GWKey `yaml:"keys,omitempty"` // 网关密钥WebUI 密钥页管理)
} }
// Defaults applied to any source (YAML or runtime) that leaves a field unset. // Defaults applied to any source (YAML or runtime) that leaves a field unset.
@ -314,32 +314,32 @@ func (c *Config) ApplyDefaults() error {
// RuntimeConfig is the legacy runtime file format (kept for migration only). // RuntimeConfig is the legacy runtime file format (kept for migration only).
type RuntimeConfig struct { type RuntimeConfig struct {
Sources []Source `json:"sources,omitempty"` Sources []Source `json:"sources,omitempty"`
SourceTemplates []SourceTemplate `json:"source_templates,omitempty"` SourceTemplates []SourceTemplate `json:"source_templates,omitempty"`
DeletedSources []string `json:"deleted_sources,omitempty"` DeletedSources []string `json:"deleted_sources,omitempty"`
DeletedAdapters []string `json:"deleted_adapters,omitempty"` DeletedAdapters []string `json:"deleted_adapters,omitempty"`
PresetTemplates []string `json:"preset_templates,omitempty"` // preset names the user has seen (or deleted) — never re-seeded PresetTemplates []string `json:"preset_templates,omitempty"` // preset names the user has seen (or deleted) — never re-seeded
Keys []GWKey `json:"keys,omitempty"` Keys []GWKey `json:"keys,omitempty"`
Auto []ModelScope `json:"auto,omitempty"` Auto []ModelScope `json:"auto,omitempty"`
AutoImage []ModelScope `json:"auto_image,omitempty"` AutoImage []ModelScope `json:"auto_image,omitempty"`
} }
// SourceTemplate stores reusable source configuration (everything except // SourceTemplate stores reusable source configuration (everything except
// name and api_key) so the WebUI can spin up multiple key-bearing sources // name and api_key) so the WebUI can spin up multiple key-bearing sources
// from one shared template. // from one shared template.
type SourceTemplate struct { type SourceTemplate struct {
Name string `json:"name"` Name string `json:"name"`
BaseURL string `json:"base_url"` BaseURL string `json:"base_url"`
Adapter string `json:"adapter"` Adapter string `json:"adapter"`
Endpoint string `json:"endpoint,omitempty"` Endpoint string `json:"endpoint,omitempty"`
ImageEndpoint string `json:"image_endpoint,omitempty"` ImageEndpoint string `json:"image_endpoint,omitempty"`
Models []Model `json:"models"` Models []Model `json:"models"`
Headers map[string]string `json:"headers,omitempty"` Headers map[string]string `json:"headers,omitempty"`
Meta map[string]interface{} `json:"meta,omitempty"` Meta map[string]interface{} `json:"meta,omitempty"`
Temperature float64 `json:"temperature,omitempty"` Temperature float64 `json:"temperature,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"` MaxTokens int `json:"max_tokens,omitempty"`
MaxConcurrent int `json:"max_concurrent,omitempty"` MaxConcurrent int `json:"max_concurrent,omitempty"`
RPM int `json:"rpm,omitempty"` RPM int `json:"rpm,omitempty"`
} }
// GWKey is a gateway API key persisted in the config file. Role is "admin" // GWKey is a gateway API key persisted in the config file. Role is "admin"

View File

@ -54,11 +54,11 @@ type RespMessage struct {
} }
type ChatChunk struct { type ChatChunk struct {
ID string `json:"id"` ID string `json:"id"`
Object string `json:"object"` Object string `json:"object"`
Created int64 `json:"created"` Created int64 `json:"created"`
Model string `json:"model"` Model string `json:"model"`
Choices []ChunkChoice `json:"choices"` Choices []ChunkChoice `json:"choices"`
// Usage is sent in the final chunk of a stream (empty choices) so // Usage is sent in the final chunk of a stream (empty choices) so
// OpenAI-compatible clients can read token usage. // OpenAI-compatible clients can read token usage.
Usage *types.TokenUsage `json:"usage,omitempty"` Usage *types.TokenUsage `json:"usage,omitempty"`

View File

@ -35,10 +35,10 @@ func (g *Gateway) handleKeysAPI(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, map[string]interface{}{"keys": g.core.ListKeys()}) writeJSON(w, http.StatusOK, map[string]interface{}{"keys": g.core.ListKeys()})
case http.MethodPost: case http.MethodPost:
var body struct { var body struct {
Name string `json:"name"` Name string `json:"name"`
Role string `json:"role"` Role string `json:"role"`
Models []config.ModelScope `json:"models"` Models []config.ModelScope `json:"models"`
Note string `json:"note"` Note string `json:"note"`
} }
if err := json.NewDecoder(r.Body).Decode(&body); err != nil { if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
writeError(w, http.StatusBadRequest, "invalid_request", "invalid json: "+err.Error()) writeError(w, http.StatusBadRequest, "invalid_request", "invalid json: "+err.Error())
@ -183,4 +183,4 @@ func (g *Gateway) handleAutoAPI(w http.ResponseWriter, r *http.Request) {
default: default:
writeError(w, http.StatusMethodNotAllowed, "method_not_allowed", "") writeError(w, http.StatusMethodNotAllowed, "method_not_allowed", "")
} }
} }

View File

@ -59,7 +59,9 @@ func TestLoginBruteForceLockout(t *testing.T) {
func TestLoginSuccessResetsFailures(t *testing.T) { func TestLoginSuccessResetsFailures(t *testing.T) {
g := newTestGateway(t) g := newTestGateway(t)
mkBad := func() *http.Request { return httptest.NewRequest("POST", "/api/login", strings.NewReader(`{"key":"nope"}`)) } mkBad := func() *http.Request {
return httptest.NewRequest("POST", "/api/login", strings.NewReader(`{"key":"nope"}`))
}
for i := 0; i < loginMaxFails-1; i++ { // one below the lockout threshold for i := 0; i < loginMaxFails-1; i++ { // one below the lockout threshold
rr := httptest.NewRecorder() rr := httptest.NewRecorder()
g.handleLoginAPI(rr, mkBad()) g.handleLoginAPI(rr, mkBad())

View File

@ -19,15 +19,15 @@ var ErrBusy = errors.New("provider busy")
// ---- OpenAI wire request (gateway input) ---- // ---- OpenAI wire request (gateway input) ----
type ChatRequest struct { type ChatRequest struct {
Model string `json:"model"` Model string `json:"model"`
Messages []ChatMessage `json:"messages"` Messages []ChatMessage `json:"messages"`
Temperature *float64 `json:"temperature,omitempty"` Temperature *float64 `json:"temperature,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"` MaxTokens int `json:"max_tokens,omitempty"`
Stream bool `json:"stream,omitempty"` Stream bool `json:"stream,omitempty"`
Tools []interface{} `json:"tools,omitempty"` Tools []interface{} `json:"tools,omitempty"`
ToolChoice interface{} `json:"tool_choice,omitempty"` ToolChoice interface{} `json:"tool_choice,omitempty"`
DisableThinking bool `json:"disable_thinking"` DisableThinking bool `json:"disable_thinking"`
ExtraBody map[string]interface{} `json:"-"` ExtraBody map[string]interface{} `json:"-"`
} }
func (r *ChatRequest) MarshalJSON() ([]byte, error) { func (r *ChatRequest) MarshalJSON() ([]byte, error) {
@ -119,23 +119,23 @@ func (t TokenUsage) MarshalJSON() ([]byte, error) {
pdetails = &PromptTokensDetails{CachedTokens: t.PromptCacheHit} pdetails = &PromptTokensDetails{CachedTokens: t.PromptCacheHit}
} }
return json.Marshal(struct { return json.Marshal(struct {
PromptTokens int `json:"prompt_tokens"` PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"` CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"` TotalTokens int `json:"total_tokens"`
Prompt int `json:"prompt"` Prompt int `json:"prompt"`
Completion int `json:"completion"` Completion int `json:"completion"`
Total int `json:"total"` Total int `json:"total"`
PromptTokensDetails *PromptTokensDetails `json:"prompt_tokens_details,omitempty"` PromptTokensDetails *PromptTokensDetails `json:"prompt_tokens_details,omitempty"`
PromptCacheHitTokens int `json:"prompt_cache_hit_tokens,omitempty"` PromptCacheHitTokens int `json:"prompt_cache_hit_tokens,omitempty"`
PromptCacheMissTokens int `json:"prompt_cache_miss_tokens,omitempty"` PromptCacheMissTokens int `json:"prompt_cache_miss_tokens,omitempty"`
}{ }{
PromptTokens: t.Prompt, PromptTokens: t.Prompt,
CompletionTokens: t.Completion, CompletionTokens: t.Completion,
TotalTokens: t.Total, TotalTokens: t.Total,
Prompt: t.Prompt, Prompt: t.Prompt,
Completion: t.Completion, Completion: t.Completion,
Total: t.Total, Total: t.Total,
PromptTokensDetails: pdetails, PromptTokensDetails: pdetails,
PromptCacheHitTokens: t.PromptCacheHit, PromptCacheHitTokens: t.PromptCacheHit,
PromptCacheMissTokens: t.PromptCacheMiss, PromptCacheMissTokens: t.PromptCacheMiss,
}) })
@ -168,8 +168,8 @@ type ImageGenResponse struct {
// streaming tool_calls array (incremental fragments with an index field), which // streaming tool_calls array (incremental fragments with an index field), which
// OpenAI-compatible clients accumulate themselves. // OpenAI-compatible clients accumulate themselves.
type UnifiedChunk struct { type UnifiedChunk struct {
Content string `json:"content"` Content string `json:"content"`
Done bool `json:"done"` Done bool `json:"done"`
// FinishReason carries the upstream finish/stop reason ("tool_calls", // FinishReason carries the upstream finish/stop reason ("tool_calls",
// "length", ...) when the adapter provides it; the gateway emits it on // "length", ...) when the adapter provides it; the gateway emits it on
// the terminating chunk instead of the default "stop". // the terminating chunk instead of the default "stop".
@ -204,4 +204,4 @@ func OneLine(s string, n int) string {
s = s[:n] + "..." s = s[:n] + "..."
} }
return s return s
} }