add conflicts_getter.go
This commit is contained in:
parent
16a4d30dbf
commit
05c0a4ebbc
53
conflicts_getter.go
Normal file
53
conflicts_getter.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user