MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / Create

Method Create

module/ai-key/iml.go:63–104  ·  view source on GitHub ↗
(ctx context.Context, providerId string, input *ai_key_dto.Create)

Source from the content-addressed store, hash-verified

61}
62
63func (i *imlKeyModule) Create(ctx context.Context, providerId string, input *ai_key_dto.Create) error {
64 _, err := i.providerService.Get(ctx, providerId)
65 if err != nil {
66 return fmt.Errorf("provider not found: %w", err)
67 }
68 p, has := model_runtime.GetProvider(providerId)
69 if !has {
70 return fmt.Errorf("provider not found: %w", err)
71 }
72 p.URI()
73 err = p.Check(input.Config)
74 if err != nil {
75 return fmt.Errorf("config check failed: %w", err)
76 }
77 priority, err := i.aiKeyService.MaxPriority(ctx, providerId)
78 if err != nil {
79 return fmt.Errorf("get key error: %v", err)
80 }
81 return i.transaction.Transaction(ctx, func(ctx context.Context) error {
82 if input.Id == "" {
83 input.Id = uuid.NewString()
84 }
85 status := ai_key_dto.KeyNormal.Int()
86 if input.ExpireTime > 0 && time.Unix(int64(input.ExpireTime), 0).Before(time.Now()) {
87 status = ai_key_dto.KeyExpired.Int()
88 }
89
90 err = i.aiKeyService.Create(ctx, &ai_key.Create{
91 ID: input.Id,
92 Name: input.Name,
93 Config: input.Config,
94 Provider: providerId,
95 Status: status,
96 ExpireTime: input.ExpireTime,
97 Priority: priority + 1,
98 })
99
100 info, _ := i.aiKeyService.Get(ctx, input.Id)
101 releases := []*gateway.DynamicRelease{newKey(info)}
102 return i.syncGateway(ctx, cluster.DefaultClusterID, releases, true)
103 })
104}
105
106func (i *imlKeyModule) syncGateway(ctx context.Context, clusterId string, releases []*gateway.DynamicRelease, online bool) error {
107 client, err := i.clusterService.GatewayClient(ctx, clusterId)

Callers

nothing calls this directly

Calls 8

syncGatewayMethod · 0.95
newKeyFunction · 0.70
GetMethod · 0.65
URIMethod · 0.65
CheckMethod · 0.65
MaxPriorityMethod · 0.65
CreateMethod · 0.65
IntMethod · 0.45

Tested by

no test coverage detected