-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62672b7
commit 581410e
Showing
5 changed files
with
72 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/dreamvo/gilfoyle/config" | ||
"github.com/ghodss/yaml" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
// Register command | ||
rootCmd.AddCommand(configCmd) | ||
} | ||
|
||
var configCmd = &cobra.Command{ | ||
Use: "config", | ||
Short: "Print configuration", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
d, err := yaml.Marshal(config.GetConfig()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(string(d)) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,54 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/jinzhu/configor" | ||
) | ||
|
||
// Config defines the application's settings | ||
type Config struct { | ||
Services servicesConfig `yaml:"services"` | ||
Settings settingsConfig `yaml:"settings"` | ||
} | ||
|
||
type servicesConfig struct { | ||
IPFS ipfsConfig `yaml:"ipfs"` | ||
DB dbConfig `yaml:"db"` | ||
Redis redisConfig `yaml:"redis"` | ||
} | ||
|
||
type ipfsConfig struct { | ||
Gateway string `yaml:"gateway" default:"gateway.ipfs.io"` | ||
Gateway string `yaml:"gateway" default:"gateway.ipfs.io" env:"IPFS_GATEWAY"` | ||
} | ||
|
||
type dbConfig struct { | ||
Dialect string `yaml:"dialect"` | ||
Host string `yaml:"host"` | ||
Port string `yaml:"port"` | ||
User string `yaml:"user"` | ||
Password string `yaml:"password"` | ||
Database string `yaml:"database"` | ||
Dialect string `yaml:"dialect" default:"postgres" env:"DB_HOST"` | ||
Host string `yaml:"host" default:"localhost" env:"DB_HOST"` | ||
Port string `yaml:"port" default:"5432" env:"DB_PORT"` | ||
User string `yaml:"user" default:"postgres" env:"DB_USER"` | ||
Password string `yaml:"password" default:"secret" env:"DB_PASSWORD"` | ||
Database string `yaml:"database" default:"gilfoyle" env:"DB_NAME"` | ||
} | ||
|
||
type redisConfig struct { | ||
Host string `yaml:"host"` | ||
Port string `yaml:"port"` | ||
Password string `yaml:"password"` | ||
Host string `yaml:"host" default:"localhost" env:"REDIS_HOST"` | ||
Port string `yaml:"port" default:"6379" env:"REDIS_PORT"` | ||
Password string `yaml:"password" default:"" env:"REDIS_PASSWORD"` | ||
} | ||
|
||
type settingsConfig struct { | ||
MaxFileSize string `yaml:"maxFileSize" default:"50mb"` | ||
} | ||
|
||
// Config defines the application's settings | ||
type Config struct { | ||
Services servicesConfig `yaml:"services"` | ||
Settings settingsConfig `yaml:"settings"` | ||
} | ||
var c Config | ||
|
||
// NewConfig a new config object | ||
func NewConfig() *Config { | ||
c := new(Config) | ||
|
||
// set default values | ||
c.Services.DB.Dialect = "postgres" | ||
c.Services.DB.Database = "gilfoyle" | ||
c.Services.DB.Host = "localhost" | ||
c.Services.DB.Port = "5432" | ||
c.Services.DB.User = "postgres" | ||
c.Services.DB.Password = "secret" | ||
_ = configor.Load(&c) | ||
|
||
return c | ||
return &c | ||
} | ||
|
||
// ParseConfigFile creates a config object from file content | ||
func ParseConfigFile(filepath string) *Config { | ||
c := NewConfig() | ||
|
||
return c | ||
// GetConfig helps you to get configuration data | ||
func GetConfig() *Config { | ||
return &c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters