add conflicts_getter.go

This commit is contained in:
Александр Шашкин 2022-10-13 22:46:14 +03:00
parent 16a4d30dbf
commit 05c0a4ebbc
No known key found for this signature in database
GPG Key ID: 9DB727EBBC568FFF

53
conflicts_getter.go Normal file
View File

@ -0,0 +1,53 @@
package main
import (
"errors"
"io"
"net/http"
)
func getRdbData(task string) ([]byte, error) {
resp, err := http.Get(
"https://rdb.altlinux.org/api/task/misconflict/" + task)
if err != nil {
return []byte{}, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return []byte{}, err
}
return body, nil
}
func getConflicts(unmData interface{}) (map[string][]string, error) {
result := make(map[string][]string)
confilcts, ok := unmData.(map[string]interface{})["conflicts"]
if !ok {
return result, errors.New(
"Can't convert umarshal data to map[string]interface{}")
}
for _, rowConflict := range confilcts.([]interface{}) {
err := processeConflict(result, rowConflict)
if err != nil {
return result, err
}
}
return result, nil
}
func processeConflict(
result map[string][]string, rowConflict interface{}) error {
conflict, ok := rowConflict.(map[string]interface{})
if !ok {
return errors.New(
"Can't processed conflict data")
}
inputPackage := conflict["input_package"].(string)
conflictPackage := conflict["conflict_package"].(string)
result[inputPackage] = append(result[inputPackage], conflictPackage)
return nil
}