MCPcopy Create free account
hub / github.com/53AI/53AIHub / ValidateAPIKey

Function ValidateAPIKey

api/model/api_key.go:189–212  ·  view source on GitHub ↗

ValidateAPIKey 验证API密钥是否有效

(key string)

Source from the content-addressed store, hash-verified

187
188// ValidateAPIKey 验证API密钥是否有效
189func ValidateAPIKey(key string) (*APIKey, error) {
190 // 验证密钥前缀
191 if !strings.HasPrefix(key, APIKeyPrefix) {
192 return nil, errors.New("无效的API密钥格式")
193 }
194
195 // 获取API密钥
196 apiKey, err := GetAPIKeyByKey(key)
197 if err != nil {
198 return nil, errors.New("无效的API密钥")
199 }
200
201 // 检查状态
202 if apiKey.Status != APIKeyStatusActive {
203 return nil, errors.New("API密钥已被禁用")
204 }
205
206 // 检查过期时间
207 if apiKey.ExpiresAt != nil && time.Now().After(*apiKey.ExpiresAt) {
208 return nil, errors.New("API密钥已过期")
209 }
210
211 return apiKey, nil
212}
213
214// GenerateAPIKey 生成新的API密钥
215func GenerateAPIKey(eid int64, creatorID int64) string {

Callers

nothing calls this directly

Calls 2

GetAPIKeyByKeyFunction · 0.85
NewMethod · 0.45

Tested by

no test coverage detected