mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-09-21 01:17:59 +00:00
refactor: unify oneLineStr/oneLine into types.OneLine
provider.oneLineStr and gateway.oneLine had byte-identical bodies (flatten whitespace + cap length). Move the single implementation into the types package, which both layers already depend on, and delete both locals.
This commit is contained in:
@ -5,6 +5,7 @@ package types
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -159,4 +160,15 @@ type BuildMeta struct {
|
||||
Source map[string]interface{} `json:"source"`
|
||||
}
|
||||
|
||||
func Now() int64 { return time.Now().Unix() }
|
||||
func Now() int64 { return time.Now().Unix() }
|
||||
|
||||
// OneLine flattens an error string to a single line capped at n chars.
|
||||
// Shared by the provider layer (upstream error reasons) and the gateway
|
||||
// layer (client-facing AUTO-chain summaries).
|
||||
func OneLine(s string, n int) string {
|
||||
s = strings.Join(strings.Fields(s), " ")
|
||||
if len(s) > n {
|
||||
s = s[:n] + "..."
|
||||
}
|
||||
return s
|
||||
}
|
||||
Reference in New Issue
Block a user