feat: Handle errors, validate model names, and calculate quota usage (#978)

- Improved error handling in various modules for better stability and responsiveness.
- Optimized code in several files for improved efficiency and readability.
- Enhanced user experience by providing more detailed error responses in the controller.
- Strengthened security by ignoring sensitive files in `.gitignore`.
This commit is contained in:
Laisky.Cai
2024-02-12 21:35:40 +08:00
committed by GitHub
parent 2cd1a78203
commit d548a01c59
11 changed files with 24 additions and 18 deletions

View File

@@ -15,10 +15,7 @@ type embedFileSystem struct {
func (e embedFileSystem) Exists(prefix string, path string) bool {
_, err := e.Open(path)
if err != nil {
return false
}
return true
return err == nil
}
func EmbedFolder(fsEmbed embed.FS, targetPath string) static.ServeFileSystem {

View File

@@ -107,13 +107,13 @@ func Seconds2Time(num int) (time string) {
}
func Interface2String(inter interface{}) string {
switch inter.(type) {
switch inter := inter.(type) {
case string:
return inter.(string)
return inter
case int:
return fmt.Sprintf("%d", inter.(int))
return fmt.Sprintf("%d", inter)
case float64:
return fmt.Sprintf("%f", inter.(float64))
return fmt.Sprintf("%f", inter)
}
return "Not Implemented"
}

View File

@@ -68,15 +68,15 @@ func Error(ctx context.Context, msg string) {
}
func Infof(ctx context.Context, format string, a ...any) {
Info(ctx, fmt.Sprintf(format, a))
Info(ctx, fmt.Sprintf(format, a...))
}
func Warnf(ctx context.Context, format string, a ...any) {
Warn(ctx, fmt.Sprintf(format, a))
Warn(ctx, fmt.Sprintf(format, a...))
}
func Errorf(ctx context.Context, format string, a ...any) {
Error(ctx, fmt.Sprintf(format, a))
Error(ctx, fmt.Sprintf(format, a...))
}
func logHelper(ctx context.Context, level string, msg string) {