some changes

This commit is contained in:
2025-12-14 16:34:42 +02:00
parent 6aae5f9fb0
commit 18a31be0b1
11 changed files with 207 additions and 34 deletions

View File

@@ -10,11 +10,18 @@ import (
"gorm.io/gorm"
)
type Logger interface {
Write(line string)
}
type RootConfig struct {
Data struct {
Driver string `json:"driver"`
Path string `json:"path"`
} `json:"data"`
Log struct {
Path string `json:"log_root_path"`
} `json:"log"`
}
type Function struct {
@@ -30,6 +37,9 @@ type FuncConfig struct {
Version string `json:"version"`
Entry string `json:"entry"`
Runtime string `json:"runtime"`
Log struct {
Output string `json:"output"`
} `json:"log"`
}
func LoadTreeConfig(root string) (*RootConfig, error) {
@@ -61,9 +71,18 @@ func OpenDB(cfg *RootConfig, root string) (*gorm.DB, error) {
func FindFunction(db *gorm.DB, name, version string) (*Function, error) {
var f Function
if err := db.Where("function_name = ? AND version = ? AND deleted_at IS NULL", name, version).
First(&f).Error; err != nil {
return nil, err
if version == "latest" {
err := db.Where("function_name = ? AND deleted_at IS NULL", name).
Order("created_at DESC").
First(&f).Error
if err != nil {
return nil, err
}
} else {
if err := db.Where("function_name = ? AND version = ? AND deleted_at IS NULL", name, version).
First(&f).Error; err != nil {
return nil, err
}
}
return &f, nil
}