github.com/wrgl/wrgl@v0.14.0/pkg/conf/fs/path.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright © 2022 Wrangle Ltd
     3  
     4  package conffs
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  	"path/filepath"
    10  )
    11  
    12  func systemConfigPath() string {
    13  	if s := os.Getenv("WRGL_SYSTEM_CONFIG_DIR"); s != "" {
    14  		return filepath.Join(s, "config.yaml")
    15  	}
    16  	return "/usr/local/etc/wrgl/config.yaml"
    17  }
    18  
    19  func localPath(rootDir string) string {
    20  	return filepath.Join(rootDir, "config.yaml")
    21  }
    22  
    23  func (s *Store) path() (string, error) {
    24  	switch s.source {
    25  	case SystemSource:
    26  		return systemConfigPath(), nil
    27  	case GlobalSource:
    28  		return globalConfigPath()
    29  	case LocalSource:
    30  		return localPath(s.rootDir), nil
    31  	case FileSource:
    32  		return s.fp, nil
    33  	default:
    34  		return "", fmt.Errorf("unrecognized source: %v", s.source)
    35  	}
    36  }