MCPcopy Create free account
hub / github.com/cloud66-oss/starter / StartAPI

Method StartAPI

api.go:63–128  ·  view source on GitHub ↗

StartAPI starts the API listeners

()

Source from the content-addressed store, hash-verified

61
62// StartAPI starts the API listeners
63func (a *API) StartAPI() error {
64 api := rest.NewApi()
65
66 router, err := rest.MakeRouter(
67 // system
68 &rest.Route{HttpMethod: "GET", PathExp: "/ping", Func: a.ping},
69 &rest.Route{HttpMethod: "GET", PathExp: "/version", Func: a.version},
70
71 // parsing
72 &rest.Route{HttpMethod: "POST", PathExp: "/analyze", Func: a.analyze},
73 &rest.Route{HttpMethod: "GET", PathExp: "/analyze/supported", Func: a.supported},
74 &rest.Route{HttpMethod: "GET", PathExp: "/analyze/dockerfiles", Func: a.dockerfiles},
75 &rest.Route{HttpMethod: "POST", PathExp: "/analyze/upload", Func: a.upload},
76 )
77 if err != nil {
78 return err
79 }
80
81 api.SetApp(router)
82
83 go func() {
84 common.PrintL0("Starting API on %s\n", a.config.APIURL)
85 common.PrintL1("API is now running...\n")
86
87 packs := []packs.Pack{ /*new(compose_to_service_yml.Pack),*/ new(ruby.Pack), new(node.Pack), new(php.Pack) /*, new(service_yml_to_kubes.Pack)*/}
88
89 for _, p := range packs {
90 support := Language{}
91 support.Name = p.Name()
92 support.Files = p.FilesToBeAnalysed()
93
94 if a.config.use_registry && p.Name() != "docker-compose" && p.Name() != "service.yml" {
95 url := "https://registry-1.docker.io/"
96 username := "" // anonymous
97 password := "" // anonymous
98 hub, err := registry.New(url, username, password)
99 if err != nil {
100 common.PrintError("Failed to start API %s", err.Error())
101 os.Exit(2)
102 }
103 tags, err := hub.Tags("library/" + p.Name())
104 if err != nil {
105 common.PrintError("Failed to start API %s", err.Error())
106 os.Exit(2)
107 }
108 tags = Filter(tags, func(v string) bool {
109 ok, _ := regexp.MatchString(`^\d+.\d+.\d+$`, v)
110 return ok
111 })
112 p.SetSupportedLanguageVersions(tags)
113 support.SupportedVersion = tags
114 } else {
115 support.SupportedVersion = p.GetSupportedLanguageVersions()
116 }
117
118 languages.Languages = append(languages.Languages, support)
119 }
120

Callers 1

mainFunction · 0.95

Calls 6

FilterFunction · 0.85
ErrorMethod · 0.80
NameMethod · 0.65
FilesToBeAnalysedMethod · 0.65

Tested by

no test coverage detected