(cmd *cobra.Command, args []string, filename string)
| 156 | } |
| 157 | |
| 158 | func 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 | |
| 201 | func updateDomain(cmd *cobra.Command, args []string, filename string) { |
| 202 | if len(args) == 0 { |
no test coverage detected