enbas/internal/utilities/utilities.go

32 lines
607 B
Go

// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
//
// SPDX-License-Identifier: GPL-3.0-or-later
package utilities
import (
"errors"
"fmt"
"os/exec"
"regexp"
)
func GetFQDN(url string) string {
r := regexp.MustCompile(`http(s)?:\/\/`)
return r.ReplaceAllString(url, "")
}
func OpenMedia(viewer, path string) error {
if viewer == "" {
return errors.New("the image viewer is not specified")
}
command := exec.Command(viewer, path)
if err := command.Start(); err != nil {
return fmt.Errorf("received an error after starting the image viewer: %w", err)
}
return nil
}