@@ -11,30 +11,42 @@ import (
1111
1212type Config struct {
1313 Location string
14+ DBName string
1415 Port string
1516 InProduction bool
1617 TemplateCache map [string ]* template.Template
1718}
1819
19- func DefaultConfig () * Config {
20+ func DefaultConfig (dbPath , dbName string ) * Config {
2021 port := os .Getenv ("PORT" )
2122 if port == "" {
2223 port = "8080"
2324 }
24- homeDir , err := homedir .Dir ()
25- if err != nil {
26- log .Printf ("unable to find the home directory: %v" , err )
27- os .Exit (1 )
28- }
29- cfgLoc := filepath .Join (homeDir , ".astra" )
30- if err = os .MkdirAll (cfgLoc , os .ModeDir ); err != nil {
31- log .Printf ("unable to create the config folder at the location %s: %v" , cfgLoc , err )
32- os .Exit (1 )
33- }
3425 cfg := & Config {
35- Location : cfgLoc ,
36- Port : port ,
26+ DBName : dbName ,
27+ Port : port ,
28+ }
29+ if dbPath == "" {
30+ homeDir , err := homedir .Dir ()
31+ if err != nil {
32+ log .Printf ("unable to find the home directory: %v" , err )
33+ os .Exit (1 )
34+ }
35+ cfgLoc := filepath .Join (homeDir , ".astra" )
36+ if err = os .MkdirAll (cfgLoc , 0750 ); err != nil {
37+ log .Printf ("unable to create the config folder at the location %s: %v" , cfgLoc , err )
38+ os .Exit (1 )
39+ }
40+ cfg .Location = cfgLoc
41+
42+ } else {
43+ if err := os .MkdirAll (dbPath , 0750 ); err != nil {
44+ log .Printf ("unable to create the config folder at the location %s: %v" , dbPath , err )
45+ os .Exit (1 )
46+ }
47+ cfg .Location = dbPath
3748 }
49+ log .Printf ("Created and set the config location %s" , cfg .Location )
3850 cfg .InProduction = false
3951
4052 return cfg
0 commit comments