MCPcopy
hub / github.com/cortexlabs/cortex / getAPI

Function getAPI

cli/cmd/get.go:462–501  ·  view source on GitHub ↗
(env cliconfig.Environment, apiName string)

Source from the content-addressed store, hash-verified

460}
461
462func getAPI(env cliconfig.Environment, apiName string) (string, error) {
463 apisRes, err := cluster.GetAPI(MustGetOperatorConfig(env.Name), apiName)
464 if err != nil {
465 return "", err
466 }
467
468 var bytes []byte
469 if _flagOutput == flags.JSONOutputType {
470 bytes, err = libjson.Marshal(apisRes)
471 } else if _flagOutput == flags.YAMLOutputType {
472 bytes, err = yaml.Marshal(apisRes)
473 }
474 if err != nil {
475 return "", err
476 }
477 if _flagOutput == flags.JSONOutputType || _flagOutput == flags.YAMLOutputType {
478 return string(bytes), nil
479 }
480
481 if len(apisRes) == 0 {
482 exit.Error(errors.ErrorUnexpected(fmt.Sprintf("unable to find api %s", apiName)))
483 }
484
485 apiRes := apisRes[0]
486
487 switch apiRes.Metadata.Kind {
488 case userconfig.RealtimeAPIKind:
489 return realtimeAPITable(apiRes, env)
490 case userconfig.AsyncAPIKind:
491 return asyncAPITable(apiRes, env)
492 case userconfig.TrafficSplitterKind:
493 return trafficSplitterTable(apiRes, env)
494 case userconfig.BatchAPIKind:
495 return batchAPITable(apiRes), nil
496 case userconfig.TaskAPIKind:
497 return taskAPITable(apiRes), nil
498 default:
499 return "", errors.ErrorUnexpected(fmt.Sprintf("encountered unexpected kind %s for api %s", apiRes.Metadata.Kind, apiRes.Metadata.Name))
500 }
501}
502
503func apiHistoryTable(apiVersions []schema.APIVersion) string {
504 t := table.Table{

Callers 1

get.goFile · 0.85

Calls 9

GetAPIFunction · 0.92
ErrorFunction · 0.92
ErrorUnexpectedFunction · 0.92
MustGetOperatorConfigFunction · 0.85
realtimeAPITableFunction · 0.85
asyncAPITableFunction · 0.85
trafficSplitterTableFunction · 0.85
batchAPITableFunction · 0.85
taskAPITableFunction · 0.85

Tested by

no test coverage detected