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

Method Create

module/router/iml.go:253–300  ·  view source on GitHub ↗
(ctx context.Context, serviceId string, dto *router_dto.Create)

Source from the content-addressed store, hash-verified

251}
252
253func (i *imlRouterModule) Create(ctx context.Context, serviceId string, dto *router_dto.Create) (*router_dto.SimpleDetail, error) {
254 info, err := i.serviceService.Check(ctx, serviceId, asServer)
255 if err != nil {
256 return nil, err
257 }
258
259 err = i.transaction.Transaction(ctx, func(ctx context.Context) error {
260 if dto.Id == "" {
261 dto.Id = uuid.New().String()
262 }
263 err = dto.Validate()
264 if err != nil {
265 return err
266 }
267
268 err = i.apiService.Exist(ctx, "", &api.Exist{Path: dto.Path, Methods: dto.Methods})
269 if err != nil {
270 return err
271 }
272
273 proxy := router_dto.ToServiceProxy(dto.Proxy)
274 err = i.apiService.SaveProxy(ctx, dto.Id, proxy)
275 if err != nil {
276 return err
277 }
278 name := dto.Name
279 if name == "" {
280 name = dto.Id
281 }
282 match, _ := json.Marshal(dto.MatchRules)
283 return i.apiService.Create(ctx, &api.Create{
284 UUID: dto.Id,
285 Name: name,
286 Description: dto.Description,
287 Service: serviceId,
288 Team: info.Team,
289 Methods: dto.Methods,
290 Protocols: dto.Protocols,
291 Path: dto.Path,
292 Match: string(match),
293 Upstream: dto.Upstream,
294 })
295 })
296 if err != nil {
297 return nil, err
298 }
299 return i.SimpleDetail(ctx, serviceId, dto.Id)
300}
301
302func (i *imlRouterModule) Edit(ctx context.Context, serviceId string, apiId string, dto *router_dto.Edit) (*router_dto.SimpleDetail, error) {
303 _, err := i.serviceService.Check(ctx, serviceId, asServer)

Callers

nothing calls this directly

Calls 8

SimpleDetailMethod · 0.95
MarshalMethod · 0.80
CheckMethod · 0.65
ExistMethod · 0.65
SaveProxyMethod · 0.65
CreateMethod · 0.65
StringMethod · 0.45
ValidateMethod · 0.45

Tested by

no test coverage detected