mirror of
https://github.com/bolkedebruin/rdpgw.git
synced 2025-07-31 23:06:09 +02:00
Clean up config handling
This commit is contained in:
parent
7e62f39579
commit
ba679b1266
2 changed files with 32 additions and 15 deletions
|
@ -1,5 +1,10 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
Server ServerConfig
|
Server ServerConfig
|
||||||
OpenId OpenIDConfig
|
OpenId OpenIDConfig
|
||||||
|
@ -34,3 +39,29 @@ type RDGCapsConfig struct {
|
||||||
DisablePnp bool
|
DisablePnp bool
|
||||||
DisableDrive bool
|
DisableDrive bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
viper.SetDefault("server.certFile", "server.pem")
|
||||||
|
viper.SetDefault("server.keyFile", "key.pem")
|
||||||
|
viper.SetDefault("server.port", 443)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Load(configFile string) Configuration {
|
||||||
|
var conf Configuration
|
||||||
|
|
||||||
|
viper.SetConfigName("rdpgw")
|
||||||
|
viper.SetConfigFile(configFile)
|
||||||
|
viper.AddConfigPath(".")
|
||||||
|
viper.SetEnvPrefix("RDPGW")
|
||||||
|
viper.AutomaticEnv()
|
||||||
|
|
||||||
|
if err := viper.ReadInConfig(); err != nil {
|
||||||
|
log.Printf("No config file found (%s). Using defaults", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := viper.Unmarshal(&conf); err != nil {
|
||||||
|
log.Fatalf("Cannot unmarshal the config file; %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return conf
|
||||||
|
}
|
16
main.go
16
main.go
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -37,20 +36,7 @@ var ctx context.Context
|
||||||
func main() {
|
func main() {
|
||||||
// get config
|
// get config
|
||||||
cmd.PersistentFlags().StringVarP(&configFile, "conf", "c", "rdpgw.yaml", "config file (json, yaml, ini)")
|
cmd.PersistentFlags().StringVarP(&configFile, "conf", "c", "rdpgw.yaml", "config file (json, yaml, ini)")
|
||||||
|
conf = config.Load(configFile)
|
||||||
viper.SetConfigName("rdpgw")
|
|
||||||
viper.SetConfigFile(configFile)
|
|
||||||
viper.AddConfigPath(".")
|
|
||||||
viper.SetEnvPrefix("RDPGW")
|
|
||||||
viper.AutomaticEnv()
|
|
||||||
|
|
||||||
if err := viper.ReadInConfig(); err != nil {
|
|
||||||
log.Printf("No config file found (%s). Using defaults", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := viper.Unmarshal(&conf); err != nil {
|
|
||||||
log.Fatalf("Cannot unmarshal the config file; %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// set oidc config
|
// set oidc config
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue