| 
4 | 4 | 	"fmt"  | 
5 | 5 | 	"github.com/spf13/viper"  | 
6 | 6 | 	"os"  | 
 | 7 | +	"runtime"  | 
7 | 8 | )  | 
8 | 9 | 
 
  | 
9 | 10 | type Config interface {  | 
@@ -31,10 +32,31 @@ func NewConfig(fileName, filePath, fileType string) Config {  | 
31 | 32 | 	viper.AddConfigPath("$HOME")  | 
32 | 33 | 	viper.SetConfigName(fileName)  | 
33 | 34 | 	viper.SetConfigType(fileType)  | 
34 |  | -	ffp := fmt.Sprintf("%s/%s.%s", filePath, fileName, fileType)  | 
 | 35 | +	ffp := fullConfigPath(filePath, fileName, fileType)  | 
 | 36 | +	createConfigFileIfNonExistent(ffp)  | 
 | 37 | + | 
35 | 38 | 	return &config{fileName: fileName, filePath: filePath, fileType: fileType, fileFullPath: ffp}  | 
36 | 39 | }  | 
37 | 40 | 
 
  | 
 | 41 | +func fullConfigPath(filePath string, fileName string, fileType string) string {  | 
 | 42 | +	ffp := fmt.Sprintf("%s/%s.%s", filePath, fileName, fileType)  | 
 | 43 | +	if runtime.GOOS == "windows" {  | 
 | 44 | +		ffp = fmt.Sprintf("%s\\%s.%s", filePath, fileName, fileType)  | 
 | 45 | +	}  | 
 | 46 | +	return ffp  | 
 | 47 | +}  | 
 | 48 | + | 
 | 49 | +func createConfigFileIfNonExistent(ffp string) {  | 
 | 50 | +	if _, err := os.Stat(ffp); os.IsExist(err) {  | 
 | 51 | +		return  | 
 | 52 | +	}  | 
 | 53 | + | 
 | 54 | +	_, err := os.Create(ffp)  | 
 | 55 | +	if err != nil {  | 
 | 56 | +		panic(fmt.Sprintf("config file does not exists and wasn't able to create it: %s\n", err))  | 
 | 57 | +	}  | 
 | 58 | +}  | 
 | 59 | + | 
38 | 60 | func (c *config) GetApiUrl() string {  | 
39 | 61 | 	return c.Get("api.url")  | 
40 | 62 | }  | 
 | 
0 commit comments