utils.go 332 B

123456789101112131415161718192021
  1. package dpcore
  2. import (
  3. "net/url"
  4. )
  5. func replaceLocationHost(urlString string, newHost string, useTLS bool) (string, error) {
  6. u, err := url.Parse(urlString)
  7. if err != nil {
  8. return "", err
  9. }
  10. if useTLS {
  11. u.Scheme = "https"
  12. } else {
  13. u.Scheme = "http"
  14. }
  15. u.Host = newHost
  16. return u.String(), nil
  17. }