MCPcopy Index your code
hub / github.com/deepflowio/deepflow / createDomain

Function createDomain

cli/ctl/domain.go:158–199  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string, filename string)

Source from the content-addressed store, hash-verified

156}
157
158func createDomain(cmd *cobra.Command, args []string, filename string) {
159 server := common.GetServerInfo(cmd)
160 url := fmt.Sprintf("http://%s:%d/v1/domains/", server.IP, server.Port)
161
162 body, err := formatBody(filename)
163 if err != nil {
164 fmt.Fprintln(os.Stderr, err)
165 return
166 }
167 if !validateBody(body) {
168 return
169 }
170
171 if domainTypeStr, ok := body["TYPE"]; ok {
172 domainType := common.GetDomainTypeByName(domainTypeStr.(string))
173 if domainType == common.DOMAIN_TYPE_UNKNOWN {
174 fmt.Fprintln(os.Stderr, fmt.Sprintf("domain type (%s) not supported, use example to see supported types", domainTypeStr))
175 return
176 }
177 body["TYPE"] = int(domainType)
178 } else {
179 fmt.Fprintln(os.Stderr, "domain type must specify")
180 return
181 }
182
183 resp, err := common.CURLPerform("POST", url, body, "", []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd))}...)
184 if err != nil {
185 fmt.Fprintln(os.Stderr, err)
186 return
187 }
188 respByte, err := resp.MarshalJSON()
189 if err != nil {
190 fmt.Fprintln(os.Stderr, err)
191 return
192 }
193 formatStr, err := common.JsonFormat(respByte)
194 if err != nil {
195 fmt.Println("format json str faild: " + err.Error())
196 return
197 }
198 fmt.Println(formatStr)
199}
200
201func updateDomain(cmd *cobra.Command, args []string, filename string) {
202 if len(args) == 0 {

Callers 1

RegisterDomainCommandFunction · 0.70

Calls 4

formatBodyFunction · 0.85
validateBodyFunction · 0.85
ErrorMethod · 0.65
MarshalJSONMethod · 0.45

Tested by

no test coverage detected