Skip to content

Commit

Permalink
feat: init storage package and config
Browse files Browse the repository at this point in the history
  • Loading branch information
sundowndev committed Nov 11, 2020
1 parent 0962c5f commit 9e3ae1e
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ var cfgFile string

var rootCmd = &cobra.Command{
Use: "gilfoyle [COMMANDS] [OPTIONS]",
Short: "Video streaming API server",
Long: "Gilfoyle is a web application from the Dreamvo project that runs a self-hosted video streaming server.",
Short: "Cloud-native media streaming server",
Long: "Gilfoyle is a web application from the Dreamvo project that runs a self-hosted media streaming server.",
Example: "gilfoyle serve -p 8080 --config ./gilfoyle.yml",
}

Expand Down
44 changes: 38 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,55 @@ import (
"github.com/jinzhu/configor"
)

// StorageClass is a choice of storage backend
type StorageClass string

// Config defines the application's settings
type Config struct {
Services servicesConfig `yaml:"services" json:"services"`
Settings settingsConfig `yaml:"settings" json:"settings"`
Storage storageConfig `yaml:"storage" json:"storage"`
}

type servicesConfig struct {
IPFS ipfsConfig `yaml:"ipfs" json:"ipfs"`
DB dbConfig `yaml:"db" json:"db"`
Redis redisConfig `yaml:"redis" json:"redis"`
}

type settingsConfig struct {
ExposeSwaggerUI bool `yaml:"expose_swagger_ui" json:"expose_swagger_ui" default:"true"`
MaxFileSize string `yaml:"max_file_size" json:"max_file_size" default:"50Mi"`
}

type storageConfig struct {
Class StorageClass `yaml:"class" json:"class" default:"fs" env:"STORAGE_CLASS"`
CachePath string `yaml:"cache_path" json:"cache_path" default:"/tmp" env:"CACHE_PATH"`
Filesystem fileSystemConfig `yaml:"fs" json:"fs"`
S3 s3Config `yaml:"s3" json:"s3"`
GCS gcsConfig `yaml:"gcs" json:"gcs"`
IPFS ipfsConfig `yaml:"ipfs" json:"ipfs"`
}

type fileSystemConfig struct {
DataPath string `yaml:"data_path" json:"data_path" default:"/data" env:"FS_DATA_PATH"`
}

type s3Config struct {
Hostname string `yaml:"hostname" json:"hostname" default:"" env:"S3_HOSTNAME"`
Port string `yaml:"port" json:"port" default:"" env:"S3_PORT"`
AccessKeyId string `yaml:"access_key_id" json:"access_key_id" env:"S3_ACCESS_KEY_ID"`
SecretAccessKey string `yaml:"secret_access_key" json:"secret_access_key" env:"S3_SECRET_ACCESS_KEY"`
Region string `yaml:"region" json:"region" env:"S3_REGION"`
Bucket string `yaml:"bucket" json:"bucket" env:"S3_BUCKET"`
EnableSSL bool `yaml:"enable_ssl" json:"enable_ssl" default:"true" env:"S3_ENABLE_SSL"`
UsePathStyle bool `yaml:"use_path_style" json:"use_path_style" default:"false" env:"S3_ENABLE_PATH_STYLE"`
}

type gcsConfig struct {
CredentialsFile string `yaml:"credentials_file" json:"credentials_file" default:"" env:"GCS_CREDENTIALS_FILE"`
Bucket string `yaml:"bucket" json:"bucket" default:"" env:"GCS_BUCKET"`
}

type ipfsConfig struct {
Gateway string `yaml:"gateway" json:"gateway" default:"gateway.ipfs.io" env:"IPFS_GATEWAY"`
}
Expand All @@ -36,11 +73,6 @@ type redisConfig struct {
Password string `yaml:"password" json:"password" default:"" env:"REDIS_PASSWORD"`
}

type settingsConfig struct {
ExposeSwaggerUI bool `yaml:"expose_swagger_ui" json:"expose_swagger_ui" default:"true"`
MaxFileSize string `yaml:"max_file_size" json:"max_file_size" default:"50mb"`
}

var config Config

// New creates a new config object
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14
github.com/swaggo/gin-swagger v1.2.0
github.com/swaggo/swag v1.6.7
github.com/ulule/gostorages v0.2.3
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
golang.org/x/tools v0.0.0-20200811215021-48a8ffc5b207 // indirect
gopkg.in/yaml.v2 v2.3.0
Expand Down
Loading

0 comments on commit 9e3ae1e

Please sign in to comment.