迁移 Flutter 端与训练脚本,模型/训练产物移出 git(遵循纯代码约定)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// Plan 套餐定价(config.yml plans 节点,静态配置;展示名由 days 派生"N天")
|
||||
type Plan struct {
|
||||
Id string `mapstructure:"id"`
|
||||
Days int `mapstructure:"days"`
|
||||
PriceCents int64 `mapstructure:"price_cents"`
|
||||
}
|
||||
|
||||
// ListPlans 全部套餐(按配置声明顺序)
|
||||
func ListPlans(ctx context.Context) ([]*Plan, error) {
|
||||
var plans []*Plan
|
||||
if err := g.Cfg().MustGet(ctx, "plans").Scan(&plans); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return plans, nil
|
||||
}
|
||||
|
||||
// GetPlan 按套餐 ID 查找,不存在返回 (nil, nil),调用方用 CodePlanNotConfigured 包装
|
||||
func GetPlan(ctx context.Context, id string) (*Plan, error) {
|
||||
plans, err := ListPlans(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, p := range plans {
|
||||
if p.Id == id {
|
||||
return p, nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
Reference in New Issue
Block a user