package utils import ( "fmt" "io" "net/http" "strings" ) func GetPubKeyFromService(username, service string) ([]byte, error) { // TODO: Read custom services from config services := map[string][2]string{ "github" : [2]string{"https://github.com/", ".keys"}, "gitlab" : [2]string{"https://gitlab.com/", ".keys"}, "codeberg": [2]string{"https://codeberg.org", ".keys"}, } url := strings.TrimSuffix(services[service][0], "/") + "/" + username + services[service][1] resp, err := http.Get(url) if err != nil { return nil, fmt.Errorf("failed to fetch key from %s: %w", service, err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("%s returned status %d", service, resp.StatusCode) } body, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("failed to read response from %s: %w", service, err) } return body, nil }