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

Method Create

module/service/iml.go:662–785  ·  view source on GitHub ↗
(ctx context.Context, teamID string, input *service_dto.CreateService)

Source from the content-addressed store, hash-verified

660}
661
662func (i *imlServiceModule) Create(ctx context.Context, teamID string, input *service_dto.CreateService) (*service_dto.Service, error) {
663 if input.Id == "" {
664 input.Id = uuid.New().String()
665 }
666 if teamID == "" {
667 item, err := i.teamService.DefaultTeam(ctx)
668 if err != nil {
669 return nil, err
670 }
671 teamID = item.Id
672 }
673 mo := &service.Create{
674 Id: input.Id,
675 Name: input.Name,
676 Description: input.Description,
677 Team: teamID,
678 ServiceType: service.ServiceType(input.ServiceType),
679 Catalogue: input.Catalogue,
680 Prefix: input.Prefix,
681 Logo: input.Logo,
682 State: service_dto.ServiceState(input.State).Int(),
683 ApprovalType: service.ApprovalType(input.ApprovalType),
684 AdditionalConfig: make(map[string]string),
685 Kind: service.Kind(input.Kind),
686 EnableMCP: input.EnableMCP,
687 }
688 if mo.ServiceType == service.PublicService && mo.Catalogue == "" {
689 return nil, fmt.Errorf("catalogue can not be empty")
690 }
691 switch mo.Kind {
692 case service.AIService:
693 if input.Provider == nil {
694 return nil, fmt.Errorf("ai service: provider can not be empty")
695 }
696 mo.AdditionalConfig["provider"] = *input.Provider
697 if input.Model == nil {
698 return nil, fmt.Errorf("ai service: model can not be empty")
699 }
700 mo.AdditionalConfig["model"] = *input.Model
701 }
702 if input.AsApp == nil {
703 // 默认值为false
704 mo.AsApp = false
705 } else {
706 mo.AsApp = *input.AsApp
707 }
708 if input.AsServer == nil {
709 // 默认值为true
710 mo.AsServer = true
711 } else {
712 mo.AsServer = *input.AsServer
713 }
714
715 //input.Prefix = strings.Trim(strings.Trim(input.Prefix, " "), "/")
716 err := i.transaction.Transaction(ctx, func(ctx context.Context) error {
717 if input.Tags != nil {
718 tags, err := i.getTagUuids(ctx, input.Tags)
719 if err != nil {

Callers

nothing calls this directly

Calls 15

getTagUuidsMethod · 0.95
updateMCPServerMethod · 0.95
deleteMCPServerMethod · 0.95
GetMethod · 0.95
ServiceTypeTypeAlias · 0.92
ApprovalTypeTypeAlias · 0.92
KindTypeAlias · 0.92
DefaultTeamMethod · 0.65
CreateMethod · 0.65
GatewayClientMethod · 0.65
OnlineMethod · 0.65
SubscribeMethod · 0.65

Tested by

no test coverage detected