github.com/pelicanplatform/pelican@v1.0.5/server_utils/server_utils.go (about)

     1  /***************************************************************
     2   *
     3   * Copyright (C) 2023, Pelican Project, Morgridge Institute for Research
     4   *
     5   * Licensed under the Apache License, Version 2.0 (the "License"); you
     6   * may not use this file except in compliance with the License.  You may
     7   * obtain a copy of the License at
     8   *
     9   *    http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   ***************************************************************/
    18  
    19  package server_utils
    20  
    21  import (
    22  	"net/url"
    23  
    24  	"github.com/pelicanplatform/pelican/param"
    25  	"github.com/pkg/errors"
    26  )
    27  
    28  // For calling from within the server. Returns the server's issuer URL/port
    29  func GetServerIssuerURL() (*url.URL, error) {
    30  	if param.Server_IssuerUrl.GetString() == "" {
    31  		return nil, errors.New("The server failed to determine its own issuer url. Something is wrong!")
    32  	}
    33  
    34  	issuerUrl, err := url.Parse(param.Server_IssuerUrl.GetString())
    35  	if err != nil {
    36  		return nil, errors.Wrapf(err, "The server's issuer URL is malformed: %s. Something is wrong!", param.Server_IssuerUrl.GetString())
    37  	}
    38  
    39  	return issuerUrl, nil
    40  }