github.com/intel/goresctrl@v0.5.0/pkg/path/path.go (about)

     1  /*
     2  Copyright 2023 Intel Corporation
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package path
    18  
    19  import "path/filepath"
    20  
    21  // RootDir is a helper for handling system directory paths
    22  type RootDir string
    23  
    24  var prefix RootDir = "/"
    25  
    26  // Path returns a full path to a file under RootDir
    27  func (d RootDir) Path(elems ...string) string {
    28  	return filepath.Join(append([]string{string(d)}, elems...)...)
    29  }
    30  
    31  // SetPrefix sets the global path prefix to use for all system files.
    32  func SetPrefix(p string) { prefix = RootDir(p) }
    33  
    34  // Path returns a path to a file, prefixed with the global prefix.
    35  func Path(elems ...string) string { return prefix.Path(elems...) }